Search in sources :

Example 1 with CauldronBlock

use of net.minecraft.block.CauldronBlock in project AntimatterAPI by GregTech-Intergalactical.

the class MaterialItem method onItemUse.

@Override
public ActionResultType onItemUse(ItemUseContext context) {
    if (context.getPlayer() == null)
        return ActionResultType.PASS;
    World world = context.getWorld();
    PlayerEntity player = context.getPlayer();
    BlockPos pos = context.getPos();
    ItemStack stack = player.getHeldItem(context.getHand());
    BlockState state = world.getBlockState(pos);
    if (type == Data.DUST_IMPURE && state.getBlock() instanceof CauldronBlock) {
        int level = state.get(CauldronBlock.LEVEL);
        if (level > 0) {
            MaterialItem item = (MaterialItem) stack.getItem();
            player.setHeldItem(context.getHand(), Data.DUST_IMPURE.get(item.getMaterial(), stack.getCount()));
            world.setBlockState(context.getPos(), state.with(CauldronBlock.LEVEL, --level));
            world.playSound(player, pos, SoundEvents.ITEM_BUCKET_EMPTY, SoundCategory.BLOCKS, 1.0F, 1.0F);
            return ActionResultType.SUCCESS;
        }
    }
    return ActionResultType.FAIL;
}
Also used : CauldronBlock(net.minecraft.block.CauldronBlock) BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 2 with CauldronBlock

use of net.minecraft.block.CauldronBlock in project SophisticatedBackpacks by P3pp3rF1y.

the class CommonProxy method onCauldronInteract.

private void onCauldronInteract(PlayerInteractEvent.RightClickBlock event) {
    PlayerEntity player = event.getPlayer();
    Hand hand = event.getHand();
    ItemStack backpack = player.getItemInHand(hand);
    if (!(backpack.getItem() instanceof BackpackItem)) {
        return;
    }
    BlockPos pos = event.getPos();
    World world = event.getWorld();
    BlockState state = world.getBlockState(pos);
    Block block = state.getBlock();
    if (block != Blocks.CAULDRON) {
        return;
    }
    int level = state.getValue(CauldronBlock.LEVEL);
    LazyOptional<IBackpackWrapper> backpackWrapperCapability = backpack.getCapability(CapabilityBackpackWrapper.getCapabilityInstance());
    if (level == 0 || backpackWrapperCapability.map(this::hasDefaultColor).orElse(true)) {
        return;
    }
    if (!world.isClientSide) {
        backpackWrapperCapability.ifPresent(w -> {
            w.setColors(BackpackWrapper.DEFAULT_CLOTH_COLOR, BackpackWrapper.DEFAULT_BORDER_COLOR);
            ((CauldronBlock) block).setWaterLevel(world, pos, state, level - 1);
        });
    }
    event.setCanceled(true);
    event.setCancellationResult(ActionResultType.SUCCESS);
}
Also used : CauldronBlock(net.minecraft.block.CauldronBlock) BlockState(net.minecraft.block.BlockState) Block(net.minecraft.block.Block) CauldronBlock(net.minecraft.block.CauldronBlock) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) Hand(net.minecraft.util.Hand) IBackpackWrapper(net.p3pp3rf1y.sophisticatedbackpacks.api.IBackpackWrapper) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) BackpackItem(net.p3pp3rf1y.sophisticatedbackpacks.backpack.BackpackItem)

Aggregations

BlockState (net.minecraft.block.BlockState)2 CauldronBlock (net.minecraft.block.CauldronBlock)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 ItemStack (net.minecraft.item.ItemStack)2 BlockPos (net.minecraft.util.math.BlockPos)2 World (net.minecraft.world.World)2 Block (net.minecraft.block.Block)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 Hand (net.minecraft.util.Hand)1 IBackpackWrapper (net.p3pp3rf1y.sophisticatedbackpacks.api.IBackpackWrapper)1 BackpackItem (net.p3pp3rf1y.sophisticatedbackpacks.backpack.BackpackItem)1