添加瞄准的排除项

This commit is contained in:
17146 2025-03-08 17:39:48 +08:00
parent 6398671f16
commit 9592fd561f

View file

@ -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<Entity> 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());
}
}