From cd3e84ba75af1249cab03d3e30b85a0c63149541 Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Mon, 16 Jun 2025 00:25:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9B=B4=E5=A4=9A=E7=9A=84OB?= =?UTF-8?q?B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/renderer/special/OBBRenderer.java | 26 ++++++---- .../superbwarfare/entity/OBBEntity.java | 4 +- .../entity/projectile/ProjectileEntity.java | 12 +++-- .../entity/vehicle/Yx100Entity.java | 4 +- .../mixins/EntityRenderDispatcherMixin.java | 3 +- .../superbwarfare/mixins/LevelMixin.java | 8 ++- .../mixins/ProjectileUtilMixin.java | 52 ++++++++++--------- 7 files changed, 62 insertions(+), 47 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/client/renderer/special/OBBRenderer.java b/src/main/java/com/atsuishio/superbwarfare/client/renderer/special/OBBRenderer.java index 409151b71..1b14c09b3 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/renderer/special/OBBRenderer.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/renderer/special/OBBRenderer.java @@ -9,6 +9,8 @@ import net.minecraft.world.phys.Vec3; import org.joml.Quaternionf; import org.joml.Vector3f; +import java.util.List; + /** * Codes based on @AnECanSaiTin's HitboxAPI **/ @@ -16,18 +18,20 @@ public class 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 obbList, PoseStack poseStack, VertexConsumer buffer, float red, float green, float blue, float alpha) { Vec3 position = entity.position(); - Vector3f center = obb.center(); - Vector3f halfExtents = obb.extents(); - Quaternionf rotation = obb.rotation(); - renderOBB( - poseStack, buffer, - (float) (center.x() - position.x()), (float) (center.y() - position.y()), (float) (center.z() - position.z()), - rotation, - halfExtents.x(), halfExtents.y(), halfExtents.z(), - red, green, blue, alpha - ); + for (OBB obb : obbList) { + Vector3f center = obb.center(); + Vector3f halfExtents = obb.extents(); + Quaternionf rotation = obb.rotation(); + renderOBB( + poseStack, buffer, + (float) (center.x() - position.x()), (float) (center.y() - position.y()), (float) (center.z() - position.z()), + rotation, + 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) { diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/OBBEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/OBBEntity.java index 557c7f5dc..2711c2726 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/OBBEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/OBBEntity.java @@ -2,9 +2,11 @@ package com.atsuishio.superbwarfare.entity; import com.atsuishio.superbwarfare.tools.OBB; +import java.util.List; + public interface OBBEntity { - OBB getOBB(); + List getOBBs(); void updateOBB(); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java index 0e41b9c01..9e4505a39 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java @@ -181,12 +181,14 @@ public class ProjectileEntity extends Projectile implements IEntityWithComplexSp private EntityResult getHitResult(Entity entity, Vec3 startVec, Vec3 endVec) { double expandHeight = entity instanceof Player && !entity.isCrouching() ? 0.0625 : 0.0; - Vec3 hitPos; + Vec3 hitPos = null; if (entity instanceof OBBEntity obbEntity) { - OBB obb = obbEntity.getOBB(); - var obbVec = obb.clip(startVec.toVector3f(), endVec.toVector3f()).orElse(null); - if (obbVec == null) return null; - hitPos = new Vec3(obbVec); + for (OBB obb : obbEntity.getOBBs()) { + var obbVec = obb.clip(startVec.toVector3f(), endVec.toVector3f()).orElse(null); + if (obbVec != null) { + hitPos = new Vec3(obbVec); + } + } } else { AABB boundingBox = entity.getBoundingBox(); Vec3 velocity = new Vec3(entity.getX() - entity.xOld, entity.getY() - entity.yOld, entity.getZ() - entity.zOld); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java index 53bcabbe0..e9b1e02e5 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java @@ -1295,8 +1295,8 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti } @Override - public OBB getOBB() { - return this.obb; + public List getOBBs() { + return List.of(this.obb, this.obbTurret); } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/mixins/EntityRenderDispatcherMixin.java b/src/main/java/com/atsuishio/superbwarfare/mixins/EntityRenderDispatcherMixin.java index bb9189706..1bfe6c893 100644 --- a/src/main/java/com/atsuishio/superbwarfare/mixins/EntityRenderDispatcherMixin.java +++ b/src/main/java/com/atsuishio/superbwarfare/mixins/EntityRenderDispatcherMixin.java @@ -5,7 +5,6 @@ import com.atsuishio.superbwarfare.entity.OBBEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; -import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.entity.EntityRenderDispatcher; import net.minecraft.world.entity.Entity; import org.spongepowered.asm.mixin.Mixin; @@ -20,7 +19,7 @@ public class EntityRenderDispatcherMixin { at = @At("RETURN")) 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) { - 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); } } } diff --git a/src/main/java/com/atsuishio/superbwarfare/mixins/LevelMixin.java b/src/main/java/com/atsuishio/superbwarfare/mixins/LevelMixin.java index 367d5a8b8..6a7a1b6c8 100644 --- a/src/main/java/com/atsuishio/superbwarfare/mixins/LevelMixin.java +++ b/src/main/java/com/atsuishio/superbwarfare/mixins/LevelMixin.java @@ -25,8 +25,12 @@ public abstract class LevelMixin { at = @At("RETURN")) public void getEntities(Entity pEntity, AABB pBoundingBox, Predicate pPredicate, CallbackInfoReturnable> cir) { this.getEntities().get(pBoundingBox, entity -> { - if (entity instanceof OBBEntity obbEntity && OBB.isColliding(obbEntity.getOBB(), pBoundingBox)) { - cir.getReturnValue().add(entity); + if (entity instanceof OBBEntity obbEntity) { + for (OBB obb : obbEntity.getOBBs()) { + if (OBB.isColliding(obb, pBoundingBox)) { + cir.getReturnValue().add(entity); + } + } } }); } diff --git a/src/main/java/com/atsuishio/superbwarfare/mixins/ProjectileUtilMixin.java b/src/main/java/com/atsuishio/superbwarfare/mixins/ProjectileUtilMixin.java index 2cd667863..4c042a50e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/mixins/ProjectileUtilMixin.java +++ b/src/main/java/com/atsuishio/superbwarfare/mixins/ProjectileUtilMixin.java @@ -1,7 +1,6 @@ package com.atsuishio.superbwarfare.mixins; import com.atsuishio.superbwarfare.entity.OBBEntity; -import com.atsuishio.superbwarfare.tools.OBB; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.projectile.Projectile; import net.minecraft.world.entity.projectile.ProjectileUtil; @@ -30,13 +29,15 @@ public class ProjectileUtilMixin { (projectile.getOwner() == entity || entity.getPassengers().contains(projectile.getOwner()))) { continue; } - OBB obb = obbEntity.getOBB().inflate(6); - - Optional optional = obb.clip(pStartVec.toVector3f(), pEndVec.toVector3f()); - if (optional.isPresent()) { - double d1 = pStartVec.distanceToSqr(new Vec3(optional.get())); - if (d1 < Double.MAX_VALUE) { - cir.setReturnValue(new EntityHitResult(entity, new Vec3(optional.get()))); + var obbList = obbEntity.getOBBs(); + for (var obb : obbList) { + obb = obb.inflate(6); + Optional optional = obb.clip(pStartVec.toVector3f(), pEndVec.toVector3f()); + if (optional.isPresent()) { + double d1 = pStartVec.distanceToSqr(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; } - OBB obb = obbEntity.getOBB().inflate(entity.getPickRadius() * 2); - Optional optional = obb.clip(pStartVec.toVector3f(), pEndVec.toVector3f()); - if (obb.contains(pStartVec)) { - if (pDistance >= 0D) { - cir.setReturnValue(new EntityHitResult(entity, new Vec3(optional.orElse(pStartVec.toVector3f())))); - return; - } - } else if (optional.isPresent()) { - var vec = new Vec3(optional.get()); - double d1 = pStartVec.distanceToSqr(vec); - if (d1 < pDistance || pDistance == 0.0D) { - if (entity.getRootVehicle() == pShooter.getRootVehicle() && !entity.canRiderInteract()) { - if (pDistance == 0.0D) { + var obbList = obbEntity.getOBBs(); + for (var obb : obbList) { + obb = obb.inflate(entity.getPickRadius() * 2); + Optional optional = obb.clip(pStartVec.toVector3f(), pEndVec.toVector3f()); + if (obb.contains(pStartVec)) { + if (pDistance >= 0D) { + cir.setReturnValue(new EntityHitResult(entity, new Vec3(optional.orElse(pStartVec.toVector3f())))); + return; + } + } else if (optional.isPresent()) { + var vec = new Vec3(optional.get()); + double d1 = pStartVec.distanceToSqr(vec); + 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)); return; } - } else { - cir.setReturnValue(new EntityHitResult(entity, vec)); - return; } } }