From 7356bf7c935bf10d2ad2e02466e612e5120abc7f Mon Sep 17 00:00:00 2001 From: Bernhard Bonigl Date: Mon, 1 Sep 2014 23:20:56 +0200 Subject: [PATCH] Refactor renaming --- .../tools/logic/ToolStationLogic.java | 59 +++++++++---------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/src/main/java/tconstruct/tools/logic/ToolStationLogic.java b/src/main/java/tconstruct/tools/logic/ToolStationLogic.java index 3606d0cc3e9..0e94ce87d85 100644 --- a/src/main/java/tconstruct/tools/logic/ToolStationLogic.java +++ b/src/main/java/tconstruct/tools/logic/ToolStationLogic.java @@ -113,42 +113,41 @@ public void setToolname (String name) protected ItemStack tryRenameTool(ItemStack output, String name) { - ItemStack temp = inventory[1].copy(); + ItemStack temp; if (output != null) temp = output; + else + temp = inventory[1].copy(); - if (temp != null) - { - NBTTagCompound tags = temp.getTagCompound(); - if (tags == null) - { - tags = new NBTTagCompound(); - temp.setTagCompound(tags); - } + if (temp == null) + return null; // output as well as inventory is null :( - 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; - } - } + NBTTagCompound tags = temp.getTagCompound(); + if (tags == null) + { + tags = new NBTTagCompound(); + temp.setTagCompound(tags); } + NBTTagCompound display = null; + if (!(tags.hasKey("display"))) + display = new NBTTagCompound(); + else if(tags.getCompoundTag("display").hasKey("Name")) + display = tags.getCompoundTag("display"); + + if(display == null) + return output; + if(display.hasKey("Name") && !display.getString("Name").equals("\u00A7f" + ToolBuilder.defaultToolName(temp))) + // no default name anymore + return output; + + String dName = temp.getItem() instanceof IModifyable ? "\u00A7f" + name : name; + display.setString("Name", dName); + tags.setTag("display", display); + temp.setRepairCost(2); + output = temp; + + return output; }