From 8e5fa1118da17d4cae605c185a7ada4695fe8d66 Mon Sep 17 00:00:00 2001 From: Bernhard Bonigl Date: Mon, 1 Sep 2014 23:13:05 +0200 Subject: [PATCH] Change default tool names to the same as the creative tool names, and still allow renaming. Also unify it for station and forge. --- .../library/crafting/ToolBuilder.java | 24 ++++++- .../tools/logic/ToolForgeLogic.java | 27 +------- .../tools/logic/ToolStationLogic.java | 68 ++++++++++++------- 3 files changed, 66 insertions(+), 53 deletions(-) diff --git a/src/main/java/tconstruct/library/crafting/ToolBuilder.java b/src/main/java/tconstruct/library/crafting/ToolBuilder.java index 23632233232..1c83efb55d9 100644 --- a/src/main/java/tconstruct/library/crafting/ToolBuilder.java +++ b/src/main/java/tconstruct/library/crafting/ToolBuilder.java @@ -322,6 +322,12 @@ else if (item.durabilityTypeExtra() == 1) compound.setTag("display", new NBTTagCompound()); compound.getCompoundTag("display").setString("Name", "\u00A7f" + name); } + // set a nice default name + else + { + compound.setTag("display", new NBTTagCompound()); + compound.getCompoundTag("display").setString("Name", "\u00A7f" + defaultToolName(headMat, item)); + } ToolCraftEvent.NormalTool event = new ToolCraftEvent.NormalTool(item, compound, new ToolMaterial[] { headMat, handleMat, accessoryMat, extraMat }); MinecraftForge.EVENT_BUS.post(event); @@ -424,7 +430,23 @@ float buildShoddy (ToolMaterial headMat, ToolMaterial handleMat, ToolMaterial ac } return (sHead + sHandle) / 2f; } - + + public static String defaultToolName(ItemStack stack) + { + if(!stack.hasTagCompound() || !stack.getTagCompound().hasKey("InfiTool")) + return null; + if(!(stack.getItem() instanceof ToolCore)) + return null; + + int mat = stack.getTagCompound().getCompoundTag("InfiTool").getInteger("Head"); + return defaultToolName(TConstructRegistry.getMaterial(mat), (ToolCore) stack.getItem()); + } + + public static String defaultToolName(ToolMaterial headMat, ToolCore tool) + { + return String.format("%s %s", headMat.prefixName(), tool.getToolName()); + } + //Passthrough for now @Deprecated public static void registerToolMod(ItemModifier mod) diff --git a/src/main/java/tconstruct/tools/logic/ToolForgeLogic.java b/src/main/java/tconstruct/tools/logic/ToolForgeLogic.java index 062d2cc24fc..6388445f9c8 100644 --- a/src/main/java/tconstruct/tools/logic/ToolForgeLogic.java +++ b/src/main/java/tconstruct/tools/logic/ToolForgeLogic.java @@ -69,32 +69,7 @@ else if (tool != null) } } if (!name.equals("")) //Name item - { - ItemStack temp = inventory[1].copy(); - if (output != null) - temp = output; - - if (temp != null) - { - NBTTagCompound tags = temp.getTagCompound(); - if (tags == null) - { - tags = new NBTTagCompound(); - temp.setTagCompound(tags); - } - - if (!(tags.hasKey("display"))) - { - NBTTagCompound display = new NBTTagCompound(); - String dName = temp.getItem() instanceof IModifyable ? "\u00A7f" + name : name; - display.setString("Name", dName); - tags.setTag("display", display); - temp.setRepairCost(2); - output = temp; - } - } - - } + output = tryRenameTool(output, name); } inventory[0] = output; } diff --git a/src/main/java/tconstruct/tools/logic/ToolStationLogic.java b/src/main/java/tconstruct/tools/logic/ToolStationLogic.java index b61ae279931..3606d0cc3e9 100644 --- a/src/main/java/tconstruct/tools/logic/ToolStationLogic.java +++ b/src/main/java/tconstruct/tools/logic/ToolStationLogic.java @@ -100,32 +100,7 @@ else if (tool != null) } } if (!name.equals("")) //Name item - { - ItemStack temp = inventory[1].copy(); - if (output != null) - temp = output; - - if (temp != null) - { - NBTTagCompound tags = temp.getTagCompound(); - if (tags == null) - { - tags = new NBTTagCompound(); - temp.setTagCompound(tags); - } - - if (!(tags.hasKey("display"))) - { - NBTTagCompound display = new NBTTagCompound(); - String dName = temp.getItem() instanceof IModifyable ? "\u00A7f" + name : name; - display.setString("Name", dName); - tags.setTag("display", display); - temp.setRepairCost(2); - output = temp; - } - } - - } + output = tryRenameTool(output, name); } inventory[0] = output; } @@ -136,6 +111,47 @@ public void setToolname (String name) buildTool(name); } + protected ItemStack tryRenameTool(ItemStack output, String name) + { + ItemStack temp = inventory[1].copy(); + if (output != null) + temp = output; + + if (temp != null) + { + NBTTagCompound tags = temp.getTagCompound(); + if (tags == null) + { + tags = new NBTTagCompound(); + temp.setTagCompound(tags); + } + + if (!(tags.hasKey("display"))) + { + NBTTagCompound display = new NBTTagCompound(); + String dName = temp.getItem() instanceof IModifyable ? "\u00A7f" + name : name; + display.setString("Name", dName); + tags.setTag("display", display); + temp.setRepairCost(2); + output = temp; + } + else if(tags.getCompoundTag("display").hasKey("Name")) + { + NBTTagCompound display = tags.getCompoundTag("display"); + if(display.getString("Name").equals("\u00A7f" + ToolBuilder.defaultToolName(temp))) + { + String dName = temp.getItem() instanceof IModifyable ? "\u00A7f" + name : name; + display.setString("Name", dName); + tags.setTag("display", display); + temp.setRepairCost(2); + output = temp; + } + } + } + + return output; + } + @Override public boolean canUpdate () {