Skip to content

Commit

Permalink
safer prickly pear detection in walknodeevaluator
Browse files Browse the repository at this point in the history
  • Loading branch information
AViewFromTheTop committed Dec 2, 2023
1 parent 568ad41 commit ae885f4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,4 @@ public class EntityTypeMixin {
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlockPathTypes> 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<Boolean> 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<BlockPathTypes> 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<Boolean> operation) {
return operation.call(blockState, block) || operation.call(blockState, RegisterBlocks.PRICKLY_PEAR_CACTUS);
}

}

0 comments on commit ae885f4

Please sign in to comment.