From ac3b049df861fe09b709473c782556359e8b4c4c Mon Sep 17 00:00:00 2001 From: Kynake Date: Sat, 28 Nov 2026 17:22:28 -0300 Subject: [PATCH] Fix Auto Chisel visuals not updating when base was replaced --- .../tileentity/TileEntityAutoChisel.java | 92 +++++++++++-------- 1 file changed, 54 insertions(+), 38 deletions(-) diff --git a/src/main/java/team/chisel/block/tileentity/TileEntityAutoChisel.java b/src/main/java/team/chisel/block/tileentity/TileEntityAutoChisel.java index ef0bd14d..2af2c111 100644 --- a/src/main/java/team/chisel/block/tileentity/TileEntityAutoChisel.java +++ b/src/main/java/team/chisel/block/tileentity/TileEntityAutoChisel.java @@ -80,8 +80,10 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory public boolean chiseling = false, breakChisel = false;; public int toChisel = 1; + // Client-side visual cache private ItemStack lastBase; + // Server-side crafting caches private ItemStack baseCache = null; private ItemStack targetCache = null; private ItemStack reversionTargetCache = null; @@ -131,13 +133,26 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory @Override public void updateEntity() { + ItemStack base = inventory[BASE]; + if (base == null) { + baseCache = targetCache = reversionTargetCache = null; + if (!worldObj.isRemote) { + return; + } + } + + if (baseCache != base) { + baseCache = base; + reversionTargetCache = null; + progress = 0; + } + // Client-side visuals if (worldObj.isRemote) { if (chiseling) { chiselRot += rotAmnt; if (chiselRot >= maxRot) { - // Play Chisel SFX - chiselItem(0, getTarget()); + playChiselingEffects(); } } else { chiselRot = Math.max(chiselRot - rotAmnt, 0); @@ -146,15 +161,13 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory } // Server-side crafting - ItemStack base = inventory[BASE]; ItemStack target = getTarget(); - if (base == null || target == null || !hasChisel()) { - baseCache = targetCache = null; + if (target == null || !hasChisel()) { + baseCache = targetCache = reversionTargetCache = null; return; } - if (baseCache != base && targetCache != target) { - baseCache = base; + if (targetCache != target) { targetCache = target; progress = 0; } @@ -190,7 +203,6 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory result.stackSize = hasUpgrade(Upgrade.STACK) ? maxCraftSize : 1; if (canChisel(result)) { - // Use (and possibly break) the chisel chiselItem(result.stackSize, target); base.stackSize -= result.stackSize; @@ -249,37 +261,41 @@ public class TileEntityAutoChisel extends TileEntity implements ISidedInventory /** Calls IChiselItem#onChisel() and sends the chisel packet for sound/animation */ private void chiselItem(int chiseled, ItemStack target) { - if (!worldObj.isRemote) { - boolean breakChisel = false; - if (((IChiselItem) inventory[CHISEL].getItem()) - .onChisel(worldObj, inventory[CHISEL], General.getVariation(target))) { - inventory[CHISEL].setItemDamage(inventory[CHISEL].getItemDamage() + 1); - if (inventory[CHISEL].getItemDamage() >= inventory[CHISEL].getMaxDamage()) { - setInventorySlotContents(CHISEL, null); - breakChisel = true; - } + if (worldObj.isRemote) { + return; + } + + boolean breakChisel = false; + if (((IChiselItem) inventory[CHISEL].getItem()) + .onChisel(worldObj, inventory[CHISEL], General.getVariation(target))) { + inventory[CHISEL].setItemDamage(inventory[CHISEL].getItemDamage() + 1); + if (inventory[CHISEL].getItemDamage() >= inventory[CHISEL].getMaxDamage()) { + setInventorySlotContents(CHISEL, null); + breakChisel = true; } - PacketHandler.INSTANCE.sendToDimension( - new MessageAutoChisel(this, chiseled, true, breakChisel), - worldObj.provider.dimensionId); - } else { - if (breakChisel) { - worldObj.playSound( - xCoord + 0.5, - yCoord + 0.5, - zCoord + 0.5, - "random.break", - 0.8F, - 0.8F + worldObj.rand.nextFloat() * 0.4F, - false); - } - GeneralChiselClient.spawnAutoChiselFX(this, lastBase != null ? lastBase : inventory[BASE]); - chiseling = false; - if (lastBase != null) { - lastBase.stackSize -= toChisel; - if (lastBase.stackSize <= 0) { - lastBase = null; - } + } + PacketHandler.INSTANCE + .sendToDimension(new MessageAutoChisel(this, chiseled, true, breakChisel), worldObj.provider.dimensionId); + } + + @SideOnly(Side.CLIENT) + private void playChiselingEffects() { + if (breakChisel) { + worldObj.playSound( + xCoord + 0.5, + yCoord + 0.5, + zCoord + 0.5, + "random.break", + 0.8F, + 0.8F + worldObj.rand.nextFloat() * 0.4F, + false); + } + GeneralChiselClient.spawnAutoChiselFX(this, lastBase != null ? lastBase : inventory[BASE]); + chiseling = false; + if (lastBase != null) { + lastBase.stackSize -= toChisel; + if (lastBase.stackSize <= 0) { + lastBase = null; } } }