Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #28 from GTNewHorizons/fix/assline-hash
Browse files Browse the repository at this point in the history
Fix persistent hash not set on some assline recipes
  • Loading branch information
Dream-Master authored Jan 29, 2022
2 parents 4be5757 + bb09b84 commit e74775c
Showing 1 changed file with 43 additions and 24 deletions.
67 changes: 43 additions & 24 deletions src/main/java/com/github/technus/tectech/recipe/TT_recipeAdder.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@
import com.github.technus.tectech.thing.item.ElementalDefinitionContainer_EM;
import com.github.technus.tectech.thing.metaTileEntity.multi.GT_MetaTileEntity_EM_crafting;
import com.github.technus.tectech.thing.metaTileEntity.multi.em_machine.GT_MetaTileEntity_EM_machine;
import cpw.mods.fml.common.registry.GameRegistry;
import gregtech.api.enums.ItemList;
import gregtech.api.util.GT_OreDictUnificator;
import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_Recipe.GT_Recipe_AssemblyLine;
import gregtech.api.util.GT_Utility;
import gregtech.common.GT_RecipeAdder;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

public class TT_recipeAdder extends GT_RecipeAdder {
Expand All @@ -39,16 +43,8 @@ public static boolean addResearchableAssemblylineRecipe(ItemStack aResearchItem,
TecTech.LOGGER.error("addResearchableAssemblingLineRecipe "+aResearchItem.getDisplayName()+" --> "+aOutput.getUnlocalizedName()+" there is some null item in that recipe");
}
}
if(researchAmperage<=0) {
researchAmperage = 1;
} else if(researchAmperage > Short.MAX_VALUE) {
researchAmperage = Short.MAX_VALUE;
}
if(computationRequiredPerSec<=0) {
computationRequiredPerSec = 1;
} else if(computationRequiredPerSec > Short.MAX_VALUE) {
computationRequiredPerSec = Short.MAX_VALUE;
}
researchAmperage = GT_Utility.clamp(researchAmperage, 1, Short.MAX_VALUE);
computationRequiredPerSec = GT_Utility.clamp(computationRequiredPerSec, 1, Short.MAX_VALUE);
TT_recipe.GT_Recipe_MapTT.sResearchableFakeRecipes.addFakeRecipe(false, new ItemStack[]{aResearchItem}, new ItemStack[]{aOutput}, new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Writes Research result")}, null, null, totalComputationRequired, researchEUt, researchAmperage| computationRequiredPerSec<<16);
GT_Recipe.GT_Recipe_Map.sAssemblylineVisualRecipes.addFakeRecipe(false, aInputs, new ItemStack[]{aOutput}, new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Reads Research result")}, aFluidInputs, null, assDuration, assEUt, 0,true);
GT_Recipe.GT_Recipe_AssemblyLine.sAssemblylineRecipes.add(new GT_Recipe.GT_Recipe_AssemblyLine(CustomItemList.UnusedStuff.get(1), totalComputationRequired/computationRequiredPerSec, aInputs, aFluidInputs, aOutput, assDuration, assEUt));
Expand All @@ -69,34 +65,48 @@ public static boolean addResearchableAssemblylineRecipe(ItemStack aResearchItem,

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] = Arrays.copyOf(aStacks, aStacks.length);
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[]) {
Object[] objs = (Object[]) obj;
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) {
ItemStack uStack = GT_Utility.copyAmount(tAmount, tStack);
if (GT_Utility.isStackValid(uStack)) {
uList.add(uStack);
if (tInputs[i] == null) tInputs[i] = uStack;
if (tInputs[i] == null)
tInputs[i] = uStack;
}
}
tAlts[i] = uList.toArray(nullItem);
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) {
TecTech.LOGGER.error("addAssemblingLineRecipe "+aResearchItem.getDisplayName()+" --> there is some ... in that recipe");
Expand All @@ -105,20 +115,29 @@ public static boolean addResearchableAssemblylineRecipe(ItemStack aResearchItem,
}
TecTech.LOGGER.error("addAssemblingLineRecipe "+aResearchItem.getDisplayName()+" --> "+aOutput.getUnlocalizedName()+" there is some null item in that recipe");
}
if(researchAmperage<=0) {
researchAmperage = 1;
} else if(researchAmperage > Short.MAX_VALUE) {
researchAmperage = Short.MAX_VALUE;
}
if(computationRequiredPerSec<=0) {
computationRequiredPerSec = 1;
} else if(computationRequiredPerSec > Short.MAX_VALUE) {
computationRequiredPerSec = Short.MAX_VALUE;
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);
}
researchAmperage = GT_Utility.clamp(researchAmperage, 1, Short.MAX_VALUE);
computationRequiredPerSec = GT_Utility.clamp(computationRequiredPerSec, 1, Short.MAX_VALUE);
tPersistentHash = tPersistentHash * 31 + totalComputationRequired;
tPersistentHash = tPersistentHash * 31 + computationRequiredPerSec;
tPersistentHash = tPersistentHash * 31 + researchAmperage;
tPersistentHash = tPersistentHash * 31 + researchEUt;
tPersistentHash = tPersistentHash * 31 + assDuration;
tPersistentHash = tPersistentHash * 31 + assEUt;
TT_recipe.GT_Recipe_MapTT.sResearchableFakeRecipes.addFakeRecipe(false, new ItemStack[]{aResearchItem}, new ItemStack[]{aOutput}, new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Writes Research result")}, null, null, totalComputationRequired, researchEUt, researchAmperage| computationRequiredPerSec<<16);
GT_Recipe.GT_Recipe_Map.sAssemblylineVisualRecipes.addFakeRecipe(false,tInputs,new ItemStack[]{aOutput},new ItemStack[]{ItemList.Tool_DataStick.getWithName(1L, "Reads Research result")},aFluidInputs,null,assDuration,assEUt,0,tAlts,true);
GT_Recipe.GT_Recipe_AssemblyLine.sAssemblylineRecipes.add(new GT_Recipe.GT_Recipe_AssemblyLine( CustomItemList.UnusedStuff.get(1), totalComputationRequired/computationRequiredPerSec, tInputs, aFluidInputs, aOutput, assDuration, assEUt, tAlts));
TT_recipe.GT_Recipe_MapTT.sAssemblylineRecipes.add(new GT_Recipe.GT_Recipe_AssemblyLine( aResearchItem, totalComputationRequired/computationRequiredPerSec, tInputs, aFluidInputs, aOutput, assDuration, assEUt, tAlts));
GT_Recipe_AssemblyLine recipeGT = new GT_Recipe_AssemblyLine(CustomItemList.UnusedStuff.get(1), totalComputationRequired / computationRequiredPerSec, tInputs, aFluidInputs, aOutput, assDuration, assEUt, tAlts);
recipeGT.setPersistentHash(tPersistentHash);
GT_Recipe.GT_Recipe_AssemblyLine.sAssemblylineRecipes.add(recipeGT);
GT_Recipe_AssemblyLine recipeTT = new GT_Recipe_AssemblyLine(aResearchItem, totalComputationRequired / computationRequiredPerSec, tInputs, aFluidInputs, aOutput, assDuration, assEUt, tAlts);
recipeTT.setPersistentHash(tPersistentHash);
TT_recipe.GT_Recipe_MapTT.sAssemblylineRecipes.add(recipeTT);
return true;
}

Expand Down

0 comments on commit e74775c

Please sign in to comment.