From 0669f5eb9d5029a8b94ec552171b0837605f7747 Mon Sep 17 00:00:00 2001 From: draknyte1 Date: Fri, 4 Nov 2016 15:23:26 +1000 Subject: $ Cleaned up the entire project. > Much neat, very nices. --- src/Java/gtPlusPlus/core/item/base/BaseEuItem.java | 893 ++++++++++++--------- .../core/item/base/BaseItemBackpack.java | 100 +-- .../gtPlusPlus/core/item/base/BaseItemBrain.java | 104 ++- .../core/item/base/BaseItemComponent.java | 187 ++--- .../gtPlusPlus/core/item/base/BaseItemGeneric.java | 26 +- .../gtPlusPlus/core/item/base/BaseItemLoot.java | 130 ++- .../core/item/base/BaseItemWithCharge.java | 62 +- .../core/item/base/BaseItemWithDamageValue.java | 24 +- .../gtPlusPlus/core/item/base/BasicSpawnEgg.java | 413 +++++----- src/Java/gtPlusPlus/core/item/base/CoreItem.java | 119 +-- .../core/item/base/bolts/BaseItemBolt.java | 4 +- .../core/item/base/cell/BaseItemCell.java | 41 +- .../core/item/base/dusts/BaseItemDust.java | 320 ++++---- .../core/item/base/dusts/BaseItemDustAbstract.java | 35 +- .../core/item/base/dusts/BaseItemDustUnique.java | 120 +-- .../item/base/dusts/decimal/BaseItemCentidust.java | 47 +- .../item/base/dusts/decimal/BaseItemDecidust.java | 47 +- .../core/item/base/foods/BaseItemFood.java | 31 +- .../core/item/base/foods/BaseItemHotFood.java | 82 +- .../core/item/base/gears/BaseItemGear.java | 6 +- .../core/item/base/ingots/BaseItemIngot.java | 120 +-- .../core/item/base/ingots/BaseItemIngotHot.java | 61 +- .../core/item/base/itemblock/ItemBlockBase.java | 21 +- .../core/item/base/itemblock/ItemBlockFluid.java | 79 +- .../core/item/base/itemblock/ItemBlockGtBlock.java | 54 +- .../item/base/itemblock/ItemBlockGtFrameBox.java | 19 +- .../item/base/itemblock/ItemBlockTileEntity.java | 46 +- .../core/item/base/nugget/BaseItemNugget.java | 6 +- .../core/item/base/plates/BaseItemPlate.java | 15 +- .../core/item/base/plates/BaseItemPlateDouble.java | 10 +- .../core/item/base/rings/BaseItemRing.java | 4 +- .../core/item/base/rods/BaseItemRod.java | 25 +- .../core/item/base/rods/BaseItemRodLong.java | 45 +- .../core/item/base/rotors/BaseItemRotor.java | 4 +- .../core/item/base/screws/BaseItemScrew.java | 25 +- 35 files changed, 1722 insertions(+), 1603 deletions(-) (limited to 'src/Java/gtPlusPlus/core/item/base') diff --git a/src/Java/gtPlusPlus/core/item/base/BaseEuItem.java b/src/Java/gtPlusPlus/core/item/base/BaseEuItem.java index e9e2317044..e92e69f0e0 100644 --- a/src/Java/gtPlusPlus/core/item/base/BaseEuItem.java +++ b/src/Java/gtPlusPlus/core/item/base/BaseEuItem.java @@ -1,8 +1,5 @@ package gtPlusPlus.core.item.base; -import static gregtech.api.enums.GT_Values.D1; -import static gregtech.api.enums.GT_Values.V; - import java.util.*; import cpw.mods.fml.common.registry.GameRegistry; @@ -33,474 +30,602 @@ import net.minecraft.util.IIcon; public class BaseEuItem extends Item implements ISpecialElectricItem, IElectricItemManager { /* ---------- CONSTRUCTOR AND MEMBER VARIABLES ---------- */ - private final HashMap>> mItemBehaviors = new HashMap>>(); - public final short mOffset, mItemAmount; - public final BitSet mEnabledItems; - public final BitSet mVisibleItems; - public final IIcon[][] mIconList; - /** The unlocalized name of this item. */ - private String unlocalizedName; - - private ArrayList> rarity = new ArrayList>(); - private ArrayList> descColour = new ArrayList>(); - private ArrayList> itemName = new ArrayList>(); - private ArrayList> itemDescription = new ArrayList>(); - private ArrayList> hasEffect = new ArrayList>(); - - public final HashMap mElectricStats = new HashMap(); - public final HashMap mBurnValues = new HashMap(); + private final HashMap>> mItemBehaviors = new HashMap>>(); + public final short mOffset, mItemAmount; + public final BitSet mEnabledItems; + public final BitSet mVisibleItems; + public final IIcon[][] mIconList; + /** The unlocalized name of this item. */ + private String unlocalizedName; + + private final ArrayList> rarity = new ArrayList>(); + private final ArrayList> descColour = new ArrayList>(); + private final ArrayList> itemName = new ArrayList>(); + private final ArrayList> itemDescription = new ArrayList>(); + private final ArrayList> hasEffect = new ArrayList>(); + + public final HashMap mElectricStats = new HashMap(); + public final HashMap mBurnValues = new HashMap(); public BaseEuItem() { - this("MU-metaitem.02", AddToCreativeTab.tabOther, (short) 1000, (short) 31766); - } - - public BaseEuItem(String unlocalizedName, CreativeTabs creativeTab, short aOffset, short aItemAmount) { - mEnabledItems = new BitSet(aItemAmount); - mVisibleItems = new BitSet(aItemAmount); - mOffset = (short) Math.min(32766, aOffset); - mItemAmount = (short) Math.min(aItemAmount, 32766 - mOffset); - mIconList = new IIcon[aItemAmount][1]; - setHasSubtypes(true); - setMaxDamage(0); - setUnlocalizedName(unlocalizedName); - setCreativeTab(creativeTab); - setMaxStackSize(1); - GameRegistry.registerItem(this, unlocalizedName); - } - - - public void registerItem(int id, String localizedName, long euStorage, int tier, String description) { - registerItem(id, localizedName, euStorage, (short) tier, description, EnumRarity.common, EnumChatFormatting.GRAY, false); - } - - public void registerItem(int id, String localizedName, long euStorage, int tier, String description, int burnTime) { - registerItem(id, localizedName, euStorage, (short) tier, description, EnumRarity.common, EnumChatFormatting.GRAY, false); - setBurnValue(id, burnTime); - } - - - public void registerItem(int id, String localizedName, long euStorage, short tier, String description, EnumRarity regRarity, EnumChatFormatting colour, boolean Effect) { - addItem(id, localizedName, EnumChatFormatting.YELLOW+"Electric", new Object[]{}); - setElectricStats(mOffset + id, euStorage, GT_Values.V[tier], tier, -3L, true); - this.rarity.add(new Pair(id, regRarity)); - this.itemName.add(new Pair(id, localizedName)); - this.itemDescription.add(new Pair(id, description)); - this.descColour.add(new Pair(id, colour)); - this.hasEffect.add(new Pair(id, Effect)); - } + this("MU-metaitem.02", AddToCreativeTab.tabOther, (short) 1000, (short) 31766); + } - @Override - @SideOnly(Side.CLIENT) - public EnumRarity getRarity(ItemStack par1ItemStack){ - if (rarity.get(par1ItemStack.getItemDamage()-mOffset) != null) - return rarity.get(par1ItemStack.getItemDamage()-mOffset).getValue(); - return EnumRarity.common; + public BaseEuItem(final String unlocalizedName, final CreativeTabs creativeTab, final short aOffset, + final short aItemAmount) { + this.mEnabledItems = new BitSet(aItemAmount); + this.mVisibleItems = new BitSet(aItemAmount); + this.mOffset = (short) Math.min(32766, aOffset); + this.mItemAmount = (short) Math.min(aItemAmount, 32766 - this.mOffset); + this.mIconList = new IIcon[aItemAmount][1]; + this.setHasSubtypes(true); + this.setMaxDamage(0); + this.setUnlocalizedName(unlocalizedName); + this.setCreativeTab(creativeTab); + this.setMaxStackSize(1); + GameRegistry.registerItem(this, unlocalizedName); } + @SuppressWarnings({ + "unchecked", "rawtypes" + }) @Override - public boolean hasEffect(ItemStack par1ItemStack){ - if (hasEffect.get(par1ItemStack.getItemDamage()-mOffset) != null) - return hasEffect.get(par1ItemStack.getItemDamage()-mOffset).getValue(); - return false; + public final void addInformation(final ItemStack aStack, final EntityPlayer aPlayer, List aList, + final boolean aF3_H) { + // aList.add("Meta: "+(aStack.getItemDamage()-mOffset)); + if (this.descColour.get(aStack.getItemDamage() - this.mOffset) != null + && this.itemDescription.get(aStack.getItemDamage() - this.mOffset) != null) { + aList.add(this.descColour.get(aStack.getItemDamage() - this.mOffset).getValue() + + this.itemDescription.get(aStack.getItemDamage() - this.mOffset).getValue()); + } + final String tKey = this.getUnlocalizedName(aStack) + ".tooltip", + tString = GT_LanguageManager.getTranslation(tKey); + if (GT_Utility.isStringValid(tString) && !tKey.equals(tString)) { + aList.add(tString); + } + final Long[] tStats = this.getElectricStats(aStack); + if (tStats != null) { + if (tStats[3] > 0) { + aList.add(EnumChatFormatting.AQUA + "Contains " + GT_Utility.formatNumbers(tStats[3]) + " EU Tier: " + + (tStats[2] >= 0 ? tStats[2] : 0) + EnumChatFormatting.GRAY); + } + else { + final long tCharge = this.getRealCharge(aStack); + if (tStats[3] == -2 && tCharge <= 0) { + aList.add(EnumChatFormatting.AQUA + "Empty. You should recycle it properly." + + EnumChatFormatting.GRAY); + } + else { + aList.add(EnumChatFormatting.AQUA + "" + GT_Utility.formatNumbers(tCharge) + " / " + + GT_Utility.formatNumbers(Math.abs(tStats[0])) + " EU - Voltage: " + + GT_Values.V[(int) (tStats[2] >= 0 + ? tStats[2] < GT_Values.V.length ? tStats[2] : GT_Values.V.length - 1 : 1)] + + EnumChatFormatting.GRAY); + } + } + } + final ArrayList> tList = this.mItemBehaviors.get((short) this.getDamage(aStack)); + if (tList != null) { + for (final IItemBehaviour tBehavior : tList) { + aList = tBehavior.getAdditionalToolTips(this, aList, aStack); + } + } } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Override - public final void addInformation(ItemStack aStack, EntityPlayer aPlayer, List aList, boolean aF3_H) { - //aList.add("Meta: "+(aStack.getItemDamage()-mOffset)); - if (descColour.get(aStack.getItemDamage()-mOffset) != null && itemDescription.get(aStack.getItemDamage()-mOffset) != null) - aList.add(descColour.get(aStack.getItemDamage()-mOffset).getValue()+itemDescription.get(aStack.getItemDamage()-mOffset).getValue()); - String tKey = getUnlocalizedName(aStack) + ".tooltip", tString = GT_LanguageManager.getTranslation(tKey); - if (GT_Utility.isStringValid(tString) && !tKey.equals(tString)) aList.add(tString); - Long[] tStats = getElectricStats(aStack); - if (tStats != null) { - if (tStats[3] > 0) { - aList.add(EnumChatFormatting.AQUA + "Contains " + GT_Utility.formatNumbers(tStats[3]) + " EU Tier: " + (tStats[2] >= 0 ? tStats[2] : 0) + EnumChatFormatting.GRAY); - } else { - long tCharge = getRealCharge(aStack); - if (tStats[3] == -2 && tCharge <= 0) { - aList.add(EnumChatFormatting.AQUA + "Empty. You should recycle it properly." + EnumChatFormatting.GRAY); - } else { - aList.add(EnumChatFormatting.AQUA + "" + GT_Utility.formatNumbers(tCharge) + " / " + GT_Utility.formatNumbers(Math.abs(tStats[0])) + " EU - Voltage: " + V[(int) (tStats[2] >= 0 ? tStats[2] < V.length ? tStats[2] : V.length - 1 : 1)] + EnumChatFormatting.GRAY); - } - } - } - ArrayList> tList = mItemBehaviors.get((short) getDamage(aStack)); - if (tList != null) for (IItemBehaviour tBehavior : tList) - aList = tBehavior.getAdditionalToolTips(this, aList, aStack); - } - - - @Override - public final Item getChargedItem(ItemStack itemStack) { - return this; + /** + * This adds a Custom Item to the ending Range. + * + * @param aID + * The Id of the assigned Item [0 - mItemAmount] (The MetaData + * gets auto-shifted by +mOffset) + * @param aEnglish + * The Default Localized Name of the created Item + * @param aToolTip + * The Default ToolTip of the created Item, you can also insert + * null for having no ToolTip + * @param aFoodBehavior + * The Food Value of this Item. Can be null aswell. Just a + * convenience thing. + * @param aRandomData + * The OreDict Names you want to give the Item. Also used for TC + * Aspects and some other things. + * @return An ItemStack containing the newly created Item. + */ + @SuppressWarnings("unchecked") + public final ItemStack addItem(final int aID, final String aEnglish, String aToolTip, final Object... aRandomData) { + if (aToolTip == null) { + aToolTip = ""; + } + if (aID >= 0 && aID < this.mItemAmount) { + final ItemStack rStack = new ItemStack(this, 1, this.mOffset + aID); + this.mEnabledItems.set(aID); + this.mVisibleItems.set(aID); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName(rStack) + ".name", aEnglish); + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName(rStack) + ".tooltip", aToolTip); + final List tAspects = new ArrayList(); + // Important Stuff to do first + for (final Object tRandomData : aRandomData) { + if (tRandomData instanceof SubTag) { + if (tRandomData == SubTag.INVISIBLE) { + this.mVisibleItems.set(aID, false); + continue; + } + if (tRandomData == SubTag.NO_UNIFICATION) { + GT_OreDictUnificator.addToBlacklist(rStack); + continue; + } + } + } + // now check for the rest + for (final Object tRandomData : aRandomData) { + if (tRandomData != null) { + boolean tUseOreDict = true; + if (tRandomData instanceof IItemBehaviour) { + this.addItemBehavior(this.mOffset + aID, (IItemBehaviour) tRandomData); + tUseOreDict = false; + } + if (tRandomData instanceof IItemContainer) { + ((IItemContainer) tRandomData).set(rStack); + tUseOreDict = false; + } + if (tRandomData instanceof SubTag) { + continue; + } + if (tRandomData instanceof TC_AspectStack) { + ((TC_AspectStack) tRandomData).addToAspectList(tAspects); + continue; + } + if (tRandomData instanceof ItemData) { + if (GT_Utility.isStringValid(tRandomData)) { + GT_OreDictUnificator.registerOre(tRandomData, rStack); + } + else { + GT_OreDictUnificator.addItemData(rStack, (ItemData) tRandomData); + } + continue; + } + if (tUseOreDict) { + GT_OreDictUnificator.registerOre(tRandomData, rStack); + continue; + } + } + } + if (GregTech_API.sThaumcraftCompat != null) { + GregTech_API.sThaumcraftCompat.registerThaumcraftAspectsToItem(rStack, tAspects, false); + } + return rStack; + } + return null; } - @Override - public final Item getEmptyItem(ItemStack itemStack) { + /** + * Adds a special Item Behaviour to the Item. + *

+ * Note: the boolean Behaviours sometimes won't be executed if another + * boolean Behaviour returned true before. + * + * @param aMetaValue + * the Meta Value of the Item you want to add it to. [0 - 32765] + * @param aBehavior + * the Click Behavior you want to add. + * @return the Item itself for convenience in constructing. + */ + public final BaseEuItem addItemBehavior(final int aMetaValue, final IItemBehaviour aBehavior) { + if (aMetaValue < 0 || aMetaValue >= 32766 || aBehavior == null) { + return this; + } + ArrayList> tList = this.mItemBehaviors.get((short) aMetaValue); + if (tList == null) { + tList = new ArrayList>(1); + this.mItemBehaviors.put((short) aMetaValue, tList); + } + tList.add(aBehavior); return this; } @Override - public final double getMaxCharge(ItemStack aStack) { - Long[] tStats = getElectricStats(aStack); - if (tStats == null) return 0; - return Math.abs(tStats[0]); + public final boolean canProvideEnergy(final ItemStack aStack) { + final Long[] tStats = this.getElectricStats(aStack); + if (tStats == null) { + return false; + } + return tStats[3] > 0 || aStack.stackSize == 1 && (tStats[3] == -2 || tStats[3] == -3); } @Override - public final double getTransferLimit(ItemStack aStack) { - Long[] tStats = getElectricStats(aStack); - if (tStats == null) return 0; - return Math.max(tStats[1], tStats[3]); + public final boolean canUse(final ItemStack aStack, final double aAmount) { + return this.getRealCharge(aStack) >= aAmount; } @Override - public final int getTier(ItemStack aStack) { - Long[] tStats = getElectricStats(aStack); - return (int) (tStats == null ? Integer.MAX_VALUE : tStats[2]); + public final double charge(final ItemStack aStack, final double aCharge, final int aTier, + final boolean aIgnoreTransferLimit, final boolean aSimulate) { + final Long[] tStats = this.getElectricStats(aStack); + if (tStats == null || tStats[2] > aTier + || !(tStats[3] == -1 || tStats[3] == -3 || tStats[3] < 0 && aCharge == Integer.MAX_VALUE) + || aStack.stackSize != 1) { + return 0; + } + final long tChargeBefore = this.getRealCharge(aStack), tNewCharge = aCharge == Integer.MAX_VALUE + ? Long.MAX_VALUE + : Math.min(Math.abs(tStats[0]), + tChargeBefore + (aIgnoreTransferLimit ? (long) aCharge : Math.min(tStats[1], (long) aCharge))); + if (!aSimulate) { + this.setCharge(aStack, tNewCharge); + } + return tNewCharge - tChargeBefore; } @Override - public final double charge(ItemStack aStack, double aCharge, int aTier, boolean aIgnoreTransferLimit, boolean aSimulate) { - Long[] tStats = getElectricStats(aStack); - if (tStats == null || tStats[2] > aTier || !(tStats[3] == -1 || tStats[3] == -3 || (tStats[3] < 0 && aCharge == Integer.MAX_VALUE)) || aStack.stackSize != 1) - return 0; - long tChargeBefore = getRealCharge(aStack), tNewCharge = aCharge == Integer.MAX_VALUE ? Long.MAX_VALUE : Math.min(Math.abs(tStats[0]), tChargeBefore + (aIgnoreTransferLimit ? (long) aCharge : Math.min(tStats[1], (long) aCharge))); - if (!aSimulate) setCharge(aStack, tNewCharge); - return tNewCharge - tChargeBefore; + public final void chargeFromArmor(final ItemStack aStack, final EntityLivingBase aPlayer) { + if (aPlayer == null || aPlayer.worldObj.isRemote) { + return; + } + for (int i = 1; i < 5; i++) { + final ItemStack tArmor = aPlayer.getEquipmentInSlot(i); + if (GT_ModHandler.isElectricItem(tArmor)) { + final IElectricItem tArmorItem = (IElectricItem) tArmor.getItem(); + if (tArmorItem.canProvideEnergy(tArmor) && tArmorItem.getTier(tArmor) >= this.getTier(aStack)) { + final double tCharge = ElectricItem.manager.discharge(tArmor, + this.charge(aStack, Integer.MAX_VALUE - 1, Integer.MAX_VALUE, true, true), + Integer.MAX_VALUE, true, true, false); + if (tCharge > 0) { + this.charge(aStack, tCharge, Integer.MAX_VALUE, true, false); + if (aPlayer instanceof EntityPlayer) { + final Container tContainer = ((EntityPlayer) aPlayer).openContainer; + if (tContainer != null) { + tContainer.detectAndSendChanges(); + } + } + } + } + } + } } @Override - public final double discharge(ItemStack aStack, double aCharge, int aTier, boolean aIgnoreTransferLimit, boolean aBatteryAlike, boolean aSimulate) { - Long[] tStats = getElectricStats(aStack); - if (tStats == null || tStats[2] > aTier) return 0; - if (aBatteryAlike && !canProvideEnergy(aStack)) return 0; + public final double discharge(final ItemStack aStack, final double aCharge, final int aTier, + final boolean aIgnoreTransferLimit, final boolean aBatteryAlike, final boolean aSimulate) { + final Long[] tStats = this.getElectricStats(aStack); + if (tStats == null || tStats[2] > aTier) { + return 0; + } + if (aBatteryAlike && !this.canProvideEnergy(aStack)) { + return 0; + } if (tStats[3] > 0) { - if (aCharge < tStats[3] || aStack.stackSize < 1) return 0; - if (!aSimulate) aStack.stackSize--; + if (aCharge < tStats[3] || aStack.stackSize < 1) { + return 0; + } + if (!aSimulate) { + aStack.stackSize--; + } return tStats[3]; } - long tChargeBefore = getRealCharge(aStack), tNewCharge = Math.max(0, tChargeBefore - (aIgnoreTransferLimit ? (long) aCharge : Math.min(tStats[1], (long) aCharge))); - if (!aSimulate) setCharge(aStack, tNewCharge); + final long tChargeBefore = this.getRealCharge(aStack), tNewCharge = Math.max(0, + tChargeBefore - (aIgnoreTransferLimit ? (long) aCharge : Math.min(tStats[1], (long) aCharge))); + if (!aSimulate) { + this.setCharge(aStack, tNewCharge); + } return tChargeBefore - tNewCharge; } @Override - public final double getCharge(ItemStack aStack) { - return getRealCharge(aStack); + public final double getCharge(final ItemStack aStack) { + return this.getRealCharge(aStack); } @Override - public final boolean canUse(ItemStack aStack, double aAmount) { - return getRealCharge(aStack) >= aAmount; + public final Item getChargedItem(final ItemStack itemStack) { + return this; } - @Override - public final boolean use(ItemStack aStack, double aAmount, EntityLivingBase aPlayer) { - chargeFromArmor(aStack, aPlayer); - if (aPlayer instanceof EntityPlayer && ((EntityPlayer) aPlayer).capabilities.isCreativeMode) return true; - double tTransfer = discharge(aStack, aAmount, Integer.MAX_VALUE, true, false, true); - if (tTransfer == aAmount) { - discharge(aStack, aAmount, Integer.MAX_VALUE, true, false, false); - chargeFromArmor(aStack, aPlayer); - return true; - } - discharge(aStack, aAmount, Integer.MAX_VALUE, true, false, false); - chargeFromArmor(aStack, aPlayer); - return false; + @SuppressWarnings("static-method") + public short getChargedMetaData(final ItemStack aStack) { + return (short) aStack.getItemDamage(); } - @Override - public final boolean canProvideEnergy(ItemStack aStack) { - Long[] tStats = getElectricStats(aStack); - if (tStats == null) return false; - return tStats[3] > 0 || (aStack.stackSize == 1 && (tStats[3] == -2 || tStats[3] == -3)); + public final Long[] getElectricStats(final ItemStack aStack) { + return this.mElectricStats.get((short) aStack.getItemDamage()); } @Override - public final void chargeFromArmor(ItemStack aStack, EntityLivingBase aPlayer) { - if (aPlayer == null || aPlayer.worldObj.isRemote) return; - for (int i = 1; i < 5; i++) { - ItemStack tArmor = aPlayer.getEquipmentInSlot(i); - if (GT_ModHandler.isElectricItem(tArmor)) { - IElectricItem tArmorItem = (IElectricItem) tArmor.getItem(); - if (tArmorItem.canProvideEnergy(tArmor) && tArmorItem.getTier(tArmor) >= getTier(aStack)) { - double tCharge = ElectricItem.manager.discharge(tArmor, charge(aStack, Integer.MAX_VALUE - 1, Integer.MAX_VALUE, true, true), Integer.MAX_VALUE, true, true, false); - if (tCharge > 0) { - charge(aStack, tCharge, Integer.MAX_VALUE, true, false); - if (aPlayer instanceof EntityPlayer) { - Container tContainer = ((EntityPlayer) aPlayer).openContainer; - if (tContainer != null) tContainer.detectAndSendChanges(); - } - } - } - } - } - } - - public final long getRealCharge(ItemStack aStack) { - Long[] tStats = getElectricStats(aStack); - if (tStats == null) return 0; - if (tStats[3] > 0) return (int) (long) tStats[3]; - NBTTagCompound tNBT = aStack.getTagCompound(); - return tNBT == null ? 0 : tNBT.getLong("GT.ItemCharge"); - } - - public final boolean setCharge(ItemStack aStack, long aCharge) { - Long[] tStats = getElectricStats(aStack); - if (tStats == null || tStats[3] > 0) return false; - NBTTagCompound tNBT = aStack.getTagCompound(); - if (tNBT == null) tNBT = new NBTTagCompound(); - tNBT.removeTag("GT.ItemCharge"); - aCharge = Math.min(tStats[0] < 0 ? Math.abs(tStats[0] / 2) : aCharge, Math.abs(tStats[0])); - if (aCharge > 0) { - aStack.setItemDamage(getChargedMetaData(aStack)); - tNBT.setLong("GT.ItemCharge", aCharge); - } else { - aStack.setItemDamage(getEmptyMetaData(aStack)); - } - if (tNBT.hasNoTags()) aStack.setTagCompound(null); - else aStack.setTagCompound(tNBT); - isItemStackUsable(aStack); - return true; + public final Item getEmptyItem(final ItemStack itemStack) { + return this; } @SuppressWarnings("static-method") - public short getChargedMetaData(ItemStack aStack) { + public short getEmptyMetaData(final ItemStack aStack) { return (short) aStack.getItemDamage(); } - @SuppressWarnings("static-method") - public short getEmptyMetaData(ItemStack aStack) { - return (short) aStack.getItemDamage(); + @Override + public final IIcon getIconFromDamage(final int aMetaData) { + if (aMetaData < 0) { + return null; + } + return aMetaData - this.mOffset < this.mIconList.length ? this.mIconList[aMetaData - this.mOffset][0] : null; } + @Override + public boolean getIsRepairable(final ItemStack aStack, final ItemStack aMaterial) { + return false; + } - public boolean isItemStackUsable(ItemStack aStack) { - ArrayList> tList = mItemBehaviors.get((short) getDamage(aStack)); - if (tList != null) for (IItemBehaviour tBehavior : tList) - if (!tBehavior.isItemStackUsable(this, aStack)) return false; - return true; + @Override + public int getItemEnchantability() { + return 0; } @Override - public final String getToolTip(ItemStack aStack) { - return null; - } // This has its own ToolTip Handler, no need to let the IC2 Handler screw us up at this Point + public String getItemStackDisplayName(final ItemStack par1ItemStack) { + return this.itemName.get(par1ItemStack.getItemDamage() - this.mOffset).getValue(); + } @Override - public final IElectricItemManager getManager(ItemStack aStack) { + public final IElectricItemManager getManager(final ItemStack aStack) { return this; } // We are our own Manager - /** - * Sets the Furnace Burn Value for the Item. - * - * @param aMetaValue the Meta Value of the Item you want to set it to. [0 - 32765] - * @param aValue 200 = 1 Burn Process = 500 EU, max = 32767 (that is 81917.5 EU) - * @return the Item itself for convenience in constructing. - */ - public final BaseEuItem setBurnValue(int aMetaValue, int aValue) { - if (aMetaValue < 0 || aValue < 0) return this; - if (aValue == 0) mBurnValues.remove((short) aMetaValue); - else mBurnValues.put((short) aMetaValue, aValue > Short.MAX_VALUE ? Short.MAX_VALUE : (short) aValue); - return this; + @Override + public final double getMaxCharge(final ItemStack aStack) { + final Long[] tStats = this.getElectricStats(aStack); + if (tStats == null) { + return 0; + } + return Math.abs(tStats[0]); } - /** - * @param aMetaValue the Meta Value of the Item you want to set it to. [0 - 32765] - * @param aMaxCharge Maximum Charge. (if this is == 0 it will remove the Electric Behavior) - * @param aTransferLimit Transfer Limit. - * @param aTier The electric Tier. - * @param aSpecialData If this Item has a Fixed Charge, like a SingleUse Battery (if > 0). - * Use -1 if you want to make this Battery chargeable (the use and canUse Functions will still discharge if you just use this) - * Use -2 if you want to make this Battery dischargeable. - * Use -3 if you want to make this Battery charge/discharge-able. - * @return the Item itself for convenience in constructing. - */ - public final BaseEuItem setElectricStats(int aMetaValue, long aMaxCharge, long aTransferLimit, long aTier, long aSpecialData, boolean aUseAnimations) { - if (aMetaValue < 0) return this; - if (aMaxCharge == 0) mElectricStats.remove((short) aMetaValue); - else { - mElectricStats.put((short) aMetaValue, new Long[]{aMaxCharge, Math.max(0, aTransferLimit), Math.max(-1, aTier), aSpecialData}); + @Override + @SideOnly(Side.CLIENT) + public EnumRarity getRarity(final ItemStack par1ItemStack) { + if (this.rarity.get(par1ItemStack.getItemDamage() - this.mOffset) != null) { + return this.rarity.get(par1ItemStack.getItemDamage() - this.mOffset).getValue(); } - return this; + return EnumRarity.common; } + public final long getRealCharge(final ItemStack aStack) { + final Long[] tStats = this.getElectricStats(aStack); + if (tStats == null) { + return 0; + } + if (tStats[3] > 0) { + return (int) (long) tStats[3]; + } + final NBTTagCompound tNBT = aStack.getTagCompound(); + return tNBT == null ? 0 : tNBT.getLong("GT.ItemCharge"); + } - @SuppressWarnings({ "rawtypes", "unchecked" }) + @SuppressWarnings({ + "rawtypes", "unchecked" + }) @Override @SideOnly(Side.CLIENT) - public void getSubItems(Item var1, CreativeTabs aCreativeTab, List aList) { - for (int i = 0, j = mEnabledItems.length(); i < j; i++) - if (mVisibleItems.get(i) || (D1 && mEnabledItems.get(i))) { - Long[] tStats = mElectricStats.get((short) (mOffset + i)); + public void getSubItems(final Item var1, final CreativeTabs aCreativeTab, final List aList) { + for (int i = 0, j = this.mEnabledItems.length(); i < j; i++) { + if (this.mVisibleItems.get(i) || GT_Values.D1 && this.mEnabledItems.get(i)) { + final Long[] tStats = this.mElectricStats.get((short) (this.mOffset + i)); if (tStats != null && tStats[3] < 0) { - ItemStack tStack = new ItemStack(this, 1, mOffset + i); - setCharge(tStack, Math.abs(tStats[0])); - isItemStackUsable(tStack); + final ItemStack tStack = new ItemStack(this, 1, this.mOffset + i); + this.setCharge(tStack, Math.abs(tStats[0])); + this.isItemStackUsable(tStack); aList.add(tStack); } if (tStats == null || tStats[3] != -2) { - ItemStack tStack = new ItemStack(this, 1, mOffset + i); - isItemStackUsable(tStack); + final ItemStack tStack = new ItemStack(this, 1, this.mOffset + i); + this.isItemStackUsable(tStack); aList.add(tStack); } } + } + } + + @Override + public final int getTier(final ItemStack aStack) { + final Long[] tStats = this.getElectricStats(aStack); + return (int) (tStats == null ? Integer.MAX_VALUE : tStats[2]); + } + + @Override + public final String getToolTip(final ItemStack aStack) { + return null; + } // This has its own ToolTip Handler, no need to let the IC2 Handler screw + // us up at this Point + + @Override + public final double getTransferLimit(final ItemStack aStack) { + final Long[] tStats = this.getElectricStats(aStack); + if (tStats == null) { + return 0; + } + return Math.max(tStats[1], tStats[3]); + } + + /** + * Returns the unlocalized name of this item. + */ + @Override + public String getUnlocalizedName() { + return this.unlocalizedName; + } + + @Override + public boolean hasEffect(final ItemStack par1ItemStack) { + if (this.hasEffect.get(par1ItemStack.getItemDamage() - this.mOffset) != null) { + return this.hasEffect.get(par1ItemStack.getItemDamage() - this.mOffset).getValue(); + } + return false; + } + + @Override + public boolean isBookEnchantable(final ItemStack aStack, final ItemStack aBook) { + return false; + } + + public boolean isItemStackUsable(final ItemStack aStack) { + final ArrayList> tList = this.mItemBehaviors.get((short) this.getDamage(aStack)); + if (tList != null) { + for (final IItemBehaviour tBehavior : tList) { + if (!tBehavior.isItemStackUsable(this, aStack)) { + return false; + } + } + } + return true; } @Override @SideOnly(Side.CLIENT) - public final void registerIcons(IIconRegister aIconRegister) { - for (short i = 0, j = (short) mEnabledItems.length(); i < j; i++) - if (mEnabledItems.get(i)) { - for (byte k = 1; k < mIconList[i].length; k++) { - mIconList[i][k] = aIconRegister.registerIcon(CORE.MODID+":" + (getUnlocalizedName() + "/" + i + "/" + k)); + public final void registerIcons(final IIconRegister aIconRegister) { + for (short i = 0, j = (short) this.mEnabledItems.length(); i < j; i++) { + if (this.mEnabledItems.get(i)) { + for (byte k = 1; k < this.mIconList[i].length; k++) { + this.mIconList[i][k] = aIconRegister + .registerIcon(CORE.MODID + ":" + this.getUnlocalizedName() + "/" + i + "/" + k); } - mIconList[i][0] = aIconRegister.registerIcon(CORE.MODID+":" + (getUnlocalizedName() + "/" + i)); + this.mIconList[i][0] = aIconRegister + .registerIcon(CORE.MODID + ":" + this.getUnlocalizedName() + "/" + i); } + } + } + + public void registerItem(final int id, final String localizedName, final long euStorage, final int tier, + final String description) { + this.registerItem(id, localizedName, euStorage, (short) tier, description, EnumRarity.common, + EnumChatFormatting.GRAY, false); + } + + public void registerItem(final int id, final String localizedName, final long euStorage, final int tier, + final String description, final int burnTime) { + this.registerItem(id, localizedName, euStorage, (short) tier, description, EnumRarity.common, + EnumChatFormatting.GRAY, false); + this.setBurnValue(id, burnTime); } - - - @Override - public final IIcon getIconFromDamage(int aMetaData) { - if (aMetaData < 0) return null; - return aMetaData - mOffset < mIconList.length ? mIconList[aMetaData - mOffset][0] : null; - } - + + public void registerItem(final int id, final String localizedName, final long euStorage, final short tier, + final String description, final EnumRarity regRarity, final EnumChatFormatting colour, + final boolean Effect) { + this.addItem(id, localizedName, EnumChatFormatting.YELLOW + "Electric", new Object[] {}); + this.setElectricStats(this.mOffset + id, euStorage, GT_Values.V[tier], tier, -3L, true); + this.rarity.add(new Pair(id, regRarity)); + this.itemName.add(new Pair(id, localizedName)); + this.itemDescription.add(new Pair(id, description)); + this.descColour.add(new Pair(id, colour)); + this.hasEffect.add(new Pair(id, Effect)); + } + /** - * Sets the unlocalized name of this item to the string passed as the parameter" - */ - @Override - public Item setUnlocalizedName(String p_77655_1_){ - this.unlocalizedName = p_77655_1_; - super.setUnlocalizedName(p_77655_1_); - return this; - } - + * Sets the Furnace Burn Value for the Item. + * + * @param aMetaValue + * the Meta Value of the Item you want to set it to. [0 - 32765] + * @param aValue + * 200 = 1 Burn Process = 500 EU, max = 32767 (that is 81917.5 + * EU) + * @return the Item itself for convenience in constructing. + */ + public final BaseEuItem setBurnValue(final int aMetaValue, final int aValue) { + if (aMetaValue < 0 || aValue < 0) { + return this; + } + if (aValue == 0) { + this.mBurnValues.remove((short) aMetaValue); + } + else { + this.mBurnValues.put((short) aMetaValue, aValue > Short.MAX_VALUE ? Short.MAX_VALUE : (short) aValue); + } + return this; + } + + public final boolean setCharge(final ItemStack aStack, long aCharge) { + final Long[] tStats = this.getElectricStats(aStack); + if (tStats == null || tStats[3] > 0) { + return false; + } + NBTTagCompound tNBT = aStack.getTagCompound(); + if (tNBT == null) { + tNBT = new NBTTagCompound(); + } + tNBT.removeTag("GT.ItemCharge"); + aCharge = Math.min(tStats[0] < 0 ? Math.abs(tStats[0] / 2) : aCharge, Math.abs(tStats[0])); + if (aCharge > 0) { + aStack.setItemDamage(this.getChargedMetaData(aStack)); + tNBT.setLong("GT.ItemCharge", aCharge); + } + else { + aStack.setItemDamage(this.getEmptyMetaData(aStack)); + } + if (tNBT.hasNoTags()) { + aStack.setTagCompound(null); + } + else { + aStack.setTagCompound(tNBT); + } + this.isItemStackUsable(aStack); + return true; + } + /** - * Returns the unlocalized name of this item. - */ - @Override - public String getUnlocalizedName() - { - return this.unlocalizedName; - } - - public final Long[] getElectricStats(ItemStack aStack) { - return mElectricStats.get((short) aStack.getItemDamage()); - } - + * @param aMetaValue + * the Meta Value of the Item you want to set it to. [0 - 32765] + * @param aMaxCharge + * Maximum Charge. (if this is == 0 it will remove the Electric + * Behavior) + * @param aTransferLimit + * Transfer Limit. + * @param aTier + * The electric Tier. + * @param aSpecialData + * If this Item has a Fixed Charge, like a SingleUse Battery (if + * > 0). Use -1 if you want to make this Battery chargeable (the + * use and canUse Functions will still discharge if you just use + * this) Use -2 if you want to make this Battery dischargeable. + * Use -3 if you want to make this Battery charge/discharge-able. + * @return the Item itself for convenience in constructing. + */ + public final BaseEuItem setElectricStats(final int aMetaValue, final long aMaxCharge, final long aTransferLimit, + final long aTier, final long aSpecialData, final boolean aUseAnimations) { + if (aMetaValue < 0) { + return this; + } + if (aMaxCharge == 0) { + this.mElectricStats.remove((short) aMetaValue); + } + else { + this.mElectricStats.put((short) aMetaValue, new Long[] { + aMaxCharge, Math.max(0, aTransferLimit), Math.max(-1, aTier), aSpecialData + }); + } + return this; + } + + /** + * Sets the unlocalized name of this item to the string passed as the + * parameter" + */ @Override - public int getItemEnchantability() { - return 0; - } - - @Override - public boolean isBookEnchantable(ItemStack aStack, ItemStack aBook) { - return false; - } - - @Override - public boolean getIsRepairable(ItemStack aStack, ItemStack aMaterial) { - return false; - } - - - /** - * Adds a special Item Behaviour to the Item. - *

- * Note: the boolean Behaviours sometimes won't be executed if another boolean Behaviour returned true before. - * - * @param aMetaValue the Meta Value of the Item you want to add it to. [0 - 32765] - * @param aBehavior the Click Behavior you want to add. - * @return the Item itself for convenience in constructing. - */ - public final BaseEuItem addItemBehavior(int aMetaValue, IItemBehaviour aBehavior) { - if (aMetaValue < 0 || aMetaValue >= 32766 || aBehavior == null) return this; - ArrayList> tList = mItemBehaviors.get((short) aMetaValue); - if (tList == null) { - tList = new ArrayList>(1); - mItemBehaviors.put((short) aMetaValue, tList); - } - tList.add(aBehavior); - return this; - } - - /** - * This adds a Custom Item to the ending Range. - * - * @param aID The Id of the assigned Item [0 - mItemAmount] (The MetaData gets auto-shifted by +mOffset) - * @param aEnglish The Default Localized Name of the created Item - * @param aToolTip The Default ToolTip of the created Item, you can also insert null for having no ToolTip - * @param aFoodBehavior The Food Value of this Item. Can be null aswell. Just a convenience thing. - * @param aRandomData The OreDict Names you want to give the Item. Also used for TC Aspects and some other things. - * @return An ItemStack containing the newly created Item. - */ - @SuppressWarnings("unchecked") - public final ItemStack addItem(int aID, String aEnglish, String aToolTip, Object... aRandomData) { - if (aToolTip == null) aToolTip = ""; - if (aID >= 0 && aID < mItemAmount) { - ItemStack rStack = new ItemStack(this, 1, mOffset + aID); - mEnabledItems.set(aID); - mVisibleItems.set(aID); - GT_LanguageManager.addStringLocalization(getUnlocalizedName(rStack) + ".name", aEnglish); - GT_LanguageManager.addStringLocalization(getUnlocalizedName(rStack) + ".tooltip", aToolTip); - List tAspects = new ArrayList(); - // Important Stuff to do first - for (Object tRandomData : aRandomData) - if (tRandomData instanceof SubTag) { - if (tRandomData == SubTag.INVISIBLE) { - mVisibleItems.set(aID, false); - continue; - } - if (tRandomData == SubTag.NO_UNIFICATION) { - GT_OreDictUnificator.addToBlacklist(rStack); - continue; - } - } - // now check for the rest - for (Object tRandomData : aRandomData) - if (tRandomData != null) { - boolean tUseOreDict = true; - if (tRandomData instanceof IItemBehaviour) { - addItemBehavior(mOffset + aID, (IItemBehaviour) tRandomData); - tUseOreDict = false; - } - if (tRandomData instanceof IItemContainer) { - ((IItemContainer) tRandomData).set(rStack); - tUseOreDict = false; - } - if (tRandomData instanceof SubTag) { - continue; - } - if (tRandomData instanceof TC_AspectStack) { - ((TC_AspectStack) tRandomData).addToAspectList(tAspects); - continue; - } - if (tRandomData instanceof ItemData) { - if (GT_Utility.isStringValid(tRandomData)) - GT_OreDictUnificator.registerOre(tRandomData, rStack); - else GT_OreDictUnificator.addItemData(rStack, (ItemData) tRandomData); - continue; - } - if (tUseOreDict) { - GT_OreDictUnificator.registerOre(tRandomData, rStack); - continue; - } - } - if (GregTech_API.sThaumcraftCompat != null) - GregTech_API.sThaumcraftCompat.registerThaumcraftAspectsToItem(rStack, tAspects, false); - return rStack; - } - return null; - } + public Item setUnlocalizedName(final String p_77655_1_) { + this.unlocalizedName = p_77655_1_; + super.setUnlocalizedName(p_77655_1_); + return this; + } @Override - public String getItemStackDisplayName(ItemStack par1ItemStack) { - return itemName.get(par1ItemStack.getItemDamage()-mOffset).getValue(); + public final boolean use(final ItemStack aStack, final double aAmount, final EntityLivingBase aPlayer) { + this.chargeFromArmor(aStack, aPlayer); + if (aPlayer instanceof EntityPlayer && ((EntityPlayer) aPlayer).capabilities.isCreativeMode) { + return true; + } + final double tTransfer = this.discharge(aStack, aAmount, Integer.MAX_VALUE, true, false, true); + if (tTransfer == aAmount) { + this.discharge(aStack, aAmount, Integer.MAX_VALUE, true, false, false); + this.chargeFromArmor(aStack, aPlayer); + return true; + } + this.discharge(aStack, aAmount, Integer.MAX_VALUE, true, false, false); + this.chargeFromArmor(aStack, aPlayer); + return false; } } diff --git a/src/Java/gtPlusPlus/core/item/base/BaseItemBackpack.java b/src/Java/gtPlusPlus/core/item/base/BaseItemBackpack.java index aa5bb3f0ea..eb61454f15 100644 --- a/src/Java/gtPlusPlus/core/item/base/BaseItemBackpack.java +++ b/src/Java/gtPlusPlus/core/item/base/BaseItemBackpack.java @@ -16,74 +16,74 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; -public class BaseItemBackpack extends Item{ - - protected final int colourValue; - protected final String unlocalName; - - - public BaseItemBackpack(String unlocalizedName, int colour){ - this.unlocalName = unlocalizedName; - this.setUnlocalizedName(unlocalizedName); - this.setTextureName(CORE.MODID + ":" + "itemBackpack"); - this.colourValue = colour; - GameRegistry.registerItem(this, unlocalizedName); - GT_OreDictUnificator.registerOre("storageBackpack", ItemUtils.getSimpleStack(this)); - setMaxStackSize(1); - setCreativeTab(AddToCreativeTab.tabOther); +public class BaseItemBackpack extends Item { + + protected final int colourValue; + protected final String unlocalName; + + public BaseItemBackpack(final String unlocalizedName, final int colour) { + this.unlocalName = unlocalizedName; + this.setUnlocalizedName(unlocalizedName); + this.setTextureName(CORE.MODID + ":" + "itemBackpack"); + this.colourValue = colour; + GameRegistry.registerItem(this, unlocalizedName); + GT_OreDictUnificator.registerOre("storageBackpack", ItemUtils.getSimpleStack(this)); + this.setMaxStackSize(1); + this.setCreativeTab(AddToCreativeTab.tabOther); + } + + @Override + public int getColorFromItemStack(final ItemStack stack, final int HEX_OxFFFFFF) { + if (this.colourValue == 0) { + return MathUtils.generateSingularRandomHexValue(); + } + return this.colourValue; + + } + + @Override + public String getItemStackDisplayName(final ItemStack p_77653_1_) { + // Name Formatting. + String temp = this.unlocalName.replace("backpack", ""); + // Lets find the colour. + if (temp.toLowerCase().contains("dark")) { + temp = this.unlocalName.substring(12, this.unlocalName.length()); + temp = "Dark " + temp; + } + return temp + " Backpack"; } // Without this method, your inventory will NOT work!!! @Override - public int getMaxItemUseDuration(ItemStack stack) { + public int getMaxItemUseDuration(final ItemStack stack) { return 1; // return any value greater than zero } - - @Override - public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player) - { - if (!world.isRemote) - { + + @Override + public ItemStack onItemRightClick(final ItemStack itemstack, final World world, final EntityPlayer player) { + if (!world.isRemote) { // If player not sneaking, open the inventory gui if (!player.isSneaking()) { player.openGui(GTplusplus.instance, GuiHandler.GUI3, world, 0, 0, 0); } - - // Otherwise, stealthily place some diamonds in there for a nice surprise next time you open it up :) + + // Otherwise, stealthily place some diamonds in there for a nice + // surprise next time you open it up :) else { - // Utils.LOG_INFO("Player is Sneaking, giving them sneaky diamonds."); - // new BaseInventoryBackpack(player.getHeldItem()).setInventorySlotContents(0, new ItemStack(Items.diamond,4)); + // Utils.LOG_INFO("Player is Sneaking, giving them sneaky + // diamonds."); + // new + // BaseInventoryBackpack(player.getHeldItem()).setInventorySlotContents(0, + // new ItemStack(Items.diamond,4)); } } - + return itemstack; } - - @Override - public int getColorFromItemStack(ItemStack stack, int HEX_OxFFFFFF) { - if (colourValue == 0){ - return MathUtils.generateSingularRandomHexValue(); - } - return colourValue; - - } - - @Override - public String getItemStackDisplayName(ItemStack p_77653_1_) { - //Name Formatting. - String temp = unlocalName.replace("backpack", ""); - //Lets find the colour. - if (temp.toLowerCase().contains("dark")){ - temp = unlocalName.substring(12, unlocalName.length()); - temp = "Dark "+ temp; - } - return (temp+" Backpack"); - } @Override @SideOnly(Side.CLIENT) - public void registerIcons(IIconRegister iconRegister) - { + public void registerIcons(final IIconRegister iconRegister) { this.itemIcon = iconRegister.registerIcon(CORE.MODID + ":" + "itemBackpack"); } } diff --git a/src/Java/gtPlusPlus/core/item/base/BaseItemBrain.java b/src/Java/gtPlusPlus/core/item/base/BaseItemBrain.java index 018f4e8e22..1a1c6fd3c9 100644 --- a/src/Java/gtPlusPlus/core/item/base/BaseItemBrain.java +++ b/src/Java/gtPlusPlus/core/item/base/BaseItemBrain.java @@ -12,8 +12,8 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.StatCollector; /* - * - * + * + * Key Point: You can access the NBT compound data from the Item class (in those methods that pass an ItemStack), but the NBT compound can only be set on an ItemStack. The steps to add NBT data to an ItemStack: @@ -21,88 +21,80 @@ import net.minecraft.util.StatCollector; Create an NBTTagCompound and fill it with the appropriate data Call ItemStack#setTagCompound() method to set it. - * + * */ -public class BaseItemBrain extends Item{ +public class BaseItemBrain extends Item { // This is an array of all the types I am going to be adding. - String[] brainTypes = { "dead", "preserved", "fresh", "tasty" }; + String[] brainTypes = { + "dead", "preserved", "fresh", "tasty" + }; - // This method allows us to have different language translation keys for - // each item we add. + // This code will allow us to tell the items apart in game. You can change + @SuppressWarnings("unchecked") + // texture based on nbt data, but I won't be covering that. @Override - public String getUnlocalizedName(ItemStack stack) - { - // This makes sure that the stack has a tag compound. This is how data - // is stored on items. - if (stack.hasTagCompound()) + @SideOnly(Side.CLIENT) + public void addInformation(final ItemStack stack, final EntityPlayer player, final List tooltip, + final boolean isAdvanced) { + if (stack.hasTagCompound() && stack.getTagCompound().hasKey("brainType")) { + // StatCollector is a class which allows us to handle string + // language translation. This requires that you fill out the + // translation in you language class. + tooltip.add(StatCollector + .translateToLocal("tooltip.yourmod." + stack.getTagCompound().getString("brainType") + ".desc")); + } + else // If the brain does not have valid tag data, a default message { - // This is the object holding all of the item data. - NBTTagCompound itemData = stack.getTagCompound(); - // This checks to see if the item has data stored under the - // brainType key. - if (itemData.hasKey("brainType")) - { - // This retrieves data from the brainType key and uses it in - // the return value - return "item." + itemData.getString("brainType"); - } + tooltip.add(StatCollector.translateToLocal("tooltip.yourmod.nullbrain.desc")); } - // This will be used if the item is obtained without nbt data on it. - return "item.nullBrain"; } - // This is a fun method which allows us to run some code when our item is - // shown in a creative tab. I am going to use it to add all the brain + // shown in a creative tab. I am going to use it to add all the brain // types. @SuppressWarnings("unchecked") @Override @SideOnly(Side.CLIENT) - public void getSubItems(Item item, CreativeTabs tab, List itemList) - { + public void getSubItems(final Item item, final CreativeTabs tab, final List itemList) { // This creates a loop with a counter. It will go through once for - // every listing in brainTypes, and gives us a number associated + // every listing in brainTypes, and gives us a number associated // with each listing. - for (int pos = 0; pos < brainTypes.length; pos++) - { - // This creates a new ItemStack instance. The item parameter + for (int pos = 0; pos < this.brainTypes.length; pos++) { + // This creates a new ItemStack instance. The item parameter // supplied is this item. - ItemStack brainStack = new ItemStack(item); - // By default, a new ItemStack does not have any nbt compound data. + final ItemStack brainStack = new ItemStack(item); + // By default, a new ItemStack does not have any nbt compound data. // We need to give it some. brainStack.setTagCompound(new NBTTagCompound()); - // Now we set the type of the item, brainType is the key, and + // Now we set the type of the item, brainType is the key, and // brainTypes[pos] is grabbing a // entry from the brainTypes array. - brainStack.getTagCompound().setString("brainType", - brainTypes[pos]); + brainStack.getTagCompound().setString("brainType", this.brainTypes[pos]); // And this adds it to the itemList, which is a list of all items // in the creative tab. itemList.add(brainStack); } } - // This code will allow us to tell the items apart in game. You can change - @SuppressWarnings("unchecked") - // texture based on nbt data, but I won't be covering that. + // This method allows us to have different language translation keys for + // each item we add. @Override - @SideOnly(Side.CLIENT) - public void addInformation(ItemStack stack, EntityPlayer player, List tooltip, boolean isAdvanced){ - if ( stack.hasTagCompound() - && stack.getTagCompound().hasKey("brainType")) - { - // StatCollector is a class which allows us to handle string - // language translation. This requires that you fill out the - // translation in you language class. - tooltip.add(StatCollector.translateToLocal("tooltip.yourmod." - + stack.getTagCompound().getString("brainType") + ".desc")); - } - else // If the brain does not have valid tag data, a default message - { - tooltip.add(StatCollector.translateToLocal( - "tooltip.yourmod.nullbrain.desc")); + public String getUnlocalizedName(final ItemStack stack) { + // This makes sure that the stack has a tag compound. This is how data + // is stored on items. + if (stack.hasTagCompound()) { + // This is the object holding all of the item data. + final NBTTagCompound itemData = stack.getTagCompound(); + // This checks to see if the item has data stored under the + // brainType key. + if (itemData.hasKey("brainType")) { + // This retrieves data from the brainType key and uses it in + // the return value + return "item." + itemData.getString("brainType"); + } } + // This will be used if the item is obtained without nbt data on it. + return "item.nullBrain"; } } - diff --git a/src/Java/gtPlusPlus/core/item/base/BaseItemComponent.java b/src/Java/gtPlusPlus/core/item/base/BaseItemComponent.java index d4be10d392..f03b5ac83f 100644 --- a/src/Java/gtPlusPlus/core/item/base/BaseItemComponent.java +++ b/src/Java/gtPlusPlus/core/item/base/BaseItemComponent.java @@ -16,80 +16,106 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import net.minecraft.world.World; -public class BaseItemComponent extends Item{ +public class BaseItemComponent extends Item { - public final Material componentMaterial; - public final String materialName; - public final String unlocalName; - public final ComponentTypes componentType; + public static enum ComponentTypes { + DUST("Dust", " Dust", "dust"), INGOT("Ingot", " Ingot", "ingot"), PLATE("Plate", " Plate", + "plate"), PLATEDOUBLE("PlateDouble", " Double Plate", "plateDouble"), ROD("Rod", " Rod", + "stick"), RODLONG("RodLong", " Long Rod", "stickLong"), GEAR("Gear", " Gear", "gear"), SCREW( + "Screw", " Screw", "screw"), BOLT("Bolt", " Bolt", "bolt"), ROTOR("Rotor", " Rotor", + "rotor"), RING("Ring", " Ring", "ring"), CELL("Cell", " Cell", + "cell"), NUGGET("Nugget", " Nugget", "nugget"); + + private String COMPONENT_NAME; + private String DISPLAY_NAME; + private String OREDICT_NAME; + + private ComponentTypes(final String LocalName, final String DisplayName, final String OreDictName) { + this.COMPONENT_NAME = LocalName; + this.DISPLAY_NAME = DisplayName; + this.OREDICT_NAME = OreDictName; + } + + public String getComponent() { + return this.COMPONENT_NAME; + } + + public String getName() { + return this.DISPLAY_NAME; + } + + public String getOreDictName() { + return this.OREDICT_NAME; + } - public BaseItemComponent(Material material, ComponentTypes componentType) { + } + public final Material componentMaterial; + public final String materialName; + public final String unlocalName; + + public final ComponentTypes componentType; + + public BaseItemComponent(final Material material, final ComponentTypes componentType) { this.componentMaterial = material; - this.unlocalName = "item"+componentType.COMPONENT_NAME+material.getUnlocalizedName(); + this.unlocalName = "item" + componentType.COMPONENT_NAME + material.getUnlocalizedName(); this.materialName = material.getLocalizedName(); this.componentType = componentType; this.setCreativeTab(AddToCreativeTab.tabMisc); - this.setUnlocalizedName(unlocalName); + this.setUnlocalizedName(this.unlocalName); this.setMaxStackSize(64); - this.setTextureName(CORE.MODID + ":" + "item"+componentType.COMPONENT_NAME); - GameRegistry.registerItem(this, unlocalName); - GT_OreDictUnificator.registerOre(componentType.getOreDictName()+material.getUnlocalizedName(), ItemUtils.getSimpleStack(this)); + this.setTextureName(CORE.MODID + ":" + "item" + componentType.COMPONENT_NAME); + GameRegistry.registerItem(this, this.unlocalName); + GT_OreDictUnificator.registerOre(componentType.getOreDictName() + material.getUnlocalizedName(), + ItemUtils.getSimpleStack(this)); } + @SuppressWarnings({ + "unchecked", "rawtypes" + }) @Override - public String getItemStackDisplayName(ItemStack p_77653_1_) { - - return (componentMaterial.getLocalizedName()+componentType.DISPLAY_NAME); - } - - public final String getMaterialName() { - return materialName; - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Override - public void addInformation(ItemStack stack, EntityPlayer aPlayer, List list, boolean bool) { - - if (materialName != null && materialName != "" && !materialName.equals("")){ + public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) { + if (this.materialName != null && this.materialName != "" && !this.materialName.equals("")) { - if (componentType == ComponentTypes.DUST){ - list.add(EnumChatFormatting.GRAY+"A pile of " + materialName + " dust."); + if (this.componentType == ComponentTypes.DUST) { + list.add(EnumChatFormatting.GRAY + "A pile of " + this.materialName + " dust."); } - if (componentType == ComponentTypes.INGOT){ - list.add(EnumChatFormatting.GRAY+"A solid ingot of " + materialName + "."); - if (materialName != null && materialName != "" && !materialName.equals("") && unlocalName.toLowerCase().contains("ingothot")){ - list.add(EnumChatFormatting.GRAY+"Warning: "+EnumChatFormatting.RED+"Very hot! "+EnumChatFormatting.GRAY+" Avoid direct handling.."); + if (this.componentType == ComponentTypes.INGOT) { + list.add(EnumChatFormatting.GRAY + "A solid ingot of " + this.materialName + "."); + if (this.materialName != null && this.materialName != "" && !this.materialName.equals("") + && this.unlocalName.toLowerCase().contains("ingothot")) { + list.add(EnumChatFormatting.GRAY + "Warning: " + EnumChatFormatting.RED + "Very hot! " + + EnumChatFormatting.GRAY + " Avoid direct handling.."); } } - if (componentType == ComponentTypes.PLATE){ - list.add(EnumChatFormatting.GRAY+"A flat plate of " + materialName + "."); + if (this.componentType == ComponentTypes.PLATE) { + list.add(EnumChatFormatting.GRAY + "A flat plate of " + this.materialName + "."); } - if (componentType == ComponentTypes.PLATEDOUBLE){ - list.add(EnumChatFormatting.GRAY+"A double plate of " + materialName + "."); + if (this.componentType == ComponentTypes.PLATEDOUBLE) { + list.add(EnumChatFormatting.GRAY + "A double plate of " + this.materialName + "."); } - if (componentType == ComponentTypes.ROD){ - list.add(EnumChatFormatting.GRAY+"A 40cm Rod of " + materialName + "."); + if (this.componentType == ComponentTypes.ROD) { + list.add(EnumChatFormatting.GRAY + "A 40cm Rod of " + this.materialName + "."); } - if (componentType == ComponentTypes.RODLONG){ - list.add(EnumChatFormatting.GRAY+"A 80cm Rod of " + materialName + "."); + if (this.componentType == ComponentTypes.RODLONG) { + list.add(EnumChatFormatting.GRAY + "A 80cm Rod of " + this.materialName + "."); } - if (componentType == ComponentTypes.ROTOR){ - list.add(EnumChatFormatting.GRAY+"A Rotor made out of " + materialName + ". "); + if (this.componentType == ComponentTypes.ROTOR) { + list.add(EnumChatFormatting.GRAY + "A Rotor made out of " + this.materialName + ". "); } - if (componentType == ComponentTypes.BOLT){ - list.add(EnumChatFormatting.GRAY+"A small Bolt, constructed from " + materialName + "."); + if (this.componentType == ComponentTypes.BOLT) { + list.add(EnumChatFormatting.GRAY + "A small Bolt, constructed from " + this.materialName + "."); } - if (componentType == ComponentTypes.SCREW){ - list.add(EnumChatFormatting.GRAY+"A 8mm Screw, fabricated out of some " + materialName + "."); + if (this.componentType == ComponentTypes.SCREW) { + list.add(EnumChatFormatting.GRAY + "A 8mm Screw, fabricated out of some " + this.materialName + "."); } - if (componentType == ComponentTypes.GEAR){ - list.add(EnumChatFormatting.GRAY+"A large Gear, constructed from " + materialName + "."); + if (this.componentType == ComponentTypes.GEAR) { + list.add(EnumChatFormatting.GRAY + "A large Gear, constructed from " + this.materialName + "."); } - if (componentType == ComponentTypes.RING){ - list.add(EnumChatFormatting.GRAY+"A " + materialName + " Ring."); + if (this.componentType == ComponentTypes.RING) { + list.add(EnumChatFormatting.GRAY + "A " + this.materialName + " Ring."); } - if (componentMaterial.isRadioactive){ + if (this.componentMaterial.isRadioactive) { list.add(CORE.GT_Tooltip_Radioactive); } @@ -98,62 +124,25 @@ public class BaseItemComponent extends Item{ super.addInformation(stack, aPlayer, list, bool); } - @Override - public int getColorFromItemStack(ItemStack stack, int HEX_OxFFFFFF) { - return componentMaterial.getRgbAsHex(); + public int getColorFromItemStack(final ItemStack stack, final int HEX_OxFFFFFF) { + return this.componentMaterial.getRgbAsHex(); } @Override - public void onUpdate(ItemStack iStack, World world, Entity entityHolding, int p_77663_4_, boolean p_77663_5_) { - EntityUtils.applyRadiationDamageToEntity(componentMaterial.vRadioationLevel, world, entityHolding); - } - - - - + public String getItemStackDisplayName(final ItemStack p_77653_1_) { + return this.componentMaterial.getLocalizedName() + this.componentType.DISPLAY_NAME; + } + public final String getMaterialName() { + return this.materialName; + } - - public static enum ComponentTypes { - DUST("Dust", " Dust", "dust"), - INGOT("Ingot", " Ingot", "ingot"), - PLATE("Plate", " Plate", "plate"), - PLATEDOUBLE("PlateDouble", " Double Plate", "plateDouble"), - ROD("Rod", " Rod", "stick"), - RODLONG("RodLong", " Long Rod", "stickLong"), - GEAR("Gear", " Gear", "gear"), - SCREW("Screw", " Screw", "screw"), - BOLT("Bolt", " Bolt", "bolt"), - ROTOR("Rotor", " Rotor", "rotor"), - RING("Ring", " Ring", "ring"), - CELL("Cell", " Cell", "cell"), - NUGGET("Nugget", " Nugget", "nugget"); - - private String COMPONENT_NAME; - private String DISPLAY_NAME; - private String OREDICT_NAME; - private ComponentTypes (final String LocalName, String DisplayName, String OreDictName){ - this.COMPONENT_NAME = LocalName; - this.DISPLAY_NAME = DisplayName; - this.OREDICT_NAME = OreDictName; - } - - public String getComponent(){ - return COMPONENT_NAME; - } - - public String getName(){ - return DISPLAY_NAME; - } - - public String getOreDictName(){ - return OREDICT_NAME; - } - + @Override + public void onUpdate(final ItemStack iStack, final World world, final Entity entityHolding, final int p_77663_4_, + final boolean p_77663_5_) { + EntityUtils.applyRadiationDamageToEntity(this.componentMaterial.vRadioationLevel, world, entityHolding); } } - - diff --git a/src/Java/gtPlusPlus/core/item