diff options
author | Glease <4586901+Glease@users.noreply.github.com> | 2024-11-19 15:03:46 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-19 08:03:46 +0100 |
commit | 5916e9e4c886e236060ae865c7eb7ef08e382bbb (patch) | |
tree | 89fbe09d6be5e60a63e1db7e6ce1171baba71968 | |
parent | 79b618f9948fde9d46f745223bda268d98755f13 (diff) | |
download | GT5-Unofficial-5916e9e4c886e236060ae865c7eb7ef08e382bbb.tar.gz GT5-Unofficial-5916e9e4c886e236060ae865c7eb7ef08e382bbb.tar.bz2 GT5-Unofficial-5916e9e4c886e236060ae865c7eb7ef08e382bbb.zip |
reinit of assline datasticks on id remap (#3513)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
-rw-r--r-- | src/main/java/gregtech/api/util/GTRecipe.java | 25 | ||||
-rw-r--r-- | src/main/java/gregtech/api/util/GTRecipeConstants.java | 9 | ||||
-rw-r--r-- | src/main/java/tectech/recipe/TTRecipeAdder.java | 18 |
3 files changed, 31 insertions, 21 deletions
diff --git a/src/main/java/gregtech/api/util/GTRecipe.java b/src/main/java/gregtech/api/util/GTRecipe.java index d27412d4ec..9f44b56c7a 100644 --- a/src/main/java/gregtech/api/util/GTRecipe.java +++ b/src/main/java/gregtech/api/util/GTRecipe.java @@ -374,6 +374,7 @@ public class GTRecipe implements Comparable<GTRecipe> { map.getBackend() .reInit(); } + RecipeAssemblyLine.reInit(); } public ItemStack getRepresentativeInput(int aIndex) { @@ -945,6 +946,8 @@ public class GTRecipe implements Comparable<GTRecipe> { public ItemStack[][] mOreDictAlt; private int mPersistentHash; + private final List<ItemStack> dataSticksForNEI = new ArrayList<>(); + /** * THIS CONSTRUCTOR DOES SET THE PERSISTENT HASH. * <p> @@ -1102,6 +1105,28 @@ public class GTRecipe implements Comparable<GTRecipe> { } /** + * WARNING: this class will maintain a strong reference over ALL data sticks created this way. DO NOT call this + * methods recklessly as it will cause memory leak! + */ + public ItemStack newDataStickForNEI(String aDisplayName) { + ItemStack dataStick = ItemList.Tool_DataStick.getWithName(1L, aDisplayName); + // we don't actually needs to set the recipe data here. no one will read the recipe data before a world load + // and before a world load id remap will happen and the recipe data will be finally set in the below + // reInit() method + // AssemblyLineUtils.setAssemblyLineRecipeOnDataStick(dataStick, this, false); + dataSticksForNEI.add(dataStick); + return dataStick; + } + + public static void reInit() { + for (RecipeAssemblyLine recipe : sAssemblylineRecipes) { + for (ItemStack stack : recipe.dataSticksForNEI) { + AssemblyLineUtils.setAssemblyLineRecipeOnDataStick(stack, recipe, false); + } + } + } + + /** * @param inputBusses List of input busses to check. * @return An array containing the amount of item to consume from the first slot of every input bus. * {@code null} if at least one item fails to match the recipe ingredient. diff --git a/src/main/java/gregtech/api/util/GTRecipeConstants.java b/src/main/java/gregtech/api/util/GTRecipeConstants.java index d1a9f2c60a..883f1060ac 100644 --- a/src/main/java/gregtech/api/util/GTRecipeConstants.java +++ b/src/main/java/gregtech/api/util/GTRecipeConstants.java @@ -16,7 +16,6 @@ import net.minecraftforge.fluids.FluidStack; import cpw.mods.fml.common.registry.GameRegistry; import gregtech.api.enums.GTValues; -import gregtech.api.enums.ItemList; import gregtech.api.enums.Materials; import gregtech.api.enums.OrePrefixes; import gregtech.api.enums.TierEU; @@ -508,14 +507,12 @@ public class GTRecipeConstants { GTRecipe.RecipeAssemblyLine.sAssemblylineRecipes.add(tRecipe); AssemblyLineUtils.addRecipeToCache(tRecipe); - ItemStack writesDataStick = ItemList.Tool_DataStick.getWithName(1L, "Writes Research result"); - AssemblyLineUtils.setAssemblyLineRecipeOnDataStick(writesDataStick, tRecipe, false); Collection<GTRecipe> ret = new ArrayList<>(3); ret.addAll( GTValues.RA.stdBuilder() .itemInputs(aResearchItem) .itemOutputs(aOutput) - .special(writesDataStick) + .special(tRecipe.newDataStickForNEI("Writes Research result")) .duration(aResearchTime) .eut(TierEU.RECIPE_LV) .specialValue(-201) // means it's scanned @@ -524,14 +521,12 @@ public class GTRecipeConstants { .fake() .addTo(scannerFakeRecipes)); - ItemStack readsDataStick = ItemList.Tool_DataStick.getWithName(1L, "Reads Research result"); - AssemblyLineUtils.setAssemblyLineRecipeOnDataStick(readsDataStick, tRecipe, false); ret.add( RecipeMaps.assemblylineVisualRecipes.addFakeRecipe( false, r.mInputs, new ItemStack[] { aOutput }, - new ItemStack[] { readsDataStick }, + new ItemStack[] { tRecipe.newDataStickForNEI("Reads Research result") }, r.mFluidInputs, null, r.mDuration, diff --git a/src/main/java/tectech/recipe/TTRecipeAdder.java b/src/main/java/tectech/recipe/TTRecipeAdder.java index 69068afce0..2e3d233695 100644 --- a/src/main/java/tectech/recipe/TTRecipeAdder.java +++ b/src/main/java/tectech/recipe/TTRecipeAdder.java @@ -15,8 +15,6 @@ import net.minecraftforge.fluids.FluidStack; import cpw.mods.fml.common.registry.GameRegistry; import gregtech.api.enums.GTValues; -import gregtech.api.enums.ItemList; -import gregtech.api.util.AssemblyLineUtils; import gregtech.api.util.GTOreDictUnificator; import gregtech.api.util.GTRecipe; import gregtech.api.util.GTRecipe.RecipeAssemblyLine; @@ -74,12 +72,10 @@ public class TTRecipeAdder extends RecipeAdder { GTRecipe.RecipeAssemblyLine.sAssemblylineRecipes.add(recipeGT); TecTechRecipeMaps.researchableALRecipeList.add(recipeTT); - ItemStack writesDataStick = ItemList.Tool_DataStick.getWithName(1L, "Writes Research result"); - AssemblyLineUtils.setAssemblyLineRecipeOnDataStick(writesDataStick, recipeTT, false); GTValues.RA.stdBuilder() .itemInputs(aResearchItem) .itemOutputs(aOutput) - .special(writesDataStick) + .special(recipeTT.newDataStickForNEI("Writes Research result")) .duration(totalComputationRequired) .eut(researchEUt) .metadata(RESEARCH_STATION_DATA, researchAmperage | computationRequiredPerSec << 16) @@ -88,13 +84,11 @@ public class TTRecipeAdder extends RecipeAdder { .fake() .addTo(researchStationFakeRecipes); - ItemStack readsDataStick = ItemList.Tool_DataStick.getWithName(1L, "Reads Research result"); - AssemblyLineUtils.setAssemblyLineRecipeOnDataStick(readsDataStick, recipeTT, false); GTValues.RA.stdBuilder() .itemInputs(aInputs) .itemOutputs(aOutput) .fluidInputs(aFluidInputs) - .special(readsDataStick) + .special(recipeTT.newDataStickForNEI("Reads Research result")) .duration(assDuration) .eut(assEUt) .ignoreCollision() @@ -218,12 +212,10 @@ public class TTRecipeAdder extends RecipeAdder { recipeTT.setPersistentHash(tPersistentHash); TecTechRecipeMaps.researchableALRecipeList.add(recipeTT); - ItemStack writesDataStick = ItemList.Tool_DataStick.getWithName(1L, "Writes Research result"); - AssemblyLineUtils.setAssemblyLineRecipeOnDataStick(writesDataStick, recipeTT, false); GTValues.RA.stdBuilder() .itemInputs(aResearchItem) .itemOutputs(aOutput) - .special(writesDataStick) + .special(recipeTT.newDataStickForNEI("Writes Research result")) .duration(totalComputationRequired) .eut(researchEUt) .metadata(RESEARCH_STATION_DATA, researchAmperage | computationRequiredPerSec << 16) @@ -232,13 +224,11 @@ public class TTRecipeAdder extends RecipeAdder { .fake() .addTo(researchStationFakeRecipes); - ItemStack readsDataStick = ItemList.Tool_DataStick.getWithName(1L, "Reads Research result"); - AssemblyLineUtils.setAssemblyLineRecipeOnDataStick(readsDataStick, recipeTT, false); assemblylineVisualRecipes.addFakeRecipe( false, tInputs, new ItemStack[] { aOutput }, - new ItemStack[] { readsDataStick }, + new ItemStack[] { recipeTT.newDataStickForNEI("Reads Research result") }, aFluidInputs, null, assDuration, |