Skip to content

Commit

Permalink
Merge pull request #47 from fxmorin/optimize_cache_previous
Browse files Browse the repository at this point in the history
Optimize recipe search by checking against last cached recipe before anything else
  • Loading branch information
gnembon authored Feb 5, 2022
2 parents 5f91f61 + 1957fcc commit db7f1af
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,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 db7f1af

Please sign in to comment.