From 03968731d920a79725812d2bf021ca7d1b67769e Mon Sep 17 00:00:00 2001 From: "Nikolay S." Date: Tue, 3 Feb 2026 08:17:41 -0600 Subject: [PATCH] Clean up Tool Station GUI code (#249) --- .../tconstruct/library/tools/ToolCore.java | 8 +- .../tconstruct/tools/ToolProxyClient.java | 7 +- .../tconstruct/tools/gui/ToolForgeGui.java | 40 +----- .../tconstruct/tools/gui/ToolStationGui.java | 121 +++++++----------- .../tools/items/CreativeModifier.java | 16 +-- .../tconstruct/weaponry/items/Boneana.java | 7 +- .../resources/assets/tinker/lang/en_US.lang | 29 +---- 7 files changed, 65 insertions(+), 163 deletions(-) diff --git a/src/main/java/tconstruct/library/tools/ToolCore.java b/src/main/java/tconstruct/library/tools/ToolCore.java index d89e9860..e1836da0 100644 --- a/src/main/java/tconstruct/library/tools/ToolCore.java +++ b/src/main/java/tconstruct/library/tools/ToolCore.java @@ -111,8 +111,12 @@ public abstract class ToolCore extends Item implements IEnergyContainerItem, IEq return this.getClass().getSimpleName(); } + public String getUnlocalizedToolName() { + return "tool." + this.getToolName().toLowerCase(); + } + public String getLocalizedToolName() { - return StatCollector.translateToLocal("tool." + getToolName().toLowerCase()); + return StatCollector.translateToLocal(this.getUnlocalizedToolName()); } /* Rendering */ @@ -334,7 +338,7 @@ public abstract class ToolCore extends Item implements IEnergyContainerItem, IEq list.add(""); int attack = (int) (tags.getCompoundTag("InfiTool").getInteger("Attack") * this.getDamageModifier()); list.add( - EnumChatFormatting.BLUE.toString() + "+" + EnumChatFormatting.BLUE + "+" + attack + " " + StatCollector.translateToLocalFormatted("attribute.name.generic.attackDamage")); diff --git a/src/main/java/tconstruct/tools/ToolProxyClient.java b/src/main/java/tconstruct/tools/ToolProxyClient.java index f40b7f53..2d0aa7da 100644 --- a/src/main/java/tconstruct/tools/ToolProxyClient.java +++ b/src/main/java/tconstruct/tools/ToolProxyClient.java @@ -23,7 +23,6 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; -import net.minecraft.util.StatCollector; import net.minecraft.world.World; import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.client.event.sound.SoundLoadEvent; @@ -762,7 +761,7 @@ public class ToolProxyClient extends ToolProxyCommon { 0, new int[] { 0, 1, 2, 13 }, new int[] { 13, 13, 13, 13 }, - StatCollector.translateToLocal("gui.toolforge1"), + "gui.toolforge1", "gui.toolforge2"); // tier 1 tools @@ -774,7 +773,7 @@ public class ToolProxyClient extends ToolProxyCommon { itemIconsT1[i][2], iconCoordsT1[i * 2], iconCoordsT1[i * 2 + 1], - tier1Tools[i].getLocalizedToolName(), + tier1Tools[i].getUnlocalizedToolName(), locString); } @@ -787,7 +786,7 @@ public class ToolProxyClient extends ToolProxyCommon { itemIconsT2[i][2], iconCoordsT2[i * 2], iconCoordsT2[i * 2 + 1], - tier2Tools[i].getLocalizedToolName(), + tier2Tools[i].getUnlocalizedToolName(), locString); } } diff --git a/src/main/java/tconstruct/tools/gui/ToolForgeGui.java b/src/main/java/tconstruct/tools/gui/ToolForgeGui.java index a2f77075..088a5f5d 100644 --- a/src/main/java/tconstruct/tools/gui/ToolForgeGui.java +++ b/src/main/java/tconstruct/tools/gui/ToolForgeGui.java @@ -1,8 +1,6 @@ package tconstruct.tools.gui; -import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.util.StatCollector; import net.minecraft.world.World; import cpw.mods.fml.relauncher.Side; @@ -14,18 +12,13 @@ import tconstruct.tools.logic.ToolForgeLogic; @SideOnly(Side.CLIENT) public class ToolForgeGui extends ToolStationGui { - int selectedButton; - public ToolForgeGui(InventoryPlayer inventoryplayer, ToolForgeLogic stationlogic, World world, int x, int y, int z) { super(inventoryplayer, stationlogic, world, x, y, z); } @Override - public void initGui() { - super.initGui(); - - this.buttonList.clear(); + protected void createToolButtons() { ToolGuiElement repair = TConstructClientRegistry.toolButtons.get(0); GuiButtonTool repairButton = new GuiButtonTool( 0, @@ -70,40 +63,13 @@ public class ToolForgeGui extends ToolStationGui { } @Override - protected void actionPerformed(GuiButton button) { - GuiButtonTool b = (GuiButtonTool) button; - ((GuiButton) this.buttonList.get(selectedButton)).enabled = true; - selectedButton = button.id; - button.enabled = false; - - setSlotType(b.element.slotType); - iconX = b.element.iconsX; - iconY = b.element.iconsY; - title = "\u00A7n" + b.element.title; - body = StatCollector.translateToLocal(b.element.body); - if (body != null) { - int i; - // for some really weird reason replaceAll doesn't find "\\n", but indexOf does. We have to replace - // manually. - while ((i = body.indexOf("\\n")) >= 0) { - body = body.substring(0, i) + '\n' + body.substring(i + 2); - } - } - } - - @Override - void resetGui() { - this.text.setText(""); - selectedButton = 0; - setSlotType(0); + protected void setIconUVs() { iconX = new int[] { 0, 1, 2, 13 }; iconY = new int[] { 13, 13, 13, 13 }; - title = "\u00A7n" + StatCollector.translateToLocal("gui.toolforge1"); - body = StatCollector.translateToLocal("gui.toolforge2"); } @Override - void setSlotType(int type) { + protected void setSlotType(int type) { switch (type) { case 0: slotX = new int[] { 56, 38, 38, 14 }; // Repair diff --git a/src/main/java/tconstruct/tools/gui/ToolStationGui.java b/src/main/java/tconstruct/tools/gui/ToolStationGui.java index 0d07c762..b3145527 100644 --- a/src/main/java/tconstruct/tools/gui/ToolStationGui.java +++ b/src/main/java/tconstruct/tools/gui/ToolStationGui.java @@ -8,6 +8,7 @@ import net.minecraft.client.gui.GuiTextField; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; import net.minecraft.world.World; @@ -35,10 +36,8 @@ public class ToolStationGui extends GuiContainer implements INEIGuiHandler { public ToolStationLogic logic; public ToolStationContainer toolSlots; public GuiTextField text; - public String toolName; - public int guiType; + public int selectedButton; public int[] slotX, slotY, iconX, iconY; - public boolean active; public String title, body = ""; public ToolStationGui(InventoryPlayer inventoryplayer, ToolStationLogic stationlogic, World world, int x, int y, @@ -46,38 +45,23 @@ public class ToolStationGui extends GuiContainer implements INEIGuiHandler { super(stationlogic.getGuiContainer(inventoryplayer, world, x, y, z)); this.logic = stationlogic; toolSlots = (ToolStationContainer) inventorySlots; - text = new GuiTextField(this.fontRendererObj, 83, 8, 30, 12); - this.text.setMaxStringLength(40); - this.text.setEnableBackgroundDrawing(false); - this.text.setVisible(true); - this.text.setCanLoseFocus(false); - this.text.setFocused(true); - this.text.setTextColor(0xffffff); - toolName = ""; - resetGui(); + selectedButton = 0; + setSlotType(0); + setIconUVs(); + title = EnumChatFormatting.UNDERLINE + StatCollector.translateToLocal("gui.toolforge1"); + body = StatCollector.translateToLocal("gui.toolforge2"); Keyboard.enableRepeatEvents(true); } @Override protected void mouseClicked(int mouseX, int mouseY, int mouseButton) { super.mouseClicked(mouseX, mouseY, mouseButton); - if (mouseButton == 0) { - int gLeft = this.guiLeft + 68 + 110; - int gTop = this.guiTop + 6; - int gwidth = 102; - int gheight = 12; - active = mouseX > gLeft && mouseX < gLeft + gwidth && mouseY > gTop && mouseY < gTop + gheight; - } + this.text.mouseClicked(mouseX - this.guiLeft, mouseY - this.guiTop, mouseButton); } - void resetGui() { - this.text.setText(""); - guiType = 0; - setSlotType(0); + protected void setIconUVs() { iconX = new int[] { 0, 1, 2 }; iconY = new int[] { 13, 13, 13 }; - title = "\u00A7n" + StatCollector.translateToLocal("gui.toolforge1"); - body = StatCollector.translateToLocal("gui.toolforge2"); } @Override @@ -86,21 +70,22 @@ public class ToolStationGui extends GuiContainer implements INEIGuiHandler { this.xSize = 176 + 110; this.guiLeft = (this.width - 176) / 2 - 110; - this.buttonList.clear(); - ToolGuiElement repair = TConstructClientRegistry.toolButtons.get(0); - GuiButtonTool repairButton = new GuiButtonTool( - 0, - this.guiLeft, - this.guiTop, - repair.buttonIconX, - repair.buttonIconY, - repair.domain, - repair.texture, - repair); // Repair - repairButton.enabled = false; - this.buttonList.add(repairButton); + if (this.text == null) { + this.text = new GuiTextField(this.fontRendererObj, 70 + 110, 8, 102, 12); + this.text.setMaxStringLength(40); + this.text.setEnableBackgroundDrawing(false); + this.text.setVisible(true); + this.text.setCanLoseFocus(true); + this.text.setFocused(false); + this.text.setTextColor(0xffffff); + } - for (int iter = 1; iter < TConstructClientRegistry.toolButtons.size(); iter++) { + this.buttonList.clear(); + createToolButtons(); + } + + protected void createToolButtons() { + for (int iter = 0; iter < TConstructClientRegistry.toolButtons.size(); iter++) { ToolGuiElement element = TConstructClientRegistry.toolButtons.get(iter); GuiButtonTool button = new GuiButtonTool( iter, @@ -113,31 +98,24 @@ public class ToolStationGui extends GuiContainer implements INEIGuiHandler { element); this.buttonList.add(button); } + this.buttonList.get(0).enabled = false; } @Override protected void actionPerformed(GuiButton button) { - ((GuiButton) this.buttonList.get(guiType)).enabled = true; - guiType = button.id; + this.buttonList.get(selectedButton).enabled = true; + selectedButton = button.id; button.enabled = false; - ToolGuiElement element = TConstructClientRegistry.toolButtons.get(guiType); + ToolGuiElement element = ((GuiButtonTool) button).element; setSlotType(element.slotType); iconX = element.iconsX; iconY = element.iconsY; - title = "\u00A7n" + element.title; - body = StatCollector.translateToLocal(element.body); - if (body != null) { - int i; - // for some really weird reason replaceAll doesn't find "\\n", but indexOf does. We have to replace - // manually. - while ((i = body.indexOf("\\n")) >= 0) { - body = body.substring(0, i) + '\n' + body.substring(i + 2); - } - } + title = "§n" + StatCollector.translateToLocal(element.title); + body = StatCollector.translateToLocal(element.body).replaceAll("\\\\n", "\n"); } - void setSlotType(int type) { + protected void setSlotType(int type) { switch (type) { case 0: slotX = new int[] { 56, 38, 38 }; // Repair @@ -177,10 +155,13 @@ public class ToolStationGui extends GuiContainer implements INEIGuiHandler { this.fontRendererObj.drawString(StatCollector.translateToLocal(logic.getInvName()), 116, 8, 0x000000); this.fontRendererObj .drawString(StatCollector.translateToLocal("container.inventory"), 118, this.ySize - 96 + 2, 0x000000); - this.fontRendererObj.drawString(toolName + "_", 180, 8, 0xffffff); + this.text.drawTextBox(); - if (logic.isStackInSlot(0)) ToolStationGuiHelper.drawToolStats(logic.getStackInSlot(0), 294, 0); - else drawToolInformation(); + if (logic.isStackInSlot(0)) { + ToolStationGuiHelper.drawToolStats(logic.getStackInSlot(0), 294, 0); + } else { + drawToolInformation(); + } } protected void drawToolInformation() { @@ -203,7 +184,7 @@ public class ToolStationGui extends GuiContainer implements INEIGuiHandler { final int cornerX = this.guiLeft + 110; this.drawTexturedModalRect(cornerX, this.guiTop, 0, 0, 176, this.ySize); - if (active) { + if (this.text.isFocused()) { this.drawTexturedModalRect(cornerX + 62, this.guiTop, 0, this.ySize, 112, 22); } @@ -231,39 +212,23 @@ public class ToolStationGui extends GuiContainer implements INEIGuiHandler { } @Override - protected void keyTyped(char par1, int keyCode) { - if (keyCode == 1 || (!active && keyCode == this.mc.gameSettings.keyBindInventory.getKeyCode())) { + protected void keyTyped(char typedChar, int keyCode) { + if (keyCode == 1 || (!this.text.isFocused() && keyCode == this.mc.gameSettings.keyBindInventory.getKeyCode())) { logic.setToolname(""); updateServer(""); Keyboard.enableRepeatEvents(false); this.mc.thePlayer.closeScreen(); - } else if (active) { - text.textboxKeyTyped(par1, keyCode); - toolName = text.getText().trim(); + } else if (text.textboxKeyTyped(typedChar, keyCode)) { + final String toolName = text.getText().trim(); logic.setToolname(toolName); updateServer(toolName); } } - void updateServer(String name) { - /* - * ByteArrayOutputStream bos = new ByteArrayOutputStream(8); DataOutputStream outputStream = new - * DataOutputStream(bos); try { outputStream.writeByte(1); - * outputStream.writeInt(logic.getWorld().provider.dimensionId); outputStream.writeInt(logic.xCoord); - * outputStream.writeInt(logic.yCoord); outputStream.writeInt(logic.zCoord); outputStream.writeUTF(name); } - * catch (Exception ex) { ex.printStackTrace(); } Packet250CustomPayload packet = new Packet250CustomPayload(); - * packet.channel = "TConstruct"; packet.data = bos.toByteArray(); packet.length = bos.size(); - * PacketDispatcher.sendPacketToServer(packet); - */ - + private void updateServer(String name) { TConstruct.packetPipeline.sendToServer(new ToolStationPacket(logic.xCoord, logic.yCoord, logic.zCoord, name)); } - /* - * protected void mouseClicked(int par1, int par2, int par3) { super.mouseClicked(par1, par2, par3); - * text.mouseClicked(par1, par2, par3); } - */ - @Override public VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility) { currentVisibility.showWidgets = width - xSize >= 107; diff --git a/src/main/java/tconstruct/tools/items/CreativeModifier.java b/src/main/java/tconstruct/tools/items/CreativeModifier.java index 35384a9b..f1756219 100644 --- a/src/main/java/tconstruct/tools/items/CreativeModifier.java +++ b/src/main/java/tconstruct/tools/items/CreativeModifier.java @@ -24,41 +24,41 @@ public class CreativeModifier extends Item { this.setCreativeTab(TConstructRegistry.materialTab); } - @SideOnly(Side.CLIENT) /** * returns a list of items with the same ID, but different meta (eg: dye returns 16 items) */ @Override - public void getSubItems(Item par1, CreativeTabs par2CreativeTabs, List par3List) { - par3List.add(new ItemStack(par1, 1, 0)); + @SideOnly(Side.CLIENT) + public void getSubItems(Item item1, CreativeTabs creativeTabs, List list) { + list.add(new ItemStack(item1, 1, 0)); for (ToolRecipe recipe : ToolBuilder.instance.combos) { ToolCore tool = recipe.getType(); - ItemStack item = new ItemStack(par1, 1, 0); + ItemStack item = new ItemStack(item1, 1, 0); NBTTagCompound compound = new NBTTagCompound(); compound.setString("TargetLock", tool.getToolName()); item.setTagCompound(compound); - par3List.add(item); + list.add(item); } } - @SideOnly(Side.CLIENT) @Override + @SideOnly(Side.CLIENT) public void registerIcons(IIconRegister iconRegister) { this.itemIcon = iconRegister.registerIcon("tinker:skull_char_gold"); } @Override @SideOnly(Side.CLIENT) - public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) { + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean adv) { list.add( StatCollector.translateToLocal("modifier.tooltip.Main") + " " + StatCollector.translateToLocal("modifier.tooltip.Creative")); if (stack.hasTagCompound()) { String targetLock; targetLock = stack.getTagCompound().getString("TargetLock"); - targetLock = StatCollector.translateToLocal("infitool." + targetLock.toLowerCase()); + targetLock = StatCollector.translateToLocal("tool." + targetLock.toLowerCase()); list.add(StatCollector.translateToLocal("creativeModLock.tooltip") + targetLock); } } diff --git a/src/main/java/tconstruct/weaponry/items/Boneana.java b/src/main/java/tconstruct/weaponry/items/Boneana.java index cc3a1002..b6f98606 100644 --- a/src/main/java/tconstruct/weaponry/items/Boneana.java +++ b/src/main/java/tconstruct/weaponry/items/Boneana.java @@ -38,12 +38,7 @@ public class Boneana extends Broadsword { } @Override - public String getLocalizedToolName() { - return "Bonæna"; - } - - @Override - public void getSubItems(Item id, CreativeTabs tab, List list) { + public void getSubItems(Item id, CreativeTabs tab, List list) { // you are not welcome here >:C } } diff --git a/src/main/resources/assets/tinker/lang/en_US.lang b/src/main/resources/assets/tinker/lang/en_US.lang index e54fe53e..97f5328c 100644 --- a/src/main/resources/assets/tinker/lang/en_US.lang +++ b/src/main/resources/assets/tinker/lang/en_US.lang @@ -187,34 +187,6 @@ item.InfiTool.Shortbow.name=Shortbow item.InfiTool.Arrow.name=Arrow item.InfiTool.Mattock.name=Mattock -infitool.pickaxe=Pickaxe -infitool.shovel=Shovel -infitool.hatchet=Hatchet -infitool.broadsword=Broadsword -infitool.longsword=Longsword -infitool.rapier=Rapier -infitool.fryingpan=Frying Pan -infitool.battlesign=Battlesign -infitool.dagger=Dagger -infitool.chisel=Chisel -infitool.scythe=Scythe -infitool.lumberaxe=Lumber Axe -infitool.cleaver=Cleaver -infitool.excavator=Excavator -infitool.hammer=Hammer -infitool.battleaxe=Battleaxe -infitool.cutlass=Cutlass -infitool.arrow=Arrow -infitool.mattock=Mattock -infitool.shortbow=Shortbow -infitool.longbow=Longbow -infitool.crossbow=Crossbow -infitool.arrowammo=Arrows -infitool.boltammo=Bolts -infitool.shuriken=Shuriken -infitool.throwingknife=Throwing Knife -infitool.javelin=Javelin - item.tconstruct.PotionLauncher.name=Potion Launcher item.tool.randomarrow=Random Streamer @@ -1049,6 +1021,7 @@ tool.boltammo=Bolts tool.shuriken=Shuriken tool.throwingknife=Throwing Knife tool.javelin=Javelin +tool.boneana=Bonæna # Customization of default tool names based on tool and material #tool.shovel.wood=Wooden Shovel