From d60118d5f6be08c0495e974e68a7099ccc1e8d91 Mon Sep 17 00:00:00 2001 From: themode Date: Wed, 24 Feb 2021 12:18:27 +0100 Subject: [PATCH] Improve block breaking code, to fix issue when breaking a block should immediately place a new one --- .../net/minestom/server/instance/InstanceContainer.java | 4 +++- .../minestom/server/listener/PlayerDiggingListener.java | 7 ++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/minestom/server/instance/InstanceContainer.java b/src/main/java/net/minestom/server/instance/InstanceContainer.java index e52b571e8..ac2e4b67c 100644 --- a/src/main/java/net/minestom/server/instance/InstanceContainer.java +++ b/src/main/java/net/minestom/server/instance/InstanceContainer.java @@ -391,7 +391,9 @@ public class InstanceContainer extends Instance { final boolean allowed = !blockBreakEvent.isCancelled(); if (allowed) { // Break or change the broken block based on event result - setSeparateBlocks(x, y, z, blockBreakEvent.getResultBlockStateId(), blockBreakEvent.getResultCustomBlockId()); + final short resultState = blockBreakEvent.getResultBlockStateId(); + final short resultCustom = blockBreakEvent.getResultCustomBlockId(); + setSeparateBlocks(x, y, z, resultState, resultCustom); // Send the block break effect packet { diff --git a/src/main/java/net/minestom/server/listener/PlayerDiggingListener.java b/src/main/java/net/minestom/server/listener/PlayerDiggingListener.java index 13aa909b9..597a65972 100644 --- a/src/main/java/net/minestom/server/listener/PlayerDiggingListener.java +++ b/src/main/java/net/minestom/server/listener/PlayerDiggingListener.java @@ -154,14 +154,11 @@ public class PlayerDiggingListener { // Unverified block break, client is fully responsible final boolean result = instance.breakBlock(player, blockPosition); - final int updatedBlockId = result ? 0 : blockStateId; - final ClientPlayerDiggingPacket.Status status = result ? - ClientPlayerDiggingPacket.Status.FINISHED_DIGGING : - ClientPlayerDiggingPacket.Status.CANCELLED_DIGGING; + final int updatedBlockId = instance.getBlockStateId(blockPosition); // Send acknowledge packet to allow or cancel the digging process sendAcknowledgePacket(player, blockPosition, updatedBlockId, - status, result); + ClientPlayerDiggingPacket.Status.FINISHED_DIGGING, result); if (!result) { final boolean solid = Block.fromStateId((short) blockStateId).isSolid();