SPIGOT-4221: Update surrounding blocks for cancelled break/place

This commit is contained in:
md_5 2018-08-03 11:34:26 +10:00
parent 3006dee4c6
commit 69970127c1
3 changed files with 32 additions and 20 deletions

View file

@ -85,7 +85,7 @@
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,136 @@ @@ -106,12 +146,142 @@
if (entityhuman != null && !entityhuman.abilities.mayBuild && !this.b(itemactioncontext.getWorld().E(), shapedetectorblock)) { if (entityhuman != null && !entityhuman.abilities.mayBuild && !this.b(itemactioncontext.getWorld().E(), shapedetectorblock)) {
return EnumInteractionResult.PASS; return EnumInteractionResult.PASS;
} else { } else {
@ -156,6 +156,12 @@
+ for (BlockState blockstate : blocks) { + for (BlockState blockstate : blocks) {
+ blockstate.update(true, false); + blockstate.update(true, false);
+ } + }
+
+ // Brute force all possible updates
+ BlockPosition placedPos = ((CraftBlock) placeEvent.getBlock()).getPosition();
+ for (EnumDirection dir : EnumDirection.values()) {
+ ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutBlockChange(world, placedPos.shift(dir)));
+ }
+ } 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) {
@ -223,7 +229,7 @@
return enuminteractionresult; return enuminteractionresult;
} }
@@ -135,7 +299,7 @@ @@ -135,7 +305,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) {
@ -232,7 +238,7 @@
} }
return nbttagcompound; return nbttagcompound;
@@ -213,6 +377,11 @@ @@ -213,6 +383,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();
@ -244,7 +250,7 @@
this.subtract(1); this.subtract(1);
if (entityliving instanceof EntityHuman) { if (entityliving instanceof EntityHuman) {
@@ -480,6 +649,14 @@ @@ -480,6 +655,14 @@
} }
public void setRepairCost(int i) { public void setRepairCost(int i) {
@ -259,7 +265,7 @@
this.getOrCreateTag().setInt("RepairCost", i); this.getOrCreateTag().setInt("RepairCost", i);
} }
@@ -522,6 +699,13 @@ @@ -522,6 +705,13 @@
nbttaglist.add((NBTBase) nbttagcompound); nbttaglist.add((NBTBase) nbttagcompound);
} }

View file

@ -53,7 +53,7 @@
if (this.isCreative()) { if (this.isCreative()) {
if (!this.world.douseFire((EntityHuman) null, blockposition, enumdirection)) { if (!this.world.douseFire((EntityHuman) null, blockposition, enumdirection)) {
this.breakBlock(blockposition); this.breakBlock(blockposition);
@@ -122,15 +144,49 @@ @@ -122,16 +144,50 @@
} }
} }
@ -96,15 +96,16 @@
+ // Let the client know the block still exists + // Let the client know the block still exists
+ ((EntityPlayer) this.player).playerConnection.sendPacket(new PacketPlayOutBlockChange(this.world, blockposition)); + ((EntityPlayer) this.player).playerConnection.sendPacket(new PacketPlayOutBlockChange(this.world, blockposition));
+ return; + return;
+ } }
+
+ if (blockEvent.getInstaBreak()) { + if (blockEvent.getInstaBreak()) {
+ f = 2.0f; + f = 2.0f;
} + }
+ // CraftBukkit end + // CraftBukkit end
+
if (!iblockdata.isAir() && f >= 1.0F) { if (!iblockdata.isAir() && f >= 1.0F) {
this.breakBlock(blockposition); this.breakBlock(blockposition);
} else {
@@ -149,6 +205,7 @@ @@ -149,6 +205,7 @@
public void a(BlockPosition blockposition) { public void a(BlockPosition blockposition) {
@ -124,7 +125,7 @@
} }
} }
@@ -190,13 +251,88 @@ @@ -190,13 +251,89 @@
public boolean breakBlock(BlockPosition blockposition) { public boolean breakBlock(BlockPosition blockposition) {
IBlockData iblockdata = this.world.getType(blockposition); IBlockData iblockdata = this.world.getType(blockposition);
@ -165,21 +166,22 @@
+ event.setExpToDrop(nmsBlock.getExpDrop(nmsData, this.world, blockposition, bonusLevel)); + event.setExpToDrop(nmsBlock.getExpDrop(nmsData, this.world, blockposition, bonusLevel));
+ } + }
+ } + }
+
+ this.world.getServer().getPluginManager().callEvent(event);
- if (!this.player.getItemInMainHand().getItem().a(iblockdata, this.world, blockposition, (EntityHuman) this.player)) { - if (!this.player.getItemInMainHand().getItem().a(iblockdata, this.world, blockposition, (EntityHuman) this.player)) {
+ this.world.getServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) { + if (event.isCancelled()) {
+ if (isSwordNoBreak) { + if (isSwordNoBreak) {
+ return false; + return false;
+ } + }
+ // Let the client know the block still exists + // Let the client know the block still exists
+ ((EntityPlayer) this.player).playerConnection.sendPacket(new PacketPlayOutBlockChange(this.world, blockposition)); + ((EntityPlayer) this.player).playerConnection.sendPacket(new PacketPlayOutBlockChange(this.world, blockposition));
+ // Send other half of the door +
+ if (nmsBlock instanceof BlockDoor) { + // Brute force all possible updates
+ boolean bottom = nmsData.get(BlockDoor.HALF) == BlockPropertyDoubleBlockHalf.LOWER; + for (EnumDirection dir : EnumDirection.values()) {
+ ((EntityPlayer) this.player).playerConnection.sendPacket(new PacketPlayOutBlockChange(world, bottom ? blockposition.up() : blockposition.down())); + ((EntityPlayer) this.player).playerConnection.sendPacket(new PacketPlayOutBlockChange(world, blockposition.shift(dir)));
+ } + }
+
+ // Update any tile entity data for this block + // Update any tile entity data for this block
+ TileEntity tileentity = this.world.getTileEntity(blockposition); + TileEntity tileentity = this.world.getTileEntity(blockposition);
+ if (tileentity != null) { + if (tileentity != null) {
@ -214,7 +216,7 @@
if ((block instanceof BlockCommand || block instanceof BlockStructure) && !this.player.isCreativeAndOp()) { if ((block instanceof BlockCommand || block instanceof BlockStructure) && !this.player.isCreativeAndOp()) {
this.world.notify(blockposition, iblockdata, iblockdata, 3); this.world.notify(blockposition, iblockdata, iblockdata, 3);
return false; return false;
@@ -221,19 +357,36 @@ @@ -221,19 +358,36 @@
} }
} }
@ -252,7 +254,7 @@
return flag; return flag;
} }
@@ -277,11 +430,40 @@ @@ -277,11 +431,40 @@
} }
} }
@ -293,7 +295,7 @@
if (tileentity instanceof ITileInventory) { if (tileentity instanceof ITileInventory) {
Block block = iblockdata.getBlock(); Block block = iblockdata.getBlock();
@@ -305,24 +487,26 @@ @@ -305,24 +488,26 @@
boolean flag = !entityhuman.getItemInMainHand().isEmpty() || !entityhuman.getItemInOffHand().isEmpty(); boolean flag = !entityhuman.getItemInMainHand().isEmpty() || !entityhuman.getItemInOffHand().isEmpty();
boolean flag1 = entityhuman.isSneaking() && flag; boolean flag1 = entityhuman.isSneaking() && flag;

View file

@ -49,6 +49,10 @@ public class CraftBlock implements Block {
return world.getType(position); return world.getType(position);
} }
public BlockPosition getPosition() {
return position;
}
public World getWorld() { public World getWorld() {
return world.getMinecraftWorld().getWorld(); return world.getMinecraftWorld().getWorld();
} }