@@ -1,6 +1,6 @@
|
||||
--- a/net/minecraft/world/item/ItemStack.java
|
||||
+++ b/net/minecraft/world/item/ItemStack.java
|
||||
@@ -76,6 +76,39 @@
|
||||
@@ -73,6 +73,40 @@
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
+import com.mojang.serialization.Dynamic;
|
||||
+import java.util.List;
|
||||
+import java.util.Map;
|
||||
+import java.util.Objects;
|
||||
+import net.minecraft.core.EnumDirection;
|
||||
+import net.minecraft.nbt.DynamicOpsNBT;
|
||||
+import net.minecraft.network.protocol.game.PacketPlayOutBlockChange;
|
||||
@@ -40,17 +41,8 @@
|
||||
public final class ItemStack {
|
||||
|
||||
public static final Codec<ItemStack> CODEC = RecordCodecBuilder.create((instance) -> {
|
||||
@@ -89,7 +122,7 @@
|
||||
});
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
public static final ItemStack EMPTY = new ItemStack((Item) null);
|
||||
- public static final DecimalFormat ATTRIBUTE_MODIFIER_FORMAT = (DecimalFormat) SystemUtils.a((Object) (new DecimalFormat("#.##")), (decimalformat) -> {
|
||||
+ public static final DecimalFormat ATTRIBUTE_MODIFIER_FORMAT = (DecimalFormat) SystemUtils.a((new DecimalFormat("#.##")), (decimalformat) -> { // CraftBukkit - decompile error
|
||||
decimalformat.setDecimalFormatSymbols(DecimalFormatSymbols.getInstance(Locale.ROOT));
|
||||
});
|
||||
public static final String TAG_ENCH = "Enchantments";
|
||||
@@ -140,16 +173,30 @@
|
||||
this.checkEmpty();
|
||||
@@ -139,16 +173,30 @@
|
||||
this.updateEmptyCacheFlag();
|
||||
}
|
||||
|
||||
+ // Called to run this stack through the data converter to handle older storage methods and serialized items
|
||||
@@ -63,7 +55,7 @@
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
private void checkEmpty() {
|
||||
private void updateEmptyCacheFlag() {
|
||||
+ if (this.emptyCacheFlag && this == ItemStack.EMPTY) throw new AssertionError("TRAP"); // CraftBukkit
|
||||
this.emptyCacheFlag = false;
|
||||
this.emptyCacheFlag = this.isEmpty();
|
||||
@@ -74,16 +66,16 @@
|
||||
+ private void load(NBTTagCompound nbttagcompound) {
|
||||
this.item = (Item) IRegistry.ITEM.get(new MinecraftKey(nbttagcompound.getString("id")));
|
||||
this.count = nbttagcompound.getByte("Count");
|
||||
if (nbttagcompound.hasKeyOfType("tag", 10)) {
|
||||
if (nbttagcompound.contains("tag", 10)) {
|
||||
- this.tag = nbttagcompound.getCompound("tag");
|
||||
+ // CraftBukkit start - make defensive copy as this data may be coming from the save thread
|
||||
+ this.tag = (NBTTagCompound) nbttagcompound.getCompound("tag").clone();
|
||||
+ this.tag = nbttagcompound.getCompound("tag").copy();
|
||||
+ // CraftBukkit end
|
||||
this.getItem().b(this.tag);
|
||||
this.getItem().verifyTagAfterLoad(this.tag);
|
||||
}
|
||||
|
||||
@@ -157,6 +204,11 @@
|
||||
this.setDamage(this.getDamage());
|
||||
@@ -156,6 +204,11 @@
|
||||
this.setDamageValue(this.getDamageValue());
|
||||
}
|
||||
|
||||
+ }
|
||||
@@ -91,26 +83,26 @@
|
||||
+ private ItemStack(NBTTagCompound nbttagcompound) {
|
||||
+ this.load(nbttagcompound);
|
||||
+ // CraftBukkit end
|
||||
this.checkEmpty();
|
||||
this.updateEmptyCacheFlag();
|
||||
}
|
||||
|
||||
@@ -194,7 +246,7 @@
|
||||
@@ -193,7 +246,7 @@
|
||||
return this.getItem() == item;
|
||||
}
|
||||
|
||||
- public EnumInteractionResult placeItem(ItemActionContext itemactioncontext) {
|
||||
+ public EnumInteractionResult placeItem(ItemActionContext itemactioncontext, EnumHand enumhand) { // CraftBukkit - add hand
|
||||
EntityHuman entityhuman = itemactioncontext.getEntity();
|
||||
BlockPosition blockposition = itemactioncontext.getClickPosition();
|
||||
ShapeDetectorBlock shapedetectorblock = new ShapeDetectorBlock(itemactioncontext.getWorld(), blockposition, false);
|
||||
@@ -202,12 +254,157 @@
|
||||
if (entityhuman != null && !entityhuman.getAbilities().mayBuild && !this.b(itemactioncontext.getWorld().r(), shapedetectorblock)) {
|
||||
- public EnumInteractionResult useOn(ItemActionContext itemactioncontext) {
|
||||
+ public EnumInteractionResult useOn(ItemActionContext itemactioncontext, EnumHand enumhand) { // CraftBukkit - add hand
|
||||
EntityHuman entityhuman = itemactioncontext.getPlayer();
|
||||
BlockPosition blockposition = itemactioncontext.getClickedPos();
|
||||
ShapeDetectorBlock shapedetectorblock = new ShapeDetectorBlock(itemactioncontext.getLevel(), blockposition, false);
|
||||
@@ -201,12 +254,157 @@
|
||||
if (entityhuman != null && !entityhuman.getAbilities().mayBuild && !this.hasAdventureModePlaceTagForBlock(itemactioncontext.getLevel().getTagManager(), shapedetectorblock)) {
|
||||
return EnumInteractionResult.PASS;
|
||||
} else {
|
||||
+ // CraftBukkit start - handle all block place event logic here
|
||||
+ NBTTagCompound oldData = this.getTagClone();
|
||||
+ int oldCount = this.getCount();
|
||||
+ WorldServer world = (WorldServer) itemactioncontext.getWorld();
|
||||
+ WorldServer world = (WorldServer) itemactioncontext.getLevel();
|
||||
+
|
||||
+ if (!(this.getItem() instanceof ItemBucket || this.getItem() instanceof SolidBucketItem)) { // if not bucket
|
||||
+ world.captureBlockStates = true;
|
||||
@@ -120,13 +112,13 @@
|
||||
+ }
|
||||
+ }
|
||||
Item item = this.getItem();
|
||||
EnumInteractionResult enuminteractionresult = item.a(itemactioncontext);
|
||||
EnumInteractionResult enuminteractionresult = item.useOn(itemactioncontext);
|
||||
+ NBTTagCompound newData = this.getTagClone();
|
||||
+ int newCount = this.getCount();
|
||||
+ this.setCount(oldCount);
|
||||
+ this.setTagClone(oldData);
|
||||
+ world.captureBlockStates = false;
|
||||
+ if (enuminteractionresult.a() && world.captureTreeGeneration && world.capturedBlockStates.size() > 0) {
|
||||
+ if (enuminteractionresult.consumesAction() && world.captureTreeGeneration && world.capturedBlockStates.size() > 0) {
|
||||
+ world.captureTreeGeneration = false;
|
||||
+ Location location = new Location(world.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ());
|
||||
+ TreeType treeType = BlockSapling.treeType;
|
||||
@@ -160,8 +152,8 @@
|
||||
+ }
|
||||
+ world.captureTreeGeneration = false;
|
||||
|
||||
if (entityhuman != null && enuminteractionresult.c()) {
|
||||
- entityhuman.b(StatisticList.ITEM_USED.b(item));
|
||||
if (entityhuman != null && enuminteractionresult.shouldAwardStats()) {
|
||||
- entityhuman.awardStat(StatisticList.ITEM_USED.get(item));
|
||||
+ org.bukkit.event.block.BlockPlaceEvent placeEvent = null;
|
||||
+ List<BlockState> blocks = new java.util.ArrayList<>(world.capturedBlockStates.values());
|
||||
+ world.capturedBlockStates.clear();
|
||||
@@ -185,7 +177,7 @@
|
||||
+ // Brute force all possible updates
|
||||
+ BlockPosition placedPos = ((CraftBlock) placeEvent.getBlock()).getPosition();
|
||||
+ for (EnumDirection dir : EnumDirection.values()) {
|
||||
+ ((EntityPlayer) entityhuman).connection.sendPacket(new PacketPlayOutBlockChange(world, placedPos.shift(dir)));
|
||||
+ ((EntityPlayer) entityhuman).connection.send(new PacketPlayOutBlockChange(world, placedPos.relative(dir)));
|
||||
+ }
|
||||
+ ItemSign.openSign = null; // SPIGOT-6758 - Reset on early return
|
||||
+ } else {
|
||||
@@ -196,44 +188,44 @@
|
||||
+ }
|
||||
+
|
||||
+ for (Map.Entry<BlockPosition, TileEntity> e : world.capturedTileEntities.entrySet()) {
|
||||
+ world.setTileEntity(e.getValue());
|
||||
+ world.setBlockEntity(e.getValue());
|
||||
+ }
|
||||
+
|
||||
+ for (BlockState blockstate : blocks) {
|
||||
+ int updateFlag = ((CraftBlockState) blockstate).getFlag();
|
||||
+ IBlockData oldBlock = ((CraftBlockState) blockstate).getHandle();
|
||||
+ BlockPosition newblockposition = ((CraftBlockState) blockstate).getPosition();
|
||||
+ IBlockData block = world.getType(newblockposition);
|
||||
+ IBlockData block = world.getBlockState(newblockposition);
|
||||
+
|
||||
+ if (!(block.getBlock() instanceof BlockTileEntity)) { // Containers get placed automatically
|
||||
+ block.getBlock().onPlace(block, world, newblockposition, oldBlock, true);
|
||||
+ }
|
||||
+
|
||||
+ world.notifyAndUpdatePhysics(newblockposition, null, oldBlock, block, world.getType(newblockposition), updateFlag, 512); // send null chunk as chunk.k() returns false by this point
|
||||
+ world.notifyAndUpdatePhysics(newblockposition, null, oldBlock, block, world.getBlockState(newblockposition), updateFlag, 512); // send null chunk as chunk.k() returns false by this point
|
||||
+ }
|
||||
+
|
||||
+ // Special case juke boxes as they update their tile entity. Copied from ItemRecord.
|
||||
+ // PAIL: checkme on updates.
|
||||
+ if (this.item instanceof ItemRecord) {
|
||||
+ ((BlockJukeBox) Blocks.JUKEBOX).a(world, blockposition, world.getType(blockposition), this);
|
||||
+ world.a((EntityHuman) null, 1010, blockposition, Item.getId(this.item));
|
||||
+ this.subtract(1);
|
||||
+ entityhuman.a(StatisticList.PLAY_RECORD);
|
||||
+ ((BlockJukeBox) Blocks.JUKEBOX).setRecord(world, blockposition, world.getBlockState(blockposition), this);
|
||||
+ world.levelEvent((EntityHuman) null, 1010, blockposition, Item.getId(this.item));
|
||||
+ this.shrink(1);
|
||||
+ entityhuman.awardStat(StatisticList.PLAY_RECORD);
|
||||
+ }
|
||||
+
|
||||
+ if (this.item == Items.WITHER_SKELETON_SKULL) { // Special case skulls to allow wither spawns to be cancelled
|
||||
+ BlockPosition bp = blockposition;
|
||||
+ if (!world.getType(blockposition).getMaterial().isReplaceable()) {
|
||||
+ if (!world.getType(blockposition).getMaterial().isBuildable()) {
|
||||
+ if (!world.getBlockState(blockposition).getMaterial().isReplaceable()) {
|
||||
+ if (!world.getBlockState(blockposition).getMaterial().isSolid()) {
|
||||
+ bp = null;
|
||||
+ } else {
|
||||
+ bp = bp.shift(itemactioncontext.getClickedFace());
|
||||
+ bp = bp.relative(itemactioncontext.getClickedFace());
|
||||
+ }
|
||||
+ }
|
||||
+ if (bp != null) {
|
||||
+ TileEntity te = world.getTileEntity(bp);
|
||||
+ TileEntity te = world.getBlockEntity(bp);
|
||||
+ if (te instanceof TileEntitySkull) {
|
||||
+ BlockWitherSkull.a(world, bp, (TileEntitySkull) te);
|
||||
+ BlockWitherSkull.checkSpawn(world, bp, (TileEntitySkull) te);
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
@@ -241,7 +233,7 @@
|
||||
+ // SPIGOT-4678
|
||||
+ if (this.item instanceof ItemSign && ItemSign.openSign != null) {
|
||||
+ try {
|
||||
+ entityhuman.openSign((TileEntitySign) world.getTileEntity(ItemSign.openSign));
|
||||
+ entityhuman.openTextEdit((TileEntitySign) world.getBlockEntity(ItemSign.openSign));
|
||||
+ } finally {
|
||||
+ ItemSign.openSign = null;
|
||||
+ }
|
||||
@@ -249,11 +241,11 @@
|
||||
+
|
||||
+ // SPIGOT-1288 - play sound stripped from ItemBlock
|
||||
+ if (this.item instanceof ItemBlock) {
|
||||
+ SoundEffectType soundeffecttype = ((ItemBlock) this.item).getBlock().getStepSound(null);
|
||||
+ SoundEffectType soundeffecttype = ((ItemBlock) this.item).getBlock().getSoundType(null);
|
||||
+ world.playSound(entityhuman, blockposition, soundeffecttype.getPlaceSound(), SoundCategory.BLOCKS, (soundeffecttype.getVolume() + 1.0F) / 2.0F, soundeffecttype.getPitch() * 0.8F);
|
||||
+ }
|
||||
+
|
||||
+ entityhuman.b(StatisticList.ITEM_USED.b(item));
|
||||
+ entityhuman.awardStat(StatisticList.ITEM_USED.get(item));
|
||||
+ }
|
||||
}
|
||||
+ world.capturedTileEntities.clear();
|
||||
@@ -262,7 +254,7 @@
|
||||
|
||||
return enuminteractionresult;
|
||||
}
|
||||
@@ -288,6 +485,21 @@
|
||||
@@ -287,6 +485,21 @@
|
||||
}
|
||||
|
||||
i -= k;
|
||||
@@ -284,8 +276,8 @@
|
||||
if (i <= 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -309,6 +521,11 @@
|
||||
if (this.isDamaged(i, t0.getRandom(), t0 instanceof EntityPlayer ? (EntityPlayer) t0 : null)) {
|
||||
@@ -308,6 +521,11 @@
|
||||
if (this.hurt(i, t0.getRandom(), t0 instanceof EntityPlayer ? (EntityPlayer) t0 : null)) {
|
||||
consumer.accept(t0);
|
||||
Item item = this.getItem();
|
||||
+ // CraftBukkit start - Check for item breaking
|
||||
@@ -294,40 +286,40 @@
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
|
||||
this.subtract(1);
|
||||
this.shrink(1);
|
||||
if (t0 instanceof EntityHuman) {
|
||||
@@ -464,6 +681,17 @@
|
||||
@@ -463,6 +681,17 @@
|
||||
return this.tag;
|
||||
}
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ @Nullable
|
||||
+ private NBTTagCompound getTagClone() {
|
||||
+ return this.tag == null ? null : this.tag.clone();
|
||||
+ return this.tag == null ? null : this.tag.copy();
|
||||
+ }
|
||||
+
|
||||
+ private void setTagClone(@Nullable NBTTagCompound nbtttagcompound) {
|
||||
+ this.setTag(nbtttagcompound == null ? null : nbtttagcompound.clone());
|
||||
+ this.setTag(nbtttagcompound == null ? null : nbtttagcompound.copy());
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
public NBTTagCompound getOrCreateTag() {
|
||||
if (this.tag == null) {
|
||||
this.setTag(new NBTTagCompound());
|
||||
@@ -844,6 +1072,12 @@
|
||||
@@ -843,6 +1072,12 @@
|
||||
}
|
||||
|
||||
public void setRepairCost(int i) {
|
||||
+ // CraftBukkit start - remove RepairCost tag when 0 (SPIGOT-3945)
|
||||
+ if (i == 0) {
|
||||
+ this.removeTag("RepairCost");
|
||||
+ this.removeTagKey("RepairCost");
|
||||
+ return;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
this.getOrCreateTag().setInt("RepairCost", i);
|
||||
this.getOrCreateTag().putInt("RepairCost", i);
|
||||
}
|
||||
|
||||
@@ -893,6 +1127,13 @@
|
||||
@@ -892,6 +1127,13 @@
|
||||
nbttaglist.add(nbttagcompound);
|
||||
}
|
||||
|
||||
@@ -338,6 +330,6 @@
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
public IChatBaseComponent G() {
|
||||
IChatMutableComponent ichatmutablecomponent = (new ChatComponentText("")).addSibling(this.getName());
|
||||
public IChatBaseComponent getDisplayName() {
|
||||
IChatMutableComponent ichatmutablecomponent = (new ChatComponentText("")).append(this.getHoverName());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user