|
| 1 | +package dev.itsmeow.whisperwoods.mixin; |
| 2 | + |
| 3 | +import dev.itsmeow.whisperwoods.util.IOverrideCollisions; |
| 4 | +import net.minecraft.world.level.BlockCollisions; |
| 5 | +import net.minecraft.world.level.BlockGetter; |
| 6 | +import net.minecraft.world.level.block.state.BlockState; |
| 7 | +import net.minecraft.world.phys.shapes.CollisionContext; |
| 8 | +import net.minecraft.world.phys.shapes.EntityCollisionContext; |
| 9 | +import net.minecraft.world.phys.shapes.Shapes; |
| 10 | +import net.minecraft.world.phys.shapes.VoxelShape; |
| 11 | +import org.spongepowered.asm.mixin.Final; |
| 12 | +import org.spongepowered.asm.mixin.Mixin; |
| 13 | +import org.spongepowered.asm.mixin.Shadow; |
| 14 | +import org.spongepowered.asm.mixin.injection.At; |
| 15 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 16 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; |
| 17 | +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; |
| 18 | + |
| 19 | +@Mixin(BlockCollisions.class) |
| 20 | +public class BlockCollisionsMixin { |
| 21 | + |
| 22 | + @Shadow |
| 23 | + @Final |
| 24 | + private CollisionContext context; |
| 25 | + |
| 26 | + @Inject(at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/level/BlockGetter;getBlockState(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/level/block/state/BlockState;"), method = "computeNext()Lnet/minecraft/world/phys/shapes/VoxelShape;", cancellable = true, locals = LocalCapture.CAPTURE_FAILSOFT) |
| 27 | + private void computeNext(CallbackInfoReturnable<VoxelShape> cir, int i, int j, int k, int l, BlockGetter blockGetter, BlockState blockState) { |
| 28 | + if(this.context instanceof EntityCollisionContext eContext) { |
| 29 | + if(eContext.getEntity() instanceof IOverrideCollisions o) { |
| 30 | + if(o.canPassThrough(blockState)) { |
| 31 | + cir.setReturnValue(Shapes.empty()); |
| 32 | + } |
| 33 | + } |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | +} |
0 commit comments