diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Hpj11Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Hpj11Entity.java index d90ae8bb0..5690f8c30 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Hpj11Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Hpj11Entity.java @@ -57,6 +57,8 @@ import java.util.Optional; import java.util.UUID; import java.util.stream.StreamSupport; +import static com.atsuishio.superbwarfare.tools.SeekTool.smokeFilter; + public class Hpj11Entity extends ContainerMobileVehicleEntity implements GeoEntity, CannonEntity, OwnableEntity { public static final EntityDataAccessor ANIM_TIME = SynchedEntityData.defineId(Hpj11Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor GUN_ROTATE = SynchedEntityData.defineId(Hpj11Entity.class, EntityDataSerializers.FLOAT); @@ -258,7 +260,7 @@ public class Hpj11Entity extends ContainerMobileVehicleEntity implements GeoEnti Entity target = EntityFindUtil.findEntity(level(), entityData.get(TARGET_UUID)); - if (target != null && this.getOwner() instanceof Player player) { + if (target != null && this.getOwner() instanceof Player player && smokeFilter(target)) { if (target instanceof LivingEntity living && living.getHealth() <= 0) { this.entityData.set(TARGET_UUID, "none"); return; @@ -314,7 +316,8 @@ public class Hpj11Entity extends ContainerMobileVehicleEntity implements GeoEnti && canAim(pos, e, minAngle, maxAngle) && e instanceof LivingEntity living && living instanceof Enemy - && living.getHealth() > 0) { + && living.getHealth() > 0 + && smokeFilter(e)) { return checkNoClip(e); } return false; diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/LaserTowerEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/LaserTowerEntity.java index d98c1a922..902ae3c8f 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/LaserTowerEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/LaserTowerEntity.java @@ -49,6 +49,7 @@ import java.util.UUID; import java.util.stream.StreamSupport; import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle; +import static com.atsuishio.superbwarfare.tools.SeekTool.smokeFilter; public class LaserTowerEntity extends EnergyVehicleEntity implements GeoEntity, OwnableEntity { @@ -252,7 +253,7 @@ public class LaserTowerEntity extends EnergyVehicleEntity implements GeoEntity, Entity target = EntityFindUtil.findEntity(level(), entityData.get(TARGET_UUID)); - if (target != null) { + if (target != null && smokeFilter(target)) { if (target instanceof LivingEntity living && living.getHealth() <= 0) { this.entityData.set(TARGET_UUID, "none"); return; @@ -322,7 +323,8 @@ public class LaserTowerEntity extends EnergyVehicleEntity implements GeoEntity, && canAim(pos, e, minAngle, maxAngle) && e instanceof LivingEntity living && living instanceof Enemy - && living.getHealth() > 0) { + && living.getHealth() > 0 + && smokeFilter(e)) { return checkNoClip(e); } return false; diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/SeekTool.java b/src/main/java/com/atsuishio/superbwarfare/tools/SeekTool.java index 8f3418748..007853060 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/SeekTool.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/SeekTool.java @@ -2,9 +2,7 @@ package com.atsuishio.superbwarfare.tools; import com.atsuishio.superbwarfare.config.server.VehicleConfig; import com.atsuishio.superbwarfare.entity.ClaymoreEntity; -import com.atsuishio.superbwarfare.entity.projectile.C4Entity; -import com.atsuishio.superbwarfare.entity.projectile.DestroyableProjectileEntity; -import com.atsuishio.superbwarfare.entity.projectile.SwarmDroneEntity; +import com.atsuishio.superbwarfare.entity.projectile.*; import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity; import net.minecraft.core.BlockPos; @@ -19,6 +17,7 @@ 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.entity.EntityTypeTest; import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; @@ -47,6 +46,7 @@ public class SeekTool { && calculateAngle(e, entity) < seekAngle && e != entity && baseFilter(e) + && smokeFilter(e) && e.getVehicle() == null ) { return level.clip(new ClipContext( @@ -69,6 +69,7 @@ public class SeekTool { && calculateAngle(e, entity) < seekAngle && e != entity && baseFilter(e) + && smokeFilter(e) && e.getVehicle() == null && !(e instanceof SwarmDroneEntity swarmDrone && swarmDrone.getOwner() != entity) && (!e.isAlliedTo(entity) || e.getTeam() == null || e.getTeam().getName().equals("TDM"))) { @@ -88,6 +89,7 @@ public class SeekTool { && calculateAngle(e, entity) < seekAngle && e != entity && baseFilter(e) + && smokeFilter(e) && e.getVehicle() == null && (!e.isAlliedTo(entity) || e.getTeam() == null || e.getTeam().getName().equals("TDM")) ) { @@ -109,6 +111,7 @@ public class SeekTool { && calculateAngleVehicle(e, vehicle) < seekAngle && e != vehicle && baseFilter(e) + && smokeFilter(e) && e.getVehicle() == null && (!e.isAlliedTo(vehicle) || e.getTeam() == null || e.getTeam().getName().equals("TDM"))) { return level.clip(new ClipContext( @@ -137,7 +140,8 @@ 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 && baseFilter(e)) + .filter(e -> e.distanceToSqr(pos.getX(), pos.getY(), pos.getZ()) <= range * range + && baseFilter(e) && smokeFilter(e) && !(e instanceof DecoyEntity)) .toList(); } @@ -168,6 +172,25 @@ public class SeekTool { || includedByConfig(entity); } + public static boolean smokeFilter(Entity pEntity) { + var Box = pEntity.getBoundingBox().inflate(8); + + var entities = pEntity.level().getEntities(EntityTypeTest.forClass(Entity.class), Box, + entity -> entity instanceof SmokeDecoyEntity) + .stream().toList(); + + boolean result = true; + + for (var e : entities) { + if (e != null) { + result = false; + break; + } + } + + return result; + } + public static boolean includedByConfig(Entity entity) { var type = BuiltInRegistries.ENTITY_TYPE.getKey(entity.getType()); return VehicleConfig.COLLISION_ENTITY_WHITELIST.get().contains(type.toString()); diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/TraceTool.java b/src/main/java/com/atsuishio/superbwarfare/tools/TraceTool.java index 4a139bc11..bc6d5d8dc 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/TraceTool.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/TraceTool.java @@ -12,6 +12,8 @@ import net.minecraft.world.entity.projectile.ProjectileUtil; import net.minecraft.world.level.ClipContext; import net.minecraft.world.phys.*; +import static com.atsuishio.superbwarfare.tools.SeekTool.smokeFilter; + public class TraceTool { public static boolean laserHeadshot = false; @@ -31,7 +33,7 @@ public class TraceTool { Vec3 viewVec = entity.getViewVector(1.0F); Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(entity, eyePos, toVec, aabb, p -> !p.isSpectator() && entity.getVehicle() != p && p.isAlive(), distance); + EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(entity, eyePos, toVec, aabb, p -> !p.isSpectator() && entity.getVehicle() != p && p.isAlive() && smokeFilter(p), distance); if (entityhitresult != null) { Vec3 targetPos = entityhitresult.getLocation(); double distanceToTarget = eyePos.distanceToSqr(targetPos); @@ -75,7 +77,7 @@ public class TraceTool { Vec3 viewVec = player.getViewVector(1.0F); Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); AABB aabb = player.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, p -> !p.isSpectator() && player.getVehicle() != p && p.isAlive(), distance); + EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, p -> !p.isSpectator() && player.getVehicle() != p && p.isAlive() && smokeFilter(p), distance); if (entityhitresult != null) { Vec3 hitVec = entityhitresult.getLocation(); if (checkNoClip(player, hitVec)) { @@ -106,7 +108,7 @@ public class TraceTool { Vec3 viewVec = vehicle.getBarrelVector(1); Vec3 toVec = eye.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach); AABB aabb = vehicle.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D); - EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(vehicle, eye, toVec, aabb, p -> !p.isSpectator() && p.isAlive() && !(p instanceof Projectile && !(p instanceof DestroyableProjectileEntity)) && SeekTool.baseFilter(p) && !(p instanceof DecoyEntity), distance); + EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(vehicle, eye, toVec, aabb, p -> !p.isSpectator() && p.isAlive() && !(p instanceof Projectile && !(p instanceof DestroyableProjectileEntity)) && SeekTool.baseFilter(p) && !(p instanceof DecoyEntity) && smokeFilter(p), distance); if (entityhitresult != null) { hitResult = entityhitresult;