注释掉OBB实体碰撞部分

This commit is contained in:
17146 2025-06-21 22:37:18 +08:00 committed by Light_Quanta
parent 40dad236dd
commit b92c421b83
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959

View file

@ -1,12 +1,9 @@
package com.atsuishio.superbwarfare.mixins; package com.atsuishio.superbwarfare.mixins;
import com.atsuishio.superbwarfare.entity.OBBEntity;
import com.atsuishio.superbwarfare.entity.mixin.OBBHitter; import com.atsuishio.superbwarfare.entity.mixin.OBBHitter;
import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity;
import com.atsuishio.superbwarfare.tools.OBB; import com.atsuishio.superbwarfare.tools.OBB;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
@ -65,29 +62,29 @@ public abstract class EntityMixin implements OBBHitter {
} }
// TODO 优化OBB面算法并排除AABB影响现在下车就动不了了 // TODO 优化OBB面算法并排除AABB影响现在下车就动不了了
@Inject(method = "collide", at = @At("HEAD"), cancellable = true) // @Inject(method = "collide", at = @At("HEAD"), cancellable = true)
private void onHitOBB(Vec3 movement, CallbackInfoReturnable<Vec3> cir) { // private void onHitOBB(Vec3 movement, CallbackInfoReturnable<Vec3> cir) {
AABB boundingBox = this.getBoundingBox(); // AABB boundingBox = this.getBoundingBox();
Entity self = (Entity) (Object) this; // Entity self = (Entity) (Object) this;
var list = this.level().getEntities(self, boundingBox.expandTowards(movement).inflate(1), e -> true); // 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); // 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; // if (entity == null || entity == self) return;
//
OBBEntity obbEntity = (OBBEntity) entity; // OBBEntity obbEntity = (OBBEntity) entity;
Vec3 position = self.position(); // Vec3 position = self.position();
// 第一版实现 // // 第一版实现
var faceInfo = OBB.findClosestFace(obbEntity.getOBBs(), position); // var faceInfo = OBB.findClosestFace(obbEntity.getOBBs(), position);
if (faceInfo == null) return; // if (faceInfo == null) return;
double dot = movement.dot(new Vec3(faceInfo.faceNormal())); // double dot = movement.dot(new Vec3(faceInfo.faceNormal()));
var vec = new Vec3(faceInfo.faceNormal()).multiply(dot, dot, dot); // var vec = new Vec3(faceInfo.faceNormal()).multiply(dot, dot, dot);
//
if (self instanceof Player player) { // if (self instanceof Player player) {
player.displayClientMessage(Component.literal("Vec: [" + vec.x + ", " + vec.y + ", " + vec.z + "]," + // player.displayClientMessage(Component.literal("Vec: [" + vec.x + ", " + vec.y + ", " + vec.z + "]," +
" Face: [" + faceInfo.faceNormal().x + ", " + faceInfo.faceNormal().y + ", " + faceInfo.faceNormal().z + "]"), true); // " Face: [" + faceInfo.faceNormal().x + ", " + faceInfo.faceNormal().y + ", " + faceInfo.faceNormal().z + "]"), true);
} // }
//
cir.setReturnValue(movement.subtract(vec)); // cir.setReturnValue(movement.subtract(vec));
} // }
// TODO 优化后续逻辑 // TODO 优化后续逻辑
// @Redirect(method = "turn(DD)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;setXRot(F)V", ordinal = 1)) // @Redirect(method = "turn(DD)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;setXRot(F)V", ordinal = 1))