可能修复OBB判定问题,但是修复了OBB判定问题不太可能
This commit is contained in:
parent
29f810eb04
commit
2fc4a4a9ce
3 changed files with 28 additions and 8 deletions
|
@ -62,6 +62,8 @@ public class ProjectileUtilMixin {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO 这个似乎有问题,OBB背后还有OBB时会返回后面那个
|
||||
|
||||
@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)
|
||||
private static void getEntityHitResult(Entity pShooter, Vec3 pStartVec, Vec3 pEndVec, AABB pBoundingBox, Predicate<Entity> pFilter, double pDistance, CallbackInfoReturnable<EntityHitResult> cir) {
|
||||
|
|
|
@ -443,23 +443,41 @@ public record OBB(Vector3f center, Vector3f extents, Quaternionf rotation, Part
|
|||
|
||||
//获取玩家看向的某个OBB
|
||||
|
||||
// TODO 修复看向的第一个OBB后方如果还有另外的OBB时,无法正确返回看向的第一个OBB的BUG
|
||||
|
||||
public static OBB getLookingObb(Player player, double range) {
|
||||
OBB lookingOBB = null;
|
||||
Entity lookingEntity = TraceTool.findLookingEntity(player, range);
|
||||
if (lookingEntity instanceof OBBEntity obbEntity) {
|
||||
var obbList = obbEntity.getOBBs();
|
||||
for (OBB obb : obbList) {
|
||||
Vec3 hitPos = TraceTool.playerFindLookingPos(player, lookingEntity, range);
|
||||
if (hitPos != null && obb.contains(hitPos.add(player.getViewVector(1).scale(0.02)))) {
|
||||
if (hitPos != null && obb.contains(hitPos.add(player.getViewVector(1).scale(0.05)))) {
|
||||
// player.displayClientMessage(Component.literal(String.valueOf(obb)), true);
|
||||
lookingOBB = obb;
|
||||
break;
|
||||
// 测试粒子
|
||||
// if (player.level() instanceof ServerLevel serverLevel) {
|
||||
// sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), hitPos.x, hitPos.y, hitPos.z, 1, 0, 0, 0, 0.01, false);
|
||||
// }
|
||||
return obb;
|
||||
}
|
||||
}
|
||||
}
|
||||
return lookingOBB;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Optional<OBB> getNearestOBB(Vec3 vec3, List<OBB> obbs) {
|
||||
if (obbs.isEmpty()) return Optional.empty();
|
||||
|
||||
OBB nearest = null;
|
||||
double minDistanceSq = Double.MAX_VALUE;
|
||||
|
||||
for (OBB obb : obbs) {
|
||||
double distanceSq = obb.center.distanceSquared((float) vec3.x, (float) vec3.y, (float) vec3.z);
|
||||
|
||||
if (distanceSq < minDistanceSq) {
|
||||
minDistanceSq = distanceSq;
|
||||
nearest = obb;
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.ofNullable(nearest);
|
||||
}
|
||||
|
||||
public enum Part {
|
||||
|
|
|
@ -130,7 +130,7 @@ public class TraceTool {
|
|||
Vec3 viewVec = player.getViewVector(1);
|
||||
Vec3 toVec = player.getEyePosition().add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach);
|
||||
AABB aabb = entity.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D);
|
||||
EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, player.getEyePosition(), toVec, aabb, p -> true, distance);
|
||||
EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player.level(), player, player.getEyePosition(), toVec, aabb, p -> true, (float) distance);
|
||||
if (entityhitresult != null) {
|
||||
hitResult = entityhitresult;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue