diff --git a/Allay-API/src/main/java/cn/allay/api/block/type/BlockState.java b/Allay-API/src/main/java/cn/allay/api/block/type/BlockState.java index 66fb7d419..3231ba8f3 100644 --- a/Allay-API/src/main/java/cn/allay/api/block/type/BlockState.java +++ b/Allay-API/src/main/java/cn/allay/api/block/type/BlockState.java @@ -2,6 +2,7 @@ import cn.allay.api.block.property.type.BlockPropertyType; import org.cloudburstmc.nbt.NbtMap; +import org.cloudburstmc.protocol.bedrock.data.definitions.BlockDefinition; import org.cloudburstmc.protocol.bedrock.data.definitions.SimpleBlockDefinition; import org.jetbrains.annotations.UnmodifiableView; @@ -48,4 +49,8 @@ default SimpleBlockDefinition toNetworkBlockDefinition() { statesBuilder.build() ); } + + default BlockDefinition toNetworkBlockDefinitionRuntime() { + return this::blockStateHash; + } } diff --git a/Allay-Server/src/main/java/cn/allay/server/client/AllayClient.java b/Allay-Server/src/main/java/cn/allay/server/client/AllayClient.java index 827eef484..e40496de8 100644 --- a/Allay-Server/src/main/java/cn/allay/server/client/AllayClient.java +++ b/Allay-Server/src/main/java/cn/allay/server/client/AllayClient.java @@ -544,11 +544,17 @@ protected void handleBlockAction(List blockActions) { //TODO: checking switch(action.getAction()) { case START_BREAK -> { - getWorld().sendLevelEventPacket(pos, LevelEvent.BLOCK_START_BREAK, 65535); + getWorld().sendLevelEventPacket(pos, LevelEvent.BLOCK_START_BREAK, 0); } case BLOCK_PREDICT_DESTROY -> { + var oldState = getWorld().getBlockState(pos.getX(), pos.getY(), pos.getZ()); + if (oldState == null) { + log.warn("Player " + name + " tried to break block at " + pos + " but it is air"); + continue; + } getWorld().setBlockState(pos.getX(), pos.getY(), pos.getZ(), VanillaBlockTypes.AIR_TYPE.getDefaultState()); - getWorld().sendLevelEventPacket(pos, LevelEvent.BLOCK_STOP_BREAK, 1); + getWorld().sendLevelEventPacket(pos, LevelEvent.BLOCK_STOP_BREAK, 0); + getWorld().sendLevelEventPacket(pos, LevelEvent.PARTICLE_DESTROY_BLOCK, oldState.blockStateHash()); } } } diff --git a/Allay-Server/src/main/java/cn/allay/server/world/chunk/AllayUnsafeChunk.java b/Allay-Server/src/main/java/cn/allay/server/world/chunk/AllayUnsafeChunk.java index 6318447b9..d2534b180 100644 --- a/Allay-Server/src/main/java/cn/allay/server/world/chunk/AllayUnsafeChunk.java +++ b/Allay-Server/src/main/java/cn/allay/server/world/chunk/AllayUnsafeChunk.java @@ -104,7 +104,7 @@ public void setBlockState(@Range(from = 0, to = 15) int x, @Range(from = -512, t if (send) { var updateBlockPacket = new UpdateBlockPacket(); updateBlockPacket.setBlockPosition(Vector3i.from((chunkX << 4) + x, y, (chunkZ << 4) + z)); - updateBlockPacket.setDefinition(blockState.toNetworkBlockDefinition()); + updateBlockPacket.setDefinition(blockState.toNetworkBlockDefinitionRuntime()); updateBlockPacket.setDataLayer(layer ? 1 : 0); updateBlockPacket.getFlags().addAll( UpdateBlockPacket.FLAG_ALL_PRIORITY ); sendChunkPacket(updateBlockPacket);