From c0a68ee410f43b11176d48aa09f63c9257c4e819 Mon Sep 17 00:00:00 2001 From: Kynake Date: Fri, 27 Nov 2026 16:15:21 -0300 Subject: [PATCH] Refactor hand chiseling to display variations with the resulting NBT data Also fix an output duplication bug whe chiseling via keyboard 1-9 or Q --- .../inventory/InventoryChiselSelection.java | 11 +++++- .../chisel/inventory/SlotChiselSelection.java | 36 ++++++++++--------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/main/java/team/chisel/inventory/InventoryChiselSelection.java b/src/main/java/team/chisel/inventory/InventoryChiselSelection.java index add98095..02fb6f75 100644 --- a/src/main/java/team/chisel/inventory/InventoryChiselSelection.java +++ b/src/main/java/team/chisel/inventory/InventoryChiselSelection.java @@ -146,7 +146,16 @@ public class InventoryChiselSelection implements IInventory { list.get(activeVariations + currentScroll) .getItem())) != null) { - inventory[activeVariations] = list.get(activeVariations + currentScroll); + ItemStack variationTemplate = list.get(activeVariations + currentScroll); + + // Preserve the original's NBT tags + if (chiseledItem.hasTagCompound()) { + variationTemplate = variationTemplate.copy(); + // We can defer the deep copy the NBT object until the player actually chisels the item + variationTemplate.setTagCompound(chiseledItem.getTagCompound()); + } + + inventory[activeVariations] = variationTemplate; activeVariations++; } } diff --git a/src/main/java/team/chisel/inventory/SlotChiselSelection.java b/src/main/java/team/chisel/inventory/SlotChiselSelection.java index 896e1eaf..68752c4b 100644 --- a/src/main/java/team/chisel/inventory/SlotChiselSelection.java +++ b/src/main/java/team/chisel/inventory/SlotChiselSelection.java @@ -4,11 +4,11 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.MathHelper; import com.cricketcraft.chisel.api.IChiselItem; import com.cricketcraft.chisel.api.Statistics; -import com.cricketcraft.chisel.api.carving.CarvingUtils; import team.chisel.carving.Carving; import team.chisel.utils.General; @@ -41,29 +41,32 @@ public class SlotChiselSelection extends Slot { @Override public void onPickupFromSlot(EntityPlayer player, ItemStack itemstack) { - ItemStack chiselInputStack = selInventory.inventory[InventoryChiselSelection.normalSlots]; + ItemStack chiselInput = selInventory.inventory[InventoryChiselSelection.normalSlots]; + ItemStack heldStack = player.inventory.getItemStack(); - if (itemstack == null) { + // Was chiseled by clicking 1-9 or Q, chisel only one item from the stack + if (heldStack == null) { selInventory.decrStackSize(InventoryChiselSelection.normalSlots, 1); - } else { - if (chiselInputStack == null) { - player.inventory.setItemStack(null); - return; + if (selInventory.inventory[InventoryChiselSelection.normalSlots] != null) { + NBTTagCompound stackNBT = itemstack.getTagCompound(); + if (stackNBT != null) { + // Deep copy the resulting stack's NBT to prevent it from sharing + // the same NBT object reference with the unchiseled ItemStack + itemstack.setTagCompound((NBTTagCompound) stackNBT.copy()); + } } + } - // Perform chisel crafting operation - ItemStack chiselingOutput = CarvingUtils.tryChiselingInto(chiselInputStack, itemstack); - player.inventory.setItemStack(chiselingOutput); - - // Clear the input stack + // Was clicked normally (or shift-clicked), chisel the entire stack + else { + heldStack.stackSize = chiselInput.stackSize; selInventory.setInventorySlotContents(InventoryChiselSelection.normalSlots, null); } selInventory.updateItems(); - // Damage and possibly break the chisel if (((IChiselItem) container.chisel.getItem()) - .onChisel(player.worldObj, container.chisel, General.getVariation(chiselInputStack))) { + .onChisel(player.worldObj, container.chisel, General.getVariation(chiselInput))) { container.chisel.damageItem(1, player); if (container.chisel.stackSize <= 0) { player.setCurrentItemOrArmor(0, null); @@ -71,8 +74,7 @@ public class SlotChiselSelection extends Slot { } if (player.worldObj.isRemote) { - String sound = Carving.chisel - .getVariationSound(chiselInputStack.getItem(), chiselInputStack.getItemDamage()); + String sound = Carving.chisel.getVariationSound(chiselInput.getItem(), chiselInput.getItemDamage()); GeneralClient.playChiselSound( player.worldObj, MathHelper.floor_double(player.posX), @@ -80,7 +82,7 @@ public class SlotChiselSelection extends Slot { MathHelper.floor_double(player.posZ), sound); } else { - container.playerInventory.player.addStat(Statistics.blocksChiseled, chiselInputStack.stackSize); + container.playerInventory.player.addStat(Statistics.blocksChiseled, itemstack.stackSize); } } }