aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/common')
-rw-r--r--src/main/java/gregtech/common/GT_RecipeAdder.java46
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AssemblyLine.java133
2 files changed, 114 insertions, 65 deletions
diff --git a/src/main/java/gregtech/common/GT_RecipeAdder.java b/src/main/java/gregtech/common/GT_RecipeAdder.java
index 69a5254c44..f130c65adf 100644
--- a/src/main/java/gregtech/common/GT_RecipeAdder.java
+++ b/src/main/java/gregtech/common/GT_RecipeAdder.java
@@ -1,6 +1,7 @@
package gregtech.common;
import cpw.mods.fml.common.Loader;
+import cpw.mods.fml.common.registry.GameRegistry;
import gregtech.GT_Mod;
import gregtech.api.GregTech_API;
import gregtech.api.enums.GT_Values;
@@ -16,6 +17,7 @@ import gregtech.common.items.GT_IntegratedCircuit_Item;
import mods.railcraft.common.blocks.aesthetics.cube.EnumCube;
import mods.railcraft.common.items.RailcraftToolItems;
import net.minecraft.init.Blocks;
+import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
@@ -23,6 +25,7 @@ import net.minecraftforge.oredict.OreDictionary;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Comparator;
import java.util.List;
import static gregtech.GT_Mod.GT_FML_LOGGER;
@@ -1418,7 +1421,19 @@ public class GT_RecipeAdder implements IGT_RecipeAdder {
}
GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe(false, new ItemStack[]{aResearchItem}, new ItemStack[]{aOutput}, new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Writes Research result", new Object[0])}, null, null, aResearchTime, 30, -201);
GT_Recipe.GT_Recipe_Map.sAssemblylineVisualRecipes.addFakeRecipe(false, aInputs, new ItemStack[]{aOutput}, new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Reads Research result", new Object[0])}, aFluidInputs, null, aDuration, aEUt, 0,true);
- GT_Recipe.GT_Recipe_AssemblyLine.sAssemblylineRecipes.add(new GT_Recipe_AssemblyLine( aResearchItem, aResearchTime, aInputs, aFluidInputs, aOutput, aDuration, aEUt));
+ GT_Recipe_AssemblyLine tRecipe = new GT_Recipe_AssemblyLine(aResearchItem, aResearchTime, aInputs, aFluidInputs, aOutput, aDuration, aEUt);
+ int tPersistentHash = 1;
+ for (ItemStack tInput : aInputs)
+ tPersistentHash = tPersistentHash * 31 + GT_Utility.persistentHash(tInput, true, false);
+ tPersistentHash = tPersistentHash * 31 + GT_Utility.persistentHash(aResearchItem, true, false);
+ tPersistentHash = tPersistentHash * 31 + GT_Utility.persistentHash(aOutput, true, false);
+ for (FluidStack tFluidInput : aFluidInputs)
+ tPersistentHash = tPersistentHash * 31 + GT_Utility.persistentHash(tFluidInput, true, false);
+ tPersistentHash = tPersistentHash * 31 + aResearchTime;
+ tPersistentHash = tPersistentHash * 31 + aDuration;
+ tPersistentHash = tPersistentHash * 31 + aEUt;
+ tRecipe.setPersistentHash(tPersistentHash == 0 ? 1 : tPersistentHash);
+ GT_Recipe.GT_Recipe_AssemblyLine.sAssemblylineRecipes.add(tRecipe);
return true;
}
@@ -1432,17 +1447,23 @@ public class GT_RecipeAdder implements IGT_RecipeAdder {
}
ItemStack[] tInputs = new ItemStack[aInputs.length];
ItemStack[][] tAlts = new ItemStack[aInputs.length][];
+ int tPersistentHash = 1;
for(int i = 0; i < aInputs.length; i++){
Object obj = aInputs[i];
if (obj instanceof ItemStack) {
tInputs[i] = (ItemStack) obj;
tAlts[i] = null;
+ tPersistentHash = tPersistentHash * 31 + GT_Utility.persistentHash(tInputs[i], true, false);
continue;
} else if (obj instanceof ItemStack[]) {
ItemStack[] aStacks = (ItemStack[]) obj;
if (aStacks.length > 0) {
tInputs[i] = aStacks[0];
tAlts[i] = (ItemStack[]) Arrays.copyOf(aStacks, aStacks.length);
+ for (ItemStack tAlt : tAlts[i]) {
+ tPersistentHash = tPersistentHash * 31 + GT_Utility.persistentHash(tAlt, true, false);
+ }
+ tPersistentHash *= 31;
continue;
}
} else if (obj instanceof Object[]) {
@@ -1450,6 +1471,11 @@ public class GT_RecipeAdder implements IGT_RecipeAdder {
List<ItemStack> tList;
if (objs.length >= 2 && !(tList = GT_OreDictUnificator.getOres(objs[0])).isEmpty()) {
try {
+ // sort the output, so the hash code is stable across launches
+ tList.sort(Comparator.<ItemStack, String>comparing(s -> GameRegistry.findUniqueIdentifierFor(s.getItem()).modId)
+ .thenComparing(s -> GameRegistry.findUniqueIdentifierFor(s.getItem()).modId)
+ .thenComparingInt(Items.feather::getDamage)
+ .thenComparingInt(s -> s.stackSize));
int tAmount = ((Number) objs[1]).intValue();
List<ItemStack> uList = new ArrayList<>();
for (ItemStack tStack : tList) {
@@ -1460,16 +1486,30 @@ public class GT_RecipeAdder implements IGT_RecipeAdder {
tInputs[i] = uStack;
}
}
- tAlts[i] = uList.toArray(new ItemStack[uList.size()]);
+ tAlts[i] = uList.toArray(new ItemStack[0]);
+ tPersistentHash = tPersistentHash * 31 + (objs[0] == null ? "" : objs[0].toString()).hashCode();
+ tPersistentHash = tPersistentHash * 31 + tAmount;
continue;
} catch (Exception t) {}
}
}
GT_FML_LOGGER.info("addAssemblingLineRecipe "+aResearchItem.getDisplayName()+" --> "+aOutput.getUnlocalizedName()+" there is some null item in that recipe");
}
+ tPersistentHash = tPersistentHash * 31 + GT_Utility.persistentHash(aResearchItem, true, false);
+ tPersistentHash = tPersistentHash * 31 + GT_Utility.persistentHash(aOutput, true, false);
+ for (FluidStack tFluidInput : aFluidInputs) {
+ if (tFluidInput == null)
+ continue;
+ tPersistentHash = tPersistentHash * 31 + GT_Utility.persistentHash(tFluidInput, true, false);
+ }
+ tPersistentHash = tPersistentHash * 31 + aResearchTime;
+ tPersistentHash = tPersistentHash * 31 + aDuration;
+ tPersistentHash = tPersistentHash * 31 + aEUt;
GT_Recipe.GT_Recipe_Map.sScannerFakeRecipes.addFakeRecipe(false, new ItemStack[]{aResearchItem}, new ItemStack[]{aOutput}, new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Writes Research result", new Object[0])}, null, null, aResearchTime, 30, -201);
GT_Recipe.GT_Recipe_Map.sAssemblylineVisualRecipes.addFakeRecipe(false,tInputs,new ItemStack[]{aOutput},new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Reads Research result", new Object[0])},aFluidInputs,null,aDuration,aEUt,0,tAlts,true);
- GT_Recipe.GT_Recipe_AssemblyLine.sAssemblylineRecipes.add(new GT_Recipe_AssemblyLine( aResearchItem, aResearchTime, tInputs, aFluidInputs, aOutput, aDuration, aEUt, tAlts));
+ GT_Recipe_AssemblyLine tRecipe = new GT_Recipe_AssemblyLine(aResearchItem, aResearchTime, tInputs, aFluidInputs, aOutput, aDuration, aEUt, tAlts);
+ tRecipe.setPersistentHash(tPersistentHash == 0 ? 1 : tPersistentHash);
+ GT_Recipe.GT_Recipe_AssemblyLine.sAssemblylineRecipes.add(tRecipe);
return true;
}
diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AssemblyLine.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AssemblyLine.java
index 41475fd600..075ca564cb 100644
--- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AssemblyLine.java
+++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AssemblyLine.java
@@ -16,6 +16,7 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_EnhancedMul
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_DataAccess;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Input;
+import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBus;
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GT_AssemblyLineUtils;
import gregtech.api.util.GT_Multiblock_Tooltip_Builder;
@@ -24,10 +25,10 @@ import gregtech.api.util.GT_Recipe.GT_Recipe_AssemblyLine;
import gregtech.api.util.GT_Utility;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
-import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
import java.util.ArrayList;
+import java.util.Arrays;
import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock;
import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlockAnyMeta;
@@ -169,77 +170,71 @@ public class GT_MetaTileEntity_AssemblyLine extends GT_MetaTileEntity_EnhancedMu
GT_FML_LOGGER.info("Stick accepted, " + tDataStickList.size() + " Data Sticks found");
}
- ItemStack[] tStack = null;
- FluidStack[] tFluids = null;
- boolean findRecipe = false;
+ int[] tStack = null;
+ int[] tFluids = null;
+ boolean foundRecipe = false;
nextDataStick:
for (ItemStack tDataStick : tDataStickList) {
- GT_Recipe_AssemblyLine aFoundRecipe = GT_AssemblyLineUtils.findAssemblyLineRecipeFromDataStick(tDataStick);
+ GT_AssemblyLineUtils.LookupResult tLookupResult = GT_AssemblyLineUtils.findAssemblyLineRecipeFromDataStick(tDataStick, false);
- if (aFoundRecipe == null)
+ if (tLookupResult.getType() == GT_AssemblyLineUtils.LookupResultType.INVALID_STICK)
continue;
+ GT_Recipe_AssemblyLine tRecipe = tLookupResult.getRecipe();
// Check if the recipe on the data stick is the current recipe for it's given output, if not we update it and continue to next.
- if (!GT_AssemblyLineUtils.processDataStick(tDataStick)) {
- continue;
- }
-
- tStack = aFoundRecipe.mInputs;
- tFluids = aFoundRecipe.mFluidInputs;
+ if (tLookupResult.getType() != GT_AssemblyLineUtils.LookupResultType.VALID_STACK_AND_VALID_HASH) {
+ tRecipe = GT_AssemblyLineUtils.processDataStick(tDataStick);
+ if (tRecipe == null) {
+ continue;
+ }
+ }
// So here we check against the recipe found on the data stick.
// If we run into missing buses/hatches or bad inputs, we go to the next data stick.
// This check only happens if we have a valid up to date data stick.
// Check Inputs allign
- int aItemCount = aFoundRecipe.mInputs.length;
- for (int i = 0; i < 15; i++) {
- if (i >= aItemCount) {
- continue;
- }
- else {
- if (mInputBusses.get(i) == null) {
- continue nextDataStick;
- }
- else {
- ItemStack stackInSlot = mInputBusses.get(i).getBaseMetaTileEntity().getStackInSlot(0);
- if (!GT_Utility.areStacksEqual(tStack[i], stackInSlot, true) || tStack[i].stackSize <= stackInSlot.stackSize) {
- continue nextDataStick;
- }
- if (GT_Values.D1) {
- GT_FML_LOGGER.info("Item: " + i + " accepted");
- }
- }
- }
+ int aItemCount = tRecipe.mInputs.length;
+ tStack = new int[aItemCount];
+ for (int i = 0; i < aItemCount; i++) {
+ GT_MetaTileEntity_Hatch_InputBus tInputBus = mInputBusses.get(i);
+ if (tInputBus == null) {
+ continue nextDataStick;
+ }
+ ItemStack tSlotStack = tInputBus.getStackInSlot(0);
+ int tRequiredStackSize = isStackValidIngredient(tSlotStack, tRecipe.mInputs[i], tRecipe.mOreDictAlt[i]);
+ if (tRequiredStackSize < 0) continue nextDataStick;
+
+ tStack[i] = tRequiredStackSize;
+ if (GT_Values.D1) {
+ GT_FML_LOGGER.info("Item: " + i + " accepted");
+ }
}
// Check Fluid Inputs allign
- int aFluidCount = aFoundRecipe.mFluidInputs.length;
- for (int i = 0; i < 4; i++){
- if (i >= aFluidCount) {
- continue;
- }
- else {
- if (mInputHatches.get(i) == null) {
+ int aFluidCount = tRecipe.mFluidInputs.length;
+ tFluids = new int[aFluidCount];
+ for (int i = 0; i < aFluidCount; i++){
+ if (mInputHatches.get(i) == null) {
+ continue nextDataStick;
+ }
+ else {
+ FluidStack fluidInHatch = mInputHatches.get(i).mFluid;
+ if (!GT_Utility.areFluidsEqual(fluidInHatch, tRecipe.mFluidInputs[i], true) || fluidInHatch.amount < tRecipe.mFluidInputs[i].amount) {
continue nextDataStick;
}
- else {
- FluidStack fluidInHatch = mInputHatches.get(i).mFluid;
- if (!GT_Utility.areFluidsEqual(fluidInHatch, tFluids[i], true) || fluidInHatch.amount < tFluids[i].amount) {
- continue nextDataStick;
- }
- if (GT_Values.D1) {
- GT_FML_LOGGER.info("Fluid:" + i + " accepted");
- }
- }
- }
+ tFluids[i] = tRecipe.mFluidInputs[i].amount;
+ if (GT_Values.D1) {
+ GT_FML_LOGGER.info("Fluid:" + i + " accepted");
+ }
+ }
}
if (GT_Values.D1) {
GT_FML_LOGGER.info("Check overclock");
}
- calculateOverclockedNessMulti(aFoundRecipe.mEUt, aFoundRecipe.mDuration, 1, getMaxInputVoltage());
+ calculateOverclockedNessMulti(tRecipe.mEUt, tRecipe.mDuration, 1, getMaxInputVoltage());
//In case recipe is too OP for that machine
if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) {
if (GT_Values.D1) {
@@ -250,11 +245,13 @@ public class GT_MetaTileEntity_AssemblyLine extends GT_MetaTileEntity_EnhancedMu
if (GT_Values.D1) {
GT_FML_LOGGER.info("Find available recipe");
}
- findRecipe = true;
+ mOutputItems = new ItemStack[] {tRecipe.mOutput};
+ foundRecipe = true;
+ break ;
}
// Best not to run this recipe.
- if (!findRecipe || tStack == null || tStack.length <= 0 || tFluids == null || tFluids.length <= 0) {
+ if (!foundRecipe || tStack.length <= 0) {
return false;
}
@@ -262,18 +259,13 @@ public class GT_MetaTileEntity_AssemblyLine extends GT_MetaTileEntity_EnhancedMu
if (GT_Values.D1) {
GT_FML_LOGGER.info("All checked start consuming inputs");
}
- for (int i = 0; i < 15; i++) {
- if (tStack[i] == null) {
- continue;
- }
- ItemStack stackInSlot = mInputBusses.get(i).getBaseMetaTileEntity().getStackInSlot(0);
- stackInSlot.stackSize -= tStack[i].stackSize;
+ for (int i = 0; i < tStack.length; i++) {
+ ItemStack stackInSlot = mInputBusses.get(i).getStackInSlot(0);
+ stackInSlot.stackSize -= tStack[i];
}
- for (int i = 0; i < 4; i++) {
- if (tFluids[i] == null)
- continue;
- mInputHatches.get(i).mFluid.amount -= tFluids[i].amount;
+ for (int i = 0; i < tFluids.length; i++) {
+ mInputHatches.get(i).mFluid.amount -= tFluids[i];
if (mInputHatches.get(i).mFluid.amount <= 0) {
mInputHatches.get(i).mFluid = null;
}
@@ -286,11 +278,28 @@ public class GT_MetaTileEntity_AssemblyLine extends GT_MetaTileEntity_EnhancedMu
this.mEfficiencyIncrease = 10000;
updateSlots();
if (GT_Values.D1) {
- GT_FML_LOGGER.info("Recipe sucessfull");
+ GT_FML_LOGGER.info("Recipe successful");
}
return true;
}
+ private static int isStackValidIngredient(ItemStack aSlotStack, ItemStack aIngredient, ItemStack[] alts) {
+ if (alts == null || alts.length == 0)
+ return isStackValidIngredient(aSlotStack, aIngredient);
+ for (ItemStack tAltStack : alts) {
+ int i = isStackValidIngredient(aSlotStack, tAltStack);
+ if (i >= 0)
+ return i;
+ }
+ return -1;
+ }
+
+ private static int isStackValidIngredient(ItemStack aSlotStack, ItemStack aIngredient) {
+ if (GT_Utility.areStacksEqual(aSlotStack, aIngredient, true) && aIngredient.stackSize <= aSlotStack.stackSize)
+ return aIngredient.stackSize;
+ return -1;
+ }
+
@Override
public boolean onRunningTick(ItemStack aStack) {
for(GT_MetaTileEntity_Hatch_DataAccess hatch_dataAccess:mDataAccessHatches){