From b92c421b83f8a39e5adc8b841c888dcf93efd1d8 Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Sat, 21 Jun 2025 22:37:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E6=8E=89OBB=E5=AE=9E?= =?UTF-8?q?=E4=BD=93=E7=A2=B0=E6=92=9E=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../superbwarfare/mixins/EntityMixin.java | 49 +++++++++---------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/mixins/EntityMixin.java b/src/main/java/com/atsuishio/superbwarfare/mixins/EntityMixin.java index cd6e292c1..249c33cb8 100644 --- a/src/main/java/com/atsuishio/superbwarfare/mixins/EntityMixin.java +++ b/src/main/java/com/atsuishio/superbwarfare/mixins/EntityMixin.java @@ -1,12 +1,9 @@ package com.atsuishio.superbwarfare.mixins; -import com.atsuishio.superbwarfare.entity.OBBEntity; import com.atsuishio.superbwarfare.entity.mixin.OBBHitter; import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity; import com.atsuishio.superbwarfare.tools.OBB; -import net.minecraft.network.chat.Component; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; @@ -65,29 +62,29 @@ public abstract class EntityMixin implements OBBHitter { } // TODO 优化OBB面算法并排除AABB影响,现在下车就动不了了 - @Inject(method = "collide", at = @At("HEAD"), cancellable = true) - private void onHitOBB(Vec3 movement, CallbackInfoReturnable cir) { - AABB boundingBox = this.getBoundingBox(); - Entity self = (Entity) (Object) this; - var list = this.level().getEntities(self, boundingBox.expandTowards(movement).inflate(1), e -> true); - var entity = list.stream().filter(e -> e instanceof OBBEntity).min((e1, e2) -> (int) (e1.position().distanceTo(self.position()) - e2.position().distanceTo(self.position()))).orElse(null); - if (entity == null || entity == self) return; - - OBBEntity obbEntity = (OBBEntity) entity; - Vec3 position = self.position(); - // 第一版实现 - var faceInfo = OBB.findClosestFace(obbEntity.getOBBs(), position); - if (faceInfo == null) return; - double dot = movement.dot(new Vec3(faceInfo.faceNormal())); - var vec = new Vec3(faceInfo.faceNormal()).multiply(dot, dot, dot); - - if (self instanceof Player player) { - player.displayClientMessage(Component.literal("Vec: [" + vec.x + ", " + vec.y + ", " + vec.z + "]," + - " Face: [" + faceInfo.faceNormal().x + ", " + faceInfo.faceNormal().y + ", " + faceInfo.faceNormal().z + "]"), true); - } - - cir.setReturnValue(movement.subtract(vec)); - } +// @Inject(method = "collide", at = @At("HEAD"), cancellable = true) +// private void onHitOBB(Vec3 movement, CallbackInfoReturnable cir) { +// AABB boundingBox = this.getBoundingBox(); +// Entity self = (Entity) (Object) this; +// var list = this.level().getEntities(self, boundingBox.expandTowards(movement).inflate(1), e -> true); +// var entity = list.stream().filter(e -> e instanceof OBBEntity).min((e1, e2) -> (int) (e1.position().distanceTo(self.position()) - e2.position().distanceTo(self.position()))).orElse(null); +// if (entity == null || entity == self) return; +// +// OBBEntity obbEntity = (OBBEntity) entity; +// Vec3 position = self.position(); +// // 第一版实现 +// var faceInfo = OBB.findClosestFace(obbEntity.getOBBs(), position); +// if (faceInfo == null) return; +// double dot = movement.dot(new Vec3(faceInfo.faceNormal())); +// var vec = new Vec3(faceInfo.faceNormal()).multiply(dot, dot, dot); +// +// if (self instanceof Player player) { +// player.displayClientMessage(Component.literal("Vec: [" + vec.x + ", " + vec.y + ", " + vec.z + "]," + +// " Face: [" + faceInfo.faceNormal().x + ", " + faceInfo.faceNormal().y + ", " + faceInfo.faceNormal().z + "]"), true); +// } +// +// cir.setReturnValue(movement.subtract(vec)); +// } // TODO 优化后续逻辑 // @Redirect(method = "turn(DD)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;setXRot(F)V", ordinal = 1))