From 425f8921fc30c15800251ee5fe8d22a1d6e09b33 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sun, 17 Mar 2019 17:08:39 +0000 Subject: [PATCH] Improve auto crafting table performance with large amount of recipes. --- .../tiles/tier1/TileAutoCraftingTable.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/techreborn/tiles/tier1/TileAutoCraftingTable.java b/src/main/java/techreborn/tiles/tier1/TileAutoCraftingTable.java index 024f2a02c..981f59bb6 100644 --- a/src/main/java/techreborn/tiles/tier1/TileAutoCraftingTable.java +++ b/src/main/java/techreborn/tiles/tier1/TileAutoCraftingTable.java @@ -287,6 +287,14 @@ public class TileAutoCraftingTable extends TilePowerAcceptor } public IRecipe findMatchingRecipe(InventoryCrafting crafting){ + if(crafting.isEmpty()){ + return null; + } + if(currentRecipe != null){ + if(currentRecipe.matches(crafting, world)){ + return currentRecipe; + } + } for (IRecipe testRecipe : CraftingManager.REGISTRY) { if (testRecipe.matches(crafting, world)) { return testRecipe; @@ -309,7 +317,19 @@ public class TileAutoCraftingTable extends TilePowerAcceptor charge(10); InventoryCrafting craftMatrix = getCraftingInventory(); - currentRecipe = findMatchingRecipe(craftMatrix); + //Only search the recipe tree when the inv changes + if(inventory.hasChanged){ + currentRecipe = findMatchingRecipe(craftMatrix); + } + + //Checks that the current recipe is still valid, if not it will check for a valid recipe next tick. + if(currentRecipe != null){ + if(!currentRecipe.matches(craftMatrix, world)){ + currentRecipe = null; + inventory.hasChanged = true; + } + } + if (currentRecipe != null) { if (world.getTotalWorldTime() % 2 == 0) { Optional balanceResult = balanceRecipe(craftMatrix); @@ -374,6 +394,7 @@ public class TileAutoCraftingTable extends TilePowerAcceptor public void setLockedInt(int lockedInt) { locked = lockedInt == 1; + inventory.hasChanged = true; } @Override @@ -412,6 +433,7 @@ public class TileAutoCraftingTable extends TilePowerAcceptor if (tag.hasKey("locked")) { locked = tag.getBoolean("locked"); } + inventory.hasChanged = true; super.readFromNBT(tag); }