From ae885f46564fd1dc6a616c199fe18073626f0dbc Mon Sep 17 00:00:00 2001 From: AViewFromTheTop <87103914+AViewFromTheTop@users.noreply.github.com> Date: Sat, 2 Dec 2023 14:48:38 -0500 Subject: [PATCH] safer prickly pear detection in walknodeevaluator --- .../mixin/block/cactus/EntityTypeMixin.java | 1 - .../block/cactus/WalkNodeEvaluatorMixin.java | 32 ++++++------------- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/src/main/java/net/frozenblock/wilderwild/mixin/block/cactus/EntityTypeMixin.java b/src/main/java/net/frozenblock/wilderwild/mixin/block/cactus/EntityTypeMixin.java index 44f0847c1a..17cf3c9905 100644 --- a/src/main/java/net/frozenblock/wilderwild/mixin/block/cactus/EntityTypeMixin.java +++ b/src/main/java/net/frozenblock/wilderwild/mixin/block/cactus/EntityTypeMixin.java @@ -40,5 +40,4 @@ public class EntityTypeMixin { } } - } diff --git a/src/main/java/net/frozenblock/wilderwild/mixin/block/cactus/WalkNodeEvaluatorMixin.java b/src/main/java/net/frozenblock/wilderwild/mixin/block/cactus/WalkNodeEvaluatorMixin.java index eed6d73838..945216b05d 100644 --- a/src/main/java/net/frozenblock/wilderwild/mixin/block/cactus/WalkNodeEvaluatorMixin.java +++ b/src/main/java/net/frozenblock/wilderwild/mixin/block/cactus/WalkNodeEvaluatorMixin.java @@ -18,44 +18,32 @@ package net.frozenblock.wilderwild.mixin.block.cactus; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import net.frozenblock.wilderwild.registry.RegisterBlocks; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.pathfinder.BlockPathTypes; import net.minecraft.world.level.pathfinder.WalkNodeEvaluator; 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; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; @Mixin(WalkNodeEvaluator.class) public class WalkNodeEvaluatorMixin { - @Inject( + @WrapOperation( method = "checkNeighbourBlocks", - at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;is(Lnet/minecraft/world/level/block/Block;)Z", ordinal = 0, shift = At.Shift.BEFORE), - locals = LocalCapture.CAPTURE_FAILHARD, - cancellable = true + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;is(Lnet/minecraft/world/level/block/Block;)Z", ordinal = 0) ) - private static void checkNeighbourBlocksWithPricklyPear(BlockGetter level, BlockPos.MutableBlockPos centerPos, BlockPathTypes nodeType, CallbackInfoReturnable info, int i, int j, int k, int l, int m, int n, BlockState blockState) { - if (blockState.is(RegisterBlocks.PRICKLY_PEAR_CACTUS)) { - info.setReturnValue(BlockPathTypes.DAMAGE_OTHER); - } + private static boolean checkNeighbourBlocksWithPricklyPear(BlockState blockState, Block block, Operation operation) { + return operation.call(blockState, block) || operation.call(blockState, RegisterBlocks.PRICKLY_PEAR_CACTUS); } - @Inject( + @WrapOperation( method = "getBlockPathTypeRaw", - at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;is(Lnet/minecraft/world/level/block/Block;)Z", ordinal = 3, shift = At.Shift.BEFORE), - locals = LocalCapture.CAPTURE_FAILHARD, - cancellable = true + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;is(Lnet/minecraft/world/level/block/Block;)Z", ordinal = 3) ) - private static void wilderWild$getBlockPathTypeRawWithPricklyPear(BlockGetter level, BlockPos pos, CallbackInfoReturnable info, BlockState blockState, Block block) { - if (blockState.is(RegisterBlocks.PRICKLY_PEAR_CACTUS)) { - info.setReturnValue(BlockPathTypes.DAMAGE_OTHER); - } + private static boolean wilderWild$getBlockPathTypeRawWithPricklyPear(BlockState blockState, Block block, Operation operation) { + return operation.call(blockState, block) || operation.call(blockState, RegisterBlocks.PRICKLY_PEAR_CACTUS); } }