mirror of
https://github.com/GTNewHorizons/Chisel.git
synced 2026-11-27 23:46:10 +00:00
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
This commit is contained in:
1 parent
c7c478684d
commit
c0a68ee410
2 files changed
+29
-18
No files matched your search
@@ -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++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user