添加更多mixin方法
This commit is contained in:
parent
1997dbb63e
commit
50eb2a4078
2 changed files with 64 additions and 6 deletions
|
@ -22,10 +22,8 @@ import java.util.function.Predicate;
|
|||
public class ProjectileUtilMixin {
|
||||
|
||||
@Inject(method = "getEntityHitResult(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/AABB;Ljava/util/function/Predicate;F)Lnet/minecraft/world/phys/EntityHitResult;",
|
||||
at = @At("RETURN"), cancellable = true)
|
||||
at = @At("HEAD"), cancellable = true)
|
||||
private static void getEntityHitResult(Level pLevel, Entity pProjectile, Vec3 pStartVec, Vec3 pEndVec, AABB pBoundingBox, Predicate<Entity> pFilter, float pInflationAmount, CallbackInfoReturnable<EntityHitResult> cir) {
|
||||
Entity res = null;
|
||||
|
||||
for (var entity : pLevel.getEntities(pProjectile, pBoundingBox, pFilter)) {
|
||||
if (entity instanceof OBBEntity obbEntity) {
|
||||
if (pProjectile instanceof Projectile projectile &&
|
||||
|
@ -38,10 +36,44 @@ public class ProjectileUtilMixin {
|
|||
if (optional.isPresent()) {
|
||||
double d1 = pStartVec.distanceToSqr(new Vec3(optional.get()));
|
||||
if (d1 < Double.MAX_VALUE) {
|
||||
res = entity;
|
||||
cir.setReturnValue(new EntityHitResult(entity, new Vec3(optional.get())));
|
||||
}
|
||||
if (res != null) {
|
||||
cir.setReturnValue(new EntityHitResult(res, new Vec3(optional.get())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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) {
|
||||
Level level = pShooter.level();
|
||||
|
||||
for (Entity entity : level.getEntities(pShooter, pBoundingBox, pFilter)) {
|
||||
if (entity instanceof OBBEntity obbEntity) {
|
||||
if (entity.getPassengers().contains(pShooter)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
OBB obb = obbEntity.getOBB().inflate(entity.getPickRadius() * 2);
|
||||
Optional<Vector3f> optional = obb.clip(pStartVec.toVector3f(), pEndVec.toVector3f());
|
||||
if (obb.contains(pStartVec)) {
|
||||
if (pDistance >= 0D) {
|
||||
cir.setReturnValue(new EntityHitResult(entity, new Vec3(optional.orElse(pStartVec.toVector3f()))));
|
||||
return;
|
||||
}
|
||||
} else if (optional.isPresent()) {
|
||||
var vec = new Vec3(optional.get());
|
||||
double d1 = pStartVec.distanceToSqr(vec);
|
||||
if (d1 < pDistance || pDistance == 0.0D) {
|
||||
if (entity.getRootVehicle() == pShooter.getRootVehicle() && !entity.canRiderInteract()) {
|
||||
if (pDistance == 0.0D) {
|
||||
cir.setReturnValue(new EntityHitResult(entity, vec));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
cir.setReturnValue(new EntityHitResult(entity, vec));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.atsuishio.superbwarfare.tools;
|
||||
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.joml.Intersectionf;
|
||||
import org.joml.Math;
|
||||
import org.joml.Quaternionf;
|
||||
|
@ -220,4 +221,29 @@ public record OBB(Vector3f center, Vector3f extents, Quaternionf rotation) {
|
|||
Vector3f newExtents = new Vector3f(extents).add(x, y, z);
|
||||
return new OBB(center, newExtents, rotation);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查点是否在OBB内部
|
||||
*
|
||||
* @return 如果点在OBB内部则返回true,否则返回false
|
||||
*/
|
||||
public boolean contains(Vec3 vec3) {
|
||||
// 计算点到OBB中心的向量
|
||||
Vector3f rel = new Vector3f(vec3.toVector3f()).sub(center);
|
||||
|
||||
Vector3f[] axes = new Vector3f[3];
|
||||
axes[0] = rotation.transform(new Vector3f(1, 0, 0));
|
||||
axes[1] = rotation.transform(new Vector3f(0, 1, 0));
|
||||
axes[2] = rotation.transform(new Vector3f(0, 0, 1));
|
||||
|
||||
// 将相对向量投影到OBB的三个轴上
|
||||
float projX = Math.abs(rel.dot(axes[0]));
|
||||
float projY = Math.abs(rel.dot(axes[1]));
|
||||
float projZ = Math.abs(rel.dot(axes[2]));
|
||||
|
||||
// 检查投影值是否小于对应轴上的半长
|
||||
return projX <= extents.x &&
|
||||
projY <= extents.y &&
|
||||
projZ <= extents.z;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue