From d00efda2d7286a581f3288e8c36bf6cf3218c3b2 Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Thu, 11 Sep 2025 15:27:01 +0800 Subject: [PATCH 1/2] =?UTF-8?q?refactor(block):=20=E6=9B=B4=E6=B8=85?= =?UTF-8?q?=E6=99=B0=E7=9A=84=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../block/behavior/BouncingBlockBehavior.java | 16 +++++++++------- .../resources/default/configuration/blocks.yml | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/BouncingBlockBehavior.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/BouncingBlockBehavior.java index edb1d4cc1..aeaa1934f 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/BouncingBlockBehavior.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/BouncingBlockBehavior.java @@ -17,19 +17,19 @@ import java.util.concurrent.Callable; public class BouncingBlockBehavior extends BukkitBlockBehavior implements TriggerOnceBlockBehavior { public static final Factory FACTORY = new Factory(); private final double bounceHeight; + private final boolean syncPlayerPosition; private final boolean fallDamage; - public BouncingBlockBehavior(CustomBlock customBlock, double bounceHeight, boolean fallDamage) { + public BouncingBlockBehavior(CustomBlock customBlock, double bounceHeight, boolean syncPlayerPosition, boolean fallDamage) { super(customBlock); this.bounceHeight = bounceHeight; + this.syncPlayerPosition = syncPlayerPosition; this.fallDamage = fallDamage; } @Override public void fallOn(Object thisBlock, Object[] args, Callable superMethod) { - if (!this.fallDamage) { - return; - } + if (!this.fallDamage) return; Object entity = args[3]; Object finalFallDistance = VersionHelper.isOrAbove1_21_5() ? (double) args[4] * 0.5 : (float) args[4] * 0.5F; FastNMS.INSTANCE.method$Entity$causeFallDamage( @@ -54,8 +54,9 @@ public class BouncingBlockBehavior extends BukkitBlockBehavior implements Trigge double d = CoreReflections.clazz$LivingEntity.isInstance(entity) ? 1.0 : 0.8; double y = -deltaMovement.y * this.bounceHeight * d; FastNMS.INSTANCE.method$Entity$setDeltaMovement(entity, deltaMovement.x, y, deltaMovement.z); - if (CoreReflections.clazz$Player.isInstance(entity) && y > 0.032) { - // 防抖 + if (CoreReflections.clazz$Player.isInstance(entity) && this.syncPlayerPosition + && /* 防抖 -> */ y > 0.032 /* <- 防抖 */ + ) { FastNMS.INSTANCE.field$Entity$hurtMarked(entity, true); } } @@ -66,8 +67,9 @@ public class BouncingBlockBehavior extends BukkitBlockBehavior implements Trigge @Override public BlockBehavior create(CustomBlock block, Map arguments) { double bounceHeight = ResourceConfigUtils.getAsDouble(arguments.getOrDefault("bounce-height", 0.66), "bounce-height"); + boolean syncPlayerPosition = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("sync-player-position", true), "sync-player-position"); boolean fallDamage = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("fall-damage", false), "fall-damage"); - return new BouncingBlockBehavior(block, bounceHeight, fallDamage); + return new BouncingBlockBehavior(block, bounceHeight, syncPlayerPosition, fallDamage); } } } diff --git a/common-files/src/main/resources/resources/default/configuration/blocks.yml b/common-files/src/main/resources/resources/default/configuration/blocks.yml index 83dbba2a3..757d0d468 100644 --- a/common-files/src/main/resources/resources/default/configuration/blocks.yml +++ b/common-files/src/main/resources/resources/default/configuration/blocks.yml @@ -590,7 +590,7 @@ items#misc: behavior: type: bouncing_block bounce-height: 0.66 - sync-player-self: false + sync-player-position: false state: id: 0 state: white_bed[facing=west,occupied=false,part=foot] From 324cba94cc7ccd5e2596d8bdcfa160069296a9e5 Mon Sep 17 00:00:00 2001 From: jhqwqmc <2110242767@qq.com> Date: Thu, 11 Sep 2025 17:59:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat(BouncingBlockBehavior):=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89=E6=8E=89=E8=90=BD=E4=BC=A4?= =?UTF-8?q?=E5=AE=B3=E5=80=8D=E6=95=B0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../block/behavior/BouncingBlockBehavior.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/BouncingBlockBehavior.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/BouncingBlockBehavior.java index aeaa1934f..2d40df2d3 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/BouncingBlockBehavior.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/BouncingBlockBehavior.java @@ -18,20 +18,20 @@ public class BouncingBlockBehavior extends BukkitBlockBehavior implements Trigge public static final Factory FACTORY = new Factory(); private final double bounceHeight; private final boolean syncPlayerPosition; - private final boolean fallDamage; + private final double fallDamageMultiplier; - public BouncingBlockBehavior(CustomBlock customBlock, double bounceHeight, boolean syncPlayerPosition, boolean fallDamage) { + public BouncingBlockBehavior(CustomBlock customBlock, double bounceHeight, boolean syncPlayerPosition, double fallDamageMultiplier) { super(customBlock); this.bounceHeight = bounceHeight; this.syncPlayerPosition = syncPlayerPosition; - this.fallDamage = fallDamage; + this.fallDamageMultiplier = fallDamageMultiplier; } @Override public void fallOn(Object thisBlock, Object[] args, Callable superMethod) { - if (!this.fallDamage) return; + if (this.fallDamageMultiplier <= 0.0) return; Object entity = args[3]; - Object finalFallDistance = VersionHelper.isOrAbove1_21_5() ? (double) args[4] * 0.5 : (float) args[4] * 0.5F; + Object finalFallDistance = VersionHelper.isOrAbove1_21_5() ? (double) args[4] * this.fallDamageMultiplier : (float) args[4] * this.fallDamageMultiplier; FastNMS.INSTANCE.method$Entity$causeFallDamage( entity, finalFallDistance, 1.0F, FastNMS.INSTANCE.method$DamageSources$fall(FastNMS.INSTANCE.method$Entity$damageSources(entity)) @@ -68,8 +68,8 @@ public class BouncingBlockBehavior extends BukkitBlockBehavior implements Trigge public BlockBehavior create(CustomBlock block, Map arguments) { double bounceHeight = ResourceConfigUtils.getAsDouble(arguments.getOrDefault("bounce-height", 0.66), "bounce-height"); boolean syncPlayerPosition = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("sync-player-position", true), "sync-player-position"); - boolean fallDamage = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("fall-damage", false), "fall-damage"); - return new BouncingBlockBehavior(block, bounceHeight, syncPlayerPosition, fallDamage); + double fallDamageMultiplier = ResourceConfigUtils.getAsDouble(arguments.getOrDefault("fall-damage-multiplier", 0.5), "fall-damage-multiplier"); + return new BouncingBlockBehavior(block, bounceHeight, syncPlayerPosition, fallDamageMultiplier); } } }