Skip to content

Commit

Permalink
perf: ⚡increase [Alloy Smelter] performance
Browse files Browse the repository at this point in the history
Before this change, registering recipes required iterate over big amounts if registry to find what custom recipes could be x3, like when you can smelt 3 cobblestone at once.

This takes 1-3 seconds on loading time for about ~16 custom recipes.

I removed this x3 functionality for those 16 custom recipes (mostly compressed cobble => stone ones).
  • Loading branch information
Krutoy242 committed Jun 15, 2024
1 parent dfb1811 commit 3787d4d
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
@@ -92,18 +92,16 @@ extends AbstractMachineRecipe {
Log.debug((Object[])new Object[]{"Recipe lookup table has been rebuilt with ", instance.rebuild(), " primary entries"});
}

- public void addRecipe(boolean prohibitDupes, @Nonnull NNList<IRecipeInput> input, @Nonnull ItemStack output, int energyCost, float xpChance, @Nonnull RecipeLevel recipeLevel) {
+ public void addRecipe(boolean prohibitDupes, NNList<IRecipeInput> input, ItemStack output, int energyCost, float xpChance, RecipeLevel recipeLevel) {
Recipe recipe = new Recipe(new RecipeOutput(output, 1.0f, xpChance), energyCost, RecipeBonusType.NONE, recipeLevel, (IRecipeInput[])input.toArray((Object[])new IRecipeInput[0]));
if (prohibitDupes && input.size() > 1) {
this.addDedupedRecipe(recipe);
- } else if (this.needsSynthetics(recipe)) {
- this.addSyntheticRecipe(recipe);
} else {
this.addRecipe((IManyToOneRecipe)new BasicManyToOneRecipe(recipe));
}
}

- private void addDedupedRecipe(@Nonnull Recipe recipe) {
+ private void addDedupedRecipe(Recipe recipe) {
ItemStack output = recipe.getOutputs()[0].getOutput();
Log.debug((Object[])new Object[]{"Beginning de-duping loop for recipe that outputs ", output});
RecipeOutput recipeOutput = recipe.getOutputs()[0];
@@ -146,7 +144,7 @@ extends AbstractMachineRecipe {
this.addRecipe(new BasicManyToOneRecipe(recipe).setDedupeInput());
}

- private void addSyntheticRecipe(@Nonnull Recipe recipe) {
+ private void addSyntheticRecipe(Recipe recipe) {
int er = recipe.getEnergyRequired();
RecipeBonusType bns = recipe.getBonusType();
RecipeLevel lvl = recipe.getRecipeLevel();
@@ -176,13 +174,13 @@ extends AbstractMachineRecipe {
return (Boolean)RecipeConfig.createSyntheticRecipes.get() != false && recipe.getInputs().length == 1 && recipe.getInputs()[0].getStackSize() <= recipe.getInputs()[0].getInput().func_77976_d() / 3 && recipe.getOutputs()[0].getOutput().func_190916_E() <= recipe.getOutputs()[0].getOutput().func_77976_d() / 3;
}

- private void addRecipe(@Nonnull IManyToOneRecipe recipe) {
+ private void addRecipe(IManyToOneRecipe recipe) {
this.dupeCheckRecipe((IRecipe)recipe);
AlloyRecipeManager.addRecipeToLookup(this.lookup, recipe);
this.addJEIIntegration(recipe);
}

- private static void addRecipeToLookup(@Nonnull TriItemLookup<IManyToOneRecipe> lookup, @Nonnull IManyToOneRecipe recipe) {
+ private static void addRecipeToLookup(TriItemLookup<IManyToOneRecipe> lookup, IManyToOneRecipe recipe) {
block7: {
NNList list;
block8: {
@@ -219,7 +217,7 @@ extends AbstractMachineRecipe {
}
}

- private void addJEIIntegration(@Nonnull IManyToOneRecipe recipe) {
+ private void addJEIIntegration(IManyToOneRecipe recipe) {
if (recipe.getInputs().length >= 2 && !recipe.isDedupeInput() && !recipe.isSynthetic()) {
NNList inputs = new NNList();
for (int i = 0; i < recipe.getInputs().length; ++i) {
@@ -252,7 +250,7 @@ extends AbstractMachineRecipe {
}
}

- public IRecipe getRecipeForInputs(@Nonnull RecipeLevel machineLevel, @Nonnull NNList<MachineRecipeInput> inputs) {
+ public IRecipe getRecipeForInputs(RecipeLevel machineLevel, NNList<MachineRecipeInput> inputs) {
for (IManyToOneRecipe rec : this.lookup.getRecipesLMRI(inputs)) {
if (!machineLevel.canMake(rec.getRecipeLevel()) || !rec.isInputForRecipe(inputs)) continue;
return rec;
@@ -260,7 +258,7 @@ extends AbstractMachineRecipe {
return null;
}

- public boolean isValidInput(@Nonnull RecipeLevel machineLevel, @Nonnull MachineRecipeInput input) {
+ public boolean isValidInput(RecipeLevel machineLevel, MachineRecipeInput input) {
for (IManyToOneRecipe recipe : this.lookup.getRecipes(input.item.func_77973_b())) {
if (!machineLevel.canMake(recipe.getRecipeLevel())) continue;
for (IRecipeInput ri : recipe.getInputs()) {
@@ -271,7 +269,7 @@ extends AbstractMachineRecipe {
return false;
}

- public boolean isValidRecipeComponents(@Nonnull RecipeLevel machineLevel, @Nonnull NNList<ItemStack> input) {
+ public boolean isValidRecipeComponents(RecipeLevel machineLevel, NNList<ItemStack> input) {
for (IManyToOneRecipe recipe : this.lookup.getRecipesL(input)) {
if (!machineLevel.canMake(recipe.getRecipeLevel()) || !recipe.isValidRecipeComponents(input)) continue;
return true;
@@ -279,7 +277,7 @@ extends AbstractMachineRecipe {
return false;
}

- public float getExperienceForOutput(@Nonnull ItemStack output) {
+ public float getExperienceForOutput(ItemStack output) {
for (IManyToOneRecipe recipe : this.lookup) {
if (recipe.getOutput().func_77973_b() != output.func_77973_b() || recipe.getOutput().func_77952_i() != output.func_77952_i()) continue;
return recipe.getOutputs()[0].getExperiance();

0 comments on commit 3787d4d

Please sign in to comment.