Skip to content

Commit

Permalink
Optimize recipe search by checking against last cached recipe before …
Browse files Browse the repository at this point in the history
…anything else
  • Loading branch information
FxMorin committed Jan 30, 2022
1 parent 7f2188f commit 1957fcc
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,13 @@ public void clear() {

private Optional<CraftingRecipe> getCurrentRecipe() {
if (this.world == null) return Optional.empty();
Optional<CraftingRecipe> optionalRecipe = this.world.getRecipeManager().getFirstMatch(RecipeType.CRAFTING, craftingInventory, world);
Optional<CraftingRecipe> optionalRecipe;
if ((optionalRecipe = Optional.ofNullable((CraftingRecipe) getLastRecipe())).isPresent()) {
if (RecipeType.CRAFTING.match(optionalRecipe.get(), world, craftingInventory).isPresent()) {
return optionalRecipe;
}
}
optionalRecipe = this.world.getRecipeManager().getFirstMatch(RecipeType.CRAFTING, craftingInventory, world);
optionalRecipe.ifPresent(this::setLastRecipe);
return optionalRecipe;
}
Expand Down

0 comments on commit 1957fcc

Please sign in to comment.