diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/MobileVehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/MobileVehicleEntity.java index 7a01a12f2..4faf486a1 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/MobileVehicleEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/MobileVehicleEntity.java @@ -1,6 +1,7 @@ package com.atsuishio.superbwarfare.entity.vehicle.base; import com.atsuishio.superbwarfare.config.server.VehicleConfig; +import com.atsuishio.superbwarfare.entity.OBBEntity; import com.atsuishio.superbwarfare.entity.TargetEntity; import com.atsuishio.superbwarfare.entity.projectile.FlareDecoyEntity; import com.atsuishio.superbwarfare.entity.projectile.SmokeDecoyEntity; @@ -9,6 +10,7 @@ import com.atsuishio.superbwarfare.init.ModDamageTypes; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.tools.EntityFindUtil; +import com.atsuishio.superbwarfare.tools.OBB; import com.mojang.math.Axis; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -661,23 +663,41 @@ public abstract class MobileVehicleEntity extends EnergyVehicleEntity implements public void crushEntities(Vec3 velocity) { if (level() instanceof ServerLevel) { if (!this.canCrushEntities()) return; - if (velocity.horizontalDistance() < 0.25) return; +// if (velocity.horizontalDistance() < 0.25) return; if (isRemoved()) return; - var frontBox = getBoundingBox().move(velocity); - var entities = level().getEntities(EntityTypeTest.forClass(Entity.class), frontBox, - entity -> entity != this && entity != getFirstPassenger() && entity.getVehicle() == null) - .stream().filter(entity -> { - if (entity.isAlive()) { - var type = BuiltInRegistries.ENTITY_TYPE.getKey(entity.getType()); - return (entity instanceof VehicleEntity || entity instanceof Boat || entity instanceof Minecart - || (entity instanceof LivingEntity living && !(living instanceof Player player && player.isSpectator()))) - || VehicleConfig.COLLISION_ENTITY_WHITELIST.get().contains(type.toString()); + List entities; + + if (this instanceof OBBEntity obbEntity) { + var frontBox = getBoundingBox().move(velocity).inflate(4); + entities = level().getEntities(EntityTypeTest.forClass(Entity.class), frontBox, + entity -> entity != this && entity != getFirstPassenger() && entity.getVehicle() == null) + .stream().filter(entity -> { + if (entity.isAlive() && isInObb(obbEntity, entity, velocity)) { + var type = BuiltInRegistries.ENTITY_TYPE.getKey(entity.getType()); + return (entity instanceof VehicleEntity || entity instanceof Boat || entity instanceof Minecart || (entity instanceof LivingEntity living && !(living instanceof Player player && player.isSpectator()))) || VehicleConfig.COLLISION_ENTITY_WHITELIST.get().contains(type.toString()); + } + return false; } - return false; - } - ) - .toList(); + ) + .toList(); + + } else { + var frontBox = getBoundingBox().move(velocity); + entities = level().getEntities(EntityTypeTest.forClass(Entity.class), frontBox, + entity -> entity != this && entity != getFirstPassenger() && entity.getVehicle() == null) + .stream().filter(entity -> { + if (entity.isAlive()) { + var type = BuiltInRegistries.ENTITY_TYPE.getKey(entity.getType()); + return (entity instanceof VehicleEntity || entity instanceof Boat || entity instanceof Minecart + || (entity instanceof LivingEntity living && !(living instanceof Player player && player.isSpectator()))) + || VehicleConfig.COLLISION_ENTITY_WHITELIST.get().contains(type.toString()); + } + return false; + } + ) + .toList(); + } for (var entity : entities) { double entitySize = entity.getBoundingBox().getSize(); @@ -730,6 +750,22 @@ public abstract class MobileVehicleEntity extends EnergyVehicleEntity implements } } + public boolean isInObb(OBBEntity obbEntity, Entity entity, Vec3 velocity) { + var obbList = obbEntity.getOBBs(); + for (var obb : obbList) { + obb = obb.move(velocity); + if (entity instanceof OBBEntity obbEntity2) { + var obbList2 = obbEntity2.getOBBs(); + for (var obb2 : obbList2) { + return OBB.isColliding(obb, obb2); + } + } else { + return OBB.isColliding(obb, entity.getBoundingBox()); + } + } + return false; + } + public Vector3f getForwardDirection() { return new Vector3f( Mth.sin(-getYRot() * ((float) Math.PI / 180)), diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/OBB.java b/src/main/java/com/atsuishio/superbwarfare/tools/OBB.java index a0260fc6b..44b6d4fec 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/OBB.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/OBB.java @@ -222,6 +222,11 @@ public record OBB(Vector3f center, Vector3f extents, Quaternionf rotation) { return new OBB(center, newExtents, rotation); } + public OBB move(Vec3 vec3) { + Vector3f newCenter = new Vector3f((float) (center.x + vec3.x), (float) (center.y + vec3.y), (float) (center.z + vec3.z)); + return new OBB(newCenter, extents, rotation); + } + /** * 检查点是否在OBB内部 *