Skip to content

Commit

Permalink
Tooltips and adjustments to some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Direwolf20-MC committed Feb 21, 2024
1 parent 9531cbb commit cf08a46
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.20.4 2024-02-18T23:04:46.408664 Languages: en_us for mod: justdirethings
64366f276278230e67d54b4ca507af0387bcf4ff assets/justdirethings/lang/en_us.json
// 1.20.4 2024-02-20T22:31:05.5426089 Languages: en_us for mod: justdirethings
6c01466ba2bdafc0f7162501d5923941c80bdd09 assets/justdirethings/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// 1.20.4 2024-02-18T21:20:13.5042139 Recipes
// 1.20.4 2024-02-20T21:30:42.6799203 Recipes
08a464b9106de5bf0e3d81194dc205ed42ef7db4 data/justdirethings/advancements/recipes/misc/fuel_canister.json
591f2dd8d997ccead841061e70aedc4a4984a60d data/justdirethings/advancements/recipes/misc/pocket_generator.json
be43fb76c8ff5e0964f378abece4cf4d77ecd06e data/justdirethings/recipes/fuel_canister.json
5b4bd1dbd73529cb2521bec1dbc1f1786fb47281 data/justdirethings/recipes/pocket_generator.json
f3525c90d81a757a6c44f0b1b15164ea62867e29 data/justdirethings/recipes/pocket_generator.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
"justdirethings.fuelcanisteramtstack": "Stack Cook time (ticks): %d",
"justdirethings.fuelcanisteritemsamt": "Fuel Amount: %f",
"justdirethings.fuelcanisteritemsamtstack": "Stack Fuel Amount: %f",
"justdirethings.pocketgeneratorburntime": "Burn Time: %f / %f",
"justdirethings.pocketgeneratorfuelstack": "Fuel: %f %s",
"justdirethings.pocketgeneratornofuel": "Fuel Empty",
"justdirethings.pocketgeneratorrf": "Forge Energy: %s / %s",
"justdirethings.screen.burn_time": "Burn time left: %ss",
"justdirethings.screen.energy": "Energy: %s/%s FE",
"justdirethings.screen.no_fuel": "Fuel source empty"
"justdirethings.screen.no_fuel": "Fuel source empty",
"justdirethings.shiftmoreinfo": "Hold Shift for details"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
"item": "minecraft:coal"
},
"f": {
"item": "justdirethings:fuel_canister"
"item": "minecraft:furnace"
},
"i": {
"tag": "forge:ingots/iron"
},
"r": {
"tag": "forge:dusts/redstone"
"item": "minecraft:redstone_block"
}
},
"pattern": [
"ici",
"rfr",
"ici"
"iri",
"cfc",
"iri"
],
"result": {
"item": "justdirethings:pocket_generator"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
import com.direwolf20.justdirethings.common.containers.PocketGeneratorContainer;
import com.direwolf20.justdirethings.setup.Config;
import com.direwolf20.justdirethings.setup.Registration;
import com.direwolf20.justdirethings.util.MagicHelpers;
import com.direwolf20.justdirethings.util.NBTUtils;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
Expand All @@ -13,6 +18,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.UseAnim;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
Expand All @@ -22,6 +28,8 @@
import net.neoforged.neoforge.items.ItemStackHandler;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public class PocketGenerator extends Item {
public static final String ENABLED = "enabled";
public static final String COUNTER = "counter";
Expand Down Expand Up @@ -117,6 +125,62 @@ private boolean initBurn(ItemStack itemStack) {
return false;
}

@Override
public void appendHoverText(ItemStack stack, @javax.annotation.Nullable Level level, List<Component> tooltip, TooltipFlag flagIn) {
super.appendHoverText(stack, level, tooltip, flagIn);

Minecraft mc = Minecraft.getInstance();

if (level == null || mc.player == null) {
return;
}
var energy = stack.getCapability(Capabilities.EnergyStorage.ITEM);
if (energy == null) {
return;
}
tooltip.add(Component.translatable("justdirethings.pocketgeneratorrf", MagicHelpers.tidyValue(energy.getEnergyStored()), MagicHelpers.tidyValue(energy.getMaxEnergyStored())).withStyle(ChatFormatting.GREEN));
boolean sneakPressed = Screen.hasShiftDown();
if (!sneakPressed) {
tooltip.add(Component.translatable("justdirethings.shiftmoreinfo").withStyle(ChatFormatting.GRAY));
} else {
tooltip.add(Component.translatable("justdirethings.pocketgeneratorburntime", NBTUtils.getIntValue(stack, COUNTER), NBTUtils.getIntValue(stack, MAXBURN)).withStyle(ChatFormatting.DARK_RED));
ItemStackHandler itemStackHandler = stack.getData(Registration.HANDLER);
ItemStack fuelStack = itemStackHandler.getStackInSlot(0);
if (fuelStack.isEmpty())
tooltip.add(Component.translatable("justdirethings.pocketgeneratornofuel").withStyle(ChatFormatting.RED));
else
tooltip.add(Component.translatable("justdirethings.pocketgeneratorfuelstack", fuelStack.getCount(), fuelStack.getItem().getName(fuelStack)).withStyle(ChatFormatting.DARK_AQUA));
}

}

@Override
public boolean isBarVisible(ItemStack stack) {
var energy = stack.getCapability(Capabilities.EnergyStorage.ITEM);
if (energy == null) {
return false;
}
return (energy.getEnergyStored() < energy.getMaxEnergyStored());
}

@Override
public int getBarWidth(ItemStack stack) {
var energy = stack.getCapability(Capabilities.EnergyStorage.ITEM);
if (energy == null) {
return 13;
}
return Math.min(13 * energy.getEnergyStored() / energy.getMaxEnergyStored(), 13);
}

@Override
public int getBarColor(ItemStack stack) {
var energy = stack.getCapability(Capabilities.EnergyStorage.ITEM);
if (energy == null) {
super.getBarColor(stack);
}
return Mth.hsvToRgb(Math.max(0.0F, (float) energy.getEnergyStored() / (float) energy.getMaxEnergyStored()) / 3.0F, 1.0F, 1.0F);
}

@Override
public boolean isFoil(ItemStack itemStack) {
return NBTUtils.getBoolean(itemStack, ENABLED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ protected void addTranslations() {
add(Registration.Pocket_Generator.get(), "Pocket Generator");

//Misc
add("justdirethings.shiftmoreinfo", "Hold Shift for details");
add("justdirethings.fuelcanisteramt", "Cook time (ticks): %d");
add("justdirethings.fuelcanisteramtstack", "Stack Cook time (ticks): %d");
add("justdirethings.fuelcanisteritemsamt", "Fuel Amount: %f");
add("justdirethings.fuelcanisteritemsamtstack", "Stack Fuel Amount: %f");
add("justdirethings.pocketgeneratorburntime", "Burn Time: %f / %f");
add("justdirethings.pocketgeneratorfuelstack", "Fuel: %f %s");
add("justdirethings.pocketgeneratornofuel", "Fuel Empty");
add("justdirethings.pocketgeneratorrf", "Forge Energy: %s / %s");

//Keys
//add("key.justdirethings.category", "Building Gadgets 2");
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/direwolf20/justdirethings/datagen/Recipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ protected void buildRecipes(RecipeOutput consumer) {
.unlockedBy("has_coal", InventoryChangeTrigger.TriggerInstance.hasItems(Items.COAL))
.save(consumer);
ShapedRecipeBuilder.shaped(RecipeCategory.MISC, Registration.Pocket_Generator.get())
.pattern("ici")
.pattern("rfr")
.pattern("ici")
.pattern("iri")
.pattern("cfc")
.pattern("iri")
.define('i', Tags.Items.INGOTS_IRON)
.define('c', Items.COAL)
.define('r', Tags.Items.DUSTS_REDSTONE)
.define('f', Registration.Fuel_Canister.get())
.define('r', Items.REDSTONE_BLOCK)
.define('f', Items.FURNACE)
.group("justdirethings")
.unlockedBy("has_fuel_canister", InventoryChangeTrigger.TriggerInstance.hasItems(Registration.Fuel_Canister.get()))
.save(consumer);
Expand Down

0 comments on commit cf08a46

Please sign in to comment.