SPIGOT-6435: send correcting "PacketPlayOutBlockChange" packet on interact for bisected items

By: Julian van den Berkmortel <julianvdberkmortel@outlook.com>
This commit is contained in:
CraftBukkit/Spigot 2021-04-27 11:37:52 +10:00
parent 4d865daa32
commit c5af0704d0

View File

@ -1,6 +1,6 @@
--- a/net/minecraft/server/level/PlayerInteractManager.java --- a/net/minecraft/server/level/PlayerInteractManager.java
+++ b/net/minecraft/server/level/PlayerInteractManager.java +++ b/net/minecraft/server/level/PlayerInteractManager.java
@@ -26,6 +26,24 @@ @@ -26,6 +26,25 @@
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -9,6 +9,7 @@
+import net.minecraft.network.protocol.game.PacketPlayOutBlockChange; +import net.minecraft.network.protocol.game.PacketPlayOutBlockChange;
+import net.minecraft.server.MinecraftServer; +import net.minecraft.server.MinecraftServer;
+import net.minecraft.world.entity.EnumItemSlot; +import net.minecraft.world.entity.EnumItemSlot;
+import net.minecraft.world.item.ItemBisected;
+import net.minecraft.world.level.block.BlockCake; +import net.minecraft.world.level.block.BlockCake;
+import net.minecraft.world.level.block.BlockDoor; +import net.minecraft.world.level.block.BlockDoor;
+import net.minecraft.world.level.block.BlockTrapdoor; +import net.minecraft.world.level.block.BlockTrapdoor;
@ -25,7 +26,7 @@
public class PlayerInteractManager { public class PlayerInteractManager {
private static final Logger LOGGER = LogManager.getLogger(); private static final Logger LOGGER = LogManager.getLogger();
@@ -60,7 +78,7 @@ @@ -60,7 +79,7 @@
this.gamemode = enumgamemode; this.gamemode = enumgamemode;
enumgamemode.a(this.player.abilities); enumgamemode.a(this.player.abilities);
this.player.updateAbilities(); this.player.updateAbilities();
@ -34,7 +35,7 @@
this.world.everyoneSleeping(); this.world.everyoneSleeping();
} }
@@ -89,7 +107,7 @@ @@ -89,7 +108,7 @@
} }
public void a() { public void a() {
@ -43,7 +44,7 @@
IBlockData iblockdata; IBlockData iblockdata;
if (this.j) { if (this.j) {
@@ -145,9 +163,31 @@ @@ -145,9 +164,31 @@
if (packetplayinblockdig_enumplayerdigtype == PacketPlayInBlockDig.EnumPlayerDigType.START_DESTROY_BLOCK) { if (packetplayinblockdig_enumplayerdigtype == PacketPlayInBlockDig.EnumPlayerDigType.START_DESTROY_BLOCK) {
if (!this.world.a((EntityHuman) this.player, blockposition)) { if (!this.world.a((EntityHuman) this.player, blockposition)) {
@ -75,7 +76,7 @@
if (this.isCreative()) { if (this.isCreative()) {
this.a(blockposition, packetplayinblockdig_enumplayerdigtype, "creative destroy"); this.a(blockposition, packetplayinblockdig_enumplayerdigtype, "creative destroy");
@@ -163,11 +203,43 @@ @@ -163,11 +204,43 @@
float f = 1.0F; float f = 1.0F;
iblockdata = this.world.getType(blockposition); iblockdata = this.world.getType(blockposition);
@ -120,7 +121,7 @@
if (!iblockdata.isAir() && f >= 1.0F) { if (!iblockdata.isAir() && f >= 1.0F) {
this.a(blockposition, packetplayinblockdig_enumplayerdigtype, "insta mine"); this.a(blockposition, packetplayinblockdig_enumplayerdigtype, "insta mine");
} else { } else {
@@ -211,7 +283,7 @@ @@ -211,7 +284,7 @@
} else if (packetplayinblockdig_enumplayerdigtype == PacketPlayInBlockDig.EnumPlayerDigType.ABORT_DESTROY_BLOCK) { } else if (packetplayinblockdig_enumplayerdigtype == PacketPlayInBlockDig.EnumPlayerDigType.ABORT_DESTROY_BLOCK) {
this.f = false; this.f = false;
if (!Objects.equals(this.h, blockposition)) { if (!Objects.equals(this.h, blockposition)) {
@ -129,7 +130,7 @@
this.world.a(this.player.getId(), this.h, -1); this.world.a(this.player.getId(), this.h, -1);
this.player.playerConnection.sendPacket(new PacketPlayOutBlockBreak(this.h, this.world.getType(this.h), packetplayinblockdig_enumplayerdigtype, true, "aborted mismatched destroying")); this.player.playerConnection.sendPacket(new PacketPlayOutBlockBreak(this.h, this.world.getType(this.h), packetplayinblockdig_enumplayerdigtype, true, "aborted mismatched destroying"));
} }
@@ -227,17 +299,73 @@ @@ -227,17 +300,73 @@
if (this.breakBlock(blockposition)) { if (this.breakBlock(blockposition)) {
this.player.playerConnection.sendPacket(new PacketPlayOutBlockBreak(blockposition, this.world.getType(blockposition), packetplayinblockdig_enumplayerdigtype, true, s)); this.player.playerConnection.sendPacket(new PacketPlayOutBlockBreak(blockposition, this.world.getType(blockposition), packetplayinblockdig_enumplayerdigtype, true, s));
} else { } else {
@ -205,7 +206,7 @@
TileEntity tileentity = this.world.getTileEntity(blockposition); TileEntity tileentity = this.world.getTileEntity(blockposition);
Block block = iblockdata.getBlock(); Block block = iblockdata.getBlock();
@@ -247,6 +375,10 @@ @@ -247,6 +376,10 @@
} else if (this.player.a((World) this.world, blockposition, this.gamemode)) { } else if (this.player.a((World) this.world, blockposition, this.gamemode)) {
return false; return false;
} else { } else {
@ -216,7 +217,7 @@
block.a((World) this.world, blockposition, iblockdata, (EntityHuman) this.player); block.a((World) this.world, blockposition, iblockdata, (EntityHuman) this.player);
boolean flag = this.world.a(blockposition, false); boolean flag = this.world.a(blockposition, false);
@@ -255,19 +387,32 @@ @@ -255,19 +388,32 @@
} }
if (this.isCreative()) { if (this.isCreative()) {
@ -239,20 +240,20 @@
+ // CraftBukkit start + // CraftBukkit start
+ if (event.isDropItems()) { + if (event.isDropItems()) {
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockDropItemEvent(bblock, state, this.player, world.captureDrops); + org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockDropItemEvent(bblock, state, this.player, world.captureDrops);
+ } }
+ world.captureDrops = null; + world.captureDrops = null;
+ +
+ // Drop event experience + // Drop event experience
+ if (flag && event != null) { + if (flag && event != null) {
+ iblockdata.getBlock().dropExperience(this.world, blockposition, event.getExpToDrop()); + iblockdata.getBlock().dropExperience(this.world, blockposition, event.getExpToDrop());
} + }
+ +
+ return true; + return true;
+ // CraftBukkit end + // CraftBukkit end
} }
} }
} }
@@ -309,12 +454,46 @@ @@ -309,12 +455,52 @@
} }
} }
@ -291,6 +292,12 @@
+ entityplayer.playerConnection.sendPacket(new PacketPlayOutBlockChange(world, bottom ? blockposition.up() : blockposition.down())); + entityplayer.playerConnection.sendPacket(new PacketPlayOutBlockChange(world, bottom ? blockposition.up() : blockposition.down()));
+ } else if (iblockdata.getBlock() instanceof BlockCake) { + } else if (iblockdata.getBlock() instanceof BlockCake) {
+ entityplayer.getBukkitEntity().sendHealthUpdate(); // SPIGOT-1341 - reset health for cake + entityplayer.getBukkitEntity().sendHealthUpdate(); // SPIGOT-1341 - reset health for cake
+ } else if (interactItemStack.getItem() instanceof ItemBisected) {
+ // send a correcting update to the client, as it already placed the upper half of the bisected item
+ entityplayer.playerConnection.sendPacket(new PacketPlayOutBlockChange(world, blockposition.shift(movingobjectpositionblock.getDirection()).up()));
+
+ // send a correcting update to the client for the block above as well, this because of replaceable blocks (such as grass, sea grass etc)
+ entityplayer.playerConnection.sendPacket(new PacketPlayOutBlockChange(world, blockposition.up()));
+ } + }
+ entityplayer.getBukkitEntity().updateInventory(); // SPIGOT-2867 + entityplayer.getBukkitEntity().updateInventory(); // SPIGOT-2867
+ enuminteractionresult = (event.useItemInHand() != Event.Result.ALLOW) ? EnumInteractionResult.SUCCESS : EnumInteractionResult.PASS; + enuminteractionresult = (event.useItemInHand() != Event.Result.ALLOW) ? EnumInteractionResult.SUCCESS : EnumInteractionResult.PASS;
@ -299,7 +306,7 @@
if (itileinventory != null) { if (itileinventory != null) {
entityplayer.openContainer(itileinventory); entityplayer.openContainer(itileinventory);
@@ -328,7 +507,7 @@ @@ -328,7 +514,7 @@
ItemStack itemstack1 = itemstack.cloneItemStack(); ItemStack itemstack1 = itemstack.cloneItemStack();
if (!flag1) { if (!flag1) {
@ -308,7 +315,7 @@
if (enuminteractionresult.a()) { if (enuminteractionresult.a()) {
CriterionTriggers.M.a(entityplayer, blockposition, itemstack1); CriterionTriggers.M.a(entityplayer, blockposition, itemstack1);
@@ -336,17 +515,17 @@ @@ -336,17 +522,17 @@
} }
} }
@ -329,7 +336,7 @@
} }
if (enuminteractionresult1.a()) { if (enuminteractionresult1.a()) {
@@ -354,10 +533,10 @@ @@ -354,10 +540,10 @@
} }
return enuminteractionresult1; return enuminteractionresult1;