Search in sources :

Example 1 with BlockView

use of net.minecraft.world.BlockView in project Rug by RubixDev.

the class WorldMixin method convertBasalt.

@Inject(method = "setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;II)Z", at = @At("HEAD"), cancellable = true)
private void convertBasalt(BlockPos pos, BlockState state, int flags, int maxUpdateDepth, CallbackInfoReturnable<Boolean> cir) {
    if (state.isOf(Blocks.BASALT)) {
        BlockState prevState = ((BlockView) this).getBlockState(pos);
        if (FluidHelper.shouldConvertToLava((BlockView) this, pos)) {
            if (prevState.isOf(Blocks.LAVA) && prevState.getFluidState().isStill()) {
                cir.setReturnValue(false);
                return;
            }
            FluidHelper.playFizzleSound((WorldAccess) this, pos);
            ((WorldAccess) this).playSound(null, pos, SoundEvents.ITEM_BUCKET_EMPTY_LAVA, SoundCategory.BLOCKS, 1.0F, 1.0F);
            cir.setReturnValue(this.setBlockState(pos, Blocks.LAVA.getDefaultState(), flags, maxUpdateDepth));
        }
    }
}
Also used : BlockView(net.minecraft.world.BlockView) WorldAccess(net.minecraft.world.WorldAccess) BlockState(net.minecraft.block.BlockState) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with BlockView

use of net.minecraft.world.BlockView in project fabric by FabricMC.

the class PickBlockEventModClient method onInitializeClient.

@Override
public void onInitializeClient() {
    ClientPickBlockGatherCallback.EVENT.register((player, result) -> {
        if (result instanceof BlockHitResult) {
            BlockView view = player.getEntityWorld();
            BlockPos pos = ((BlockHitResult) result).getBlockPos();
            BlockState state = view.getBlockState(pos);
            if (state.getBlock() == Blocks.STONE) {
                return new ItemStack(Blocks.OAK_WOOD);
            }
        }
        return ItemStack.EMPTY;
    });
    ClientPickBlockApplyCallback.EVENT.register((player, result, stack) -> {
        if (stack.getItem() == Item.getItemFromBlock(Blocks.OAK_WOOD)) {
            return new ItemStack(Blocks.ACACIA_WOOD);
        } else {
            return stack;
        }
    });
}
Also used : BlockView(net.minecraft.world.BlockView) BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) ItemStack(net.minecraft.item.ItemStack)

Aggregations

BlockState (net.minecraft.block.BlockState)2 BlockView (net.minecraft.world.BlockView)2 ItemStack (net.minecraft.item.ItemStack)1 BlockHitResult (net.minecraft.util.hit.BlockHitResult)1 BlockPos (net.minecraft.util.math.BlockPos)1 WorldAccess (net.minecraft.world.WorldAccess)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1