From 5d90e121697d519b71e08d633fa5c50e96d7b800 Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Sun, 15 Jun 2025 19:14:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0projectile=E5=AF=B9=E4=BA=8Eo?= =?UTF-8?q?bb=20entity=E7=9A=84=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/projectile/ProjectileEntity.java | 1 - .../superbwarfare/mixins/LevelMixin.java | 33 +++++++++++++++++++ src/main/resources/mixins.superbwarfare.json | 1 + 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/atsuishio/superbwarfare/mixins/LevelMixin.java diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java index bbdb6fcbf..0e41b9c01 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java @@ -156,7 +156,6 @@ public class ProjectileEntity extends Projectile implements IEntityWithComplexSp @Nullable protected List findEntitiesOnPath(Vec3 startVec, Vec3 endVec) { List hitEntities = new ArrayList<>(); - // TODO 换一个允许检测obb的方法 List entities = this.level().getEntities( this, this.getBoundingBox() diff --git a/src/main/java/com/atsuishio/superbwarfare/mixins/LevelMixin.java b/src/main/java/com/atsuishio/superbwarfare/mixins/LevelMixin.java new file mode 100644 index 000000000..367d5a8b8 --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/mixins/LevelMixin.java @@ -0,0 +1,33 @@ +package com.atsuishio.superbwarfare.mixins; + +import com.atsuishio.superbwarfare.entity.OBBEntity; +import com.atsuishio.superbwarfare.tools.OBB; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.entity.LevelEntityGetter; +import net.minecraft.world.phys.AABB; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.List; +import java.util.function.Predicate; + +@Mixin(Level.class) +public abstract class LevelMixin { + + @Shadow + protected abstract LevelEntityGetter getEntities(); + + @Inject(method = "getEntities(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/phys/AABB;Ljava/util/function/Predicate;)Ljava/util/List;", + at = @At("RETURN")) + public void getEntities(Entity pEntity, AABB pBoundingBox, Predicate pPredicate, CallbackInfoReturnable> cir) { + this.getEntities().get(pBoundingBox, entity -> { + if (entity instanceof OBBEntity obbEntity && OBB.isColliding(obbEntity.getOBB(), pBoundingBox)) { + cir.getReturnValue().add(entity); + } + }); + } +} diff --git a/src/main/resources/mixins.superbwarfare.json b/src/main/resources/mixins.superbwarfare.json index bf1fc72a8..d04d9c658 100644 --- a/src/main/resources/mixins.superbwarfare.json +++ b/src/main/resources/mixins.superbwarfare.json @@ -8,6 +8,7 @@ "ClientboundSetPassengersPacketMixin", "EntityMixin", "FishingHookMixin", + "LevelMixin", "LivingEntityMixin", "PlayerMixin", "VillagerMixin"