From a8b54d4e6349b336230cefca51d29313313230ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=80=E5=93=A5?= <3523206925@qq.com> Date: Wed, 9 Aug 2023 15:57:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=9D=E6=AD=A5=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E6=96=B9=E5=9D=97=E7=A0=B4=E5=9D=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/cn/allay/api/block/type/BlockState.java | 5 +++++ .../main/java/cn/allay/server/client/AllayClient.java | 10 ++++++++-- .../cn/allay/server/world/chunk/AllayUnsafeChunk.java | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) 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);