From 1afc21435668302459143b590508e2b7f8a1f5da Mon Sep 17 00:00:00 2001 From: Kynake Date: Sat, 28 Nov 2026 16:22:43 -0300 Subject: [PATCH] Refactor Auto Chisel logic to not require caching the result, only the inputs Now baseCache and inputCache are only used to detect changes to the inputs, which resets the progress --- .../tileentity/TileEntityAutoChisel.java | 50 +++++++------------ 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/src/main/java/team/chisel/block/tileentity/TileEntityAutoChisel.java b/src/main/java/team/chisel/block/tileentity/TileEntityAutoChisel.java index 3d897a9e..ef0bd14d 100644 --- a/src/main/java/team/chisel/block/tileentity/TileEntityAutoChisel.java +++ b/src/main/java/team/chisel/block/tileentity/TileEntityAutoChisel.java @@ -82,7 +82,6 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory private ItemStack lastBase; - // Crafting caches to avoid creating a new ItemStack result each tick private ItemStack baseCache = null; private ItemStack targetCache = null; private ItemStack reversionTargetCache = null; @@ -150,71 +149,60 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory ItemStack base = inventory[BASE]; ItemStack target = getTarget(); if (base == null || target == null || !hasChisel()) { - baseCache = targetCache = resultCache = null; + baseCache = targetCache = null; return; } - // Something has changed about the recipe, regenerate caches - if (resultCache == null || baseCache != base || targetCache != target) { - // Unfiltered chisel result. Actual crafting might fail or be of a lower stack size than this. - resultCache = CarvingUtils.tryChiselingInto(base, target); - if (resultCache == null) { - // Not a valid chisel recipe - baseCache = targetCache = null; - return; - } - + if (baseCache != base && targetCache != target) { baseCache = base; targetCache = target; + progress = 0; } if (progress < (hasUpgrade(Upgrade.SPEED) ? FAST_SPEED : SLOW_SPEED)) { if (worldObj.getTotalWorldTime() % 10 == 0) { progress++; } - - // Update progress and return return; } - // Crafting finished progress = 0; - // Use the template's stack size as the max possible for this craft - int canBeMade = target.getMaxStackSize(); + ItemStack result = CarvingUtils.tryChiselingInto(base, target); + if (result == null) { + baseCache = targetCache = null; + return; + } + + int maxCraftSize = result.getMaxStackSize(); // If there are items in the output, they count towards the max we can make ItemStack output = inventory[OUTPUT]; if (output != null) { - canBeMade -= output.stackSize; + maxCraftSize -= output.stackSize; } - // Can't make more than we have - canBeMade = Math.min(base.stackSize, canBeMade); - - // If we can't make any, forget it - if (canBeMade <= 0) { + maxCraftSize = Math.min(base.stackSize, maxCraftSize); + if (maxCraftSize <= 0) { return; } - // If we have the stack upgrade, boost the stack size to the max possible, otherwise just one - resultCache.stackSize = hasUpgrade(Upgrade.STACK) ? canBeMade : 1; + result.stackSize = hasUpgrade(Upgrade.STACK) ? maxCraftSize : 1; - if (canChisel(resultCache)) { + if (canChisel(result)) { // Use (and possibly break) the chisel - chiselItem(resultCache.stackSize, target); + chiselItem(result.stackSize, target); - // Remove what we made from the input stack and add it to the output stack - base.stackSize -= resultCache.stackSize; + base.stackSize -= result.stackSize; if (base.stackSize <= 0) { setInventorySlotContents(BASE, null); baseCache = null; } if (output == null) { - setInventorySlotContents(OUTPUT, resultCache.copy()); + setInventorySlotContents(OUTPUT, result); } else { - inventory[OUTPUT].stackSize += resultCache.stackSize; + inventory[OUTPUT].stackSize += result.stackSize; slotChanged(OUTPUT); } }