From 8ed0f1ecddc7cc0a6d78e6d19acead2622b3d923 Mon Sep 17 00:00:00 2001 From: pahimar Date: Thu, 2 Jan 2014 03:55:01 -0500 Subject: [PATCH] Some optimizing of Item code --- .../java/com/pahimar/ee3/item/IDyeable.java | 14 ++++++++ .../pahimar/ee3/item/ItemAlchemicalBag.java | 9 ++++-- .../pahimar/ee3/item/ItemAlchemicalDust.java | 12 ++++--- .../pahimar/ee3/item/ItemAlchemicalFuel.java | 16 ---------- .../ee3/item/ItemAlchemicalFuelBlock.java | 3 +- .../java/com/pahimar/ee3/item/ItemChalk.java | 4 +-- .../com/pahimar/ee3/item/ItemDiviningRod.java | 4 +-- .../java/com/pahimar/ee3/item/ItemEE.java | 32 +++++++++++++------ .../com/pahimar/ee3/item/ItemInertStone.java | 4 +-- .../com/pahimar/ee3/item/ItemMiniumShard.java | 4 +-- .../com/pahimar/ee3/item/ItemMiniumStone.java | 3 +- .../ee3/item/ItemMultiTextureBlockEE.java | 17 ---------- .../ee3/item/ItemPhilosophersStone.java | 3 +- .../java/com/pahimar/ee3/item/ModItems.java | 3 +- .../java/com/pahimar/ee3/lib/Reference.java | 1 - .../ee3/recipe/CalcinationManager.java | 3 +- 16 files changed, 62 insertions(+), 70 deletions(-) create mode 100644 src/main/java/com/pahimar/ee3/item/IDyeable.java delete mode 100644 src/main/java/com/pahimar/ee3/item/ItemMultiTextureBlockEE.java diff --git a/src/main/java/com/pahimar/ee3/item/IDyeable.java b/src/main/java/com/pahimar/ee3/item/IDyeable.java new file mode 100644 index 00000000..a6990650 --- /dev/null +++ b/src/main/java/com/pahimar/ee3/item/IDyeable.java @@ -0,0 +1,14 @@ +package com.pahimar.ee3.item; + +import net.minecraft.item.ItemStack; + +public interface IDyeable +{ + public abstract boolean hasColor(ItemStack itemStack); + + public abstract int getColor(ItemStack itemStack); + + public abstract void setColor(ItemStack itemStack, int color); + + public abstract void removeColor(ItemStack itemStack); +} diff --git a/src/main/java/com/pahimar/ee3/item/ItemAlchemicalBag.java b/src/main/java/com/pahimar/ee3/item/ItemAlchemicalBag.java index deabf8da..9046c174 100644 --- a/src/main/java/com/pahimar/ee3/item/ItemAlchemicalBag.java +++ b/src/main/java/com/pahimar/ee3/item/ItemAlchemicalBag.java @@ -22,7 +22,7 @@ import net.minecraft.world.World; * * @author pahimar */ -public class ItemAlchemicalBag extends ItemEE +public class ItemAlchemicalBag extends ItemEE implements IDyeable { private static final String[] ALCHEMICAL_BAG_ICONS = {"Open", "OpenDrawString", "Closed", "ClosedDrawString"}; @@ -32,8 +32,7 @@ public class ItemAlchemicalBag extends ItemEE public ItemAlchemicalBag(int id) { super(id); - this.setUnlocalizedName(Strings.RESOURCE_PREFIX + Strings.ALCHEMICAL_BAG_NAME); - this.setCreativeTab(EquivalentExchange3.tabsEE3); + this.setUnlocalizedName(Strings.ALCHEMICAL_BAG_NAME); } @Override @@ -123,16 +122,19 @@ public class ItemAlchemicalBag extends ItemEE } } + @Override public boolean hasColor(ItemStack itemStack) { return ItemHelper.hasColor(itemStack); } + @Override public int getColor(ItemStack itemStack) { return ItemHelper.getColor(itemStack); } + @Override public void setColor(ItemStack itemStack, int color) { if (itemStack != null) @@ -144,6 +146,7 @@ public class ItemAlchemicalBag extends ItemEE } } + @Override public void removeColor(ItemStack itemStack) { if (itemStack != null) diff --git a/src/main/java/com/pahimar/ee3/item/ItemAlchemicalDust.java b/src/main/java/com/pahimar/ee3/item/ItemAlchemicalDust.java index 30f1f780..ce8d04ca 100644 --- a/src/main/java/com/pahimar/ee3/item/ItemAlchemicalDust.java +++ b/src/main/java/com/pahimar/ee3/item/ItemAlchemicalDust.java @@ -1,6 +1,5 @@ package com.pahimar.ee3.item; -import com.pahimar.ee3.EquivalentExchange3; import com.pahimar.ee3.lib.Colours; import com.pahimar.ee3.lib.Strings; import cpw.mods.fml.relauncher.Side; @@ -26,8 +25,6 @@ public class ItemAlchemicalDust extends ItemEE { super(id); this.setHasSubtypes(true); - this.setUnlocalizedName(Strings.RESOURCE_PREFIX + Strings.ALCHEMICAL_DUST_NAME); - this.setCreativeTab(EquivalentExchange3.tabsEE3); maxStackSize = 64; } @@ -66,6 +63,12 @@ public class ItemAlchemicalDust extends ItemEE return Integer.parseInt(Colours.PURE_WHITE, 16); } + @Override + public String getUnlocalizedName() + { + return String.format("item.%s%s", Strings.RESOURCE_PREFIX, Strings.ALCHEMICAL_DUST_NAME); + } + @Override public String getUnlocalizedName(ItemStack itemStack) { @@ -122,8 +125,7 @@ public class ItemAlchemicalDust extends ItemEE } } - @Override - public List getSubTypes() + public static List getAlchemicalDusts() { List alchemicalDustStacks = new ArrayList(); diff --git a/src/main/java/com/pahimar/ee3/item/ItemAlchemicalFuel.java b/src/main/java/com/pahimar/ee3/item/ItemAlchemicalFuel.java index 1ac3b08a..dd66259f 100644 --- a/src/main/java/com/pahimar/ee3/item/ItemAlchemicalFuel.java +++ b/src/main/java/com/pahimar/ee3/item/ItemAlchemicalFuel.java @@ -1,6 +1,5 @@ package com.pahimar.ee3.item; -import com.pahimar.ee3.EquivalentExchange3; import com.pahimar.ee3.lib.Strings; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -10,7 +9,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.Icon; import net.minecraft.util.MathHelper; -import java.util.ArrayList; import java.util.List; public class ItemAlchemicalFuel extends ItemEE @@ -22,7 +20,6 @@ public class ItemAlchemicalFuel extends ItemEE { super(id); this.setHasSubtypes(true); - this.setCreativeTab(EquivalentExchange3.tabsEE3); this.maxStackSize = 64; } @@ -61,17 +58,4 @@ public class ItemAlchemicalFuel extends ItemEE list.add(new ItemStack(id, 1, meta)); } } - - @Override - public List getSubTypes() - { - List alchemicalFuelStacks = new ArrayList(); - - for (int meta = 0; meta < Strings.ALCHEMICAL_FUEL_SUBTYPE_NAMES.length; meta++) - { - alchemicalFuelStacks.add(new ItemStack(ModItems.alchemicalFuel, 1, meta)); - } - - return alchemicalFuelStacks; - } } diff --git a/src/main/java/com/pahimar/ee3/item/ItemAlchemicalFuelBlock.java b/src/main/java/com/pahimar/ee3/item/ItemAlchemicalFuelBlock.java index 7fc60391..7103b37f 100644 --- a/src/main/java/com/pahimar/ee3/item/ItemAlchemicalFuelBlock.java +++ b/src/main/java/com/pahimar/ee3/item/ItemAlchemicalFuelBlock.java @@ -2,8 +2,9 @@ package com.pahimar.ee3.item; import com.pahimar.ee3.block.ModBlocks; import com.pahimar.ee3.lib.Strings; +import net.minecraft.item.ItemMultiTextureTile; -public class ItemAlchemicalFuelBlock extends ItemMultiTextureBlockEE +public class ItemAlchemicalFuelBlock extends ItemMultiTextureTile { public ItemAlchemicalFuelBlock(int id) { diff --git a/src/main/java/com/pahimar/ee3/item/ItemChalk.java b/src/main/java/com/pahimar/ee3/item/ItemChalk.java index 10daba98..d2414cce 100644 --- a/src/main/java/com/pahimar/ee3/item/ItemChalk.java +++ b/src/main/java/com/pahimar/ee3/item/ItemChalk.java @@ -1,6 +1,5 @@ package com.pahimar.ee3.item; -import com.pahimar.ee3.EquivalentExchange3; import com.pahimar.ee3.lib.Strings; public class ItemChalk extends ItemEE @@ -8,8 +7,7 @@ public class ItemChalk extends ItemEE public ItemChalk(int id) { super(id); - this.setUnlocalizedName(Strings.RESOURCE_PREFIX + Strings.CHALK_NAME); - this.setCreativeTab(EquivalentExchange3.tabsEE3); + this.setUnlocalizedName(Strings.CHALK_NAME); this.maxStackSize = 64; } } diff --git a/src/main/java/com/pahimar/ee3/item/ItemDiviningRod.java b/src/main/java/com/pahimar/ee3/item/ItemDiviningRod.java index 5a9b5bc7..1e628cc7 100644 --- a/src/main/java/com/pahimar/ee3/item/ItemDiviningRod.java +++ b/src/main/java/com/pahimar/ee3/item/ItemDiviningRod.java @@ -1,6 +1,5 @@ package com.pahimar.ee3.item; -import com.pahimar.ee3.EquivalentExchange3; import com.pahimar.ee3.lib.Strings; public class ItemDiviningRod extends ItemEE @@ -9,7 +8,6 @@ public class ItemDiviningRod extends ItemEE { super(id); this.setHasSubtypes(true); - this.setUnlocalizedName(Strings.RESOURCE_PREFIX + Strings.DIVINING_ROD_NAME); - this.setCreativeTab(EquivalentExchange3.tabsEE3); + this.setUnlocalizedName(Strings.DIVINING_ROD_NAME); } } diff --git a/src/main/java/com/pahimar/ee3/item/ItemEE.java b/src/main/java/com/pahimar/ee3/item/ItemEE.java index 665e4c5a..116df43a 100644 --- a/src/main/java/com/pahimar/ee3/item/ItemEE.java +++ b/src/main/java/com/pahimar/ee3/item/ItemEE.java @@ -1,14 +1,13 @@ package com.pahimar.ee3.item; -import com.pahimar.ee3.lib.Reference; +import com.pahimar.ee3.EquivalentExchange3; +import com.pahimar.ee3.lib.Strings; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import java.util.List; - /** * Equivalent-Exchange-3 *

@@ -18,22 +17,37 @@ import java.util.List; */ public class ItemEE extends Item { + private static final int SHIFTED_ID_RANGE_CORRECTION = 256; + public ItemEE(int id) { - super(id - Reference.SHIFTED_ID_RANGE_CORRECTION); + super(id - SHIFTED_ID_RANGE_CORRECTION); + this.setCreativeTab(EquivalentExchange3.tabsEE3); maxStackSize = 1; setNoRepair(); } + @Override + public String getUnlocalizedName() + { + return String.format("item.%s%s", Strings.RESOURCE_PREFIX, getUnwrappedUnlocalizedName(super.getUnlocalizedName())); + } + + @Override + public String getUnlocalizedName(ItemStack itemStack) + { + return String.format("item.%s%s", Strings.RESOURCE_PREFIX, getUnwrappedUnlocalizedName(super.getUnlocalizedName())); + } + + protected String getUnwrappedUnlocalizedName(String unlocalizedName) + { + return unlocalizedName.substring(unlocalizedName.indexOf(".") + 1); + } + @Override @SideOnly(Side.CLIENT) public void registerIcons(IconRegister iconRegister) { itemIcon = iconRegister.registerIcon(this.getUnlocalizedName().substring(this.getUnlocalizedName().indexOf(".") + 1)); } - - public List getSubTypes() - { - return null; - } } diff --git a/src/main/java/com/pahimar/ee3/item/ItemInertStone.java b/src/main/java/com/pahimar/ee3/item/ItemInertStone.java index a029f7bf..fc201e99 100644 --- a/src/main/java/com/pahimar/ee3/item/ItemInertStone.java +++ b/src/main/java/com/pahimar/ee3/item/ItemInertStone.java @@ -1,6 +1,5 @@ package com.pahimar.ee3.item; -import com.pahimar.ee3.EquivalentExchange3; import com.pahimar.ee3.lib.Strings; /** @@ -15,7 +14,6 @@ public class ItemInertStone extends ItemEE public ItemInertStone(int id) { super(id); - this.setUnlocalizedName(Strings.RESOURCE_PREFIX + Strings.INERT_STONE_NAME); - this.setCreativeTab(EquivalentExchange3.tabsEE3); + this.setUnlocalizedName(Strings.INERT_STONE_NAME); } } diff --git a/src/main/java/com/pahimar/ee3/item/ItemMiniumShard.java b/src/main/java/com/pahimar/ee3/item/ItemMiniumShard.java index 540113fe..3665346e 100644 --- a/src/main/java/com/pahimar/ee3/item/ItemMiniumShard.java +++ b/src/main/java/com/pahimar/ee3/item/ItemMiniumShard.java @@ -1,6 +1,5 @@ package com.pahimar.ee3.item; -import com.pahimar.ee3.EquivalentExchange3; import com.pahimar.ee3.lib.Strings; /** @@ -15,8 +14,7 @@ public class ItemMiniumShard extends ItemEE public ItemMiniumShard(int id) { super(id); - this.setUnlocalizedName(Strings.RESOURCE_PREFIX + Strings.MINIUM_SHARD_NAME); - this.setCreativeTab(EquivalentExchange3.tabsEE3); + this.setUnlocalizedName(Strings.MINIUM_SHARD_NAME); maxStackSize = 64; } } diff --git a/src/main/java/com/pahimar/ee3/item/ItemMiniumStone.java b/src/main/java/com/pahimar/ee3/item/ItemMiniumStone.java index b376991d..0be5be37 100644 --- a/src/main/java/com/pahimar/ee3/item/ItemMiniumStone.java +++ b/src/main/java/com/pahimar/ee3/item/ItemMiniumStone.java @@ -25,8 +25,7 @@ public class ItemMiniumStone extends ItemEE implements ITransmutationStone, IKey public ItemMiniumStone(int id) { super(id); - this.setUnlocalizedName(Strings.RESOURCE_PREFIX + Strings.MINIUM_STONE_NAME); - this.setCreativeTab(EquivalentExchange3.tabsEE3); + this.setUnlocalizedName(Strings.MINIUM_STONE_NAME); this.setMaxDamage(ConfigurationSettings.MINIUM_STONE_MAX_DURABILITY - 1); } diff --git a/src/main/java/com/pahimar/ee3/item/ItemMultiTextureBlockEE.java b/src/main/java/com/pahimar/ee3/item/ItemMultiTextureBlockEE.java deleted file mode 100644 index c25216c9..00000000 --- a/src/main/java/com/pahimar/ee3/item/ItemMultiTextureBlockEE.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.pahimar.ee3.item; - -import com.pahimar.ee3.block.BlockEE; -import net.minecraft.item.ItemMultiTextureTile; - -public class ItemMultiTextureBlockEE extends ItemMultiTextureTile -{ - public ItemMultiTextureBlockEE(int id, BlockEE block, String[] unlocalizedNameArray) - { - super(id, block, unlocalizedNameArray); - } - - protected String getUnwrappedUnlocalizedName(String unlocalizedName) - { - return unlocalizedName.substring(unlocalizedName.indexOf(".") + 1); - } -} diff --git a/src/main/java/com/pahimar/ee3/item/ItemPhilosophersStone.java b/src/main/java/com/pahimar/ee3/item/ItemPhilosophersStone.java index 6e1fd7d3..5970e130 100644 --- a/src/main/java/com/pahimar/ee3/item/ItemPhilosophersStone.java +++ b/src/main/java/com/pahimar/ee3/item/ItemPhilosophersStone.java @@ -31,8 +31,7 @@ public class ItemPhilosophersStone extends ItemEE implements ITransmutationStone public ItemPhilosophersStone(int id) { super(id); - this.setUnlocalizedName(Strings.RESOURCE_PREFIX + Strings.PHILOSOPHERS_STONE_NAME); - this.setCreativeTab(EquivalentExchange3.tabsEE3); + this.setUnlocalizedName(Strings.PHILOSOPHERS_STONE_NAME); this.setMaxDamage(ConfigurationSettings.PHILOSOPHERS_STONE_MAX_DURABILITY - 1); maxChargeLevel = 3; } diff --git a/src/main/java/com/pahimar/ee3/item/ModItems.java b/src/main/java/com/pahimar/ee3/item/ModItems.java index 0d3918cb..331aec5e 100644 --- a/src/main/java/com/pahimar/ee3/item/ModItems.java +++ b/src/main/java/com/pahimar/ee3/item/ModItems.java @@ -3,6 +3,7 @@ package com.pahimar.ee3.item; import com.pahimar.ee3.lib.ItemIds; import com.pahimar.ee3.lib.Strings; import cpw.mods.fml.common.registry.GameRegistry; +import net.minecraft.item.ItemMultiTextureTile; /** * Equivalent-Exchange-3 @@ -24,7 +25,7 @@ public class ModItems public static ItemEE diviningRod; public static ItemEE alchemicalFuel; - public static ItemMultiTextureBlockEE alchemicalFuelBlock; + public static ItemMultiTextureTile alchemicalFuelBlock; public static void init() { diff --git a/src/main/java/com/pahimar/ee3/lib/Reference.java b/src/main/java/com/pahimar/ee3/lib/Reference.java index 694008d2..c99f7441 100644 --- a/src/main/java/com/pahimar/ee3/lib/Reference.java +++ b/src/main/java/com/pahimar/ee3/lib/Reference.java @@ -42,7 +42,6 @@ public class Reference public static final String DEPENDENCIES = "required-after:Forge@[9.10.1.849,)"; public static final String FINGERPRINT = "@FINGERPRINT@"; public static final int SECOND_IN_TICKS = 20; - public static final int SHIFTED_ID_RANGE_CORRECTION = 256; public static final String SERVER_PROXY_CLASS = "com.pahimar.ee3.proxy.ServerProxy"; public static final String CLIENT_PROXY_CLASS = "com.pahimar.ee3.proxy.ClientProxy"; public static final int VERSION_CHECK_ATTEMPTS = 3; diff --git a/src/main/java/com/pahimar/ee3/recipe/CalcinationManager.java b/src/main/java/com/pahimar/ee3/recipe/CalcinationManager.java index 6977cfd7..dc75b38b 100644 --- a/src/main/java/com/pahimar/ee3/recipe/CalcinationManager.java +++ b/src/main/java/com/pahimar/ee3/recipe/CalcinationManager.java @@ -3,6 +3,7 @@ package com.pahimar.ee3.recipe; import com.pahimar.ee3.emc.EmcRegistry; import com.pahimar.ee3.emc.EmcValue; import com.pahimar.ee3.helper.ItemHelper; +import com.pahimar.ee3.item.ItemAlchemicalDust; import com.pahimar.ee3.item.ModItems; import net.minecraft.item.ItemStack; @@ -25,7 +26,7 @@ public class CalcinationManager TreeMap sortedItems = new TreeMap(); - for (ItemStack dustStack : ModItems.alchemicalDust.getSubTypes()) + for (ItemStack dustStack : ItemAlchemicalDust.getAlchemicalDusts()) { // If the item to be calcined is an alchemical dust, return null (you cannot calcine what's already been calcined) if (ItemHelper.equals(itemStack, dustStack))