9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2026-01-06 15:52:03 +00:00
This commit is contained in:
XiaoMoMi
2025-09-11 18:29:52 +08:00
2 changed files with 14 additions and 12 deletions

View File

@@ -17,21 +17,21 @@ import java.util.concurrent.Callable;
public class BouncingBlockBehavior extends BukkitBlockBehavior implements TriggerOnceBlockBehavior { public class BouncingBlockBehavior extends BukkitBlockBehavior implements TriggerOnceBlockBehavior {
public static final Factory FACTORY = new Factory(); public static final Factory FACTORY = new Factory();
private final double bounceHeight; private final double bounceHeight;
private final boolean fallDamage; private final boolean syncPlayerPosition;
private final double fallDamageMultiplier;
public BouncingBlockBehavior(CustomBlock customBlock, double bounceHeight, boolean fallDamage) { public BouncingBlockBehavior(CustomBlock customBlock, double bounceHeight, boolean syncPlayerPosition, double fallDamageMultiplier) {
super(customBlock); super(customBlock);
this.bounceHeight = bounceHeight; this.bounceHeight = bounceHeight;
this.fallDamage = fallDamage; this.syncPlayerPosition = syncPlayerPosition;
this.fallDamageMultiplier = fallDamageMultiplier;
} }
@Override @Override
public void fallOn(Object thisBlock, Object[] args, Callable<Object> superMethod) { public void fallOn(Object thisBlock, Object[] args, Callable<Object> superMethod) {
if (!this.fallDamage) { if (this.fallDamageMultiplier <= 0.0) return;
return;
}
Object entity = args[3]; 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( FastNMS.INSTANCE.method$Entity$causeFallDamage(
entity, finalFallDistance, 1.0F, entity, finalFallDistance, 1.0F,
FastNMS.INSTANCE.method$DamageSources$fall(FastNMS.INSTANCE.method$Entity$damageSources(entity)) FastNMS.INSTANCE.method$DamageSources$fall(FastNMS.INSTANCE.method$Entity$damageSources(entity))
@@ -54,8 +54,9 @@ public class BouncingBlockBehavior extends BukkitBlockBehavior implements Trigge
double d = CoreReflections.clazz$LivingEntity.isInstance(entity) ? 1.0 : 0.8; double d = CoreReflections.clazz$LivingEntity.isInstance(entity) ? 1.0 : 0.8;
double y = -deltaMovement.y * this.bounceHeight * d; double y = -deltaMovement.y * this.bounceHeight * d;
FastNMS.INSTANCE.method$Entity$setDeltaMovement(entity, deltaMovement.x, y, deltaMovement.z); 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); FastNMS.INSTANCE.field$Entity$hurtMarked(entity, true);
} }
} }
@@ -66,8 +67,9 @@ public class BouncingBlockBehavior extends BukkitBlockBehavior implements Trigge
@Override @Override
public BlockBehavior create(CustomBlock block, Map<String, Object> arguments) { public BlockBehavior create(CustomBlock block, Map<String, Object> arguments) {
double bounceHeight = ResourceConfigUtils.getAsDouble(arguments.getOrDefault("bounce-height", 0.66), "bounce-height"); double bounceHeight = ResourceConfigUtils.getAsDouble(arguments.getOrDefault("bounce-height", 0.66), "bounce-height");
boolean fallDamage = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("fall-damage", false), "fall-damage"); boolean syncPlayerPosition = ResourceConfigUtils.getAsBoolean(arguments.getOrDefault("sync-player-position", true), "sync-player-position");
return new BouncingBlockBehavior(block, bounceHeight, fallDamage); double fallDamageMultiplier = ResourceConfigUtils.getAsDouble(arguments.getOrDefault("fall-damage-multiplier", 0.5), "fall-damage-multiplier");
return new BouncingBlockBehavior(block, bounceHeight, syncPlayerPosition, fallDamageMultiplier);
} }
} }
} }

View File

@@ -590,7 +590,7 @@ items#misc:
behavior: behavior:
type: bouncing_block type: bouncing_block
bounce-height: 0.66 bounce-height: 0.66
sync-player-self: false sync-player-position: false
state: state:
id: 0 id: 0
state: white_bed[facing=west,occupied=false,part=foot] state: white_bed[facing=west,occupied=false,part=foot]