aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/api/util')
-rw-r--r--src/main/java/gregtech/api/util/GT_BaseCrop.java10
-rw-r--r--src/main/java/gregtech/api/util/GT_CoverBehavior.java4
-rw-r--r--src/main/java/gregtech/api/util/GT_FoodStat.java4
-rw-r--r--src/main/java/gregtech/api/util/GT_ModHandler.java57
-rw-r--r--src/main/java/gregtech/api/util/GT_OreDictUnificator.java8
-rw-r--r--src/main/java/gregtech/api/util/GT_Recipe.java30
-rw-r--r--src/main/java/gregtech/api/util/GT_RecipeRegistrator.java150
-rw-r--r--src/main/java/gregtech/api/util/GT_Utility.java32
8 files changed, 163 insertions, 132 deletions
diff --git a/src/main/java/gregtech/api/util/GT_BaseCrop.java b/src/main/java/gregtech/api/util/GT_BaseCrop.java
index c06bf82b89..97f8db0547 100644
--- a/src/main/java/gregtech/api/util/GT_BaseCrop.java
+++ b/src/main/java/gregtech/api/util/GT_BaseCrop.java
@@ -68,7 +68,7 @@ public class GT_BaseCrop extends CropCard implements ICropCardInfo {
aID = GT_Config.addIDConfig(ConfigCategories.IDs.crops, mName.replaceAll(" ", "_"), aID);
if (aDiscoveredBy != null && !aDiscoveredBy.equals(E)) mDiscoveredBy = aDiscoveredBy;
if (aDrop != null && aID > 0 && aID < 256) {
- mDrop = GT_Utility.copy(aDrop);
+ mDrop = GT_Utility.copyOrNull(aDrop);
mSpecialDrops = aSpecialDrops;
mTier = Math.max(1, aTier);
mMaxSize = Math.max(3, aMaxSize);
@@ -177,9 +177,9 @@ public class GT_BaseCrop extends CropCard implements ICropCardInfo {
public ItemStack getGain(ICropTile aCrop) {
int tDrop = 0;
if (mSpecialDrops != null && (tDrop = java.util.concurrent.ThreadLocalRandom.current().nextInt(0, (mSpecialDrops.length*2) + 2)) < mSpecialDrops.length && mSpecialDrops[tDrop] != null) {
- return GT_Utility.copy(mSpecialDrops[tDrop]);
+ return GT_Utility.copyOrNull(mSpecialDrops[tDrop]);
}
- return GT_Utility.copy(mDrop);
+ return GT_Utility.copyOrNull(mDrop);
}
@Override
@@ -247,9 +247,9 @@ public class GT_BaseCrop extends CropCard implements ICropCardInfo {
@Override
public ItemStack getDisplayItem() {
if (mSpecialDrops != null && mSpecialDrops[mSpecialDrops.length - 1] != null) {
- return GT_Utility.copy(mSpecialDrops[mSpecialDrops.length - 1]);
+ return GT_Utility.copyOrNull(mSpecialDrops[mSpecialDrops.length - 1]);
}
- return GT_Utility.copy(mDrop);
+ return GT_Utility.copyOrNull(mDrop);
}
}
diff --git a/src/main/java/gregtech/api/util/GT_CoverBehavior.java b/src/main/java/gregtech/api/util/GT_CoverBehavior.java
index ebd3a98d55..14c8cc1308 100644
--- a/src/main/java/gregtech/api/util/GT_CoverBehavior.java
+++ b/src/main/java/gregtech/api/util/GT_CoverBehavior.java
@@ -18,6 +18,10 @@ public abstract class GT_CoverBehavior {
public EntityPlayer lastPlayer = null;
+ public boolean isRedstoneSensitive(byte aSide, int aCoverID, int aCoverVariable, ICoverable aTileEntity, long aTimer) {
+ return true;
+ }
+
/**
* Called by updateEntity inside the covered TileEntity. aCoverVariable is the Value you returned last time.
*/
diff --git a/src/main/java/gregtech/api/util/GT_FoodStat.java b/src/main/java/gregtech/api/util/GT_FoodStat.java
index ce89881a5b..193977476a 100644
--- a/src/main/java/gregtech/api/util/GT_FoodStat.java
+++ b/src/main/java/gregtech/api/util/GT_FoodStat.java
@@ -36,7 +36,7 @@ public class GT_FoodStat implements IFoodStat {
mSaturation = aSaturation;
mAction = aAction == null ? EnumAction.eat : aAction;
mPotionEffects = aPotionEffects;
- mEmptyContainer = GT_Utility.copy(aEmptyContainer);
+ mEmptyContainer = GT_Utility.copyOrNull(aEmptyContainer);
mInvisibleParticles = aInvisibleParticles;
mAlwaysEdible = aAlwaysEdible;
mIsRotten = aIsRotten;
@@ -65,7 +65,7 @@ public class GT_FoodStat implements IFoodStat {
@Override
public void onEaten(GT_MetaBase_Item aItem, ItemStack aStack, EntityPlayer aPlayer) {
aStack.stackSize--;
- ItemStack tStack = GT_OreDictUnificator.get(GT_Utility.copy(mEmptyContainer));
+ ItemStack tStack = GT_OreDictUnificator.get(GT_Utility.copyOrNull(mEmptyContainer));
if (tStack != null && !aPlayer.inventory.addItemStackToInventory(tStack))
aPlayer.dropPlayerItemWithRandomChoice(tStack, true);
diff --git a/src/main/java/gregtech/api/util/GT_ModHandler.java b/src/main/java/gregtech/api/util/GT_ModHandler.java
index f82b0ecb7e..7e66e6cc2a 100644
--- a/src/main/java/gregtech/api/util/GT_ModHandler.java
+++ b/src/main/java/gregtech/api/util/GT_ModHandler.java
@@ -460,8 +460,8 @@ public class GT_ModHandler {
aChance = (float) GregTech_API.sRecipeFile.get(ConfigCategories.Machines.scrapboxdrops, aOutput, aChance);
if (aChance <= 0) return false;
try {
- GT_Utility.callMethod(GT_Utility.getFieldContent("ic2.api.recipe.Recipes", "scrapboxDrops", true, true), "addDrop", true, false, true, GT_Utility.copy(aOutput), aChance);
- GT_Utility.callMethod(GT_Utility.getFieldContent("ic2.api.recipe.Recipes", "scrapboxDrops", true, true), "addRecipe", true, true, false, GT_Utility.copy(aOutput), aChance);
+ GT_Utility.callMethod(GT_Utility.getFieldContent("ic2.api.recipe.Recipes", "scrapboxDrops", true, true), "addDrop", true, false, true, GT_Utility.copyOrNull(aOutput), aChance);
+ GT_Utility.callMethod(GT_Utility.getFieldContent("ic2.api.recipe.Recipes", "scrapboxDrops", true, true), "addRecipe", true, true, false, GT_Utility.copyOrNull(aOutput), aChance);
} catch (Throwable e) {/*Do nothing*/}
return true;
}
@@ -484,7 +484,7 @@ public class GT_ModHandler {
aOutput = GT_OreDictUnificator.get(true, aOutput);
if (aInput == null || aOutput == null || GT_Utility.getContainerItem(aInput, false) != null) return false;
if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.smelting, aInput, true)) return false;
- FurnaceRecipes.smelting().func_151394_a(aInput, GT_Utility.copy(aOutput), 0.0F);
+ FurnaceRecipes.smelting().func_151394_a(aInput, GT_Utility.copyOrNull(aOutput), 0.0F);
return true;
}
@@ -562,8 +562,8 @@ public class GT_ModHandler {
aOutput = GT_OreDictUnificator.get(true, aOutput);
if (aInput == null || aOutput == null || aTime <= 0) return false;
if (!GregTech_API.sRecipeFile.get(ConfigCategories.Machines.rcblastfurnace, aInput, true)) return false;
- aInput = GT_Utility.copy(aInput);
- aOutput = GT_Utility.copy(aOutput);
+ aInput = GT_Utility.copyOrNull(aInput);
+ aOutput = GT_Utility.copyOrNull(aOutput);
try {
mods.railcraft.api.crafting.RailcraftCraftingManager.blastFurnace.addRecipe(aInput, true, false, aTime, aOutput);
} catch (Throwable e) {
@@ -614,28 +614,28 @@ public class GT_ModHandler {
if (Materials.Wood.contains(aOutput1)) {
if (aEnableTEMachineRecipes && GregTech_API.sRecipeFile.get(ConfigCategories.Machines.pulverization, aInput, true)) {
if (aOutput2 == null)
- ThermalExpansion.addSawmillRecipe(32000, GT_Utility.copy(aInput), GT_Utility.copy(aOutput1));
+ ThermalExpansion.addSawmillRecipe(32000, GT_Utility.copyOrNull(aInput), GT_Utility.copyOrNull(aOutput1));
else
- ThermalExpansion.addSawmillRecipe(32000, GT_Utility.copy(aInput), GT_Utility.copy(aOutput1), GT_Utility.copy(aOutput2), aChance2 <= 0 ? 10 : aChance2);
+ ThermalExpansion.addSawmillRecipe(32000, GT_Utility.copyOrNull(aInput), GT_Utility.copyOrNull(aOutput1), GT_Utility.copyOrNull(aOutput2), aChance2 <= 0 ? 10 : aChance2);
}
} else {
if (GregTech_API.sRecipeFile.get(ConfigCategories.Machines.rockcrushing, aInput, true)) {
try {
if (GT_Utility.getBlockFromStack(aInput) != Blocks.obsidian && GT_Utility.getBlockFromStack(aInput) != Blocks.gravel) {
mods.railcraft.api.crafting.IRockCrusherRecipe tRecipe = mods.railcraft.api.crafting.RailcraftCraftingManager.rockCrusher.createNewRecipe(GT_Utility.copyAmount(1, aInput), aInput.getItemDamage() != W, false);
- tRecipe.addOutput(GT_Utility.copy(aOutput1), 1.0F / aInput.stackSize);
+ tRecipe.addOutput(GT_Utility.copyOrNull(aOutput1), 1.0F / aInput.stackSize);
if (aOutput2 != null)
- tRecipe.addOutput(GT_Utility.copy(aOutput2), (0.01F * (aChance2 <= 0 ? 10 : aChance2)) / aInput.stackSize);
+ tRecipe.addOutput(GT_Utility.copyOrNull(aOutput2), (0.01F * (aChance2 <= 0 ? 10 : aChance2)) / aInput.stackSize);
if (aOutput3 != null)
- tRecipe.addOutput(GT_Utility.copy(aOutput3), (0.01F * (aChance3 <= 0 ? 10 : aChance3)) / aInput.stackSize);
+ tRecipe.addOutput(GT_Utility.copyOrNull(aOutput3), (0.01F * (aChance3 <= 0 ? 10 : aChance3)) / aInput.stackSize);
}
} catch (Throwable e) {/*Do nothing*/}
}
if (aEnableTEMachineRecipes && GregTech_API.sRecipeFile.get(ConfigCategories.Machines.pulverization, aInput, true)) {
if (aOutput2 == null)
- ThermalExpansion.addPulverizerRecipe(32000, GT_Utility.copy(aInput), GT_Utility.copy(aOutput1));
+ ThermalExpansion.addPulverizerRecipe(32000, GT_Utility.copyOrNull(aInput), GT_Utility.copyOrNull(aOutput1));
else
- ThermalExpansion.addPulverizerRecipe(32000, GT_Utility.copy(aInput), GT_Utility.copy(aOutput1), GT_Utility.copy(aOutput2), aChance2 <= 0 ? 10 : aChance2);
+ ThermalExpansion.addPulverizerRecipe(32000, GT_Utility.copyOrNull(aInput), GT_Utility.copyOrNull(aOutput1), GT_Utility.copyOrNull(aOutput2), aChance2 <= 0 ? 10 : aChance2);
}
}
}
@@ -702,7 +702,7 @@ public class GT_ModHandler {
if (!GT_Mod.gregtechproxy.mTEMachineRecipes && !GregTech_API.sRecipeFile.get(ConfigCategories.Machines.inductionsmelter, aInput2 == null ? aInput1 : aOutput1, true))
return false;
try {
- ThermalExpansion.addSmelterRecipe(aEnergy * 10, GT_Utility.copy(aInput1), aInput2 == null ? new ItemStack(Blocks.sand, 1, 0) : aInput2, aOutput1, aOutput2, aChance);
+ ThermalExpansion.addSmelterRecipe(aEnergy * 10, GT_Utility.copyOrNull(aInput1), aInput2 == null ? new ItemStack(Blocks.sand, 1, 0) : aInput2, aOutput1, aOutput2, aChance);
} catch (Throwable e) {/*Do nothing*/}
return true;
}
@@ -713,7 +713,7 @@ public class GT_ModHandler {
public static boolean addOreToIngotSmeltingRecipe(ItemStack aInput, ItemStack aOutput) {
aOutput = GT_OreDictUnificator.get(true, aOutput);
if (aInput == null || aOutput == null) return false;
- FurnaceRecipes.smelting().func_151394_a(aInput, GT_Utility.copy(aOutput), 0.0F);
+ FurnaceRecipes.smelting().func_151394_a(aInput, GT_Utility.copyOrNull(aOutput), 0.0F);
return true;
}
@@ -847,9 +847,9 @@ public class GT_ModHandler {
aResult = GT_OreDictUnificator.get(true, aResult);
if (aResult == null || aRecipe == null || aResult.stackSize <= 0) return false;
try {
- mods.railcraft.api.crafting.RailcraftCraftingManager.rollingMachine.getRecipeList().add(new ShapedOreRecipe(GT_Utility.copy(aResult), aRecipe));
+ mods.railcraft.api.crafting.RailcraftCraftingManager.rollingMachine.getRecipeList().add(new ShapedOreRecipe(GT_Utility.copyOrNull(aResult), aRecipe));
} catch (Throwable e) {
- return addCraftingRecipe(GT_Utility.copy(aResult), aRecipe);
+ return addCraftingRecipe(GT_Utility.copyOrNull(aResult), aRecipe);
}
return true;
}
@@ -1084,8 +1084,9 @@ public class GT_ModHandler {
Character chr = (Character) aRecipe[idx];
Object in = aRecipe[idx + 1];
if (in instanceof ItemStack) {
- tItemStackMap.put(chr, GT_Utility.copy(in));
- tItemDataMap.put(chr, GT_OreDictUnificator.getItemData((ItemStack) in));
+ ItemStack is = (ItemStack) in;
+ tItemStackMap.put(chr, GT_Utility.copyOrNull(is));
+ tItemDataMap.put(chr, GT_OreDictUnificator.getItemData(is));
} else if (in instanceof ItemData) {
String tString = in.toString();
switch (tString) {
@@ -1184,9 +1185,9 @@ public class GT_ModHandler {
if (tThereWasARecipe || !aOnlyAddIfThereIsAnyRecipeOutputtingThis) {
if (sBufferCraftingRecipes && aBuffered)
- sBufferRecipeList.add(new GT_Shaped_Recipe(GT_Utility.copy(aResult), aDismantleable, aRemovable, aKeepNBT, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe).setMirrored(aMirrored));
+ sBufferRecipeList.add(new GT_Shaped_Recipe(GT_Utility.copyOrNull(aResult), aDismantleable, aRemovable, aKeepNBT, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe).setMirrored(aMirrored));
else
- GameRegistry.addRecipe(new GT_Shaped_Recipe(GT_Utility.copy(aResult), aDismantleable, aRemovable, aKeepNBT, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe).setMirrored(aMirrored));
+ GameRegistry.addRecipe(new GT_Shaped_Recipe(GT_Utility.copyOrNull(aResult), aDismantleable, aRemovable, aKeepNBT, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe).setMirrored(aMirrored));
}
return true;
}
@@ -1260,9 +1261,9 @@ public class GT_ModHandler {
GT_Utility.updateItemStack(aResult);
if (sBufferCraftingRecipes && aBuffered)
- sBufferRecipeList.add(new GT_Shapeless_Recipe(GT_Utility.copy(aResult), aDismantleable, aRemovable, aKeepNBT, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe));
+ sBufferRecipeList.add(new GT_Shapeless_Recipe(GT_Utility.copyOrNull(aResult), aDismantleable, aRemovable, aKeepNBT, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe));
else
- GameRegistry.addRecipe(new GT_Shapeless_Recipe(GT_Utility.copy(aResult), aDismantleable, aRemovable, aKeepNBT, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe));
+ GameRegistry.addRecipe(new GT_Shapeless_Recipe(GT_Utility.copyOrNull(aResult), aDismantleable, aRemovable, aKeepNBT, aEnchantmentsAdded, aEnchantmentLevelsAdded, aRecipe));
return true;
}
@@ -1531,7 +1532,7 @@ public class GT_ModHandler {
throw new GT_ItsNotMyFaultException("Seems another Mod added a Crafting Recipe with null Output. Tell the Developer of said Mod to fix that.");
} else {
if (aUncopiedStack) return tOutput;
- return GT_Utility.copy(tOutput);
+ return GT_Utility.copyOrNull(tOutput);
}
}
}
@@ -1679,7 +1680,7 @@ public class GT_ModHandler {
if (tRecipe instanceof ShapelessRecipes) continue;
if (tRecipe instanceof ShapelessOreRecipe) continue;
if (tRecipe instanceof IGT_CraftingRecipe) continue;
- rList.add(GT_Utility.copy(tOutput));
+ rList.add(GT_Utility.copyOrNull(tOutput));
aList.remove(i--);
}
}
@@ -1691,7 +1692,7 @@ public class GT_ModHandler {
*/
@Deprecated
public static ItemStack getMaceratorOutput(ItemStack aInput, boolean aRemoveInput, ItemStack aOutputSlot) {
- return GT_Utility.copy(getMachineOutput(aInput, getMaceratorRecipeList(), aRemoveInput, new NBTTagCompound(), aOutputSlot)[0]);
+ return GT_Utility.copyOrNull(getMachineOutput(aInput, getMaceratorRecipeList(), aRemoveInput, new NBTTagCompound(), aOutputSlot)[0]);
}
/**
@@ -1699,7 +1700,7 @@ public class GT_ModHandler {
*/
@Deprecated
public static ItemStack getExtractorOutput(ItemStack aInput, boolean aRemoveInput, ItemStack aOutputSlot) {
- return GT_Utility.copy(getMachineOutput(aInput, getExtractorRecipeList(), aRemoveInput, new NBTTagCompound(), aOutputSlot)[0]);
+ return GT_Utility.copyOrNull(getMachineOutput(aInput, getExtractorRecipeList(), aRemoveInput, new NBTTagCompound(), aOutputSlot)[0]);
}
/**
@@ -1707,7 +1708,7 @@ public class GT_ModHandler {
*/
@Deprecated
public static ItemStack getCompressorOutput(ItemStack aInput, boolean aRemoveInput, ItemStack aOutputSlot) {
- return GT_Utility.copy(getMachineOutput(aInput, getCompressorRecipeList(), aRemoveInput, new NBTTagCompound(), aOutputSlot)[0]);
+ return GT_Utility.copyOrNull(getMachineOutput(aInput, getCompressorRecipeList(), aRemoveInput, new NBTTagCompound(), aOutputSlot)[0]);
}
/**
@@ -1748,7 +1749,7 @@ public class GT_ModHandler {
for (byte i = 0; i < aOutputSlots.length && i < tList.length; i++) {
if (tList[i] != null) {
if (aOutputSlots[i] == null || (GT_Utility.areStacksEqual(tList[i], aOutputSlots[i]) && tList[i].stackSize + aOutputSlots[i].stackSize <= aOutputSlots[i].getMaxStackSize())) {
- rList[i] = GT_Utility.copy(tList[i]);
+ rList[i] = GT_Utility.copyOrNull(tList[i]);
} else {
return new ItemStack[aOutputSlots.length];
}
diff --git a/src/main/java/gregtech/api/util/GT_OreDictUnificator.java b/src/main/java/gregtech/api/util/GT_OreDictUnificator.java
index 98809bbf45..54ef5b2866 100644
--- a/src/main/java/gregtech/api/util/GT_OreDictUnificator.java
+++ b/src/main/java/gregtech/api/util/GT_OreDictUnificator.java
@@ -123,7 +123,7 @@ public class GT_OreDictUnificator {
}
public static ItemStack[] setStackArray(boolean aUseBlackList, ItemStack... aStacks) {
- for (int i = 0; i < aStacks.length; i++) aStacks[i] = get(aUseBlackList, GT_Utility.copy(aStacks[i]));
+ for (int i = 0; i < aStacks.length; i++) aStacks[i] = get(aUseBlackList, GT_Utility.copyOrNull(aStacks[i]));
return aStacks;
}
@@ -155,15 +155,15 @@ public class GT_OreDictUnificator {
ItemData tPrefixMaterial = getAssociation(aStack);
ItemStack rStack = null;
if (tPrefixMaterial == null || !tPrefixMaterial.hasValidPrefixMaterialData() || (aUseBlackList && tPrefixMaterial.mBlackListed))
- return GT_Utility.copy(aStack);
+ return GT_Utility.copyOrNull(aStack);
if (aUseBlackList && !GregTech_API.sUnificationEntriesRegistered && isBlacklisted(aStack)) {
tPrefixMaterial.mBlackListed = true;
- return GT_Utility.copy(aStack);
+ return GT_Utility.copyOrNull(aStack);
}
if (tPrefixMaterial.mUnificationTarget == null)
tPrefixMaterial.mUnificationTarget = sName2StackMap.get(tPrefixMaterial.toString());
rStack = tPrefixMaterial.mUnificationTarget;
- if (GT_Utility.isStackInvalid(rStack)) return GT_Utility.copy(aStack);
+ if (GT_Utility.isStackInvalid(rStack)) return GT_Utility.copyOrNull(aStack);
assert rStack != null;
rStack.setTagCompound(aStack.getTagCompound());
return GT_Utility.copyAmount(aStack.stackSize, rStack);
diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java
index aa54b55277..a04df205b7 100644
--- a/src/main/java/gregtech/api/util/GT_Recipe.java
+++ b/src/main/java/gregtech/api/util/GT_Recipe.java
@@ -23,6 +23,7 @@ import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidContainerItem;
import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import static gregtech.api.enums.GT_Values.*;
@@ -312,12 +313,12 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
public ItemStack getRepresentativeInput(int aIndex) {
if (aIndex < 0 || aIndex >= mInputs.length) return null;
- return GT_Utility.copy(mInputs[aIndex]);
+ return GT_Utility.copyOrNull(mInputs[aIndex]);
}
public ItemStack getOutput(int aIndex) {
if (aIndex < 0 || aIndex >= mOutputs.length) return null;
- return GT_Utility.copy(mOutputs[aIndex]);
+ return GT_Utility.copyOrNull(mOutputs[aIndex]);
}
public int getOutputChance(int aIndex) {
@@ -365,6 +366,8 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
public static boolean GTppRecipeHelper;
public boolean isRecipeInputEqual(boolean aDecreaseStacksizeBySuccess, boolean aDontCheckStackSizes, FluidStack[] aFluidInputs, ItemStack... aInputs) {
+
+ if (mInputs.length > 0 && aInputs == null) return false;
if (mFluidInputs.length > 0 && aFluidInputs == null) return false;
int amt;
for (FluidStack tFluid : mFluidInputs)
@@ -386,15 +389,18 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
if (temp) return false;
}
- if (mInputs.length > 0 && aInputs == null) return false;
-
+ HashSet<Integer> isVisited = new HashSet<>();
+
for (ItemStack tStack : mInputs) {
ItemStack unified_tStack = GT_OreDictUnificator.get_nocopy(true, tStack);
if (unified_tStack != null) {
amt = tStack.stackSize;
boolean temp = true;
+ int it = 0;
for (ItemStack aStack : aInputs) {
- if (GT_OreDictUnificator.isInputStackEqual(aStack, unified_tStack)) {
+ it ++;
+ if (GT_OreDictUnificator.isInputStackEqual(aStack, unified_tStack) && !isVisited.contains(it)) {
+ isVisited.add(it);
if (GTppRecipeHelper) {//remove once the fix is out
if (GT_Utility.areStacksEqual(aStack, Ic2Items.FluidCell.copy(), true) || GT_Utility.areStacksEqual(aStack, ItemList.Tool_DataStick.get(1L), true) || GT_Utility.areStacksEqual(aStack, ItemList.Tool_DataOrb.get(1L), true)) {
if (!GT_Utility.areStacksEqual(aStack, tStack, false))
@@ -1215,7 +1221,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
public GT_Recipe findRecipe(IHasWorldObjectAndCoords aTileEntity, GT_Recipe aRecipe, boolean aNotUnificated, long aVoltage, FluidStack[] aFluids, ItemStack aSpecialSlot, ItemStack... aInputs) {
if (aInputs == null || aInputs.length <= 0 || aInputs[0] == null) return null;
if (aRecipe != null && aRecipe.isRecipeInputEqual(false, true, aFluids, aInputs)) return aRecipe;
- ItemStack tComparedInput = GT_Utility.copy(aInputs[0]);
+ ItemStack tComparedInput = GT_Utility.copyOrNull(aInputs[0]);
ItemStack[] tOutputItems = GT_ModHandler.getMachineOutput(tComparedInput, ic2.api.recipe.Recipes.compressor.getRecipes(), true, new NBTTagCompound(), null, null, null);
return GT_Utility.arrayContainsNonNull(tOutputItems) ? new GT_Recipe(false, new ItemStack[]{GT_Utility.copyAmount(aInputs[0].stackSize - tComparedInput.stackSize, aInputs[0])}, tOutputItems, null, null, null, null, 400, 2, 0) : null;
}
@@ -1238,7 +1244,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
public GT_Recipe findRecipe(IHasWorldObjectAndCoords aTileEntity, GT_Recipe aRecipe, boolean aNotUnificated, long aVoltage, FluidStack[] aFluids, ItemStack aSpecialSlot, ItemStack... aInputs) {
if (aInputs == null || aInputs.length <= 0 || aInputs[0] == null) return null;
if (aRecipe != null && aRecipe.isRecipeInputEqual(false, true, aFluids, aInputs)) return aRecipe;
- ItemStack tComparedInput = GT_Utility.copy(aInputs[0]);
+ ItemStack tComparedInput = GT_Utility.copyOrNull(aInputs[0]);
ItemStack[] tOutputItems = GT_ModHandler.getMachineOutput(tComparedInput, ic2.api.recipe.Recipes.extractor.getRecipes(), true, new NBTTagCompound(), null, null, null);
return GT_Utility.arrayContainsNonNull(tOutputItems) ? new GT_Recipe(false, new ItemStack[]{GT_Utility.copyAmount(aInputs[0].stackSize - tComparedInput.stackSize, aInputs[0])}, tOutputItems, null, null, null, null, 400, 2, 0) : null;
}
@@ -1261,7 +1267,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
public GT_Recipe findRecipe(IHasWorldObjectAndCoords aTileEntity, GT_Recipe aRecipe, boolean aNotUnificated, long aVoltage, FluidStack[] aFluids, ItemStack aSpecialSlot, ItemStack... aInputs) {
if (aInputs == null || aInputs.length <= 0 || aInputs[0] == null) return null;
if (aRecipe != null && aRecipe.isRecipeInputEqual(false, true, aFluids, aInputs)) return aRecipe;
- ItemStack tComparedInput = GT_Utility.copy(aInputs[0]);
+ ItemStack tComparedInput = GT_Utility.copyOrNull(aInputs[0]);
ItemStack[] tOutputItems = GT_ModHandler.getMachineOutput(tComparedInput, ic2.api.recipe.Recipes.centrifuge.getRecipes(), true, new NBTTagCompound(), null, null, null);
return GT_Utility.arrayContainsNonNull(tOutputItems) ? new GT_Recipe(false, new ItemStack[]{GT_Utility.copyAmount(aInputs[0].stackSize - tComparedInput.stackSize, aInputs[0])}, tOutputItems, null, null, null, null, 400, 48, 0) : null;
}
@@ -1285,7 +1291,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
if (aInputs == null || aInputs.length <= 0 || aInputs[0] == null || aFluids == null || aFluids.length < 1 || !GT_ModHandler.isWater(aFluids[0]))
return null;
if (aRecipe != null && aRecipe.isRecipeInputEqual(false, true, aFluids, aInputs)) return aRecipe;
- ItemStack tComparedInput = GT_Utility.copy(aInputs[0]);
+ ItemStack tComparedInput = GT_Utility.copyOrNull(aInputs[0]);
NBTTagCompound aRecipeMetaData = new NBTTagCompound();
ItemStack[] tOutputItems = GT_ModHandler.getMachineOutput(tComparedInput, ic2.api.recipe.Recipes.oreWashing.getRecipes(), true, aRecipeMetaData, null, null, null);
return GT_Utility.arrayContainsNonNull(tOutputItems) ? new GT_Recipe(false, new ItemStack[]{GT_Utility.copyAmount(aInputs[0].stackSize - tComparedInput.stackSize, aInputs[0])}, tOutputItems, null, null, new FluidStack[]{new FluidStack(aFluids[0].getFluid(), ((NBTTagCompound) aRecipeMetaData.getTag("return")).getInteger("amount"))}, null, 400, 16, 0) : null;
@@ -1334,7 +1340,7 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
if (D1) GT_Log.err.println("Railcraft Not loaded");
} catch (NullPointerException e) {/**/}
- ItemStack tComparedInput = GT_Utility.copy(aInputs[0]);
+ ItemStack tComparedInput = GT_Utility.copyOrNull(aInputs[0]);
ItemStack[] tOutputItems = GT_ModHandler.getMachineOutput(tComparedInput, ic2.api.recipe.Recipes.macerator.getRecipes(), true, new NBTTagCompound(), null, null, null);
return GT_Utility.arrayContainsNonNull(tOutputItems) ? new GT_Recipe(false, new ItemStack[]{GT_Utility.copyAmount(aInputs[0].stackSize - tComparedInput.stackSize, aInputs[0])}, tOutputItems, null, null, null, null, 400, 2, 0) : null;
}
@@ -1823,13 +1829,13 @@ public class GT_Recipe implements Comparable<GT_Recipe> {
if (mOreDictAlt[aIndex] != null && mOreDictAlt[aIndex].length > 0) {
ItemStack[] rStacks = new ItemStack[mOreDictAlt[aIndex].length];
for (int i = 0; i < mOreDictAlt[aIndex].length; i++) {
- rStacks[i] = GT_Utility.copy(mOreDictAlt[aIndex][i]);
+ rStacks[i] = GT_Utility.copyOrNull(mOreDictAlt[aIndex][i]);
}
return rStacks;
}
}
if (aIndex >= mInputs.length) return null;
- return GT_Utility.copy(mInputs[aIndex]);
+ return GT_Utility.copyOrNull(mInputs[aIndex]);
}
}
diff --git a/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java b/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java
index 0868ff41c8..34cf7ca80e 100644
--- a/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java
+++ b/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java
@@ -1,5 +1,6 @@
package gregtech.api.util;
+import com.google.common.base.Stopwatch;
import gregtech.GT_Mod;
import gregtech.api.GregTech_API;
import gregtech.api.enums.*;
@@ -28,52 +29,52 @@ public class GT_RecipeRegistrator {
public static final List<Materials> sRodMaterialList = new ArrayList<Materials>();
private static final ItemStack sMt1 = new ItemStack(Blocks.dirt, 1, 0), sMt2 = new ItemStack(Blocks.dirt, 1, 0);
private static final String s_H = "h", s_F = "f", s_I = "I", s_P = "P", s_R = "R";
- private static final ItemStack[][]
- sShapes1 = new ItemStack[][]{
- {sMt1, null, sMt1, sMt1, sMt1, sMt1, null, sMt1, null},
- {sMt1, null, sMt1, sMt1, null, sMt1, sMt1, sMt1, sMt1},
- {null, sMt1, null, sMt1, sMt1, sMt1, sMt1, null, sMt1},
- {sMt1, sMt1, sMt1, sMt1, null, sMt1, null, null, null},
- {sMt1, null, sMt1, sMt1, sMt1, sMt1, sMt1, sMt1, sMt1},
- {sMt1, sMt1, sMt1, sMt1, null, sMt1, sMt1, null, sMt1},
- {null, null, null, sMt1, null, sMt1, sMt1, null, sMt1},
- {null, sMt1, null, null, sMt1, null, null, sMt2, null},
- {sMt1, sMt1, sMt1, null, sMt2, null, null, sMt2, null},
- {null, sMt1, null, null, sMt2, null, null, sMt2, null},
- {sMt1, sMt1, null, sMt1, sMt2, null, null, sMt2, null},
- {null, sMt1, sMt1, null, sMt2, sMt1, null, sMt2, null},
- {sMt1, sMt1, null, null, sMt2, null, null, sMt2, null},
- {null, sMt1, sMt1, null, sMt2, null, null, sMt2, null},
- {null, sMt1, null, sMt1, null, null, null, sMt1, sMt2},
- {null, sMt1, null, null, null, sMt1, sMt2, sMt1, null},
- {null, sMt1, null, sMt1, null, sMt1, null, null, sMt2},
- {null, sMt1, null, sMt1, null, sMt1, sMt2, null, null},
- {null, sMt2, null, null, sMt1, null, null, sMt1, null},
- {null, sMt2, null, null, sMt2, null, sMt1, sMt1, sMt1},
- {null, sMt2, null, null, sMt2, null, null, sMt1, null},
- {null, sMt2, null, sMt1, sMt2, null, sMt1, sMt1, null},
- {null, sMt2, null, null, sMt2, sMt1, null, sMt1, sMt1},
- {null, sMt2, null, null, sMt2, null, sMt1, sMt1, null},
- {sMt1, null, null, null, sMt2, null, null, null, sMt2},
- {null, null, sMt1, null, sMt2, null, sMt2, null, null},
- {sMt1, null, null, null, sMt2, null, null, null, null},
- {null, null, sMt1, null, sMt2, null, null, null, null},
- {sMt1, sMt2, null, null, null, null, null, null, null},
- {sMt2, sMt1, null, null, null, null, null, null, null},
- {sMt1, null, null, sMt2, null, null, null, null, null},
- {sMt2, null, null, sMt1, null, null, null, null, null},
- {sMt1, sMt1, sMt1, sMt1, sMt1, sMt1, null, sMt2, null},
- {sMt1, sMt1, null, sMt1, sMt1, sMt2, sMt1, sMt1, null},
- {null, sMt1, sMt1, sMt2, sMt1, sMt1, null, sMt1, sMt1},
- {null, sMt2, null, sMt1, sMt1, sMt1, sMt1, sMt1, sMt1},
- {sMt1, sMt1, sMt1, sMt1, sMt2, sMt1, null, sMt2, null},
- {sMt1, sMt1, null, sMt1, sMt2, sMt2, sMt1, sMt1, null},
- {null, sMt1, sMt1, sMt2, sMt2, sMt1, null, sMt1, sMt1},
- {null, sMt2, null, sMt1, sMt2, sMt1, sMt1, sMt1, sMt1},
- {sMt1, null, null, null, sMt1, null, null, null, null},
- {null, sMt1, null, sMt1, null, null, null, null, null},
- {sMt1, sMt1, null, sMt2, null, sMt1, sMt2, null, null},
- {null, sMt1, sMt1, sMt1, null, sMt2, null, null, sMt2}
+ private static final RecipeShape[]
+ sShapes = new RecipeShape[]{
+ new RecipeShape(sMt1, null, sMt1, sMt1, sMt1, sMt1, null, sMt1, null),
+ new RecipeShape(sMt1, null, sMt1, sMt1, null, sMt1, sMt1, sMt1, sMt1),
+ new RecipeShape(null, sMt1, null, sMt1, sMt1, sMt1, sMt1, null, sMt1),
+ new RecipeShape(sMt1, sMt1, sMt1, sMt1, null, sMt1, null, null, null),
+ new RecipeShape(sMt1, null, sMt1, sMt1, sMt1, sMt1, sMt1, sMt1, sMt1),
+ new RecipeShape(sMt1, sMt1, sMt1, sMt1, null, sMt1, sMt1, null, sMt1),
+ new RecipeShape(null, null, null, sMt1, null, sMt1, sMt1, null, sMt1),
+ new RecipeShape(null, sMt1, null, null, sMt1, null, null, sMt2, null),
+ new RecipeShape(sMt1, sMt1, sMt1, null, sMt2, null, null, sMt2, null),
+ new RecipeShape(null, sMt1, null, null, sMt2, null, null, sMt2, null),
+ new RecipeShape(sMt1, sMt1, null, sMt1, sMt2, null, null, sMt2, null),
+ new RecipeShape(null, sMt1, sMt1, null, sMt2, sMt1, null, sMt2, null),
+ new RecipeShape(sMt1, sMt1, null, null, sMt2, null, null, sMt2, null),
+ new RecipeShape(null, sMt1, sMt1, null, sMt2, null, null, sMt2, null),
+ new RecipeShape(null, sMt1, null, sMt1, null, null, null, sMt1, sMt2),
+ new RecipeShape(null, sMt1, null, null, null, sMt1, sMt2, sMt1, null),
+ new RecipeShape(null, sMt1, null, sMt1, null, sMt1, null, null, sMt2),
+ new RecipeShape(null, sMt1, null, sMt1, null, sMt1, sMt2, null, null),
+ new RecipeShape(null, sMt2, null, null, sMt1, null, null, sMt1, null),
+ new RecipeShape(null, sMt2, null, null, sMt2, null, sMt1, sMt1, sMt1),
+ new RecipeShape(null, sMt2, null, null, sMt2, null, null, sMt1, null),
+ new RecipeShape(null, sMt2, null, sMt1, sMt2, null, sMt1, sMt1, null),
+ new RecipeShape(null, sMt2, null, null, sMt2, sMt1, null, sMt1, sMt1),
+ new RecipeShape(null, sMt2, null, null, sMt2, null, sMt1, sMt1, null),
+ new RecipeShape(sMt1, null, null, null, sMt2, null, null, null, sMt2),
+ new RecipeShape(null, null, sMt1, null, sMt2, null, sMt2, null, null),
+ new RecipeShape(sMt1, null, null, null, sMt2, null, null, null, null),
+ new RecipeShape(null, null, sMt1, null, sMt2, null, null, null, null),
+ new RecipeShape(sMt1, sMt2, null, null, null, null, null, null, null),
+ new RecipeShape(sMt2, sMt1, null, null, null, null, null, null, null),
+ new RecipeShape(sMt1, null, null, sMt2, null, null, null, null, null),
+ new RecipeShape(sMt2, null, null, sMt1, null, null, null, null, null),
+ new RecipeShape(sMt1, sMt1, sMt1, sMt1, sMt1, sMt1, null, sMt2, null),
+ new RecipeShape(sMt1, sMt1, null, sMt1, sMt1, sMt2, sMt1, sMt1, null),
+ new RecipeShape(null, sMt1, sMt1, sMt2, sMt1, sMt1, null, sMt1, sMt1),
+ new RecipeShape(null, sMt2, null, sMt1, sMt1, sMt1, sMt1, sMt1, sMt1),
+ new RecipeShape(sMt1, sMt1, sMt1, sMt1, sMt2, sMt1, null, sMt2, null),
+ new RecipeShape(sMt1, sMt1, null, sMt1, sMt2, sMt2, sMt1, sMt1, null),
+ new RecipeShape(null, sMt1, sMt1, sMt2, sMt2, sMt1, null, sMt1, sMt1),
+ new RecipeShape(null, sMt2, null, sMt1, sMt2, sMt1, sMt1, sMt1, sMt1),
+ new RecipeShape(sMt1, null, null, null, sMt1, null, null, null, null),
+ new RecipeShape(null, sMt1, null, sMt1, null, null, null, null, null),
+ new RecipeShape(sMt1, sMt1, null, sMt2, null, sMt1, sMt2, null, null),
+ new RecipeShape(null, sMt1, sMt1, sMt1, null, sMt2, null, null, sMt2)
};
private static final String[][] sShapesA = new String[][]{
null,
@@ -307,10 +308,7 @@ public class GT_RecipeRegistrator {
*/
public static synchronized void registerUsagesForMaterials(String aPlate, boolean aRecipeReplacing, ItemStack... aMats) {
for (ItemStack aMat : aMats) {
- if (aMat == null)
- continue;
-
- aMat = GT_Utility.copy(aMat);
+ aMat = GT_Utility.copyOrNull(aMat);
if (aMat == null)
continue;
@@ -327,20 +325,17 @@ public class GT_RecipeRegistrator {
sMt2.stackSize = 1;
Items.feather.setDamage(sMt2, 0);
- for (ItemStack[] tRecipe : sShapes1) {
- int tAmount1 = 0;
- for (ItemStack tMat : tRecipe) {
- if (tMat == sMt1) tAmount1++;
- }
- if (aItemData != null && aItemData.hasValidPrefixMaterialData())
- for (ItemStack tCrafted : GT_ModHandler.getRecipeOutputsBuffered(tRecipe)) {
- GT_OreDictUnificator.addItemData(tCrafted, new ItemData(aItemData.mMaterial.mMaterial, aItemData.mMaterial.mAmount * tAmount1));
-// GT_Log.out.println("###################################################################################");
-// GT_Log.out.println("registerUsagesForMaterials used aPlate: "+aPlate);
-// GT_Log.out.println("registerUsagesForMaterials used aPlate: "+aMat.getUnlocalizedName());
-// GT_Log.out.println("registerUsagesForMaterials used aPlate: "+aMat.getDisplayName());
-// GT_Log.out.println("###################################################################################");
+ if(aItemData != null && aItemData.hasValidPrefixMaterialData()) {
+ for (RecipeShape tRecipe : sShapes) {
+ for (ItemStack tCrafted : GT_ModHandler.getRecipeOutputsBuffered(tRecipe.shape)) {
+ GT_OreDictUnificator.addItemData(tCrafted, new ItemData(aItemData.mMaterial.mMaterial, aItemData.mMaterial.mAmount * tRecipe.amount1));
+ // GT_Log.out.println("###################################################################################");
+ // GT_Log.out.println("registerUsagesForMaterials used aPlate: "+aPlate);
+ // GT_Log.out.println("registerUsagesForMaterials used aPlate: "+aMat.getUnlocalizedName());
+ // GT_Log.out.println("registerUsagesForMaterials used aPlate: "+aMat.getDisplayName());
+ // GT_Log.out.println("###################################################################################");
}
+ }
}
registerStickStuff(aPlate, aItemData, aRecipeReplacing);
}
@@ -355,22 +350,17 @@ public class GT_RecipeRegistrator {
sMt2.stackSize = 1;
Items.feather.setDamage(sMt2, Items.feather.getDamage(tMt2));
- for (int i = 0; i < sShapes1.length; i++) {
- ItemStack[] tRecipe = sShapes1[i];
+ for (int i = 0; i < sShapes.length; i++) {
+ RecipeShape tRecipe = sShapes[i];
- int tAmount1 = 0, tAmount2 = 0;
- for (ItemStack tMat : tRecipe) {
- if (tMat == sMt1) tAmount1++;
- if (tMat == sMt2) tAmount2++;
- }
- for (ItemStack tCrafted : GT_ModHandler.getVanillyToolRecipeOutputs(tRecipe)) {
+ for (ItemStack tCrafted : GT_ModHandler.getVanillyToolRecipeOutputs(tRecipe.shape)) {
if (aItemData != null && aItemData.hasValidPrefixMaterialData())
- GT_OreDictUnificator.addItemData(tCrafted, new ItemData(aItemData.mMaterial.mMaterial, aItemData.mMaterial.mAmount * tAmount1, new MaterialStack(tMaterial, OrePrefixes.stick.mMaterialAmount * tAmount2)));
+ GT_OreDictUnificator.addItemData(tCrafted, new ItemData(aItemData.mMaterial.mMaterial, aItemData.mMaterial.mAmount * tRecipe.amount1, new MaterialStack(tMaterial, OrePrefixes.stick.mMaterialAmount * tRecipe.amount2)));
if (aRecipeReplacing && aPlate != null && sShapesA[i] != null && sShapesA[i].length > 1) {
assert aItemData != null;
if (GregTech_API.sRecipeFile.get(ConfigCategories.Recipes.recipereplacements, aItemData.mMaterial.mMaterial + "." + sShapesA[i][0], true)) {
- if (null != (tStack = GT_ModHandler.removeRecipe(tRecipe))) {
+ if (null != (tStack = GT_ModHandler.removeRecipe(tRecipe.shape))) {
// GT_Log.out.println("###################################################################################");
// GT_Log.out.println("registerStickStuff used aPlate: "+aPlate);
// GT_Log.out.println("###################################################################################");
@@ -398,4 +388,18 @@ public class GT_RecipeRegistrator {
return Arrays.stream(VANILLA_MATS).anyMatch(mat -> mat == materials);
}
+ private static class RecipeShape {
+ private final ItemStack[] shape;
+ private int amount1;
+ private int amount2;
+
+ public RecipeShape(ItemStack... shape) {
+ this.shape = shape;
+
+ for (ItemStack stack : shape) {
+ if(stack == sMt1) this.amount1++;
+ if(stack == sMt2) this.amount2++;
+ }
+ }
+ }
}
diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java
index 8cbb44fe07..28faeae7e3 100644
--- a/src/main/java/gregtech/api/util/GT_Utility.java
+++ b/src/main/java/gregtech/api/util/GT_Utility.java
@@ -89,7 +89,10 @@ import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidContainerItem;
import net.minecraftforge.fluids.IFluidHandler;
import net.minecraftforge.oredict.OreDictionary;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import javax.annotation.Nullable;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@@ -108,7 +111,6 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
@@ -438,7 +440,7 @@ public class GT_Utility {
if (isAllowedToTakeFromSlot(aTileEntity1, aGrabSlot, (byte) aGrabFrom, aTileEntity1.getStackInSlot(aGrabSlot))) {
if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) <= aTileEntity1.getStackInSlot(aGrabSlot).stackSize) {
ItemStack tStack = copyAmount(Math.min(aTileEntity1.getStackInSlot(aGrabSlot).stackSize, Math.min(aMaxMoveAtOnce, aMaxTargetStackSize)), aTileEntity1.getStackInSlot(aGrabSlot));
- ItemStack rStack = ((IItemDuct) aTileEntity2).insertItem(ForgeDirection.getOrientation(aPutTo), copy(tStack));
+ ItemStack rStack = ((IItemDuct) aTileEntity2).insertItem(ForgeDirection.getOrientation(aPutTo), copyOrNull(tStack));
byte tMovedItemCount = (byte) (tStack.stackSize - (rStack == null ? 0 : rStack.stackSize));
if (tMovedItemCount >= 1/*Math.max(aMinMoveAtOnce, aMinTargetStackSize)*/) {
//((cofh.api.transport.IItemConduit)aTileEntity2).insertItem(ForgeDirection.getOrientation(aPutTo), copyAmount(tMovedItemCount, tStack), F);
@@ -458,7 +460,7 @@ public class GT_Utility {
if (isAllowedToTakeFromSlot(aTileEntity1, aGrabSlot, (byte) aGrabFrom, aTileEntity1.getStackInSlot(aGrabSlot))) {
if (Math.max(aMinMoveAtOnce, aMinTargetStackSize) <= aTileEntity1.getStackInSlot(aGrabSlot).stackSize) {
ItemStack tStack = copyAmount(Math.min(aTileEntity1.getStackInSlot(aGrabSlot).stackSize, Math.min(aMaxMoveAtOnce, aMaxTargetStackSize)), aTileEntity1.getStackInSlot(aGrabSlot));
- byte tMovedItemCount = (byte) ((buildcraft.api.transport.IPipeTile) aTileEntity2).injectItem(copy(tStack), false, ForgeDirection.getOrientation(aPutTo));
+ byte tMovedItemCount = (byte) ((buildcraft.api.transport.IPipeTile) aTileEntity2).injectItem(copyOrNull(tStack), false, ForgeDirection.getOrientation(aPutTo));
if (tMovedItemCount >= Math.max(aMinMoveAtOnce, aMinTargetStackSize)) {
tMovedItemCount = (byte) (((buildcraft.api.transport.IPipeTile) aTileEntity2).injectItem(copyAmount(tMovedItemCount, tStack), true, ForgeDirection.getOrientation(aPutTo)));
aTileEntity1.decrStackSize(aGrabSlot, tMovedItemCount);
@@ -509,7 +511,7 @@ public class GT_Utility {
ItemStack tStack1 = aTileEntity1.getStackInSlot(aGrabFrom), tStack2 = aTileEntity2.getStackInSlot(aPutTo), tStack3 = null;
if (tStack1 != null) {
if (tStack2 != null && !areStacksEqual(tStack1, tStack2)) return 0;
- tStack3 = copy(tStack1);
+ tStack3 = copyOrNull(tStack1);
aMaxTargetStackSize = (byte) Math.min(aMaxTargetStackSize, Math.min(tStack3.getMaxStackSize(), Math.min(tStack2 == null ? Integer.MAX_VALUE : tStack2.getMaxStackSize(), aTileEntity2.getInventoryStackLimit())));
tStack3.stackSize = Math.min(tStack3.stackSize, aMaxTargetStackSize - (tStack2 == null ? 0 : tStack2.stackSize));
if (tStack3.stackSize > aMaxMoveAtOnce) tStack3.stackSize = aMaxMoveAtOnce;
@@ -518,7 +520,7 @@ public class GT_Utility {
aTileEntity1.markDirty();
if (tStack3 != null) {
if (tStack2 == null) {
- aTileEntity2.setInventorySlotContents(aPutTo, copy(tStack3));
+ aTileEntity2.setInventorySlotContents(aPutTo, copyOrNull(tStack3));
} else {
tStack2.stackSize += tStack3.stackSize;
}
@@ -999,6 +1001,10 @@ public class GT_Utility {
}
public static ItemStack getFluidDisplayStack(FluidStack aFluid, boolean aUseStackSize) {
+ return getFluidDisplayStack(aFluid, aUseStackSize, false);
+ }
+
+ public static ItemStack getFluidDisplayStack(FluidStack aFluid, boolean aUseStackSize, boolean aHideStackSize) {
if (aFluid == null || aFluid.getFluid() == null) return null;
int tmp = 0;
try {
@@ -1011,6 +1017,7 @@ public class GT_Utility {
tNBT.setLong("mFluidDisplayAmount", aUseStackSize ? aFluid.amount : 0);
tNBT.setLong("mFluidDisplayHeat", aFluid.getFluid().getTemperature(aFluid));
tNBT.setBoolean("mFluidState", aFluid.getFluid().isGaseous(aFluid));
+ tNBT.setBoolean("mHideStackSize", aHideStackSize);
rStack.setTagCompound(tNBT);
return rStack;
}
@@ -1146,7 +1153,7 @@ public class GT_Utility {
if(tOreName.toString().equals("dustAsh")&&tStack[0].getUnlocalizedName().equals("tile.volcanicAsh"))return false;
aRecipeList.put(new RecipeInputOreDict(tOreName.toString(), aInput.stackSize), new RecipeOutput(aNBT, tStack));
} else {
- aRecipeList.put(new RecipeInputItemStack(copy(aInput), aInput.stackSize), new RecipeOutput(aNBT, tStack));
+ aRecipeList.put(new RecipeInputItemStack(copyOrNull(aInput), aInput.stackSize), new RecipeOutput(aNBT, tStack));
}
return true;
}
@@ -1190,7 +1197,7 @@ public class GT_Utility {
rStack.setTagCompound(tNBT);
GT_Log.out.println("GT_Mod: Added Book to Book List - Mapping: '" + aMapping + "' - Name: '" + aTitle + "' - Author: '" + aAuthor + "'");
GregTech_API.sBookList.put(aMapping, rStack);
- return copy(rStack);
+ return copyOrNull(rStack);
}
public static boolean doSoundAtClient(String aSoundName, int aTimeUntilNextSound, float aSoundStrength) {
@@ -1283,6 +1290,7 @@ public class GT_Utility {
return rList;
}
+ @Deprecated // why do you use Objects?
public static Block getBlock(Object aBlock) {
return (Block) aBlock;
}
@@ -1296,12 +1304,14 @@ public class GT_Utility {
return Block.getBlockFromItem(item);
}
+ @Deprecated // why do you use Objects? And if you want to check your block to be not null, check it directly!
public static boolean isBlockValid(Object aBlock) {
return (aBlock instanceof Block);
}
+ @Deprecated // why do you use Objects? And if you want to check your block to be null, check it directly!
public static boolean isBlockInvalid(Object aBlock) {
- return aBlock == null || !(aBlock instanceof Block);
+ return !(aBlock instanceof Block);
}
public static boolean isStringValid(Object aString) {
@@ -1651,6 +1661,12 @@ public class GT_Utility {
return null;
}
+ @Nullable
+ public static ItemStack copyOrNull(@Nullable ItemStack stack) {
+ if (isStackValid(stack)) return stack.copy();
+ return null;
+ }
+
public static ItemStack copyAmount(long aAmount, Object... aStacks) {
ItemStack rStack = copy(aStacks);
if (isStackInvalid(rStack)) return null;