Skip to content

Commit

Permalink
Add condition for fetching vanilla recipe cache
Browse files Browse the repository at this point in the history
  • Loading branch information
wendavid552 committed Aug 15, 2024
1 parent 709dea7 commit d03cfe1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,10 @@ public void onClientTick(MinecraftClient mc)
}

RecipePattern recipe = RecipeStorage.getInstance().getSelectedRecipe();
if (recipe.getVanillaRecipe() == null) {
recipe.lookupVanillaRecipe(mc.world);
}

int limit = Configs.Generic.MASS_CRAFT_ITERATIONS.getIntegerValue();

if (Configs.Generic.MASS_CRAFT_RECIPE_BOOK.getBooleanValue() && recipe.getVanillaRecipe() != null)
if (Configs.Generic.MASS_CRAFT_RECIPE_BOOK.getBooleanValue() && recipe.lookupVanillaRecipe(mc.world) != null)
{
InventoryUtils.dontUpdateRecipeBook = true;
for (int i = 0; i < limit; ++i)
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/fi/dy/masa/itemscroller/recipes/RecipePattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public void ensureRecipeSizeAndClearRecipe(int size)
this.clearRecipe();
}

public void lookupVanillaRecipe(World world) {
@Nullable
public <T extends RecipeInput> Recipe<T> lookupVanillaRecipe(World world) {
//Assume all recipes here are of type CraftingRecipe
this.vanillaRecipe = null;
var mc = MinecraftClient.getInstance();
int recipeSize;
Expand All @@ -69,17 +71,18 @@ else if (recipe.length == 9)
}
else
{
return;
return null;
}

for (RecipeEntry<CraftingRecipe> match : mc.world.getRecipeManager().getAllMatches(RecipeType.CRAFTING, CraftingRecipeInput.create(recipeSize, recipeSize, Arrays.asList(recipe)), world))
{
if (InventoryUtils.areStacksEqual(result, match.value().getResult(world.getRegistryManager())))
{
this.vanillaRecipe = match;
return;
return (Recipe<T>) match.value();
}
}
return null;
}

public void storeCraftingRecipe(Slot slot, HandledScreen<? extends ScreenHandler> gui, boolean clearIfEmpty)
Expand Down Expand Up @@ -224,7 +227,7 @@ public RecipeEntry<?> getVanillaRecipeEntry()
@Nullable
public <T extends RecipeInput> Recipe<T> getVanillaRecipe()
{
if (vanillaRecipe == null)
if (recipe == null)
{
return null;
}
Expand Down

0 comments on commit d03cfe1

Please sign in to comment.