添加更多的OBB
This commit is contained in:
parent
b802eaa29b
commit
cd3e84ba75
7 changed files with 62 additions and 47 deletions
|
@ -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 <a href="https://github.com/AnECanSaiTin/HitboxAPI">HitboxAPI</a>
|
||||
**/
|
||||
|
@ -16,8 +18,9 @@ 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<OBB> obbList, PoseStack poseStack, VertexConsumer buffer, float red, float green, float blue, float alpha) {
|
||||
Vec3 position = entity.position();
|
||||
for (OBB obb : obbList) {
|
||||
Vector3f center = obb.center();
|
||||
Vector3f halfExtents = obb.extents();
|
||||
Quaternionf rotation = obb.rotation();
|
||||
|
@ -29,6 +32,7 @@ public class OBBRenderer {
|
|||
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) {
|
||||
poseStack.pushPose();
|
||||
|
|
|
@ -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<OBB> getOBBs();
|
||||
|
||||
void updateOBB();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
for (OBB obb : obbEntity.getOBBs()) {
|
||||
var obbVec = obb.clip(startVec.toVector3f(), endVec.toVector3f()).orElse(null);
|
||||
if (obbVec == null) return 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);
|
||||
|
|
|
@ -1295,8 +1295,8 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
|
|||
}
|
||||
|
||||
@Override
|
||||
public OBB getOBB() {
|
||||
return this.obb;
|
||||
public List<OBB> getOBBs() {
|
||||
return List.of(this.obb, this.obbTurret);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,9 +25,13 @@ public abstract class LevelMixin {
|
|||
at = @At("RETURN"))
|
||||
public void getEntities(Entity pEntity, AABB pBoundingBox, Predicate<? super Entity> pPredicate, CallbackInfoReturnable<List<Entity>> cir) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,8 +29,9 @@ public class ProjectileUtilMixin {
|
|||
(projectile.getOwner() == entity || entity.getPassengers().contains(projectile.getOwner()))) {
|
||||
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());
|
||||
if (optional.isPresent()) {
|
||||
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;",
|
||||
at = @At("HEAD"), cancellable = true)
|
||||
|
@ -54,7 +55,9 @@ public class ProjectileUtilMixin {
|
|||
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());
|
||||
if (obb.contains(pStartVec)) {
|
||||
if (pDistance >= 0D) {
|
||||
|
@ -79,4 +82,5 @@ public class ProjectileUtilMixin {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue