Skip to content

Commit

Permalink
Allow for playerless block raycasts
Browse files Browse the repository at this point in the history
  • Loading branch information
vgskye committed Aug 19, 2024
1 parent de10fa6 commit 90ca0e8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -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 interface MixinCollisionContext {
@Inject(method = "of", cancellable = true, at = @At("HEAD"))
private static void acceptNull(Entity entity, CallbackInfoReturnable<CollisionContext> cir) {
if (entity == null) {
cir.setReturnValue(CollisionContext.empty());
cir.cancel();
}
}
}
1 change: 1 addition & 0 deletions Common/src/main/resources/hexplat.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"package": "at.petrak.hexcasting.mixin",
"mixins": [
"MixinAbstractVillager",
"MixinCollisionContext",
"MixinMob",
"MixinRaider",
"MixinVillager",
Expand Down

0 comments on commit 90ca0e8

Please sign in to comment.