mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-04 15:41:38 +00:00
@@ -1,15 +1,18 @@
|
||||
package net.momirealms.craftengine.bukkit.block.behavior;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||
import net.momirealms.craftengine.bukkit.util.LocationUtils;
|
||||
import net.momirealms.craftengine.core.block.BlockBehavior;
|
||||
import net.momirealms.craftengine.core.block.CustomBlock;
|
||||
import net.momirealms.craftengine.core.block.behavior.BlockBehaviorFactory;
|
||||
import net.momirealms.craftengine.core.block.behavior.special.TriggerOnceBlockBehavior;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
import net.momirealms.craftengine.core.world.Vec3d;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
@@ -31,9 +34,9 @@ public class BouncingBlockBehavior extends BukkitBlockBehavior implements Trigge
|
||||
public void fallOn(Object thisBlock, Object[] args, Callable<Object> superMethod) {
|
||||
if (this.fallDamageMultiplier <= 0.0) return;
|
||||
Object entity = args[3];
|
||||
Object finalFallDistance = VersionHelper.isOrAbove1_21_5() ? (double) args[4] * this.fallDamageMultiplier : (float) args[4] * this.fallDamageMultiplier;
|
||||
Number fallDistance = (Number) args[4];
|
||||
FastNMS.INSTANCE.method$Entity$causeFallDamage(
|
||||
entity, finalFallDistance, 1.0F,
|
||||
entity, fallDistance.doubleValue() * this.fallDamageMultiplier, 1.0F,
|
||||
FastNMS.INSTANCE.method$DamageSources$fall(FastNMS.INSTANCE.method$Entity$damageSources(entity))
|
||||
);
|
||||
}
|
||||
@@ -55,9 +58,21 @@ public class BouncingBlockBehavior extends BukkitBlockBehavior implements Trigge
|
||||
double y = -deltaMovement.y * this.bounceHeight * d;
|
||||
FastNMS.INSTANCE.method$Entity$setDeltaMovement(entity, deltaMovement.x, y, deltaMovement.z);
|
||||
if (CoreReflections.clazz$Player.isInstance(entity) && this.syncPlayerPosition
|
||||
&& /* 防抖 -> */ y > 0.032 /* <- 防抖 */
|
||||
&& /* 防抖 -> */ y > 0.035 /* <- 防抖 */
|
||||
) {
|
||||
FastNMS.INSTANCE.field$Entity$hurtMarked(entity, true);
|
||||
// 这里一定要延迟 1t 不然就会出问题
|
||||
if (VersionHelper.isFolia()) {
|
||||
Entity bukkitEntity = FastNMS.INSTANCE.method$Entity$getBukkitEntity(entity);
|
||||
bukkitEntity.getScheduler().runDelayed(BukkitCraftEngine.instance().javaPlugin(),
|
||||
r -> FastNMS.INSTANCE.field$Entity$hurtMarked(entity, true),
|
||||
null, 1L
|
||||
);
|
||||
} else {
|
||||
CraftEngine.instance().scheduler().sync().runLater(
|
||||
() -> FastNMS.INSTANCE.field$Entity$hurtMarked(entity, true),
|
||||
1L
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,6 +337,7 @@ public class BukkitFurnitureManager extends AbstractFurnitureManager {
|
||||
plugin.scheduler().sync().runDelayed(() -> tryLeavingSeat(player, entity), player.getWorld(), location.getBlockX() >> 4, location.getBlockZ() >> 4);
|
||||
}
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
protected void tryLeavingSeat(@NotNull Player player, @NotNull Entity vehicle) {
|
||||
Integer baseFurniture = vehicle.getPersistentDataContainer().get(FURNITURE_SEAT_BASE_ENTITY_KEY, PersistentDataType.INTEGER);
|
||||
if (baseFurniture == null) return;
|
||||
@@ -375,6 +376,7 @@ public class BukkitFurnitureManager extends AbstractFurnitureManager {
|
||||
return (entity instanceof ArmorStand || entity instanceof ItemDisplay);
|
||||
}
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
private boolean isSafeLocation(Location location) {
|
||||
World world = location.getWorld();
|
||||
if (world == null) return false;
|
||||
@@ -386,6 +388,7 @@ public class BukkitFurnitureManager extends AbstractFurnitureManager {
|
||||
return world.getBlockAt(x, y + 1, z).isPassable();
|
||||
}
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
@Nullable
|
||||
private Location findSafeLocationNearby(Location center) {
|
||||
World world = center.getWorld();
|
||||
|
||||
Reference in New Issue
Block a user