Java Code Examples for net.minecraft.world.World.playSound()

The following are Jave code examples for showing how to use playSound() of the net.minecraft.world.World class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: pnc-repressurized   File: ItemVortexCannon.java   View Source Code Vote up 6 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer playerIn, EnumHand handIn) {
    ItemStack iStack = playerIn.getHeldItem(handIn);
    if (iStack.getItemDamage() < iStack.getMaxDamage()) {
        double factor = 0.2D * getPressure(iStack);
        world.playSound(playerIn.posX, playerIn.posY, playerIn.posZ, Sounds.CANNON_SOUND, SoundCategory.PLAYERS, 1.0F, 0.7F + (float) factor * 0.2F, false);
        EntityVortex vortex = new EntityVortex(world, playerIn);
        Vec3d directionVec = playerIn.getLookVec().normalize();
        vortex.posX += directionVec.x;
        vortex.posY += directionVec.y;
        vortex.posZ += directionVec.z;
        vortex.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 0.0F);
        vortex.motionX *= factor;
        vortex.motionY *= factor;
        vortex.motionZ *= factor;
        if (!world.isRemote) world.spawnEntity(vortex);

        iStack.setItemDamage(iStack.getItemDamage() + PneumaticValues.USAGE_VORTEX_CANNON);
        if (iStack.getItemDamage() > iStack.getMaxDamage()) {
            iStack.setItemDamage(iStack.getMaxDamage());
        }
    }

    return ActionResult.newResult(EnumActionResult.SUCCESS, iStack);
}
 
Example 2
Project: Bewitchment   File: ItemRitual.java   View Source Code Vote up 6 votes
@SuppressWarnings("ConstantConditions")
@Override
public void onFinish(TileCauldron tile, World world, BlockPos pos) {
	for (int i = 0; i < 20; i++) {
		final float x = pos.getX() + 0.2F + MathHelper.clamp(world.rand.nextFloat(), 0F, 0.5F);
		final float y = pos.getY() + 0.2F + world.rand.nextFloat();
		final float z = pos.getZ() + 0.2F + MathHelper.clamp(world.rand.nextFloat(), 0F, 0.5F);

		PacketHandler.spawnParticle(ParticleF.STEAM, world, x, y, z, 10, 0, 0, 0);
	}
	if (!stack.isEmpty()) {
		if (tile.getContainer().isEmpty()) {
			tile.setContainer(stack);
		} else {
			spawnItem(world, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D);
		}
	}
	world.playSound(null, pos, SoundEvents.BLOCK_LAVA_EXTINGUISH, SoundCategory.BLOCKS, 1F, 1F);
	IFluidHandler handler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null);
	handler.drain(1000, true);
}
 
Example 3
Project: CustomWorldGen   File: BlockTripWireHook.java   View Source Code Vote up 6 votes
private void playSound(World worldIn, BlockPos pos, boolean p_180694_3_, boolean p_180694_4_, boolean p_180694_5_, boolean p_180694_6_)
{
    if (p_180694_4_ && !p_180694_6_)
    {
        worldIn.playSound((EntityPlayer)null, pos, SoundEvents.BLOCK_TRIPWIRE_CLICK_ON, SoundCategory.BLOCKS, 0.4F, 0.6F);
    }
    else if (!p_180694_4_ && p_180694_6_)
    {
        worldIn.playSound((EntityPlayer)null, pos, SoundEvents.BLOCK_TRIPWIRE_CLICK_OFF, SoundCategory.BLOCKS, 0.4F, 0.5F);
    }
    else if (p_180694_3_ && !p_180694_5_)
    {
        worldIn.playSound((EntityPlayer)null, pos, SoundEvents.BLOCK_TRIPWIRE_ATTACH, SoundCategory.BLOCKS, 0.4F, 0.7F);
    }
    else if (!p_180694_3_ && p_180694_5_)
    {
        worldIn.playSound((EntityPlayer)null, pos, SoundEvents.BLOCK_TRIPWIRE_DETACH, SoundCategory.BLOCKS, 0.4F, 1.2F / (worldIn.rand.nextFloat() * 0.2F + 0.9F));
    }
}
 
Example 4
Project: Genesis   File: GenesisEventHandler.java   View Source Code Vote up 6 votes
@SubscribeEvent
public static void onUseHoe(UseHoeEvent event) {
    EntityPlayer player = event.getEntityPlayer();
    World world = event.getWorld();
    BlockPos pos = event.getPos();
    IBlockState state = world.getBlockState(pos);
    Block block = state.getBlock();

    if (block == GenesisBlocks.HUMUS || block == GenesisBlocks.HUMUS_PATH) {
        world.playSound(player, pos, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F);

        if (!world.isRemote) {
            IBlockState farmland = GenesisBlocks.HUMUS_FARMLAND.getDefaultState();
            world.setBlockState(pos, farmland, WorldFlags.UPDATE_BLOCK_AND_CLIENT_AND_RERENDER_ON_MAIN);
        }

        event.setResult(Event.Result.ALLOW);
    }
}
 
Example 5
Project: Backmemed   File: BlockLiquid.java   View Source Code Vote up 5 votes
protected void triggerMixEffects(World worldIn, BlockPos pos)
{
    double d0 = (double)pos.getX();
    double d1 = (double)pos.getY();
    double d2 = (double)pos.getZ();
    worldIn.playSound((EntityPlayer)null, pos, SoundEvents.BLOCK_LAVA_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (worldIn.rand.nextFloat() - worldIn.rand.nextFloat()) * 0.8F);

    for (int i = 0; i < 8; ++i)
    {
        worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d0 + Math.random(), d1 + 1.2D, d2 + Math.random(), 0.0D, 0.0D, 0.0D, new int[0]);
    }
}
 
Example 6
Project: CustomWorldGen   File: ItemHoe.java   View Source Code Vote up 5 votes
protected void setBlock(ItemStack stack, EntityPlayer player, World worldIn, BlockPos pos, IBlockState state)
{
    worldIn.playSound(player, pos, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F);

    if (!worldIn.isRemote)
    {
        worldIn.setBlockState(pos, state, 11);
        stack.damageItem(1, player);
    }
}
 
Example 7
Project: Backmemed   File: ItemEnderEye.java   View Source Code Vote up 5 votes
public ActionResult<ItemStack> onItemRightClick(World itemStackIn, EntityPlayer worldIn, EnumHand playerIn)
{
    ItemStack itemstack = worldIn.getHeldItem(playerIn);
    RayTraceResult raytraceresult = this.rayTrace(itemStackIn, worldIn, false);

    if (raytraceresult != null && raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK && itemStackIn.getBlockState(raytraceresult.getBlockPos()).getBlock() == Blocks.END_PORTAL_FRAME)
    {
        return new ActionResult(EnumActionResult.PASS, itemstack);
    }
    else
    {
        worldIn.setActiveHand(playerIn);

        if (!itemStackIn.isRemote)
        {
            BlockPos blockpos = ((WorldServer)itemStackIn).getChunkProvider().getStrongholdGen(itemStackIn, "Stronghold", new BlockPos(worldIn), false);

            if (blockpos != null)
            {
                EntityEnderEye entityendereye = new EntityEnderEye(itemStackIn, worldIn.posX, worldIn.posY + (double)(worldIn.height / 2.0F), worldIn.posZ);
                entityendereye.moveTowards(blockpos);
                itemStackIn.spawnEntityInWorld(entityendereye);
                itemStackIn.playSound((EntityPlayer)null, worldIn.posX, worldIn.posY, worldIn.posZ, SoundEvents.ENTITY_ENDEREYE_LAUNCH, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
                itemStackIn.playEvent((EntityPlayer)null, 1003, new BlockPos(worldIn), 0);

                if (!worldIn.capabilities.isCreativeMode)
                {
                    itemstack.func_190918_g(1);
                }

                worldIn.addStat(StatList.getObjectUseStats(this));
                return new ActionResult(EnumActionResult.SUCCESS, itemstack);
            }
        }

        return new ActionResult(EnumActionResult.SUCCESS, itemstack);
    }
}
 
Example 8
Project: CustomWorldGen   File: BlockTNT.java   View Source Code Vote up 5 votes
public void explode(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase igniter)
{
    if (!worldIn.isRemote)
    {
        if (((Boolean)state.getValue(EXPLODE)).booleanValue())
        {
            EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(worldIn, (double)((float)pos.getX() + 0.5F), (double)pos.getY(), (double)((float)pos.getZ() + 0.5F), igniter);
            worldIn.spawnEntityInWorld(entitytntprimed);
            worldIn.playSound((EntityPlayer)null, entitytntprimed.posX, entitytntprimed.posY, entitytntprimed.posZ, SoundEvents.ENTITY_TNT_PRIMED, SoundCategory.BLOCKS, 1.0F, 1.0F);
        }
    }
}
 
Example 9
Project: Loot-Slash-Conquer   File: ItemLEMagical.java   View Source Code Vote up 4 votes
@Override
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityLivingBase entity, int count)
{	
	if (entity instanceof EntityPlayer)
	{
		EntityPlayer player = (EntityPlayer) entity;
		Stats statsCap = (Stats) player.getCapability(CapabilityPlayerStats.STATS, null);	
		PlayerInformation info = (PlayerInformation) player.getCapability(CapabilityPlayerInformation.PLAYER_INFORMATION, null);
		NBTTagCompound nbt = NBTHelper.loadStackNBT(stack);
		
		if (info != null)
		{
			// check to see if we have held it long enough
			double attackSpeed = nbt.getDouble("AttackSpeed") + (PlayerStatHelper.ATTACK_SPEED_MULTIPLIER * (info.getTotalAgility()));
			
			if (count > (this.getMaxItemUseDuration(stack) - ((1 / attackSpeed) * 20))) 
			{
				return;
			}
			
			// fire projectile because check passed
			if (statsCap != null)
			{
				world.playSound(player, player.getPosition(), SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 1.0F, 1.0F);
				
				if (!world.isRemote)
				{
					// spawn entity and set position to specified direction
					Vec3d look = player.getLookVec();

					fireProjectile(world, player, stack, nbt, look);
					
					// update mana and send to client
					statsCap.decreaseMana(this.manaPerUse);
					LootSlashConquer.network.sendTo(new PacketUpdateStats(statsCap), (EntityPlayerMP) player);
					
					// damage item
					stack.damageItem(1, player);
				}
			}
		}
	}
}
 
Example 10
Project: ArcaneMagic   File: ItemParchment.java   View Source Code Vote up 4 votes
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
{
	ItemStack stack = player.getHeldItem(hand);
	if (stack.getItem().equals(ModRegistry.WRITTEN_PARCHMENT))
	{
		Pair<NotebookCategory, Boolean> catInfo = getToUnlock(stack);
		if (catInfo != null)
		{
			if (!world.isRemote)
			{
				INotebookInfo cap = player.getCapability(INotebookInfo.CAP, null);
				if (cap != null)
				{
					NotebookCategory cat = catInfo.first();
					if (cat != null)
					{
						if (!cat.equals(NotebookCategories.UNKNOWN_REALMS)
								&& cap.isUnlocked(cat.getPrerequisiteTag())
								&& !cap.isUnlocked(cat.getRequiredTag()))
						{
							cap.setUnlocked(cat.getRequiredTag());
						}
						if (catInfo.second())
						{
							for (NotebookCategory mightBeParent : NotebookCategory.REGISTRY.getValues())
							{
								if (mightBeParent != null && mightBeParent.getRequiredTag() != null)
								{
									if (mightBeParent.getRequiredTag().equals(cat.getPrerequisiteTag()))
									{
										ArcaneMagicPacketHandler.INSTANCE
												.sendTo(new PacketNotebookToastExpanded(mightBeParent,
														cat.getRequiredTag(), true), (EntityPlayerMP) player);
									}
								}
							}
						} else
						{
							ArcaneMagicPacketHandler.INSTANCE.sendTo(new PacketNotebookToastOrFail(cat, true),
									(EntityPlayerMP) player);
						}

					} else
					{
						ArcaneMagicPacketHandler.INSTANCE.sendTo(new PacketNotebookToastOrFail(cat, true),
								(EntityPlayerMP) player);
					}
				}
			}
		}

		world.playSound(player, player.getPosition(), ArcaneMagicSoundHandler.randomWriteSound(),
				SoundCategory.PLAYERS, 1, 1);
		player.setHeldItem(hand, ItemStack.EMPTY);
		player.swingArm(hand);
		if (!world.isRemote)
		{
			return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
		}
	}
	return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
}
 
Example 11
Project: ExPetrum   File: BlockBerryBush.java   View Source Code Vote up 4 votes
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    if (this.getState() == EnumShrubState.BLOOMING)
    {
        if (!worldIn.isRemote)
        {
            ItemStack held = playerIn.getHeldItem(hand);
            int allowHarvest;
            if (!held.isEmpty() && held.getItem() == ExPItems.basket)
            {
                held.damageItem(1, playerIn);
                allowHarvest = 2;
            }
            else
            {
                allowHarvest = worldIn.rand.nextFloat() < 0.1F ? 1 : 0;
                if (allowHarvest == 0)
                {
                    worldIn.playSound(null, pos, SoundEvents.BLOCK_GRASS_BREAK, SoundCategory.BLOCKS, 1, 1);
                }
            }

            if (allowHarvest > 0)
            {
                worldIn.setBlockState(pos, ExPBlocks.berryBushes[EnumShrubState.NORMAL.ordinal()].getDefaultState().withProperty(ExPBlockProperties.BERRY_BUSH_TYPE, state.getValue(ExPBlockProperties.BERRY_BUSH_TYPE)));
                if (allowHarvest == 2 || worldIn.rand.nextFloat() <= 0.75F)
                {
                    float amt = 50 + worldIn.rand.nextFloat() * 250;
                    ItemStack food = new ItemStack(ExPItems.food, 1, EnumCrop.values().length + state.getValue(ExPBlockProperties.BERRY_BUSH_TYPE).ordinal() + 1);
                    ItemFood item = (ItemFood) food.getItem();
                    item.setLastTickTime(food, IExPWorld.of(worldIn).today());
                    item.setTotalWeight(food, amt);
                    EntityItem drop = new EntityItem(worldIn, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, food.copy());
                    worldIn.spawnEntity(drop);
                }
            }
        }

        return true;
    }

    return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
 
Example 12
Project: CustomWorldGen   File: ItemArmorStand.java   View Source Code Vote up 4 votes
/**
 * Called when a Block is right-clicked with this Item
 */
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    if (facing == EnumFacing.DOWN)
    {
        return EnumActionResult.FAIL;
    }
    else
    {
        boolean flag = worldIn.getBlockState(pos).getBlock().isReplaceable(worldIn, pos);
        BlockPos blockpos = flag ? pos : pos.offset(facing);

        if (!playerIn.canPlayerEdit(blockpos, facing, stack))
        {
            return EnumActionResult.FAIL;
        }
        else
        {
            BlockPos blockpos1 = blockpos.up();
            boolean flag1 = !worldIn.isAirBlock(blockpos) && !worldIn.getBlockState(blockpos).getBlock().isReplaceable(worldIn, blockpos);
            flag1 = flag1 | (!worldIn.isAirBlock(blockpos1) && !worldIn.getBlockState(blockpos1).getBlock().isReplaceable(worldIn, blockpos1));

            if (flag1)
            {
                return EnumActionResult.FAIL;
            }
            else
            {
                double d0 = (double)blockpos.getX();
                double d1 = (double)blockpos.getY();
                double d2 = (double)blockpos.getZ();
                List<Entity> list = worldIn.getEntitiesWithinAABBExcludingEntity((Entity)null, new AxisAlignedBB(d0, d1, d2, d0 + 1.0D, d1 + 2.0D, d2 + 1.0D));

                if (!list.isEmpty())
                {
                    return EnumActionResult.FAIL;
                }
                else
                {
                    if (!worldIn.isRemote)
                    {
                        worldIn.setBlockToAir(blockpos);
                        worldIn.setBlockToAir(blockpos1);
                        EntityArmorStand entityarmorstand = new EntityArmorStand(worldIn, d0 + 0.5D, d1, d2 + 0.5D);
                        float f = (float)MathHelper.floor_float((MathHelper.wrapDegrees(playerIn.rotationYaw - 180.0F) + 22.5F) / 45.0F) * 45.0F;
                        entityarmorstand.setLocationAndAngles(d0 + 0.5D, d1, d2 + 0.5D, f, 0.0F);
                        this.applyRandomRotations(entityarmorstand, worldIn.rand);
                        ItemMonsterPlacer.applyItemEntityDataToEntity(worldIn, playerIn, stack, entityarmorstand);
                        worldIn.spawnEntityInWorld(entityarmorstand);
                        worldIn.playSound((EntityPlayer)null, entityarmorstand.posX, entityarmorstand.posY, entityarmorstand.posZ, SoundEvents.ENTITY_ARMORSTAND_PLACE, SoundCategory.BLOCKS, 0.75F, 0.8F);
                    }

                    --stack.stackSize;
                    return EnumActionResult.SUCCESS;
                }
            }
        }
    }
}
 
Example 13
Project: Backmemed   File: BlockFire.java   View Source Code Vote up 4 votes
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand)
{
    if (rand.nextInt(24) == 0)
    {
        worldIn.playSound((double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), SoundEvents.BLOCK_FIRE_AMBIENT, SoundCategory.BLOCKS, 1.0F + rand.nextFloat(), rand.nextFloat() * 0.7F + 0.3F, false);
    }

    if (!worldIn.getBlockState(pos.down()).isFullyOpaque() && !Blocks.FIRE.canCatchFire(worldIn, pos.down()))
    {
        if (Blocks.FIRE.canCatchFire(worldIn, pos.west()))
        {
            for (int j = 0; j < 2; ++j)
            {
                double d3 = (double)pos.getX() + rand.nextDouble() * 0.10000000149011612D;
                double d8 = (double)pos.getY() + rand.nextDouble();
                double d13 = (double)pos.getZ() + rand.nextDouble();
                worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d3, d8, d13, 0.0D, 0.0D, 0.0D, new int[0]);
            }
        }

        if (Blocks.FIRE.canCatchFire(worldIn, pos.east()))
        {
            for (int k = 0; k < 2; ++k)
            {
                double d4 = (double)(pos.getX() + 1) - rand.nextDouble() * 0.10000000149011612D;
                double d9 = (double)pos.getY() + rand.nextDouble();
                double d14 = (double)pos.getZ() + rand.nextDouble();
                worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d4, d9, d14, 0.0D, 0.0D, 0.0D, new int[0]);
            }
        }

        if (Blocks.FIRE.canCatchFire(worldIn, pos.north()))
        {
            for (int l = 0; l < 2; ++l)
            {
                double d5 = (double)pos.getX() + rand.nextDouble();
                double d10 = (double)pos.getY() + rand.nextDouble();
                double d15 = (double)pos.getZ() + rand.nextDouble() * 0.10000000149011612D;
                worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d5, d10, d15, 0.0D, 0.0D, 0.0D, new int[0]);
            }
        }

        if (Blocks.FIRE.canCatchFire(worldIn, pos.south()))
        {
            for (int i1 = 0; i1 < 2; ++i1)
            {
                double d6 = (double)pos.getX() + rand.nextDouble();
                double d11 = (double)pos.getY() + rand.nextDouble();
                double d16 = (double)(pos.getZ() + 1) - rand.nextDouble() * 0.10000000149011612D;
                worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d6, d11, d16, 0.0D, 0.0D, 0.0D, new int[0]);
            }
        }

        if (Blocks.FIRE.canCatchFire(worldIn, pos.up()))
        {
            for (int j1 = 0; j1 < 2; ++j1)
            {
                double d7 = (double)pos.getX() + rand.nextDouble();
                double d12 = (double)(pos.getY() + 1) - rand.nextDouble() * 0.10000000149011612D;
                double d17 = (double)pos.getZ() + rand.nextDouble();
                worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d7, d12, d17, 0.0D, 0.0D, 0.0D, new int[0]);
            }
        }
    }
    else
    {
        for (int i = 0; i < 3; ++i)
        {
            double d0 = (double)pos.getX() + rand.nextDouble();
            double d1 = (double)pos.getY() + rand.nextDouble() * 0.5D + 0.5D;
            double d2 = (double)pos.getZ() + rand.nextDouble();
            worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d0, d1, d2, 0.0D, 0.0D, 0.0D, new int[0]);
        }
    }
}
 
Example 14
Project: CustomWorldGen   File: ItemBlockSpecial.java   View Source Code Vote up 4 votes
/**
 * Called when a Block is right-clicked with this Item
 */
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    IBlockState iblockstate = worldIn.getBlockState(pos);
    Block block = iblockstate.getBlock();

    if (block == Blocks.SNOW_LAYER && ((Integer)iblockstate.getValue(BlockSnow.LAYERS)).intValue() < 1)
    {
        facing = EnumFacing.UP;
    }
    else if (!block.isReplaceable(worldIn, pos))
    {
        pos = pos.offset(facing);
    }

    if (playerIn.canPlayerEdit(pos, facing, stack) && stack.stackSize != 0 && worldIn.canBlockBePlaced(this.block, pos, false, facing, (Entity)null, stack))
    {
        IBlockState iblockstate1 = this.block.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, 0, playerIn, stack);

        if (!worldIn.setBlockState(pos, iblockstate1, 11))
        {
            return EnumActionResult.FAIL;
        }
        else
        {
            iblockstate1 = worldIn.getBlockState(pos);

            if (iblockstate1.getBlock() == this.block)
            {
                ItemBlock.setTileEntityNBT(worldIn, playerIn, pos, stack);
                iblockstate1.getBlock().onBlockPlacedBy(worldIn, pos, iblockstate1, playerIn, stack);
            }

            SoundType soundtype = iblockstate1.getBlock().getSoundType(iblockstate1, worldIn, pos, playerIn);
            worldIn.playSound(playerIn, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
            --stack.stackSize;
            return EnumActionResult.SUCCESS;
        }
    }
    else
    {
        return EnumActionResult.FAIL;
    }
}
 
Example 15
Project: CustomWorldGen   File: ItemBed.java   View Source Code Vote up 4 votes
/**
 * Called when a Block is right-clicked with this Item
 */
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    if (worldIn.isRemote)
    {
        return EnumActionResult.SUCCESS;
    }
    else if (facing != EnumFacing.UP)
    {
        return EnumActionResult.FAIL;
    }
    else
    {
        IBlockState iblockstate = worldIn.getBlockState(pos);
        Block block = iblockstate.getBlock();
        boolean flag = block.isReplaceable(worldIn, pos);

        if (!flag)
        {
            pos = pos.up();
        }

        int i = MathHelper.floor_double((double)(playerIn.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
        EnumFacing enumfacing = EnumFacing.getHorizontal(i);
        BlockPos blockpos = pos.offset(enumfacing);

        if (playerIn.canPlayerEdit(pos, facing, stack) && playerIn.canPlayerEdit(blockpos, facing, stack))
        {
            boolean flag1 = worldIn.getBlockState(blockpos).getBlock().isReplaceable(worldIn, blockpos);
            boolean flag2 = flag || worldIn.isAirBlock(pos);
            boolean flag3 = flag1 || worldIn.isAirBlock(blockpos);

            if (flag2 && flag3 && worldIn.getBlockState(pos.down()).isFullyOpaque() && worldIn.getBlockState(blockpos.down()).isFullyOpaque())
            {
                IBlockState iblockstate1 = Blocks.BED.getDefaultState().withProperty(BlockBed.OCCUPIED, Boolean.valueOf(false)).withProperty(BlockBed.FACING, enumfacing).withProperty(BlockBed.PART, BlockBed.EnumPartType.FOOT);

                if (worldIn.setBlockState(pos, iblockstate1, 11))
                {
                    IBlockState iblockstate2 = iblockstate1.withProperty(BlockBed.PART, BlockBed.EnumPartType.HEAD);
                    worldIn.setBlockState(blockpos, iblockstate2, 11);
                }

                SoundType soundtype = iblockstate1.getBlock().getSoundType(iblockstate1, worldIn, pos, playerIn);
                worldIn.playSound((EntityPlayer)null, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
                --stack.stackSize;
                return EnumActionResult.SUCCESS;
            }
            else
            {
                return EnumActionResult.FAIL;
            }
        }
        else
        {
            return EnumActionResult.FAIL;
        }
    }
}
 
Example 16
Project: Backmemed   File: BlockLiquid.java   View Source Code Vote up 4 votes
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand)
{
    double d0 = (double)pos.getX();
    double d1 = (double)pos.getY();
    double d2 = (double)pos.getZ();

    if (this.blockMaterial == Material.WATER)
    {
        int i = ((Integer)stateIn.getValue(LEVEL)).intValue();

        if (i > 0 && i < 8)
        {
            if (rand.nextInt(64) == 0)
            {
                worldIn.playSound(d0 + 0.5D, d1 + 0.5D, d2 + 0.5D, SoundEvents.BLOCK_WATER_AMBIENT, SoundCategory.BLOCKS, rand.nextFloat() * 0.25F + 0.75F, rand.nextFloat() + 0.5F, false);
            }
        }
        else if (rand.nextInt(10) == 0)
        {
            worldIn.spawnParticle(EnumParticleTypes.SUSPENDED, d0 + (double)rand.nextFloat(), d1 + (double)rand.nextFloat(), d2 + (double)rand.nextFloat(), 0.0D, 0.0D, 0.0D, new int[0]);
        }
    }

    if (this.blockMaterial == Material.LAVA && worldIn.getBlockState(pos.up()).getMaterial() == Material.AIR && !worldIn.getBlockState(pos.up()).isOpaqueCube())
    {
        if (rand.nextInt(100) == 0)
        {
            double d8 = d0 + (double)rand.nextFloat();
            double d4 = d1 + stateIn.getBoundingBox(worldIn, pos).maxY;
            double d6 = d2 + (double)rand.nextFloat();
            worldIn.spawnParticle(EnumParticleTypes.LAVA, d8, d4, d6, 0.0D, 0.0D, 0.0D, new int[0]);
            worldIn.playSound(d8, d4, d6, SoundEvents.BLOCK_LAVA_POP, SoundCategory.BLOCKS, 0.2F + rand.nextFloat() * 0.2F, 0.9F + rand.nextFloat() * 0.15F, false);
        }

        if (rand.nextInt(200) == 0)
        {
            worldIn.playSound(d0, d1, d2, SoundEvents.BLOCK_LAVA_AMBIENT, SoundCategory.BLOCKS, 0.2F + rand.nextFloat() * 0.2F, 0.9F + rand.nextFloat() * 0.15F, false);
        }
    }

    if (rand.nextInt(10) == 0 && worldIn.getBlockState(pos.down()).isFullyOpaque())
    {
        Material material = worldIn.getBlockState(pos.down(2)).getMaterial();

        if (!material.blocksMovement() && !material.isLiquid())
        {
            double d3 = d0 + (double)rand.nextFloat();
            double d5 = d1 - 1.05D;
            double d7 = d2 + (double)rand.nextFloat();

            if (this.blockMaterial == Material.WATER)
            {
                worldIn.spawnParticle(EnumParticleTypes.DRIP_WATER, d3, d5, d7, 0.0D, 0.0D, 0.0D, new int[0]);
            }
            else
            {
                worldIn.spawnParticle(EnumParticleTypes.DRIP_LAVA, d3, d5, d7, 0.0D, 0.0D, 0.0D, new int[0]);
            }
        }
    }
}
 
Example 17
Project: DecompiledMinecraft   File: BlockFire.java   View Source Code Vote up 4 votes
public void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
    if (rand.nextInt(24) == 0)
    {
        worldIn.playSound((double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), "fire.fire", 1.0F + rand.nextFloat(), rand.nextFloat() * 0.7F + 0.3F, false);
    }

    if (!World.doesBlockHaveSolidTopSurface(worldIn, pos.down()) && !Blocks.fire.canCatchFire(worldIn, pos.down()))
    {
        if (Blocks.fire.canCatchFire(worldIn, pos.west()))
        {
            for (int j = 0; j < 2; ++j)
            {
                double d3 = (double)pos.getX() + rand.nextDouble() * 0.10000000149011612D;
                double d8 = (double)pos.getY() + rand.nextDouble();
                double d13 = (double)pos.getZ() + rand.nextDouble();
                worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d3, d8, d13, 0.0D, 0.0D, 0.0D, new int[0]);
            }
        }

        if (Blocks.fire.canCatchFire(worldIn, pos.east()))
        {
            for (int k = 0; k < 2; ++k)
            {
                double d4 = (double)(pos.getX() + 1) - rand.nextDouble() * 0.10000000149011612D;
                double d9 = (double)pos.getY() + rand.nextDouble();
                double d14 = (double)pos.getZ() + rand.nextDouble();
                worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d4, d9, d14, 0.0D, 0.0D, 0.0D, new int[0]);
            }
        }

        if (Blocks.fire.canCatchFire(worldIn, pos.north()))
        {
            for (int l = 0; l < 2; ++l)
            {
                double d5 = (double)pos.getX() + rand.nextDouble();
                double d10 = (double)pos.getY() + rand.nextDouble();
                double d15 = (double)pos.getZ() + rand.nextDouble() * 0.10000000149011612D;
                worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d5, d10, d15, 0.0D, 0.0D, 0.0D, new int[0]);
            }
        }

        if (Blocks.fire.canCatchFire(worldIn, pos.south()))
        {
            for (int i1 = 0; i1 < 2; ++i1)
            {
                double d6 = (double)pos.getX() + rand.nextDouble();
                double d11 = (double)pos.getY() + rand.nextDouble();
                double d16 = (double)(pos.getZ() + 1) - rand.nextDouble() * 0.10000000149011612D;
                worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d6, d11, d16, 0.0D, 0.0D, 0.0D, new int[0]);
            }
        }

        if (Blocks.fire.canCatchFire(worldIn, pos.up()))
        {
            for (int j1 = 0; j1 < 2; ++j1)
            {
                double d7 = (double)pos.getX() + rand.nextDouble();
                double d12 = (double)(pos.getY() + 1) - rand.nextDouble() * 0.10000000149011612D;
                double d17 = (double)pos.getZ() + rand.nextDouble();
                worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d7, d12, d17, 0.0D, 0.0D, 0.0D, new int[0]);
            }
        }
    }
    else
    {
        for (int i = 0; i < 3; ++i)
        {
            double d0 = (double)pos.getX() + rand.nextDouble();
            double d1 = (double)pos.getY() + rand.nextDouble() * 0.5D + 0.5D;
            double d2 = (double)pos.getZ() + rand.nextDouble();
            worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d0, d1, d2, 0.0D, 0.0D, 0.0D, new int[0]);
        }
    }
}
 
Example 18
Project: Backmemed   File: ItemSnow.java   View Source Code Vote up 4 votes
/**
 * Called when a Block is right-clicked with this Item
 */
public EnumActionResult onItemUse(EntityPlayer stack, World playerIn, BlockPos worldIn, EnumHand pos, EnumFacing hand, float facing, float hitX, float hitY)
{
    ItemStack itemstack = stack.getHeldItem(pos);

    if (!itemstack.func_190926_b() && stack.canPlayerEdit(worldIn, hand, itemstack))
    {
        IBlockState iblockstate = playerIn.getBlockState(worldIn);
        Block block = iblockstate.getBlock();
        BlockPos blockpos = worldIn;

        if ((hand != EnumFacing.UP || block != this.block) && !block.isReplaceable(playerIn, worldIn))
        {
            blockpos = worldIn.offset(hand);
            iblockstate = playerIn.getBlockState(blockpos);
            block = iblockstate.getBlock();
        }

        if (block == this.block)
        {
            int i = ((Integer)iblockstate.getValue(BlockSnow.LAYERS)).intValue();

            if (i < 8)
            {
                IBlockState iblockstate1 = iblockstate.withProperty(BlockSnow.LAYERS, Integer.valueOf(i + 1));
                AxisAlignedBB axisalignedbb = iblockstate1.getCollisionBoundingBox(playerIn, blockpos);

                if (axisalignedbb != Block.NULL_AABB && playerIn.checkNoEntityCollision(axisalignedbb.offset(blockpos)) && playerIn.setBlockState(blockpos, iblockstate1, 10))
                {
                    SoundType soundtype = this.block.getSoundType();
                    playerIn.playSound(stack, blockpos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
                    itemstack.func_190918_g(1);
                    return EnumActionResult.SUCCESS;
                }
            }
        }

        return super.onItemUse(stack, playerIn, worldIn, pos, hand, facing, hitX, hitY);
    }
    else
    {
        return EnumActionResult.FAIL;
    }
}
 
Example 19
Project: CustomWorldGen   File: BlockButtonStone.java   View Source Code Vote up 4 votes
protected void playReleaseSound(World worldIn, BlockPos pos)
{
    worldIn.playSound((EntityPlayer)null, pos, SoundEvents.BLOCK_STONE_BUTTON_CLICK_OFF, SoundCategory.BLOCKS, 0.3F, 0.5F);
}
 
Example 20
Project: rtap   File: armorBolognaHelmet.java   View Source Code Vote up 3 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {

	if (playerIn.getItemStackFromSlot(EntityEquipmentSlot.HEAD) == ItemStack.EMPTY) {
		
		System.out.println("successfully equipped!");
		
		worldIn.playSound(playerIn, playerIn.getPosition(), ModSoundHandler.BOLOGNAARMOREQIUP, SoundCategory.PLAYERS, 1F, 1F);
		
	}
	
	return super.onItemRightClick(worldIn, playerIn, handIn);
	
}