From 8f88972666e343b884501340429179d777b0f4f7 Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Sun, 18 May 2025 19:29:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E8=B0=83=E6=95=B4=E9=AB=98?= =?UTF-8?q?=E5=BA=A6=E5=88=A4=E5=AE=9A=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../superbwarfare/tools/SeekTool.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/SeekTool.java b/src/main/java/com/atsuishio/superbwarfare/tools/SeekTool.java index bd5f9ec04..9e6b7542d 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/SeekTool.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/SeekTool.java @@ -17,7 +17,6 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.projectile.Projectile; import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.entity.EntityTypeTest; import net.minecraft.world.phys.AABB; @@ -212,15 +211,34 @@ public class SeekTool { || includedByConfig(entity); } + public static boolean isOnGround(Entity entity) { + return isOnGround(entity, 0); + } + + /** + * 判断实体是否位于离地面n米的范围内 + */ public static boolean isOnGround(Entity entity, double height) { + Level level = entity.level(); + + double y = entity.getY(); + int minY = level.getMinBuildHeight(); + int maxY = level.getMaxBuildHeight(); + + // 如果实体已低于世界底部或高于顶部 + if (y < minY || y > maxY) { + return false; + } + AtomicBoolean onGround = new AtomicBoolean(false); AABB aabb = entity.getBoundingBox().expandTowards(0, -height, 0); BlockPos.betweenClosedStream(aabb).forEach((pos) -> { - BlockState blockstate = entity.level().getBlockState(pos); - if (!blockstate.is(Blocks.AIR)) { + if (pos.getY() < minY || pos.getY() > maxY) return; + + BlockState state = level.getBlockState(pos); + if (!state.isAir()) { onGround.set(true); } - // TODO 添加超出可建筑高度之外的判断 }); return entity.onGround() || entity.isInWater() || onGround.get(); }