添加更多的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,8 +18,9 @@ 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();
for (OBB obb : obbList) {
Vector3f center = obb.center(); Vector3f center = obb.center();
Vector3f halfExtents = obb.extents(); Vector3f halfExtents = obb.extents();
Quaternionf rotation = obb.rotation(); Quaternionf rotation = obb.rotation();
@ -29,6 +32,7 @@ public class OBBRenderer {
red, green, blue, alpha 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) {
poseStack.pushPose(); poseStack.pushPose();

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,9 +25,13 @@ 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) {
for (OBB obb : obbEntity.getOBBs()) {
if (OBB.isColliding(obb, pBoundingBox)) {
cir.getReturnValue().add(entity); 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,8 +29,9 @@ 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) {
obb = obb.inflate(6);
Optional<Vector3f> optional = obb.clip(pStartVec.toVector3f(), pEndVec.toVector3f()); Optional<Vector3f> optional = obb.clip(pStartVec.toVector3f(), pEndVec.toVector3f());
if (optional.isPresent()) { if (optional.isPresent()) {
double d1 = pStartVec.distanceToSqr(new Vec3(optional.get())); double d1 = pStartVec.distanceToSqr(new Vec3(optional.get()));
@ -42,6 +42,7 @@ public class ProjectileUtilMixin {
} }
} }
} }
}
@Inject(method = "getEntityHitResult(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/AABB;Ljava/util/function/Predicate;D)Lnet/minecraft/world/phys/EntityHitResult;", @Inject(method = "getEntityHitResult(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/AABB;Ljava/util/function/Predicate;D)Lnet/minecraft/world/phys/EntityHitResult;",
at = @At("HEAD"), cancellable = true) at = @At("HEAD"), cancellable = true)
@ -54,7 +55,9 @@ public class ProjectileUtilMixin {
continue; continue;
} }
OBB obb = obbEntity.getOBB().inflate(entity.getPickRadius() * 2); var obbList = obbEntity.getOBBs();
for (var obb : obbList) {
obb = obb.inflate(entity.getPickRadius() * 2);
Optional<Vector3f> optional = obb.clip(pStartVec.toVector3f(), pEndVec.toVector3f()); Optional<Vector3f> optional = obb.clip(pStartVec.toVector3f(), pEndVec.toVector3f());
if (obb.contains(pStartVec)) { if (obb.contains(pStartVec)) {
if (pDistance >= 0D) { if (pDistance >= 0D) {
@ -79,4 +82,5 @@ public class ProjectileUtilMixin {
} }
} }
} }
}
} }