From 8a978e4c40a58090677d0e9157562b8396318a43 Mon Sep 17 00:00:00 2001 From: Lordmau5 Date: Thu, 19 Oct 2017 20:36:06 +0200 Subject: [PATCH] Better implementation for crafting grid (#1496) * Better implementation for crafting grid Tackles #1368 and tries to fix it by caching the recipe to not call "CraftingManager.findMatchingResult" every single time it tries to craft * Fix code-style and update changelog --- CHANGELOG.md | 1 + .../apiimpl/network/node/NetworkNodeGrid.java | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d131a3d32..7ad6ca5fc 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### 1.5.21 - Updated Portuguese (Brazilian) translation (Pinz714) - Fixed crash with External Storage (raoulvdberge) +- Fixed stack-crafting in the crafting grid (crafting table) causing lag on a dedicated server (Lordmau5) ### 1.5.20 - Restore MC 1.12.0 compatibility (raoulvdberge) diff --git a/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/network/node/NetworkNodeGrid.java b/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/network/node/NetworkNodeGrid.java index 4c3ba61a9..bd3cdee03 100755 --- a/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/network/node/NetworkNodeGrid.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/network/node/NetworkNodeGrid.java @@ -27,6 +27,7 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.*; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; +import net.minecraft.item.crafting.IRecipe; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; @@ -67,6 +68,7 @@ public class NetworkNodeGrid extends NetworkNode implements IGrid { onCraftingMatrixChanged(); } }; + private IRecipe currentRecipe; private InventoryCrafting matrix = new InventoryCrafting(craftingContainer, 3, 3); private InventoryCraftResult result = new InventoryCraftResult(); private ItemHandlerBase matrixProcessing = new ItemHandlerBase(9 * 2, new ItemHandlerListenerNetworkNode(this)); @@ -238,7 +240,15 @@ public class NetworkNodeGrid extends NetworkNode implements IGrid { @Override public void onCraftingMatrixChanged() { - result.setInventorySlotContents(0, CraftingManager.findMatchingResult(matrix, world)); + if (currentRecipe == null || !currentRecipe.matches(matrix, world)) { + currentRecipe = CraftingManager.findMatchingRecipe(matrix, world); + } + + if (currentRecipe == null) { + result.setInventorySlotContents(0, ItemStack.EMPTY); + } else { + result.setInventorySlotContents(0, currentRecipe.getCraftingResult(matrix)); + } markDirty(); }