From 85f6093ac2ded0578667abc16169474137c9a994 Mon Sep 17 00:00:00 2001 From: Skye Date: Mon, 19 Aug 2024 04:43:19 +0000 Subject: [PATCH] Allow for playerless block raycasts --- .../actions/raycast/OpBlockAxisRaycast.kt | 3 +-- .../casting/actions/raycast/OpBlockRaycast.kt | 4 ++-- .../mixin/MixinCollisionContext.java | 19 +++++++++++++++++++ Common/src/main/resources/hexplat.mixins.json | 1 + 4 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 Common/src/main/java/at/petrak/hexcasting/mixin/MixinCollisionContext.java diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/raycast/OpBlockAxisRaycast.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/raycast/OpBlockAxisRaycast.kt index 6e066638d6..2aa68ecf28 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/raycast/OpBlockAxisRaycast.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/raycast/OpBlockAxisRaycast.kt @@ -8,12 +8,10 @@ import at.petrak.hexcasting.api.casting.getVec3 import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.NullIota import at.petrak.hexcasting.api.misc.MediaConstants -import net.minecraft.world.entity.Entity import net.minecraft.world.level.ClipContext import net.minecraft.world.phys.HitResult import net.minecraft.world.phys.Vec3 -@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS") object OpBlockAxisRaycast : ConstMediaAction { override val argc = 2 override val mediaCost: Long = MediaConstants.DUST_UNIT / 100 @@ -29,6 +27,7 @@ object OpBlockAxisRaycast : ConstMediaAction { Action.raycastEnd(origin, look), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, + @Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS") env.castingEntity ) ) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/raycast/OpBlockRaycast.kt b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/raycast/OpBlockRaycast.kt index 1fce74df5a..33a2e990eb 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/raycast/OpBlockRaycast.kt +++ b/Common/src/main/java/at/petrak/hexcasting/common/casting/actions/raycast/OpBlockRaycast.kt @@ -8,7 +8,6 @@ import at.petrak.hexcasting.api.casting.getVec3 import at.petrak.hexcasting.api.casting.iota.Iota import at.petrak.hexcasting.api.casting.iota.NullIota import at.petrak.hexcasting.api.misc.MediaConstants -import net.minecraft.world.entity.Entity import net.minecraft.world.level.ClipContext import net.minecraft.world.phys.HitResult import net.minecraft.world.phys.Vec3 @@ -28,7 +27,8 @@ object OpBlockRaycast : ConstMediaAction { Action.raycastEnd(origin, look), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, - env.castingEntity as Entity + @Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS") + env.castingEntity ) ) diff --git a/Common/src/main/java/at/petrak/hexcasting/mixin/MixinCollisionContext.java b/Common/src/main/java/at/petrak/hexcasting/mixin/MixinCollisionContext.java new file mode 100644 index 0000000000..ad0c0762b3 --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/mixin/MixinCollisionContext.java @@ -0,0 +1,19 @@ +package at.petrak.hexcasting.mixin; + +import net.minecraft.world.entity.Entity; +import net.minecraft.world.phys.shapes.CollisionContext; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(CollisionContext.class) +public class MixinCollisionContext { + @Inject(method = "of", cancellable = true, at = @At("HEAD")) + private static void acceptNull(Entity entity, CallbackInfoReturnable cir) { + if (entity == null) { + cir.setReturnValue(CollisionContext.empty()); + cir.cancel(); + } + } +} diff --git a/Common/src/main/resources/hexplat.mixins.json b/Common/src/main/resources/hexplat.mixins.json index 1d2ac13000..ec31ea61d7 100644 --- a/Common/src/main/resources/hexplat.mixins.json +++ b/Common/src/main/resources/hexplat.mixins.json @@ -6,6 +6,7 @@ "package": "at.petrak.hexcasting.mixin", "mixins": [ "MixinAbstractVillager", + "MixinCollisionContext", "MixinMob", "MixinRaider", "MixinVillager",