Some optimizing of Item code

This commit is contained in:
pahimar 2014-01-02 03:55:01 -05:00
parent 391cd2b03d
commit 8ed0f1ecdd
16 changed files with 62 additions and 70 deletions

View file

@ -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);
}

View file

@ -22,7 +22,7 @@ import net.minecraft.world.World;
* *
* @author pahimar * @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"}; private static final String[] ALCHEMICAL_BAG_ICONS = {"Open", "OpenDrawString", "Closed", "ClosedDrawString"};
@ -32,8 +32,7 @@ public class ItemAlchemicalBag extends ItemEE
public ItemAlchemicalBag(int id) public ItemAlchemicalBag(int id)
{ {
super(id); super(id);
this.setUnlocalizedName(Strings.RESOURCE_PREFIX + Strings.ALCHEMICAL_BAG_NAME); this.setUnlocalizedName(Strings.ALCHEMICAL_BAG_NAME);
this.setCreativeTab(EquivalentExchange3.tabsEE3);
} }
@Override @Override
@ -123,16 +122,19 @@ public class ItemAlchemicalBag extends ItemEE
} }
} }
@Override
public boolean hasColor(ItemStack itemStack) public boolean hasColor(ItemStack itemStack)
{ {
return ItemHelper.hasColor(itemStack); return ItemHelper.hasColor(itemStack);
} }
@Override
public int getColor(ItemStack itemStack) public int getColor(ItemStack itemStack)
{ {
return ItemHelper.getColor(itemStack); return ItemHelper.getColor(itemStack);
} }
@Override
public void setColor(ItemStack itemStack, int color) public void setColor(ItemStack itemStack, int color)
{ {
if (itemStack != null) if (itemStack != null)
@ -144,6 +146,7 @@ public class ItemAlchemicalBag extends ItemEE
} }
} }
@Override
public void removeColor(ItemStack itemStack) public void removeColor(ItemStack itemStack)
{ {
if (itemStack != null) if (itemStack != null)

View file

@ -1,6 +1,5 @@
package com.pahimar.ee3.item; package com.pahimar.ee3.item;
import com.pahimar.ee3.EquivalentExchange3;
import com.pahimar.ee3.lib.Colours; import com.pahimar.ee3.lib.Colours;
import com.pahimar.ee3.lib.Strings; import com.pahimar.ee3.lib.Strings;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
@ -26,8 +25,6 @@ public class ItemAlchemicalDust extends ItemEE
{ {
super(id); super(id);
this.setHasSubtypes(true); this.setHasSubtypes(true);
this.setUnlocalizedName(Strings.RESOURCE_PREFIX + Strings.ALCHEMICAL_DUST_NAME);
this.setCreativeTab(EquivalentExchange3.tabsEE3);
maxStackSize = 64; maxStackSize = 64;
} }
@ -66,6 +63,12 @@ public class ItemAlchemicalDust extends ItemEE
return Integer.parseInt(Colours.PURE_WHITE, 16); 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 @Override
public String getUnlocalizedName(ItemStack itemStack) public String getUnlocalizedName(ItemStack itemStack)
{ {
@ -122,8 +125,7 @@ public class ItemAlchemicalDust extends ItemEE
} }
} }
@Override public static List<ItemStack> getAlchemicalDusts()
public List<ItemStack> getSubTypes()
{ {
List<ItemStack> alchemicalDustStacks = new ArrayList<ItemStack>(); List<ItemStack> alchemicalDustStacks = new ArrayList<ItemStack>();

View file

@ -1,6 +1,5 @@
package com.pahimar.ee3.item; package com.pahimar.ee3.item;
import com.pahimar.ee3.EquivalentExchange3;
import com.pahimar.ee3.lib.Strings; import com.pahimar.ee3.lib.Strings;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@ -10,7 +9,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon; import net.minecraft.util.Icon;
import net.minecraft.util.MathHelper; import net.minecraft.util.MathHelper;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public class ItemAlchemicalFuel extends ItemEE public class ItemAlchemicalFuel extends ItemEE
@ -22,7 +20,6 @@ public class ItemAlchemicalFuel extends ItemEE
{ {
super(id); super(id);
this.setHasSubtypes(true); this.setHasSubtypes(true);
this.setCreativeTab(EquivalentExchange3.tabsEE3);
this.maxStackSize = 64; this.maxStackSize = 64;
} }
@ -61,17 +58,4 @@ public class ItemAlchemicalFuel extends ItemEE
list.add(new ItemStack(id, 1, meta)); list.add(new ItemStack(id, 1, meta));
} }
} }
@Override
public List<ItemStack> getSubTypes()
{
List<ItemStack> alchemicalFuelStacks = new ArrayList<ItemStack>();
for (int meta = 0; meta < Strings.ALCHEMICAL_FUEL_SUBTYPE_NAMES.length; meta++)
{
alchemicalFuelStacks.add(new ItemStack(ModItems.alchemicalFuel, 1, meta));
}
return alchemicalFuelStacks;
}
} }

View file

@ -2,8 +2,9 @@ package com.pahimar.ee3.item;
import com.pahimar.ee3.block.ModBlocks; import com.pahimar.ee3.block.ModBlocks;
import com.pahimar.ee3.lib.Strings; 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) public ItemAlchemicalFuelBlock(int id)
{ {

View file

@ -1,6 +1,5 @@
package com.pahimar.ee3.item; package com.pahimar.ee3.item;
import com.pahimar.ee3.EquivalentExchange3;
import com.pahimar.ee3.lib.Strings; import com.pahimar.ee3.lib.Strings;
public class ItemChalk extends ItemEE public class ItemChalk extends ItemEE
@ -8,8 +7,7 @@ public class ItemChalk extends ItemEE
public ItemChalk(int id) public ItemChalk(int id)
{ {
super(id); super(id);
this.setUnlocalizedName(Strings.RESOURCE_PREFIX + Strings.CHALK_NAME); this.setUnlocalizedName(Strings.CHALK_NAME);
this.setCreativeTab(EquivalentExchange3.tabsEE3);
this.maxStackSize = 64; this.maxStackSize = 64;
} }
} }

View file

@ -1,6 +1,5 @@
package com.pahimar.ee3.item; package com.pahimar.ee3.item;
import com.pahimar.ee3.EquivalentExchange3;
import com.pahimar.ee3.lib.Strings; import com.pahimar.ee3.lib.Strings;
public class ItemDiviningRod extends ItemEE public class ItemDiviningRod extends ItemEE
@ -9,7 +8,6 @@ public class ItemDiviningRod extends ItemEE
{ {
super(id); super(id);
this.setHasSubtypes(true); this.setHasSubtypes(true);
this.setUnlocalizedName(Strings.RESOURCE_PREFIX + Strings.DIVINING_ROD_NAME); this.setUnlocalizedName(Strings.DIVINING_ROD_NAME);
this.setCreativeTab(EquivalentExchange3.tabsEE3);
} }
} }

View file

@ -1,14 +1,13 @@
package com.pahimar.ee3.item; 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.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import java.util.List;
/** /**
* Equivalent-Exchange-3 * Equivalent-Exchange-3
* <p/> * <p/>
@ -18,22 +17,37 @@ import java.util.List;
*/ */
public class ItemEE extends Item public class ItemEE extends Item
{ {
private static final int SHIFTED_ID_RANGE_CORRECTION = 256;
public ItemEE(int id) public ItemEE(int id)
{ {
super(id - Reference.SHIFTED_ID_RANGE_CORRECTION); super(id - SHIFTED_ID_RANGE_CORRECTION);
this.setCreativeTab(EquivalentExchange3.tabsEE3);
maxStackSize = 1; maxStackSize = 1;
setNoRepair(); 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 @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister) public void registerIcons(IconRegister iconRegister)
{ {
itemIcon = iconRegister.registerIcon(this.getUnlocalizedName().substring(this.getUnlocalizedName().indexOf(".") + 1)); itemIcon = iconRegister.registerIcon(this.getUnlocalizedName().substring(this.getUnlocalizedName().indexOf(".") + 1));
} }
public List<ItemStack> getSubTypes()
{
return null;
}
} }

View file

@ -1,6 +1,5 @@
package com.pahimar.ee3.item; package com.pahimar.ee3.item;
import com.pahimar.ee3.EquivalentExchange3;
import com.pahimar.ee3.lib.Strings; import com.pahimar.ee3.lib.Strings;
/** /**
@ -15,7 +14,6 @@ public class ItemInertStone extends ItemEE
public ItemInertStone(int id) public ItemInertStone(int id)
{ {
super(id); super(id);
this.setUnlocalizedName(Strings.RESOURCE_PREFIX + Strings.INERT_STONE_NAME); this.setUnlocalizedName(Strings.INERT_STONE_NAME);
this.setCreativeTab(EquivalentExchange3.tabsEE3);
} }
} }

View file

@ -1,6 +1,5 @@
package com.pahimar.ee3.item; package com.pahimar.ee3.item;
import com.pahimar.ee3.EquivalentExchange3;
import com.pahimar.ee3.lib.Strings; import com.pahimar.ee3.lib.Strings;
/** /**
@ -15,8 +14,7 @@ public class ItemMiniumShard extends ItemEE
public ItemMiniumShard(int id) public ItemMiniumShard(int id)
{ {
super(id); super(id);
this.setUnlocalizedName(Strings.RESOURCE_PREFIX + Strings.MINIUM_SHARD_NAME); this.setUnlocalizedName(Strings.MINIUM_SHARD_NAME);
this.setCreativeTab(EquivalentExchange3.tabsEE3);
maxStackSize = 64; maxStackSize = 64;
} }
} }

View file

@ -25,8 +25,7 @@ public class ItemMiniumStone extends ItemEE implements ITransmutationStone, IKey
public ItemMiniumStone(int id) public ItemMiniumStone(int id)
{ {
super(id); super(id);
this.setUnlocalizedName(Strings.RESOURCE_PREFIX + Strings.MINIUM_STONE_NAME); this.setUnlocalizedName(Strings.MINIUM_STONE_NAME);
this.setCreativeTab(EquivalentExchange3.tabsEE3);
this.setMaxDamage(ConfigurationSettings.MINIUM_STONE_MAX_DURABILITY - 1); this.setMaxDamage(ConfigurationSettings.MINIUM_STONE_MAX_DURABILITY - 1);
} }

View file

@ -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);
}
}

View file

@ -31,8 +31,7 @@ public class ItemPhilosophersStone extends ItemEE implements ITransmutationStone
public ItemPhilosophersStone(int id) public ItemPhilosophersStone(int id)
{ {
super(id); super(id);
this.setUnlocalizedName(Strings.RESOURCE_PREFIX + Strings.PHILOSOPHERS_STONE_NAME); this.setUnlocalizedName(Strings.PHILOSOPHERS_STONE_NAME);
this.setCreativeTab(EquivalentExchange3.tabsEE3);
this.setMaxDamage(ConfigurationSettings.PHILOSOPHERS_STONE_MAX_DURABILITY - 1); this.setMaxDamage(ConfigurationSettings.PHILOSOPHERS_STONE_MAX_DURABILITY - 1);
maxChargeLevel = 3; maxChargeLevel = 3;
} }

View file

@ -3,6 +3,7 @@ package com.pahimar.ee3.item;
import com.pahimar.ee3.lib.ItemIds; import com.pahimar.ee3.lib.ItemIds;
import com.pahimar.ee3.lib.Strings; import com.pahimar.ee3.lib.Strings;
import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.item.ItemMultiTextureTile;
/** /**
* Equivalent-Exchange-3 * Equivalent-Exchange-3
@ -24,7 +25,7 @@ public class ModItems
public static ItemEE diviningRod; public static ItemEE diviningRod;
public static ItemEE alchemicalFuel; public static ItemEE alchemicalFuel;
public static ItemMultiTextureBlockEE alchemicalFuelBlock; public static ItemMultiTextureTile alchemicalFuelBlock;
public static void init() public static void init()
{ {

View file

@ -42,7 +42,6 @@ public class Reference
public static final String DEPENDENCIES = "required-after:Forge@[9.10.1.849,)"; public static final String DEPENDENCIES = "required-after:Forge@[9.10.1.849,)";
public static final String FINGERPRINT = "@FINGERPRINT@"; public static final String FINGERPRINT = "@FINGERPRINT@";
public static final int SECOND_IN_TICKS = 20; 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 SERVER_PROXY_CLASS = "com.pahimar.ee3.proxy.ServerProxy";
public static final String CLIENT_PROXY_CLASS = "com.pahimar.ee3.proxy.ClientProxy"; public static final String CLIENT_PROXY_CLASS = "com.pahimar.ee3.proxy.ClientProxy";
public static final int VERSION_CHECK_ATTEMPTS = 3; public static final int VERSION_CHECK_ATTEMPTS = 3;

View file

@ -3,6 +3,7 @@ package com.pahimar.ee3.recipe;
import com.pahimar.ee3.emc.EmcRegistry; import com.pahimar.ee3.emc.EmcRegistry;
import com.pahimar.ee3.emc.EmcValue; import com.pahimar.ee3.emc.EmcValue;
import com.pahimar.ee3.helper.ItemHelper; import com.pahimar.ee3.helper.ItemHelper;
import com.pahimar.ee3.item.ItemAlchemicalDust;
import com.pahimar.ee3.item.ModItems; import com.pahimar.ee3.item.ModItems;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -25,7 +26,7 @@ public class CalcinationManager
TreeMap<EmcValue, ItemStack> sortedItems = new TreeMap<EmcValue, ItemStack>(); TreeMap<EmcValue, ItemStack> sortedItems = new TreeMap<EmcValue, ItemStack>();
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 the item to be calcined is an alchemical dust, return null (you cannot calcine what's already been calcined)
if (ItemHelper.equals(itemStack, dustStack)) if (ItemHelper.equals(itemStack, dustStack))