Search in sources :

Example 11 with SoundType

use of net.minecraft.block.SoundType in project MorePlanets by SteveKunG.

the class ItemBlockMultiFlower method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    IBlockState state = world.getBlockState(pos);
    Block block = state.getBlock();
    ItemStack itemStack = player.getHeldItem(hand);
    if (!block.isReplaceable(world, pos)) {
        pos = pos.offset(facing);
    }
    if (!itemStack.isEmpty() && player.canPlayerEdit(pos, facing, itemStack) && world.mayPlace(this.block, pos, false, facing, (Entity) null)) {
        int i = this.getMetadata(itemStack.getMetadata());
        IBlockState iblockstate1 = this.block.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, i, player, hand);
        if (this.placeBlockAt(itemStack, player, world, pos, facing, hitX, hitY, hitZ, iblockstate1)) {
            SoundType sound = world.getBlockState(pos).getBlock().getSoundType(world.getBlockState(pos), world, pos, player);
            world.playSound(player, pos, sound.getPlaceSound(), SoundCategory.BLOCKS, (sound.getVolume() + 1.0F) / 2.0F, sound.getPitch() * 0.8F);
            itemStack.shrink(1);
            return EnumActionResult.SUCCESS;
        }
        return EnumActionResult.PASS;
    } else {
        return EnumActionResult.FAIL;
    }
}
Also used : SoundType(net.minecraft.block.SoundType) Entity(net.minecraft.entity.Entity) IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Example 12 with SoundType

use of net.minecraft.block.SoundType in project SecurityCraft by Geforce132.

the class ItemReinforcedDoor method onItemUse.

/**
 * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
 * True if something happen and false if it don't. This is for ITEMS, not BLOCKS
 */
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (facing != EnumFacing.UP)
        return EnumActionResult.FAIL;
    else {
        IBlockState iblockstate = worldIn.getBlockState(pos);
        Block block = iblockstate.getBlock();
        if (!block.isReplaceable(worldIn, pos))
            pos = pos.offset(facing);
        if (playerIn.canPlayerEdit(pos, facing, stack) && SCContent.reinforcedDoor.canPlaceBlockAt(worldIn, pos)) {
            EnumFacing enumfacing = EnumFacing.fromAngle(playerIn.rotationYaw);
            int i = enumfacing.getFrontOffsetX();
            int j = enumfacing.getFrontOffsetZ();
            boolean flag = i < 0 && hitZ < 0.5F || i > 0 && hitZ > 0.5F || j < 0 && hitX > 0.5F || j > 0 && hitX < 0.5F;
            placeDoor(worldIn, pos, enumfacing, SCContent.reinforcedDoor, flag);
            SoundType soundtype = worldIn.getBlockState(pos).getBlock().getSoundType(worldIn.getBlockState(pos), worldIn, pos, playerIn);
            worldIn.playSound(playerIn, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
            ((TileEntityOwnable) worldIn.getTileEntity(pos)).getOwner().set(playerIn.getGameProfile().getId().toString(), playerIn.getName());
            ((TileEntityOwnable) worldIn.getTileEntity(pos.up())).getOwner().set(playerIn.getGameProfile().getId().toString(), playerIn.getName());
            --stack.stackSize;
            return EnumActionResult.SUCCESS;
        } else
            return EnumActionResult.FAIL;
    }
}
Also used : SoundType(net.minecraft.block.SoundType) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) Block(net.minecraft.block.Block)

Example 13 with SoundType

use of net.minecraft.block.SoundType in project Almura by AlmuraDev.

the class SlabItemImpl method tryPlaceSingle.

private EnumActionResult tryPlaceSingle(final World world, final EntityPlayer player, final EnumHand hand, final ItemStack itemStack, BlockPos pos, final EnumFacing facing, final float hitX, final float hitY, final float hitZ) {
    IBlockState previousState = world.getBlockState(pos);
    final Block previousBlock = previousState.getBlock();
    if (!previousBlock.isReplaceable(world, pos)) {
        pos = pos.offset(facing);
    }
    if (!itemStack.isEmpty() && player.canPlayerEdit(pos, facing, itemStack) && world.mayPlace(this.singleSlab, pos, false, facing, player)) {
        final IBlockState singleState = this.singleSlab.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, 0, player, hand);
        if (world.setBlockState(pos, singleState, 11)) {
            previousState = world.getBlockState(pos);
            if (singleState.equals(previousState)) {
                this.getBlock().onBlockPlacedBy(world, pos, singleState, player, itemStack);
                if (player instanceof EntityPlayerMP) {
                    CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP) player, pos, itemStack);
                }
                final SoundType sounds = singleState.getBlock().getSoundType(singleState, world, pos, player);
                world.playSound(player, pos, sounds.getPlaceSound(), SoundCategory.BLOCKS, (sounds.getVolume() + 1.0F) / 2.0F, sounds.getPitch() * 0.8F);
                itemStack.shrink(1);
                return EnumActionResult.SUCCESS;
            }
        }
    }
    return EnumActionResult.FAIL;
}
Also used : SoundType(net.minecraft.block.SoundType) IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 14 with SoundType

use of net.minecraft.block.SoundType in project AgriCraft by AgriCraft.

the class ItemCrop method onItemUseFirst.

// This is called when you right click with this item in hand.
@Override
public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    // Skip if remote, or clicked wrong face of block.
    if (world.isRemote || side != EnumFacing.UP) {
        return EnumActionResult.PASS;
    }
    // Fetch information.
    final BlockPos cropPos = pos.up();
    // Test if placement is valid.
    if (!world.isAirBlock(cropPos)) {
        return EnumActionResult.FAIL;
    }
    // Test if soil is valid.
    if (!AgriApi.getSoilRegistry().contains(world.getBlockState(pos))) {
        return EnumActionResult.FAIL;
    }
    // Set the block to a crop.
    world.setBlockState(pos.up(), AgriBlocks.getInstance().CROP.getDefaultState());
    // Remove the crop used from the stack.
    stack.stackSize = player.capabilities.isCreativeMode ? stack.stackSize : stack.stackSize - 1;
    // Handle sneak placing of crosscrops.
    if (player.isSneaking() && stack.stackSize > 0) {
        WorldHelper.getTile(world, pos.add(0, 1, 0), TileEntityCrop.class).ifPresent(c -> {
            c.setCrossCrop(true);
            stack.stackSize = player.capabilities.isCreativeMode ? stack.stackSize : stack.stackSize - 1;
        });
    }
    // Play placement sound.
    SoundType type = Blocks.LEAVES.getSoundType();
    world.playSound(null, (double) ((float) cropPos.getX() + 0.5F), (double) ((float) cropPos.getY() + 0.5F), (double) ((float) cropPos.getZ() + 0.5F), type.getPlaceSound(), SoundCategory.PLAYERS, (type.getVolume() + 1.0F) / 4.0F, type.getPitch() * 0.8F);
    // Action was a success.
    return EnumActionResult.SUCCESS;
}
Also used : SoundType(net.minecraft.block.SoundType) TileEntityCrop(com.infinityraider.agricraft.tiles.TileEntityCrop) BlockPos(net.minecraft.util.math.BlockPos)

Example 15 with SoundType

use of net.minecraft.block.SoundType in project Overloaded by CJ-MC-Mods.

the class PlayerInteractionUtil method placeBlock.

public static boolean placeBlock(@Nonnull ItemStack searchStack, @Nonnull EntityPlayerMP player, @Nonnull World worldIn, @Nonnull BlockPos newPosition, @Nonnull EnumFacing facing, @Nonnull IEnergyStorage energy, float hitX, float hitY, float hitZ) {
    // Can we place a block at this Pos
    ItemBlock itemBlock = ((ItemBlock) searchStack.getItem());
    if (!worldIn.mayPlace(itemBlock.getBlock(), newPosition, false, facing, null)) {
        return false;
    }
    BlockEvent.PlaceEvent event = ForgeEventFactory.onPlayerBlockPlace(player, new BlockSnapshot(worldIn, newPosition, worldIn.getBlockState(newPosition)), facing, EnumHand.MAIN_HAND);
    if (event.isCanceled())
        return false;
    long distance = Math.round(player.getPosition().getDistance(newPosition.getX(), newPosition.getY(), newPosition.getZ()));
    long cost = OverloadedConfig.multiToolConfig.placeBaseCost + OverloadedConfig.multiToolConfig.costPerMeterAway * distance;
    if (cost > Integer.MAX_VALUE || cost < 0 || energy.getEnergyStored() < cost)
        return false;
    IItemHandler inventory = player.getCapability(ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
    int foundStackSlot = findItemStack(searchStack, inventory);
    if (foundStackSlot == -1) {
        System.out.println("Stack not found");
        return false;
    }
    System.out.println("Stack found at index: " + foundStackSlot);
    ItemStack foundStack = inventory.extractItem(foundStackSlot, 1, player.capabilities.isCreativeMode);
    int i = itemBlock.getMetadata(foundStack.getMetadata());
    IBlockState iblockstate1 = itemBlock.block.getStateForPlacement(worldIn, newPosition, facing, hitX, hitY, hitZ, i, player, EnumHand.MAIN_HAND);
    if (itemBlock.placeBlockAt(foundStack, player, worldIn, newPosition, facing, hitX, hitY, hitZ, iblockstate1)) {
        SoundType soundtype = worldIn.getBlockState(newPosition).getBlock().getSoundType(worldIn.getBlockState(newPosition), worldIn, newPosition, player);
        worldIn.playSound(null, newPosition, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
        energy.extractEnergy((int) cost, false);
        System.out.println("Place Block Successs");
        return true;
    }
    System.out.println("Place Block Failed");
    inventory.insertItem(foundStackSlot, foundStack, player.capabilities.isCreativeMode);
    return false;
}
Also used : SoundType(net.minecraft.block.SoundType) IBlockState(net.minecraft.block.state.IBlockState) IItemHandler(net.minecraftforge.items.IItemHandler) BlockSnapshot(net.minecraftforge.common.util.BlockSnapshot) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack) BlockEvent(net.minecraftforge.event.world.BlockEvent)

Aggregations

SoundType (net.minecraft.block.SoundType)27 IBlockState (net.minecraft.block.state.IBlockState)21 Block (net.minecraft.block.Block)17 ItemStack (net.minecraft.item.ItemStack)15 ItemBlock (net.minecraft.item.ItemBlock)8 EnumFacing (net.minecraft.util.EnumFacing)6 Entity (net.minecraft.entity.Entity)4 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)4 BlockPos (net.minecraft.util.math.BlockPos)4 TileEntityCrop (com.infinityraider.agricraft.tiles.TileEntityCrop)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 SoundEvent (net.minecraft.util.SoundEvent)2 BlockSapling (net.minecraft.block.BlockSapling)1 BlockSlab (net.minecraft.block.BlockSlab)1 EnumBlockHalf (net.minecraft.block.BlockSlab.EnumBlockHalf)1 IProperty (net.minecraft.block.properties.IProperty)1 ISound (net.minecraft.client.audio.ISound)1 PositionedSound (net.minecraft.client.audio.PositionedSound)1 World (net.minecraft.world.World)1