添加obb载具撞击实体的功能
This commit is contained in:
parent
a96cbcdd63
commit
8ce0c5c9f8
2 changed files with 55 additions and 14 deletions
|
@ -1,6 +1,7 @@
|
||||||
package com.atsuishio.superbwarfare.entity.vehicle.base;
|
package com.atsuishio.superbwarfare.entity.vehicle.base;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.config.server.VehicleConfig;
|
import com.atsuishio.superbwarfare.config.server.VehicleConfig;
|
||||||
|
import com.atsuishio.superbwarfare.entity.OBBEntity;
|
||||||
import com.atsuishio.superbwarfare.entity.TargetEntity;
|
import com.atsuishio.superbwarfare.entity.TargetEntity;
|
||||||
import com.atsuishio.superbwarfare.entity.projectile.FlareDecoyEntity;
|
import com.atsuishio.superbwarfare.entity.projectile.FlareDecoyEntity;
|
||||||
import com.atsuishio.superbwarfare.entity.projectile.SmokeDecoyEntity;
|
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.ModSounds;
|
||||||
import com.atsuishio.superbwarfare.init.ModTags;
|
import com.atsuishio.superbwarfare.init.ModTags;
|
||||||
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
|
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
|
||||||
|
import com.atsuishio.superbwarfare.tools.OBB;
|
||||||
import com.mojang.math.Axis;
|
import com.mojang.math.Axis;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
|
@ -661,11 +663,28 @@ public abstract class MobileVehicleEntity extends EnergyVehicleEntity implements
|
||||||
public void crushEntities(Vec3 velocity) {
|
public void crushEntities(Vec3 velocity) {
|
||||||
if (level() instanceof ServerLevel) {
|
if (level() instanceof ServerLevel) {
|
||||||
if (!this.canCrushEntities()) return;
|
if (!this.canCrushEntities()) return;
|
||||||
if (velocity.horizontalDistance() < 0.25) return;
|
// if (velocity.horizontalDistance() < 0.25) return;
|
||||||
if (isRemoved()) return;
|
if (isRemoved()) return;
|
||||||
var frontBox = getBoundingBox().move(velocity);
|
|
||||||
|
|
||||||
var entities = level().getEntities(EntityTypeTest.forClass(Entity.class), frontBox,
|
List<Entity> 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;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
var frontBox = getBoundingBox().move(velocity);
|
||||||
|
entities = level().getEntities(EntityTypeTest.forClass(Entity.class), frontBox,
|
||||||
entity -> entity != this && entity != getFirstPassenger() && entity.getVehicle() == null)
|
entity -> entity != this && entity != getFirstPassenger() && entity.getVehicle() == null)
|
||||||
.stream().filter(entity -> {
|
.stream().filter(entity -> {
|
||||||
if (entity.isAlive()) {
|
if (entity.isAlive()) {
|
||||||
|
@ -678,6 +697,7 @@ public abstract class MobileVehicleEntity extends EnergyVehicleEntity implements
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.toList();
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
for (var entity : entities) {
|
for (var entity : entities) {
|
||||||
double entitySize = entity.getBoundingBox().getSize();
|
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() {
|
public Vector3f getForwardDirection() {
|
||||||
return new Vector3f(
|
return new Vector3f(
|
||||||
Mth.sin(-getYRot() * ((float) Math.PI / 180)),
|
Mth.sin(-getYRot() * ((float) Math.PI / 180)),
|
||||||
|
|
|
@ -222,6 +222,11 @@ public record OBB(Vector3f center, Vector3f extents, Quaternionf rotation) {
|
||||||
return new OBB(center, newExtents, 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内部
|
* 检查点是否在OBB内部
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue