diff options
Diffstat (limited to 'src/Java/gtPlusPlus/core/util')
-rw-r--r-- | src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java | 145 |
1 files changed, 69 insertions, 76 deletions
diff --git a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java index be35c40dd8..cd5583e223 100644 --- a/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java +++ b/src/Java/gtPlusPlus/core/util/minecraft/ItemUtils.java @@ -33,7 +33,6 @@ import gtPlusPlus.core.material.Material; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.core.util.reflect.ReflectionUtils; -import gtPlusPlus.xmod.gregtech.api.enums.GregtechItemList; import gtPlusPlus.xmod.gregtech.api.items.Gregtech_MetaTool; import gtPlusPlus.xmod.gregtech.common.items.MetaGeneratedGregtechTools; import gtPlusPlus.xmod.gregtech.loaders.RecipeGen_DustGeneration; @@ -44,8 +43,8 @@ import net.minecraft.init.Items; import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.Item.ToolMaterial; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; import net.minecraftforge.fluids.FluidStack; @@ -60,13 +59,13 @@ public class ItemUtils { public static ItemStack getSimpleStack(final Block x) { return simpleMetaStack(Item.getItemFromBlock(x), 0, 1); } - + public static ItemStack getSimpleStack(final Block x, int i) { if (i == 0) { return getSimpleStack(x, i, 1); } - + return getSimpleStack(x, 0, i); } @@ -208,29 +207,23 @@ public class ItemUtils { } } - @SuppressWarnings("unused") - public static ItemStack simpleMetaStack(final Item item, final int meta, final int size) { - try { - if (item == null) { - return null; - } - Item em = item; - final Item em1 = item; - Logger.WARNING("Found: " + em1.getUnlocalizedName() + ":" + meta); - if (em1 != null) { - if (null == em) { - em = em1; - } - if (em != null) { - final ItemStack metaStack = new ItemStack(em, size, meta); - return metaStack; - } - } - return null; - } catch (final NullPointerException e) { - // Utils.LOG_ERROR(item.getUnlocalizedName()+" not found. [NULL]"); + public static ItemStack simpleMetaStack(ItemStack simpleStack, int meta, int size) { + return simpleMetaStack(simpleStack.getItem(), meta, size); + } + + public static ItemStack simpleMetaStack(final Item item, int meta, int size) { + if (item == null) { return null; } + if (meta < 0 || meta > Short.MAX_VALUE) { + meta = 0; + } + if (size < 0 || size > 64) { + size = 1; + } + Logger.INFO("Found Metastack: " + item.getUnlocalizedName() + ":" + meta); + final ItemStack metaStack = new ItemStack(item, size, meta); + return metaStack; } public static ItemStack simpleMetaStack(final Block block, final int meta, final int size) { @@ -305,9 +298,9 @@ public class ItemUtils { else { mTemp = Utils.sanitizeString(mTemp); } - - - + + + if (oredictName.contains("rod")) { String s = "stick"+oredictName.substring(3); oredictName = s; @@ -374,7 +367,7 @@ public class ItemUtils { return returnValue.copy(); } } - + Logger.RECIPE(oredictName + " was not valid."); return null; } catch (final Throwable t) { @@ -405,7 +398,7 @@ public class ItemUtils { new BaseItemDustUnique("itemDust" + unlocalizedName, materialName, mChemForm, Colour, "Dust"), new BaseItemDustUnique("itemDustSmall" + unlocalizedName, materialName, mChemForm, Colour, "Small"), new BaseItemDustUnique("itemDustTiny" + unlocalizedName, materialName, mChemForm, Colour, "Tiny") }; - + //Generate Shaped/Shapeless Recipes final ItemStack normalDust = ItemUtils.getSimpleStack(output[0]); @@ -459,7 +452,7 @@ public class ItemUtils { Logger.WARNING("4 Small dust from 1 Dust Recipe: "+materialName+" - Failed"); } } - + return output; } @@ -489,7 +482,7 @@ public class ItemUtils { public static Item[] generateSpecialUseDusts(final Material material, final boolean onlyLargeDust) { return generateSpecialUseDusts(material, onlyLargeDust, false); } - + public static Item[] generateSpecialUseDusts(final Material material, final boolean onlyLargeDust, final boolean disableExtraRecipes) { final String materialName = material.getLocalizedName(); final String unlocalizedName = Utils.sanitizeString(materialName); @@ -697,19 +690,19 @@ public class ItemUtils { public static String[] getArrayStackNamesAsArray(final ItemStack[] aStack) { final String[] itemNames = aStack == null ? new String[] {} : new String[aStack.length]; Logger.INFO(""+aStack.length); - + if (aStack == null || aStack.length < 1) { return itemNames; } - + int arpos = 0; for (final ItemStack alph : aStack) { if (alph == null) { continue; } try { - itemNames[arpos] = alph.getDisplayName(); - arpos++; + itemNames[arpos] = alph.getDisplayName(); + arpos++; } catch (Throwable t) { t.printStackTrace(); @@ -1001,15 +994,15 @@ public class ItemUtils { return true; } - - + + public static IInventory organiseInventory(IInventory aInputInventory) { ItemStack[] p = new ItemStack[aInputInventory.getSizeInventory()]; for (int o = 0; o < aInputInventory.getSizeInventory(); o++) { p[o] = aInputInventory.getStackInSlot(o); } //ItemStack[] g = organiseInventory(p); - + IInventory aTemp = aInputInventory; for (int i = 0; i < p.length; ++i) { for (int j = i + 1; j < p.length; ++j) { @@ -1019,22 +1012,22 @@ public class ItemUtils { } } } - + /* for (int o = 0; o < aInputInventory.getSizeInventory(); o++) { aTemp.setInventorySlotContents(o, g[o]); }*/ return aTemp; } - - + + public static ItemStack[] organiseInventory(ItemStack[] aInputs) { //Update Slots int aInvSize = aInputs.length; ItemStack[] newArray = new ItemStack[aInvSize]; - - + + //Try merge stacks for (int i = 0; i < aInvSize; i++) { for (int i2 = 0; i2 < aInvSize; i2++) { @@ -1048,29 +1041,29 @@ public class ItemUtils { } //Try Merge else { - + if (GT_Utility.areStacksEqual(t1[0], t1[1])) { - while ((t1[0].stackSize < 64 && t1[1].stackSize > 0)) { - t1[0].stackSize++; - t1[1].stackSize--; - if (t1[1].stackSize <= 0) { - t1[1] = null; - break; - } - if (t1[0].stackSize == 64) { - break; - } - } - newArray[i] = t1[1]; - newArray[i2] = t1[0]; + while ((t1[0].stackSize < 64 && t1[1].stackSize > 0)) { + t1[0].stackSize++; + t1[1].stackSize--; + if (t1[1].stackSize <= 0) { + t1[1] = null; + break; + } + if (t1[0].stackSize == 64) { + break; + } + } + newArray[i] = t1[1]; + newArray[i2] = t1[0]; } } } } } - + ItemStack[] newArray2 = new ItemStack[aInvSize]; - + //Move nulls to end int count2 = 0; for (int i = 0; i < aInvSize; i++) @@ -1078,10 +1071,10 @@ public class ItemUtils { newArray2[count2++] = newArray[i]; while (count2 < aInvSize) newArray2[count2++] = null; - + return newArray2; - + } public static String getItemName(ItemStack aStack) { @@ -1092,7 +1085,7 @@ public class ItemUtils { try { aDisplay = ("" + StatCollector .translateToLocal(aStack.getItem().getUnlocalizedNameInefficiently(aStack) + ".name")) - .trim(); + .trim(); if (aStack.hasTagCompound()) { if (aStack.stackTagCompound != null && aStack.stackTagCompound.hasKey("display", 10)) { NBTTagCompound nbttagcompound = aStack.stackTagCompound.getCompoundTag("display"); @@ -1120,7 +1113,7 @@ public class ItemUtils { String aDisplay = null; try { aDisplay = (aStack.getUnlocalizedName()).trim(); - + } catch (Throwable t) { aDisplay = aStack.getItem().getUnlocalizedName(); } @@ -1129,7 +1122,7 @@ public class ItemUtils { } return aDisplay; } - + public static boolean isItemGregtechTool(ItemStack aStack) { if (aStack == null) { return false; @@ -1142,49 +1135,49 @@ public class ItemUtils { } return false; } - + public static boolean isToolWrench(ItemStack aWrench) { if (isItemGregtechTool(aWrench) && (aWrench.getItemDamage() == 16 || aWrench.getItemDamage() == 120 || aWrench.getItemDamage() == 122 || aWrench.getItemDamage() == 124 || aWrench.getItemDamage() == 7734)) { return true; } return false; } - + public static boolean isToolMallet(ItemStack aMallet) { if (isItemGregtechTool(aMallet) && (aMallet.getItemDamage() == 14)) { return true; } return false; } - + public static boolean isToolScrewdriver(ItemStack aScrewdriver) { if (isItemGregtechTool(aScrewdriver) && (aScrewdriver.getItemDamage() == 22 || aScrewdriver.getItemDamage() == 150)) { return true; } return false; } - + public static boolean isToolCrowbar(ItemStack aCrowbar) { if (isItemGregtechTool(aCrowbar) && (aCrowbar.getItemDamage() == 20)) { return true; } return false; } - + public static boolean isToolWirecutters(ItemStack aWirecutters) { if (isItemGregtechTool(aWirecutters) && (aWirecutters.getItemDamage() == 26)) { return true; } return false; } - + public static boolean isToolHammer(ItemStack aHammer) { if (isItemGregtechTool(aHammer) && (aHammer.getItemDamage() == 12 || aHammer.getItemDamage() == 7734)) { return true; } return false; } - + public static boolean isToolSolderingIron(ItemStack aSoldering) { if (isItemGregtechTool(aSoldering) && (aSoldering.getItemDamage() == 160)) { return true; @@ -1213,7 +1206,7 @@ public class ItemUtils { public static ItemStack getEnchantedBook(Enchantment aEnch, int aLevel) { return enchantItem(new ItemStack(Items.enchanted_book), aEnch, aLevel); } - + public static ItemStack enchantItem(ItemStack aStack, Enchantment aEnch, int aLevel) { Items.enchanted_book.addEnchantment(aStack, new EnchantmentData(aEnch, aLevel)); return aStack; @@ -1226,16 +1219,16 @@ public class ItemUtils { public static void hideItemFromNEI(ItemStack aItemToHide) { codechicken.nei.api.API.hideItem(aItemToHide); } - + public static ItemStack getNullStack() { return GT_Values.NI; } - + public static ItemStack depleteStack(ItemStack aStack) { return depleteStack(aStack, 1); } - + public static ItemStack depleteStack(ItemStack aStack, int aAmount) { final int cap = aStack.stackSize; if (cap > 1 && cap > aAmount) { |