Skip to content

Commit

Permalink
Refactor renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
bonii-xx committed Sep 1, 2014
1 parent 8e5fa11 commit 7356bf7
Showing 1 changed file with 29 additions and 30 deletions.
59 changes: 29 additions & 30 deletions src/main/java/tconstruct/tools/logic/ToolStationLogic.java
Expand Up @@ -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;
}

Expand Down

0 comments on commit 7356bf7

Please sign in to comment.