diff options
| author | Martin Robertz <dream-master@gmx.net> | 2022-01-29 17:26:43 +0100 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-29 17:26:43 +0100 | 
| commit | e74775cf42b430dd4e871d4e44a12f3669ad3d49 (patch) | |
| tree | 7f195fe6c24484579f3cfbcca9abe33462fa0398 /src/main/java | |
| parent | 4be5757c37802f2a92fa9d16f2d59d1fdb906cba (diff) | |
| parent | bb09b84d7a0a863532778fa63938243e5fe25cd7 (diff) | |
| download | GT5-Unofficial-e74775cf42b430dd4e871d4e44a12f3669ad3d49.tar.gz GT5-Unofficial-e74775cf42b430dd4e871d4e44a12f3669ad3d49.tar.bz2 GT5-Unofficial-e74775cf42b430dd4e871d4e44a12f3669ad3d49.zip  | |
Merge pull request #28 from GTNewHorizons/fix/assline-hash
Fix persistent hash not set on some assline recipes
Diffstat (limited to 'src/main/java')
| -rw-r--r-- | src/main/java/com/github/technus/tectech/recipe/TT_recipeAdder.java | 67 | 
1 files changed, 43 insertions, 24 deletions
diff --git a/src/main/java/com/github/technus/tectech/recipe/TT_recipeAdder.java b/src/main/java/com/github/technus/tectech/recipe/TT_recipeAdder.java index b08265d2c5..71a5419500 100644 --- a/src/main/java/com/github/technus/tectech/recipe/TT_recipeAdder.java +++ b/src/main/java/com/github/technus/tectech/recipe/TT_recipeAdder.java @@ -8,16 +8,20 @@ import com.github.technus.tectech.thing.CustomItemList;  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 { @@ -39,16 +43,8 @@ public class  TT_recipeAdder extends GT_RecipeAdder {                  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)); @@ -69,17 +65,23 @@ public class  TT_recipeAdder extends GT_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] = 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[]) { @@ -87,16 +89,24 @@ public class  TT_recipeAdder extends GT_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) {                              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"); @@ -105,20 +115,29 @@ public class  TT_recipeAdder extends GT_RecipeAdder {              }              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;      }  | 
