Search in sources :

Example 1 with BlockSoundGroup

use of net.minecraft.sound.BlockSoundGroup in project Biome-Makeover by Lemonszz.

the class SmallLilyPadBlock method onUse.

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
    ItemStack stack = player.getStackInHand(hand);
    if (world.canPlayerModifyAt(player, pos) && state.get(PADS) < 3 && !stack.isEmpty() && stack.getItem() == BMBlocks.SMALL_LILY_PAD.asItem()) {
        world.setBlockState(pos, state.with(PADS, state.get(PADS) + 1));
        if (!player.isCreative())
            stack.decrement(1);
        BlockSoundGroup blockSoundGroup = state.getSoundGroup();
        world.playSound(player, pos, state.getSoundGroup().getPlaceSound(), SoundCategory.BLOCKS, (blockSoundGroup.getVolume() + 1.0F) / 2.0F, blockSoundGroup.getPitch() * 0.8F);
        return ActionResult.SUCCESS;
    }
    return super.onUse(state, world, pos, player, hand, hit);
}
Also used : ItemStack(net.minecraft.item.ItemStack) BlockSoundGroup(net.minecraft.sound.BlockSoundGroup)

Example 2 with BlockSoundGroup

use of net.minecraft.sound.BlockSoundGroup in project artifality by PinkGoosik.

the class FloralStaffItem method useOnBlock.

@Override
public ActionResult useOnBlock(ItemUsageContext context) {
    if (context.getWorld().isClient || context.getPlayer() == null)
        return super.useOnBlock(context);
    BlockPos pos = context.getBlockPos();
    BlockState state = context.getWorld().getBlockState(pos);
    PlayerEntity player = context.getPlayer();
    World world = context.getWorld();
    if (!player.getInventory().contains(Items.BONE_MEAL.getDefaultStack()))
        return super.useOnBlock(context);
    ItemStack boneMeal = player.getInventory().getStack(player.getInventory().getSlotWithStack(Items.BONE_MEAL.getDefaultStack()));
    if (FLOWERS.contains(state.getBlock())) {
        boneMeal.decrement(1);
        ExpUtils.drop(world, pos, world.getRandom().nextInt(2) + TiersUtils.getTier(context.getStack()));
        Block.dropStacks(state, world, pos);
        world.playSound(null, pos, SoundEvents.ITEM_BONE_MEAL_USE, SoundCategory.BLOCKS, 1.0F, 1.0F);
        return ActionResult.SUCCESS;
    } else if (Feature.isSoil(state) && context.getSide().equals(Direction.UP) && world.getBlockState(pos.up()).isAir()) {
        boneMeal.decrement(1);
        ExpUtils.drop(world, pos, world.getRandom().nextInt(2) + TiersUtils.getTier(context.getStack()));
        BlockSoundGroup blockSoundGroup = Blocks.AZALEA.getSoundGroup(Blocks.AZALEA.getDefaultState());
        world.playSound(null, pos, blockSoundGroup.getPlaceSound(), SoundCategory.BLOCKS, (blockSoundGroup.getVolume() + 1.0F) / 2.0F, blockSoundGroup.getPitch() * 0.8F);
        world.setBlockState(pos.up(), FLOWERS.get(world.getRandom().nextInt(FLOWERS.size())).getDefaultState());
        return ActionResult.SUCCESS;
    }
    return ActionResult.PASS;
}
Also used : BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) BlockSoundGroup(net.minecraft.sound.BlockSoundGroup) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 3 with BlockSoundGroup

use of net.minecraft.sound.BlockSoundGroup in project artifality by PinkGoosik.

the class ForestStaffItem method useOnBlock.

@Override
public ActionResult useOnBlock(ItemUsageContext context) {
    if (context.getWorld().isClient || context.getPlayer() == null)
        return super.useOnBlock(context);
    BlockPos pos = context.getBlockPos();
    BlockState state = context.getWorld().getBlockState(pos);
    PlayerEntity player = context.getPlayer();
    World world = context.getWorld();
    if (state.getBlock() instanceof SaplingBlock && player.getInventory().contains(Items.BONE_MEAL.getDefaultStack())) {
        if (BoneMealItem.useOnFertilizable(player.getInventory().getStack(player.getInventory().getSlotWithStack(Items.BONE_MEAL.getDefaultStack())), world, pos)) {
            world.syncWorldEvent(WorldEvents.BONE_MEAL_USED, pos, 0);
            ExpUtils.drop(world, pos, world.getRandom().nextInt(2) + TiersUtils.getTier(context.getStack()));
            return ActionResult.SUCCESS;
        }
    } else if (Feature.isSoil(state) && context.getSide().equals(Direction.UP)) {
        if (hasSapling(player) && world.isAir(pos.up())) {
            BlockSoundGroup blockSoundGroup = Blocks.AZALEA.getSoundGroup(Blocks.AZALEA.getDefaultState());
            world.playSound(null, pos, blockSoundGroup.getPlaceSound(), SoundCategory.BLOCKS, (blockSoundGroup.getVolume() + 1.0F) / 2.0F, blockSoundGroup.getPitch() * 0.8F);
            world.setBlockState(pos.up(), SAPLINGS.get(consumeSapling(player)).getDefaultState());
            return ActionResult.SUCCESS;
        }
    }
    return ActionResult.PASS;
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) BlockSoundGroup(net.minecraft.sound.BlockSoundGroup) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

BlockSoundGroup (net.minecraft.sound.BlockSoundGroup)3 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 BlockState (net.minecraft.block.BlockState)1