添加更多的OBB

This commit is contained in:
17146 2025-06-16 00:25:35 +08:00 committed by Light_Quanta
parent b802eaa29b
commit cd3e84ba75
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
7 changed files with 62 additions and 47 deletions

View file

@ -9,6 +9,8 @@ import net.minecraft.world.phys.Vec3;
import org.joml.Quaternionf; import org.joml.Quaternionf;
import org.joml.Vector3f; import org.joml.Vector3f;
import java.util.List;
/** /**
* Codes based on @AnECanSaiTin's <a href="https://github.com/AnECanSaiTin/HitboxAPI">HitboxAPI</a> * Codes based on @AnECanSaiTin's <a href="https://github.com/AnECanSaiTin/HitboxAPI">HitboxAPI</a>
**/ **/
@ -16,18 +18,20 @@ public class OBBRenderer {
public static final OBBRenderer INSTANCE = new OBBRenderer(); public static final OBBRenderer INSTANCE = new OBBRenderer();
public void render(VehicleEntity entity, OBB obb, PoseStack poseStack, VertexConsumer buffer, float red, float green, float blue, float alpha, float pPartialTicks) { public void render(VehicleEntity entity, List<OBB> obbList, PoseStack poseStack, VertexConsumer buffer, float red, float green, float blue, float alpha) {
Vec3 position = entity.position(); Vec3 position = entity.position();
Vector3f center = obb.center(); for (OBB obb : obbList) {
Vector3f halfExtents = obb.extents(); Vector3f center = obb.center();
Quaternionf rotation = obb.rotation(); Vector3f halfExtents = obb.extents();
renderOBB( Quaternionf rotation = obb.rotation();
poseStack, buffer, renderOBB(
(float) (center.x() - position.x()), (float) (center.y() - position.y()), (float) (center.z() - position.z()), poseStack, buffer,
rotation, (float) (center.x() - position.x()), (float) (center.y() - position.y()), (float) (center.z() - position.z()),
halfExtents.x(), halfExtents.y(), halfExtents.z(), rotation,
red, green, blue, alpha halfExtents.x(), halfExtents.y(), halfExtents.z(),
); red, green, blue, alpha
);
}
} }
public static void renderOBB(PoseStack poseStack, VertexConsumer buffer, float centerX, float centerY, float centerZ, Quaternionf rotation, float halfX, float halfY, float halfZ, float red, float green, float blue, float alpha) { public static void renderOBB(PoseStack poseStack, VertexConsumer buffer, float centerX, float centerY, float centerZ, Quaternionf rotation, float halfX, float halfY, float halfZ, float red, float green, float blue, float alpha) {

View file

@ -2,9 +2,11 @@ package com.atsuishio.superbwarfare.entity;
import com.atsuishio.superbwarfare.tools.OBB; import com.atsuishio.superbwarfare.tools.OBB;
import java.util.List;
public interface OBBEntity { public interface OBBEntity {
OBB getOBB(); List<OBB> getOBBs();
void updateOBB(); void updateOBB();
} }

View file

@ -181,12 +181,14 @@ public class ProjectileEntity extends Projectile implements IEntityWithComplexSp
private EntityResult getHitResult(Entity entity, Vec3 startVec, Vec3 endVec) { private EntityResult getHitResult(Entity entity, Vec3 startVec, Vec3 endVec) {
double expandHeight = entity instanceof Player && !entity.isCrouching() ? 0.0625 : 0.0; double expandHeight = entity instanceof Player && !entity.isCrouching() ? 0.0625 : 0.0;
Vec3 hitPos; Vec3 hitPos = null;
if (entity instanceof OBBEntity obbEntity) { if (entity instanceof OBBEntity obbEntity) {
OBB obb = obbEntity.getOBB(); for (OBB obb : obbEntity.getOBBs()) {
var obbVec = obb.clip(startVec.toVector3f(), endVec.toVector3f()).orElse(null); var obbVec = obb.clip(startVec.toVector3f(), endVec.toVector3f()).orElse(null);
if (obbVec == null) return null; if (obbVec != null) {
hitPos = new Vec3(obbVec); hitPos = new Vec3(obbVec);
}
}
} else { } else {
AABB boundingBox = entity.getBoundingBox(); AABB boundingBox = entity.getBoundingBox();
Vec3 velocity = new Vec3(entity.getX() - entity.xOld, entity.getY() - entity.yOld, entity.getZ() - entity.zOld); Vec3 velocity = new Vec3(entity.getX() - entity.xOld, entity.getY() - entity.yOld, entity.getZ() - entity.zOld);

View file

@ -1295,8 +1295,8 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
} }
@Override @Override
public OBB getOBB() { public List<OBB> getOBBs() {
return this.obb; return List.of(this.obb, this.obbTurret);
} }
@Override @Override

View file

@ -5,7 +5,6 @@ import com.atsuishio.superbwarfare.entity.OBBEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.EntityRenderDispatcher; import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@ -20,7 +19,7 @@ public class EntityRenderDispatcherMixin {
at = @At("RETURN")) at = @At("RETURN"))
private static void renderHitbox(PoseStack poseStack, VertexConsumer buffer, Entity p_entity, float red, float green, float blue, float alpha, CallbackInfo ci) { private static void renderHitbox(PoseStack poseStack, VertexConsumer buffer, Entity p_entity, float red, float green, float blue, float alpha, CallbackInfo ci) {
if (p_entity instanceof OBBEntity obbEntity && p_entity instanceof VehicleEntity vehicle) { if (p_entity instanceof OBBEntity obbEntity && p_entity instanceof VehicleEntity vehicle) {
OBBRenderer.INSTANCE.render(vehicle, obbEntity.getOBB(), poseStack, buffer, 0, 1, 0, 1, Minecraft.getInstance().getTimer().getRealtimeDeltaTicks()); OBBRenderer.INSTANCE.render(vehicle, obbEntity.getOBBs(), poseStack, buffer, 0, 1, 0, 1);
} }
} }
} }

View file

@ -25,8 +25,12 @@ public abstract class LevelMixin {
at = @At("RETURN")) at = @At("RETURN"))
public void getEntities(Entity pEntity, AABB pBoundingBox, Predicate<? super Entity> pPredicate, CallbackInfoReturnable<List<Entity>> cir) { public void getEntities(Entity pEntity, AABB pBoundingBox, Predicate<? super Entity> pPredicate, CallbackInfoReturnable<List<Entity>> cir) {
this.getEntities().get(pBoundingBox, entity -> { this.getEntities().get(pBoundingBox, entity -> {
if (entity instanceof OBBEntity obbEntity && OBB.isColliding(obbEntity.getOBB(), pBoundingBox)) { if (entity instanceof OBBEntity obbEntity) {
cir.getReturnValue().add(entity); for (OBB obb : obbEntity.getOBBs()) {
if (OBB.isColliding(obb, pBoundingBox)) {
cir.getReturnValue().add(entity);
}
}
} }
}); });
} }

View file

@ -1,7 +1,6 @@
package com.atsuishio.superbwarfare.mixins; package com.atsuishio.superbwarfare.mixins;
import com.atsuishio.superbwarfare.entity.OBBEntity; import com.atsuishio.superbwarfare.entity.OBBEntity;
import com.atsuishio.superbwarfare.tools.OBB;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.projectile.Projectile; import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.entity.projectile.ProjectileUtil; import net.minecraft.world.entity.projectile.ProjectileUtil;
@ -30,13 +29,15 @@ public class ProjectileUtilMixin {
(projectile.getOwner() == entity || entity.getPassengers().contains(projectile.getOwner()))) { (projectile.getOwner() == entity || entity.getPassengers().contains(projectile.getOwner()))) {
continue; continue;
} }
OBB obb = obbEntity.getOBB().inflate(6); var obbList = obbEntity.getOBBs();
for (var obb : obbList) {
Optional<Vector3f> optional = obb.clip(pStartVec.toVector3f(), pEndVec.toVector3f()); obb = obb.inflate(6);
if (optional.isPresent()) { Optional<Vector3f> optional = obb.clip(pStartVec.toVector3f(), pEndVec.toVector3f());
double d1 = pStartVec.distanceToSqr(new Vec3(optional.get())); if (optional.isPresent()) {
if (d1 < Double.MAX_VALUE) { double d1 = pStartVec.distanceToSqr(new Vec3(optional.get()));
cir.setReturnValue(new EntityHitResult(entity, new Vec3(optional.get()))); if (d1 < Double.MAX_VALUE) {
cir.setReturnValue(new EntityHitResult(entity, new Vec3(optional.get())));
}
} }
} }
} }
@ -54,25 +55,28 @@ public class ProjectileUtilMixin {
continue; continue;
} }
OBB obb = obbEntity.getOBB().inflate(entity.getPickRadius() * 2); var obbList = obbEntity.getOBBs();
Optional<Vector3f> optional = obb.clip(pStartVec.toVector3f(), pEndVec.toVector3f()); for (var obb : obbList) {
if (obb.contains(pStartVec)) { obb = obb.inflate(entity.getPickRadius() * 2);
if (pDistance >= 0D) { Optional<Vector3f> optional = obb.clip(pStartVec.toVector3f(), pEndVec.toVector3f());
cir.setReturnValue(new EntityHitResult(entity, new Vec3(optional.orElse(pStartVec.toVector3f())))); if (obb.contains(pStartVec)) {
return; if (pDistance >= 0D) {
} cir.setReturnValue(new EntityHitResult(entity, new Vec3(optional.orElse(pStartVec.toVector3f()))));
} else if (optional.isPresent()) { return;
var vec = new Vec3(optional.get()); }
double d1 = pStartVec.distanceToSqr(vec); } else if (optional.isPresent()) {
if (d1 < pDistance || pDistance == 0.0D) { var vec = new Vec3(optional.get());
if (entity.getRootVehicle() == pShooter.getRootVehicle() && !entity.canRiderInteract()) { double d1 = pStartVec.distanceToSqr(vec);
if (pDistance == 0.0D) { if (d1 < pDistance || pDistance == 0.0D) {
if (entity.getRootVehicle() == pShooter.getRootVehicle() && !entity.canRiderInteract()) {
if (pDistance == 0.0D) {
cir.setReturnValue(new EntityHitResult(entity, vec));
return;
}
} else {
cir.setReturnValue(new EntityHitResult(entity, vec)); cir.setReturnValue(new EntityHitResult(entity, vec));
return; return;
} }
} else {
cir.setReturnValue(new EntityHitResult(entity, vec));
return;
} }
} }
} }