Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reinit of assline datasticks on id remap #3513

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/main/java/gregtech/api/util/GTRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ public static void reInit() {
map.getBackend()
.reInit();
}
RecipeAssemblyLine.reInit();
}

public ItemStack getRepresentativeInput(int aIndex) {
Expand Down Expand Up @@ -945,6 +946,8 @@ private static void checkInvalidRecipes() {
public ItemStack[][] mOreDictAlt;
private int mPersistentHash;

private final List<ItemStack> dataSticksForNEI = new ArrayList<>();

/**
* THIS CONSTRUCTOR DOES SET THE PERSISTENT HASH.
* <p>
Expand Down Expand Up @@ -1101,6 +1104,28 @@ public void setPersistentHash(int aPersistentHash) {
else this.mPersistentHash = aPersistentHash;
}

/**
* 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.
Expand Down
9 changes: 2 additions & 7 deletions src/main/java/gregtech/api/util/GTRecipeConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

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;
Expand Down Expand Up @@ -508,14 +507,12 @@ enum Wafer{
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
Expand All @@ -524,14 +521,12 @@ enum Wafer{
.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,
Expand Down
18 changes: 4 additions & 14 deletions src/main/java/tectech/recipe/TTRecipeAdder.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

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;
Expand Down Expand Up @@ -74,12 +72,10 @@ public static boolean addResearchableAssemblylineRecipe(ItemStack aResearchItem,
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)
Expand All @@ -88,13 +84,11 @@ public static boolean addResearchableAssemblylineRecipe(ItemStack aResearchItem,
.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()
Expand Down Expand Up @@ -218,12 +212,10 @@ public static boolean addResearchableAssemblylineRecipe(ItemStack aResearchItem,
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)
Expand All @@ -232,13 +224,11 @@ public static boolean addResearchableAssemblylineRecipe(ItemStack aResearchItem,
.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,
Expand Down