优化obb命中判定
This commit is contained in:
parent
7a96a131fc
commit
a1b062504d
2 changed files with 24 additions and 10 deletions
|
@ -1,6 +1,7 @@
|
||||||
package com.atsuishio.superbwarfare.mixins;
|
package com.atsuishio.superbwarfare.mixins;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.entity.OBBEntity;
|
import com.atsuishio.superbwarfare.entity.OBBEntity;
|
||||||
|
import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
|
||||||
import com.atsuishio.superbwarfare.tools.OBB;
|
import com.atsuishio.superbwarfare.tools.OBB;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
@ -24,6 +25,19 @@ public abstract class LevelMixin {
|
||||||
@Inject(method = "getEntities(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/phys/AABB;Ljava/util/function/Predicate;)Ljava/util/List;",
|
@Inject(method = "getEntities(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/phys/AABB;Ljava/util/function/Predicate;)Ljava/util/List;",
|
||||||
at = @At("RETURN"))
|
at = @At("RETURN"))
|
||||||
public void getEntities(Entity pEntity, AABB pBoundingBox, Predicate<? super Entity> pPredicate, CallbackInfoReturnable<List<Entity>> cir) {
|
public void getEntities(Entity pEntity, AABB pBoundingBox, Predicate<? super Entity> pPredicate, CallbackInfoReturnable<List<Entity>> cir) {
|
||||||
|
if (pEntity instanceof ProjectileEntity) {
|
||||||
|
this.getEntities().get(pBoundingBox.inflate(2), entity -> {
|
||||||
|
if (entity instanceof OBBEntity obbEntity) {
|
||||||
|
for (OBB obb : obbEntity.getOBBs()) {
|
||||||
|
if (OBB.isColliding(obb, pBoundingBox)) {
|
||||||
|
if (!cir.getReturnValue().contains(entity)) {
|
||||||
|
cir.getReturnValue().add(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
this.getEntities().get(pBoundingBox, entity -> {
|
this.getEntities().get(pBoundingBox, entity -> {
|
||||||
if (entity instanceof OBBEntity obbEntity) {
|
if (entity instanceof OBBEntity obbEntity) {
|
||||||
for (OBB obb : obbEntity.getOBBs()) {
|
for (OBB obb : obbEntity.getOBBs()) {
|
||||||
|
@ -36,4 +50,5 @@ public abstract class LevelMixin {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ 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;",
|
@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("HEAD"), 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) {
|
private static void getEntityHitResult(Level pLevel, Entity pProjectile, Vec3 pStartVec, Vec3 pEndVec, AABB pBoundingBox, Predicate<Entity> pFilter, float pInflationAmount, CallbackInfoReturnable<EntityHitResult> cir) {
|
||||||
for (var entity : pLevel.getEntities(pProjectile, pBoundingBox, pFilter)) {
|
for (var entity : pLevel.getEntities(pProjectile, pBoundingBox.inflate(2), pFilter)) {
|
||||||
if (entity instanceof OBBEntity obbEntity) {
|
if (entity instanceof OBBEntity obbEntity) {
|
||||||
if (pProjectile instanceof Projectile projectile &&
|
if (pProjectile instanceof Projectile projectile &&
|
||||||
(projectile.getOwner() == entity || entity.getPassengers().contains(projectile.getOwner()))) {
|
(projectile.getOwner() == entity || entity.getPassengers().contains(projectile.getOwner()))) {
|
||||||
|
@ -31,7 +31,6 @@ public class ProjectileUtilMixin {
|
||||||
}
|
}
|
||||||
var obbList = obbEntity.getOBBs();
|
var obbList = obbEntity.getOBBs();
|
||||||
for (var obb : obbList) {
|
for (var obb : obbList) {
|
||||||
obb = obb.inflate(6);
|
|
||||||
Optional<Vector3f> optional = obb.clip(pStartVec.toVector3f(), pEndVec.toVector3f());
|
Optional<Vector3f> optional = obb.clip(pStartVec.toVector3f(), pEndVec.toVector3f());
|
||||||
if (optional.isPresent()) {
|
if (optional.isPresent()) {
|
||||||
double d1 = pStartVec.distanceToSqr(new Vec3(optional.get()));
|
double d1 = pStartVec.distanceToSqr(new Vec3(optional.get()));
|
||||||
|
|
Loading…
Add table
Reference in a new issue