From 9592fd561feb507ab5347733cd3ec23af37d1d4f Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Sat, 8 Mar 2025 17:39:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=9E=84=E5=87=86=E7=9A=84?= =?UTF-8?q?=E6=8E=92=E9=99=A4=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../superbwarfare/tools/SeekTool.java | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/SeekTool.java b/src/main/java/com/atsuishio/superbwarfare/tools/SeekTool.java index 66b6c0019..edc4d4498 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/SeekTool.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/SeekTool.java @@ -1,8 +1,8 @@ package com.atsuishio.superbwarfare.tools; +import com.atsuishio.superbwarfare.config.server.VehicleConfig; import com.atsuishio.superbwarfare.entity.C4Entity; import com.atsuishio.superbwarfare.entity.ClaymoreEntity; -import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.AreaEffectCloud; @@ -17,6 +17,7 @@ import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.Level; import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; +import net.minecraftforge.registries.ForgeRegistries; import java.util.Comparator; import java.util.List; @@ -36,10 +37,8 @@ public class SeekTool { .filter(e -> { if (e.distanceTo(entity) <= seekRange && calculateAngle(e, entity) < seekAngle && e != entity - && e.isAlive() + && baseFilter(e) && e.getVehicle() == null - && !(e instanceof Player player && (player.isSpectator())) - && !(e instanceof ItemEntity || e instanceof ExperienceOrb || e instanceof HangingEntity || e instanceof ProjectileEntity || e instanceof Projectile || e instanceof ArmorStand || e instanceof ClaymoreEntity || e instanceof C4Entity || e instanceof AreaEffectCloud) ) { return level.clip(new ClipContext(entity.getEyePosition(), e.getEyePosition(), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, entity)).getType() != HitResult.Type.BLOCK; @@ -53,10 +52,8 @@ public class SeekTool { .filter(e -> { if (e.distanceTo(entity) <= seekRange && calculateAngle(e, entity) < seekAngle && e != entity - && e.isAlive() - && !(e instanceof ItemEntity || e instanceof ExperienceOrb || e instanceof HangingEntity || e instanceof ProjectileEntity || e instanceof Projectile || e instanceof ArmorStand || e instanceof ClaymoreEntity || e instanceof C4Entity || e instanceof AreaEffectCloud) + && baseFilter(e) && e.getVehicle() == null - && !(e instanceof Player player && (player.isSpectator())) && (!e.isAlliedTo(entity) || e.getTeam() == null || e.getTeam().getName().equals("TDM"))) { return level.clip(new ClipContext(entity.getEyePosition(), e.getEyePosition(), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, entity)).getType() != HitResult.Type.BLOCK; @@ -70,10 +67,8 @@ public class SeekTool { .filter(e -> { if (e.distanceTo(entity) <= seekRange && calculateAngle(e, entity) < seekAngle && e != entity - && e.isAlive() - && !(e instanceof ItemEntity || e instanceof ExperienceOrb || e instanceof HangingEntity || e instanceof ProjectileEntity || e instanceof Projectile || e instanceof ArmorStand || e instanceof ClaymoreEntity || e instanceof C4Entity || e instanceof AreaEffectCloud) + && baseFilter(e) && e.getVehicle() == null - && !(e instanceof Player player && (player.isSpectator())) && (!e.isAlliedTo(entity) || e.getTeam() == null || e.getTeam().getName().equals("TDM"))) { return level.clip(new ClipContext(entity.getEyePosition(), e.getEyePosition(), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, entity)).getType() != HitResult.Type.BLOCK; @@ -85,9 +80,7 @@ public class SeekTool { public static List getEntitiesWithinRange(BlockPos pos, Level level, double range) { return StreamSupport.stream(EntityFindUtil.getEntities(level).getAll().spliterator(), false) .filter(e -> e.distanceToSqr(pos.getX(), pos.getY(), pos.getZ()) <= range * range - && e.isAlive() - && !(e instanceof ItemEntity || e instanceof ExperienceOrb || e instanceof HangingEntity || e instanceof ProjectileEntity || e instanceof Projectile || e instanceof ArmorStand || e instanceof ClaymoreEntity || e instanceof C4Entity || e instanceof AreaEffectCloud) - && !(e instanceof Player player && player.isSpectator())) + && baseFilter(e)) .toList(); } @@ -97,4 +90,16 @@ public class SeekTool { return VectorTool.calculateAngle(start, end); } + public static boolean baseFilter(Entity entity) { + return entity.isAlive() + && !(entity instanceof ItemEntity || entity instanceof ExperienceOrb || entity instanceof HangingEntity || entity instanceof Projectile || entity instanceof ArmorStand || entity instanceof ClaymoreEntity || entity instanceof C4Entity || entity instanceof AreaEffectCloud) + && !(entity instanceof Player player && player.isSpectator()) + && excludedByConfig(entity); + } + + public static boolean excludedByConfig(Entity entity) { + var type = ForgeRegistries.ENTITY_TYPES.getKey(entity.getType()); + if (type == null) return false; + return !VehicleConfig.COLLISION_ENTITY_BLACKLIST.get().contains(type.toString()); + } }