SPIGOT-4387: Durability looping from cancelled BlockPlaceEvent

This commit is contained in:
md_5 2018-12-22 11:25:14 +11:00
parent 24c5e68c5f
commit 91cae6efbf

View File

@ -85,11 +85,12 @@
EntityHuman entityhuman = itemactioncontext.getEntity(); EntityHuman entityhuman = itemactioncontext.getEntity();
BlockPosition blockposition = itemactioncontext.getClickPosition(); BlockPosition blockposition = itemactioncontext.getClickPosition();
ShapeDetectorBlock shapedetectorblock = new ShapeDetectorBlock(itemactioncontext.getWorld(), blockposition, false); ShapeDetectorBlock shapedetectorblock = new ShapeDetectorBlock(itemactioncontext.getWorld(), blockposition, false);
@@ -106,12 +146,142 @@ @@ -106,12 +146,147 @@
if (entityhuman != null && !entityhuman.abilities.mayBuild && !this.b(itemactioncontext.getWorld().F(), shapedetectorblock)) { if (entityhuman != null && !entityhuman.abilities.mayBuild && !this.b(itemactioncontext.getWorld().F(), shapedetectorblock)) {
return EnumInteractionResult.PASS; return EnumInteractionResult.PASS;
} else { } else {
+ // CraftBukkit start - handle all block place event logic here + // CraftBukkit start - handle all block place event logic here
+ NBTTagCompound oldData = this.getTagClone();
+ int oldCount = this.getCount(); + int oldCount = this.getCount();
+ World world = itemactioncontext.getWorld(); + World world = itemactioncontext.getWorld();
+ +
@ -102,8 +103,10 @@
+ } + }
Item item = this.getItem(); Item item = this.getItem();
EnumInteractionResult enuminteractionresult = item.a(itemactioncontext); EnumInteractionResult enuminteractionresult = item.a(itemactioncontext);
+ NBTTagCompound newData = this.getTagClone();
+ int newCount = this.getCount(); + int newCount = this.getCount();
+ this.setCount(oldCount); + this.setCount(oldCount);
+ this.setTagClone(oldData);
+ world.captureBlockStates = false; + world.captureBlockStates = false;
+ if (enuminteractionresult == EnumInteractionResult.SUCCESS && world.captureTreeGeneration && world.capturedBlockStates.size() > 0) { + if (enuminteractionresult == EnumInteractionResult.SUCCESS && world.captureTreeGeneration && world.capturedBlockStates.size() > 0) {
+ world.captureTreeGeneration = false; + world.captureTreeGeneration = false;
@ -125,7 +128,8 @@
+ +
+ if (!fertilizeEvent.isCancelled()) { + if (!fertilizeEvent.isCancelled()) {
+ // Change the stack to its new contents if it hasn't been tampered with. + // Change the stack to its new contents if it hasn't been tampered with.
+ if (this.getCount() == oldCount) { + if (this.getCount() == oldCount && Objects.equals(this.tag, oldData)) {
+ this.setTag(newData);
+ this.setCount(newCount); + this.setCount(newCount);
+ } + }
+ for (BlockState blockstate : blocks) { + for (BlockState blockstate : blocks) {
@ -164,7 +168,8 @@
+ } + }
+ } else { + } else {
+ // Change the stack to its new contents if it hasn't been tampered with. + // Change the stack to its new contents if it hasn't been tampered with.
+ if (this.getCount() == oldCount) { + if (this.getCount() == oldCount && Objects.equals(this.tag, oldData)) {
+ this.setTag(newData);
+ this.setCount(newCount); + this.setCount(newCount);
+ } + }
+ +
@ -229,7 +234,7 @@
return enuminteractionresult; return enuminteractionresult;
} }
@@ -135,7 +305,7 @@ @@ -135,7 +310,7 @@
nbttagcompound.setString("id", minecraftkey == null ? "minecraft:air" : minecraftkey.toString()); nbttagcompound.setString("id", minecraftkey == null ? "minecraft:air" : minecraftkey.toString());
nbttagcompound.setByte("Count", (byte) this.count); nbttagcompound.setByte("Count", (byte) this.count);
if (this.tag != null) { if (this.tag != null) {
@ -238,7 +243,7 @@
} }
return nbttagcompound; return nbttagcompound;
@@ -213,6 +383,11 @@ @@ -213,6 +388,11 @@
if (this.isDamaged(i, entityliving.getRandom(), entityliving instanceof EntityPlayer ? (EntityPlayer) entityliving : null)) { if (this.isDamaged(i, entityliving.getRandom(), entityliving instanceof EntityPlayer ? (EntityPlayer) entityliving : null)) {
entityliving.c(this); entityliving.c(this);
Item item = this.getItem(); Item item = this.getItem();
@ -250,7 +255,25 @@
this.subtract(1); this.subtract(1);
if (entityliving instanceof EntityHuman) { if (entityliving instanceof EntityHuman) {
@@ -480,6 +655,14 @@ @@ -336,6 +516,17 @@
return this.tag;
}
+ // CraftBukkit start
+ @Nullable
+ private NBTTagCompound getTagClone() {
+ return this.tag == null ? null : this.tag.clone();
+ }
+
+ private void setTagClone(@Nullable NBTTagCompound nbtttagcompound) {
+ this.setTag(nbtttagcompound == null ? null : nbtttagcompound.clone());
+ }
+ // CraftBukkit end
+
public NBTTagCompound getOrCreateTag() {
if (this.tag == null) {
this.setTag(new NBTTagCompound());
@@ -480,6 +671,14 @@
} }
public void setRepairCost(int i) { public void setRepairCost(int i) {
@ -265,7 +288,7 @@
this.getOrCreateTag().setInt("RepairCost", i); this.getOrCreateTag().setInt("RepairCost", i);
} }
@@ -522,6 +705,13 @@ @@ -522,6 +721,13 @@
nbttaglist.add((NBTBase) nbttagcompound); nbttaglist.add((NBTBase) nbttagcompound);
} }