From 128bdb60452c30b518bf25eb08832b3d678b3133 Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Wed, 20 Aug 2025 23:19:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=8C=96=E6=8E=98=E9=80=9F?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/user/BukkitServerPlayer.java | 38 ++++++++----------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java index 523e9cd92..243911557 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java @@ -470,7 +470,21 @@ public class BukkitServerPlayer extends Player { @Override public float getDestroyProgress(Object blockState, BlockPos pos) { - return FastNMS.INSTANCE.method$BlockStateBase$getDestroyProgress(blockState, serverPlayer(), FastNMS.INSTANCE.field$CraftWorld$ServerLevel(platformPlayer().getWorld()), LocationUtils.toBlockPos(pos)); + Optional optionalCustomState = BlockStateUtils.getOptionalCustomBlockState(blockState); + float progress = FastNMS.INSTANCE.method$BlockStateBase$getDestroyProgress(blockState, serverPlayer(), FastNMS.INSTANCE.field$CraftWorld$ServerLevel(platformPlayer().getWorld()), LocationUtils.toBlockPos(pos)); + if (optionalCustomState.isPresent()) { + ImmutableBlockState customState = optionalCustomState.get(); + Item tool = getItemInHand(InteractionHand.MAIN_HAND); + boolean isCorrectTool = FastNMS.INSTANCE.method$ItemStack$isCorrectToolForDrops(tool.getLiteralObject(), blockState); + // 如果自定义方块在服务端侧未使用正确地工具,那么需要还原挖掘速度 + if (!isCorrectTool) { + progress *= (10f / 3f); + } + if (!BlockStateUtils.isCorrectTool(customState, tool)) { + progress *= customState.settings().incorrectToolSpeed(); + } + } + return progress; } private void predictNextBlockToMine() { @@ -655,28 +669,6 @@ public class BukkitServerPlayer extends Player { // double check custom block if (optionalCustomState.isPresent()) { ImmutableBlockState customState = optionalCustomState.get(); - BlockSettings blockSettings = customState.settings(); - if (blockSettings.requireCorrectTool()) { - if (!item.isEmpty()) { - // it's correct on plugin side - if (blockSettings.isCorrectTool(item.id())) { - // but not on serverside - if (!FastNMS.INSTANCE.method$ItemStack$isCorrectToolForDrops(item.getLiteralObject(), destroyedState)) { - // we fix the speed - progressToAdd = progressToAdd * (10f / 3f); - } - } else { - // not a correct tool on plugin side and not a correct tool on serverside - if (!blockSettings.respectToolComponent() || !FastNMS.INSTANCE.method$ItemStack$isCorrectToolForDrops(item.getLiteralObject(), destroyedState)) { - progressToAdd = progressToAdd * (10f / 3f) * blockSettings.incorrectToolSpeed(); - } - } - } else { - // item is null, but it requires correct tool, then we reset the speed - progressToAdd = progressToAdd * (10f / 3f) * blockSettings.incorrectToolSpeed(); - } - } - // accumulate progress this.miningProgress = progressToAdd + miningProgress; int packetStage = (int) (this.miningProgress * 10.0F);