From 1957fcc11dca1acaecf93be422c742ad5f0ef367 Mon Sep 17 00:00:00 2001 From: FX - PR0CESS Date: Sat, 29 Jan 2022 22:16:46 -0500 Subject: [PATCH] Optimize recipe search by checking against last cached recipe before anything else --- .../CraftingTableBlockEntity.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/carpet_autocraftingtable/CraftingTableBlockEntity.java b/src/main/java/carpet_autocraftingtable/CraftingTableBlockEntity.java index 69db61d..52c8380 100644 --- a/src/main/java/carpet_autocraftingtable/CraftingTableBlockEntity.java +++ b/src/main/java/carpet_autocraftingtable/CraftingTableBlockEntity.java @@ -188,7 +188,13 @@ public void clear() { private Optional getCurrentRecipe() { if (this.world == null) return Optional.empty(); - Optional optionalRecipe = this.world.getRecipeManager().getFirstMatch(RecipeType.CRAFTING, craftingInventory, world); + Optional 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; }