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 1b14c09b3..8201ab059 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 @@ -2,6 +2,7 @@ package com.atsuishio.superbwarfare.client.renderer.special; import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity; import com.atsuishio.superbwarfare.tools.OBB; +import com.atsuishio.superbwarfare.tools.VectorTool; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; import net.minecraft.client.renderer.LevelRenderer; @@ -18,12 +19,18 @@ public class OBBRenderer { public static final OBBRenderer INSTANCE = new OBBRenderer(); - public void render(VehicleEntity entity, List obbList, PoseStack poseStack, VertexConsumer buffer, float red, float green, float blue, float alpha) { + public void render(VehicleEntity entity, List obbList, PoseStack poseStack, VertexConsumer buffer, float red, float green, float blue, float alpha, float pPartialTicks) { Vec3 position = entity.position(); for (OBB obb : obbList) { Vector3f center = obb.center(); Vector3f halfExtents = obb.extents(); - Quaternionf rotation = obb.rotation(); + Quaternionf rotation; + + if (obb.turret()) { + rotation = VectorTool.combineRotationsTurret(pPartialTicks, entity); + } else { + rotation = VectorTool.combineRotations(pPartialTicks, entity); + } renderOBB( poseStack, buffer, (float) (center.x() - position.x()), (float) (center.y() - position.y()), (float) (center.z() - position.z()), 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 e9b1e02e5..c1e33d8d9 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java @@ -93,8 +93,8 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti public Yx100Entity(EntityType type, Level world) { super(type, world); - this.obb = new OBB(this.position().toVector3f(), new Vector3f(2.53125f, 1.0625f, 4.75f), new Quaternionf()); - this.obbTurret = new OBB(this.position().toVector3f(), new Vector3f(2, 1, 2), new Quaternionf()); + this.obb = new OBB(this.position().toVector3f(), new Vector3f(2.53125f, 1.0625f, 4.75f), new Quaternionf(), false); + this.obbTurret = new OBB(this.position().toVector3f(), new Vector3f(2.375f, 0.5625f, 3f), new Quaternionf(), true); } @Override @@ -1307,7 +1307,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti this.obb.setRotation(VectorTool.combineRotations(1, this)); Matrix4f transformT = getTurretTransform(1); - Vector4f worldPositionT = transformPosition(transformT, 0, 1, 0); + Vector4f worldPositionT = transformPosition(transformT, 0, 0.5625f, -0.1875f); this.obbTurret.center().set(new Vector3f(worldPositionT.x, worldPositionT.y, worldPositionT.z)); this.obbTurret.setRotation(VectorTool.combineRotationsTurret(1, this)); } diff --git a/src/main/java/com/atsuishio/superbwarfare/mixins/EntityRenderDispatcherMixin.java b/src/main/java/com/atsuishio/superbwarfare/mixins/EntityRenderDispatcherMixin.java index 1bfe6c893..cef9923d1 100644 --- a/src/main/java/com/atsuishio/superbwarfare/mixins/EntityRenderDispatcherMixin.java +++ b/src/main/java/com/atsuishio/superbwarfare/mixins/EntityRenderDispatcherMixin.java @@ -5,6 +5,7 @@ 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; @@ -19,7 +20,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.getOBBs(), poseStack, buffer, 0, 1, 0, 1); + OBBRenderer.INSTANCE.render(vehicle, obbEntity.getOBBs(), poseStack, buffer, 0, 1, 0, 1, Minecraft.getInstance().getTimer().getRealtimeDeltaTicks()); } } } diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/OBB.java b/src/main/java/com/atsuishio/superbwarfare/tools/OBB.java index a0260fc6b..582e65fc8 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/OBB.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/OBB.java @@ -16,7 +16,7 @@ import java.util.Optional; * @param extents 三个轴向上的半长 * @param rotation 旋转 */ -public record OBB(Vector3f center, Vector3f extents, Quaternionf rotation) { +public record OBB(Vector3f center, Vector3f extents, Quaternionf rotation, boolean turret) { public void setCenter(Vector3f center) { this.center.set(center); @@ -214,12 +214,12 @@ public record OBB(Vector3f center, Vector3f extents, Quaternionf rotation) { public OBB inflate(float amount) { Vector3f newExtents = new Vector3f(extents).add(amount, amount, amount); - return new OBB(center, newExtents, rotation); + return new OBB(center, newExtents, rotation, false); } public OBB inflate(float x, float y, float z) { Vector3f newExtents = new Vector3f(extents).add(x, y, z); - return new OBB(center, newExtents, rotation); + return new OBB(center, newExtents, rotation, false); } /**