From af081c614f0514d78a0e8e374386374c8844b4e1 Mon Sep 17 00:00:00 2001 From: CovertJaguar Date: Tue, 12 Aug 2014 05:13:09 -0700 Subject: [PATCH] Simplify some of the backpack code and "fix" the localization code so that it isn't prefixing "Woven" in a non-localization friendly way. This is only hack fix though, all the bags will lose the "Woven" prefix entirely until Forestry is converted to the vanilla localization api. --- api | 2 +- .../forestry/storage/BackpackDefinition.java | 5 +++ .../java/forestry/storage/BackpackHelper.java | 2 +- .../forestry/storage/items/ItemBackpack.java | 35 ++++++++++--------- .../storage/items/ItemNaturalistBackpack.java | 3 +- 5 files changed, 27 insertions(+), 20 deletions(-) diff --git a/api b/api index 960034e1e..529b28959 160000 --- a/api +++ b/api @@ -1 +1 @@ -Subproject commit 960034e1e62ba1e89f1c293cbb8240f22cc28f3b +Subproject commit 529b28959c6ee01674464838a4fe21626c5573f8 diff --git a/src/main/java/forestry/storage/BackpackDefinition.java b/src/main/java/forestry/storage/BackpackDefinition.java index e55dfe6a6..8fa87bfdb 100755 --- a/src/main/java/forestry/storage/BackpackDefinition.java +++ b/src/main/java/forestry/storage/BackpackDefinition.java @@ -48,6 +48,11 @@ public class BackpackDefinition implements IBackpackDefinition { return StringUtil.localize("storage.backpack." + name); } + @Override + public String getName(ItemStack backpack) { + return getName(); + } + @Override public int getPrimaryColour() { return primaryColor; diff --git a/src/main/java/forestry/storage/BackpackHelper.java b/src/main/java/forestry/storage/BackpackHelper.java index 6ebba77f3..6fdb5b07c 100755 --- a/src/main/java/forestry/storage/BackpackHelper.java +++ b/src/main/java/forestry/storage/BackpackHelper.java @@ -23,7 +23,7 @@ public class BackpackHelper implements IBackpackInterface { @Override public Item addBackpack(IBackpackDefinition definition, EnumBackpackType type) { BackpackManager.definitions.put(definition.getKey(), definition); - return new ItemBackpack(definition, type.ordinal() + 1); + return new ItemBackpack(definition, type); } } diff --git a/src/main/java/forestry/storage/items/ItemBackpack.java b/src/main/java/forestry/storage/items/ItemBackpack.java index ae7b6bf57..de106b9ea 100755 --- a/src/main/java/forestry/storage/items/ItemBackpack.java +++ b/src/main/java/forestry/storage/items/ItemBackpack.java @@ -43,16 +43,17 @@ import forestry.core.render.TextureManager; import forestry.core.utils.ItemInventory; import forestry.core.utils.StringUtil; import forestry.storage.BackpackMode; +import java.util.EnumSet; public class ItemBackpack extends ItemInventoried { IBackpackDefinition info; - byte type; + EnumBackpackType type; - public ItemBackpack(IBackpackDefinition info, int type) { + public ItemBackpack(IBackpackDefinition info, EnumBackpackType type) { super(); this.info = info; - this.type = (byte) type; + this.type = type; setMaxStackSize(1); } @@ -250,10 +251,11 @@ public class ItemBackpack extends ItemInventoried { @Override public String getItemStackDisplayName(ItemStack itemstack) { - if (type > 1) - return StringUtil.localize("storage.backpack.t2adj") + " " + info.getName(); - else + try { + return info.getName(itemstack); + } catch (Error er) { return info.getName(); + } } /* ICONS */ @@ -263,13 +265,14 @@ public class ItemBackpack extends ItemInventoried { @SideOnly(Side.CLIENT) @Override public void registerIcons(IIconRegister register) { - icons = new IIcon[EnumBackpackType.values().length][6]; + icons = new IIcon[2][6]; - for (int i = 0; i < EnumBackpackType.values().length; i++) { + for (EnumBackpackType t : EnumSet.of(EnumBackpackType.T1, EnumBackpackType.T2)) { + int i = t.ordinal() - 1; icons[i][0] = TextureManager.getInstance().registerTex( - register, "backpacks/" + EnumBackpackType.values()[i].toString().toLowerCase(Locale.ENGLISH) + ".cloth"); + register, "backpacks/" + t.toString().toLowerCase(Locale.ENGLISH) + ".cloth"); icons[i][1] = TextureManager.getInstance().registerTex( - register, "backpacks/" + EnumBackpackType.values()[i].toString().toLowerCase(Locale.ENGLISH) + ".outline"); + register, "backpacks/" + t.toString().toLowerCase(Locale.ENGLISH) + ".outline"); icons[i][2] = TextureManager.getInstance().registerTex(register, "backpacks/neutral"); icons[i][3] = TextureManager.getInstance().registerTex(register, "backpacks/locked"); icons[i][4] = TextureManager.getInstance().registerTex(register, "backpacks/receive"); @@ -303,9 +306,7 @@ public class ItemBackpack extends ItemInventoried { @Override public IIcon getIconFromDamageForRenderPass(int i, int j) { - int iconType = type; - if (type > 0) - iconType--; + int iconType = type.ordinal() - 1; if (j == 0) return icons[iconType][0]; @@ -322,13 +323,13 @@ public class ItemBackpack extends ItemInventoried { return icons[iconType][2]; } - public static int getSlotsForType(int type) { + public static int getSlotsForType(EnumBackpackType type) { switch (type) { - case 0: + case APIARIST: return Defaults.SLOTS_BACKPACK_APIARIST; - case 2: + case T2: return Defaults.SLOTS_BACKPACK_T2; - case 1: + case T1: default: return Defaults.SLOTS_BACKPACK_DEFAULT; } diff --git a/src/main/java/forestry/storage/items/ItemNaturalistBackpack.java b/src/main/java/forestry/storage/items/ItemNaturalistBackpack.java index 194e8f254..281e7a4d2 100755 --- a/src/main/java/forestry/storage/items/ItemNaturalistBackpack.java +++ b/src/main/java/forestry/storage/items/ItemNaturalistBackpack.java @@ -14,6 +14,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import forestry.api.core.ForestryAPI; +import forestry.api.storage.EnumBackpackType; import forestry.plugins.PluginApiculture; import forestry.plugins.PluginLepidopterology; import forestry.storage.BackpackDefinition; @@ -46,7 +47,7 @@ public class ItemNaturalistBackpack extends ItemBackpack { private final int guiId; public ItemNaturalistBackpack(int guiId, BackpackDefinition definition) { - super(definition, 0); + super(definition, EnumBackpackType.APIARIST); this.guiId = guiId; }