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

The following examples show how to use net.minecraft.world.World#playSound() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
@SideOnly(Side.CLIENT)
@Override
public void randomTickDisplay(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) {
	if (this.isActive) {
		if (rand.nextInt(16) == 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);
		}
		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);
		}
	}
}
 
Example 2
Source Project: Production-Line   File: ItemGravityRay.java    License: MIT License 6 votes vote down vote up
/**
 * called when the player releases the use item button. Args: itemstack, world, entityplayer, itemInUseCount
 */
@Override
public void onPlayerStoppedUsing(ItemStack itemStack, World world, EntityLivingBase player, int itemInUseCount) {
    if (ElectricItem.manager.getCharge(itemStack) >= 100) {
        int i = this.getMaxItemUseDuration(itemStack) - itemInUseCount;

        float damge = (float) i / 20.0F;
        damge = (damge * damge + damge * 2.0F) / 3.0F;
        if ((double)damge < 0.1D) {
            return;
        }
        if (damge > 1.0F) {
            damge = 1.0F;
        }

        world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ARROW_SHOOT,
                SoundCategory.PLAYERS, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + damge * 0.5F);
        if (!(player instanceof EntityPlayer
                && ((EntityPlayer) player).capabilities.isCreativeMode)) {
            ElectricItem.manager.discharge(itemStack, 100, this.tier, false, true, false);
        }
        if (!world.isRemote) {
            world.spawnEntity(new EntityRay(world, player, damge * 2.0F));
        }
    }
}
 
Example 3
Source Project: the-hallow   File: ColoredPumpkinBlock.java    License: MIT License 6 votes vote down vote up
@Override
public ActionResult onUse(BlockState blockState, World world, BlockPos blockPos, PlayerEntity playerEntity, Hand hand, BlockHitResult blockHitResult) {
	ItemStack stack = playerEntity.getStackInHand(hand);

	if (stack.getItem() == Items.SHEARS) {
		if (!world.isClient) {
			Direction side = blockHitResult.getSide();
			Direction facingTowardPlayer = side.getAxis() == Direction.Axis.Y ? playerEntity.getHorizontalFacing().getOpposite() : side;

			world.playSound(null, blockPos, SoundEvents.BLOCK_PUMPKIN_CARVE, SoundCategory.BLOCKS, 1.0F, 1.0F);
			world.setBlockState(blockPos, HallowedBlocks.CARVED_PUMPKIN_COLORS.get(this.color).getDefaultState().with(CarvedPumpkinBlock.FACING, facingTowardPlayer), 11);
			ItemEntity itemEntity = new ItemEntity(world, blockPos.getX() + 0.5D + facingTowardPlayer.getOffsetX() * 0.65D, blockPos.getY() + 0.1D, blockPos.getZ() + 0.5D + facingTowardPlayer.getOffsetZ() * 0.65D, new ItemStack(Items.PUMPKIN_SEEDS, 4));

			itemEntity.setVelocity(0.05D * (double) facingTowardPlayer.getOffsetX() + world.random.nextDouble() * 0.02D, 0.05D, 0.05D * (double) facingTowardPlayer.getOffsetZ() + world.random.nextDouble() * 0.02D);
			world.spawnEntity(itemEntity);
			stack.damage(1, playerEntity, (playerEntityVar) -> {
				playerEntityVar.sendToolBreakStatus(hand);
			});
		}

		return ActionResult.SUCCESS;
	}

	return super.onUse(blockState, world, blockPos, playerEntity, hand, blockHitResult);
}
 
Example 4
@Override
public boolean runOnStart(@Nonnull World world, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
	Entity entity = spell.getVictim(world);

	BlockPos pos = spell.getTargetPos();
	if (pos == null) return true;

	double time = spellRing.getAttributeValue(world, AttributeRegistry.DURATION, spell) * 10;

	if (!spellRing.taxCaster(world, spell, true)) return false;

	if (entity instanceof EntityLivingBase) {
		BounceManager.INSTANCE.forEntity((EntityLivingBase) entity, (int) time);
	} else if (!BlockUtils.isAnyAir(world, pos)) {
		BounceManager.INSTANCE.forBlock(world, pos, (int) time);
		PacketHandler.NETWORK.sendToAll(new PacketAddBouncyBlock(world, pos, (int) time));
	}

	world.playSound(null, pos, ModSounds.SLIME_SQUISHING, SoundCategory.NEUTRAL, RandUtil.nextFloat(0.6f, 1f), RandUtil.nextFloat(0.5f, 1f));
	return true;
}
 
Example 5
/**
 * {@inheritDoc}
 */
@Override
public boolean run(@NotNull World world, ModuleInstanceShape instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
	if (world.isRemote) return true;

	Vec3d origin = spell.getOriginWithFallback(world);
	if (origin == null) return false;

	double dist = spellRing.getAttributeValue(world, AttributeRegistry.RANGE, spell);
	double speed = spellRing.getAttributeValue(world, AttributeRegistry.SPEED, spell);

	if (!spellRing.taxCaster(world, spell, true)) return false;
	
	IShapeOverrides overrides = spellRing.getOverrideHandler().getConsumerInterface(IShapeOverrides.class);

	EntitySpellProjectile proj = new EntitySpellProjectile(world, spellRing, spell, (float) dist, (float) speed, (float) 0.1, !overrides.onRunProjectile(world, spell, spellRing));
	proj.setPosition(origin.x, origin.y, origin.z);
	proj.velocityChanged = true;

	boolean success = world.spawnEntity(proj);
	if (success)
		world.playSound(null, new BlockPos(origin), ModSounds.PROJECTILE_LAUNCH, SoundCategory.PLAYERS, 1f, (float) RandUtil.nextDouble(1, 1.5));
	return success;
}
 
Example 6
Source Project: Sakura_mod   File: BlockTatara.java    License: MIT License 6 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (worldIn.isRemote) {
    	worldIn.playSound(playerIn, pos, SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.BLOCKS, 1.0F, 0.8F);
           return true;
       }
	ItemStack stack = playerIn.getHeldItem(hand);
	if (hand == EnumHand.MAIN_HAND) {
        if (stack.getItem() == Items.FLINT_AND_STEEL) {
            worldIn.setBlockState(pos, BlockLoader.TATARA_SMELTING.getDefaultState());
            stack.damageItem(1, playerIn);
            return true;
        }
	}
	return true;
}
 
Example 7
@Override
public ActionResult onUse(BlockState blockState, World world, BlockPos blockPos, PlayerEntity playerEntity, Hand hand, BlockHitResult blockHitResult) {
    if (playerEntity.getStackInHand(hand).getItem() instanceof ShearsItem) {
        world.setBlockState(blockPos, GalacticraftBlocks.CAVERNOUS_VINE.getDefaultState().with(VINES, blockState.get(VINES)));
        world.playSound(blockPos.getX(), blockPos.getY(), blockPos.getZ(), SoundEvents.BLOCK_GRASS_BREAK, SoundCategory.BLOCKS, 1f, 1f, true);
        return ActionResult.SUCCESS;
    }
    return ActionResult.SUCCESS;
}
 
Example 8
@ModuleOverride("shape_zone_run")
public boolean onRunZone(World world, SpellData data, SpellRing ring, @ContextRing SpellRing childRing) {
	if(!world.isRemote) return false;

	double aoe = ring.getAttributeValue(world, AttributeRegistry.AREA, data);
	double range = ring.getAttributeValue(world, AttributeRegistry.RANGE, data);

	Vec3d targetPos = data.getTarget(world);

	if (targetPos == null) return false;

	Vec3d min = targetPos.subtract(aoe, range, aoe);
	Vec3d max = targetPos.add(aoe, range, aoe);

	List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(min, max));
	for (Entity entity : entities) {
		entity.extinguish();
		if (entity instanceof EntityLivingBase) {
			if (!((EntityLivingBase) entity).isPotionActive(ModPotions.SLIPPERY) && entity.getDistanceSq(targetPos.x, targetPos.y, targetPos.z) <= aoe * aoe) {

				double time = childRing.getAttributeValue(world, AttributeRegistry.DURATION, data) * 10;
				world.playSound(null, entity.getPosition(), ModSounds.FROST_FORM, SoundCategory.NEUTRAL, 1, 1);
				((EntityLivingBase) entity).addPotionEffect(new PotionEffect(ModPotions.SLIPPERY, (int) time, 0, true, false));
			}
		}
	}
	return false;
}
 
Example 9
public EnumActionResult onItemUse(EntityPlayer player, 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);
        }

        ItemStack itemstack = player.getHeldItem(hand);

        if (player.canPlayerEdit(pos, facing, itemstack) && this.block.canPlaceBlockAt(worldIn, pos)) {
            EnumFacing enumfacing = EnumFacing.fromAngle((double) player.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, this.block, flag);
            SoundType soundtype = worldIn.getBlockState(pos).getBlock().getSoundType(worldIn.getBlockState(pos), worldIn, pos, player);
            worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
            itemstack.shrink(1);
            return EnumActionResult.SUCCESS;
        } else {
            return EnumActionResult.FAIL;
        }
    }
}
 
Example 10
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
{
    ItemStack stack = player.getHeldItem(hand);

    if (world.isRemote)
    {
        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
    }

    // Damage 1: "Elite version" of the pearl, makes the thrower fly with it. Idea by xisumavoid in episode Hermitcraft III 303 :)

    EntityEnderPearlReusable pearl = new EntityEnderPearlReusable(world, player, stack.getMetadata() == 1);
    float velocity = stack.getMetadata() == 1 ? 2.5f : 1.9f;
    pearl.shoot(player, player.rotationPitch, player.rotationYaw, 0.0f, velocity, 0.8f);
    world.spawnEntity(pearl);

    if (stack.getMetadata() == 1)
    {
        Entity bottomEntity = player.getLowestRidingEntity();

        // Dismount the previous pearl if we are already riding one
        // (by selecting the entity riding that pearl to be the one mounted to the new pearl)
        if (bottomEntity instanceof EntityEnderPearlReusable)
        {
            bottomEntity = bottomEntity.getPassengers().get(0);
        }

        bottomEntity.startRiding(pearl);
    }

    stack.shrink(1);

    world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ENDERPEARL_THROW,
            SoundCategory.MASTER, 0.5f, 0.4f / (itemRand.nextFloat() * 0.4f + 0.8f));

    return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
 
Example 11
public boolean taxCaster(@Nonnull World world, SpellData data, double multiplier, boolean failSound) {
	if(data.getData(SpellData.DefaultKeys.CASTER) == null) return true;

	Entity caster = world.getEntityByID(data.getData(SpellData.DefaultKeys.CASTER));

	if(caster == null) {
		Wizardry.LOGGER.warn("Caster was null!");
		return true;
	}

	IManaCapability cap = ManaCapabilityProvider.getCap(caster);
	if (cap == null) return false;

	double manaDrain = getManaDrain(data) * multiplier;
	double burnoutFill = getBurnoutFill(data) * multiplier;

	boolean fail = false;

	try (ManaManager.CapManagerBuilder mgr = ManaManager.forObject(cap)) {
		if (mgr.getMana() < manaDrain) fail = true;

		mgr.removeMana(manaDrain);
		mgr.addBurnout(burnoutFill);
	}

	if (fail && failSound) {

		Vec3d origin = data.getOriginWithFallback(world);
		if (origin != null)
			world.playSound(null, new BlockPos(origin), ModSounds.SPELL_FAIL, SoundCategory.NEUTRAL, 1f, 1f);
	}

	return !fail;
}
 
Example 12
@Nonnull
@Override
public ItemStack onItemUseFinish(@Nonnull ItemStack stack, World worldIn, EntityLivingBase entityLiving) {
	stack.shrink(1);
	if (entityLiving instanceof EntityPlayer) {
		((EntityPlayer) entityLiving).addItemStackToInventory(new ItemStack(ModBlocks.JAR));
		EntityPlayer entityplayer = (EntityPlayer) entityLiving;
		entityplayer.getFoodStats().addStats(4, 7f);
		worldIn.playSound(null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_PLAYER_BURP, SoundCategory.PLAYERS, 0.5F, worldIn.rand.nextFloat() * 0.1F + 0.9F);
		worldIn.playSound(null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, ModSounds.SPARKLE, SoundCategory.PLAYERS, 0.5F, worldIn.rand.nextFloat() * 0.1F + 0.9F);
		entityLiving.addPotionEffect(new PotionEffect(ModPotions.NULLIFY_GRAVITY, 200, 1, true, false));
	}

	return stack;
}
 
Example 13
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player,
        EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
    if (world.isRemote == false)
    {
        // Returns the "id" of the pointed element of this block the player is currently looking at.
        // The target selection buttons are ids 0..7, the middle button is 8 and the base of the panel is 9.
        Integer id = this.getPointedElementId(world, pos, state.getValue(FACING), player);

        if (id != null && id >= 0 && id <= 8)
        {
            TileEntityPortalPanel te = getTileEntitySafely(world, pos, TileEntityPortalPanel.class);

            if (te != null)
            {
                if (id == 8)
                {
                    te.tryTogglePortal();
                }
                else
                {
                    te.setActiveTargetId(id);
                    world.notifyBlockUpdate(pos, state, state, 3);
                }

                world.playSound(null, pos, SoundEvents.BLOCK_STONE_BUTTON_CLICK_ON, SoundCategory.MASTER, 0.5f, 1.0f);
            }

            return true;
        }
    }

    return super.onBlockActivated(world, pos, state, player, hand, side, hitX, hitY, hitZ);
}
 
Example 14
Source Project: Sakura_mod   File: ItemShinai.java    License: MIT License 5 votes vote down vote up
@Override
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) {
    int i = this.getMaxItemUseDuration(stack) - timeLeft;
    if (i < 0) return;
        entityLiving.swingArm(entityLiving.getActiveHand());

        float f = (float) entityLiving.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue();
        f += EnchantmentHelper.getModifierForCreature(stack, entityLiving.getCreatureAttribute()) / 1.2F;

        float f1 = i / 15F;
        f1 = (f1 * f1 + f1 * 2.0F) / 2F;
        if(f1>8F) f1=8f;
        float f3 = f1 + EnchantmentHelper.getSweepingDamageRatio(entityLiving) * f ;

        float sweepingRatio = EnchantmentHelper.getSweepingDamageRatio(entityLiving);

        for (Entity entitylivingbase : worldIn.getEntitiesWithinAABB(Entity.class, entityLiving.getEntityBoundingBox().grow(1.6D + sweepingRatio * 1.2D, 0.5D + sweepingRatio * 0.15D, 1.6D + sweepingRatio * 1.2D))) {
            if (entitylivingbase != entityLiving && !entityLiving.isOnSameTeam(entitylivingbase)) {
                if (entitylivingbase instanceof EntityLivingBase) {
                	f1 = f1/10;
                    ((EntityLivingBase) entitylivingbase).knockBack(entityLiving, 0.4F + 0.6F * f1 * EnchantmentHelper.getSweepingDamageRatio(entityLiving), MathHelper.sin(entityLiving.rotationYaw * 0.017453292F), (-MathHelper.cos(entityLiving.rotationYaw * 0.017453292F)));
                    entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityLiving), f3);
                }

                if (entitylivingbase instanceof MultiPartEntityPart) {
                    entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityLiving), f3);
                }
            }
        }
        worldIn.playSound(null, entityLiving.posX, entityLiving.posY, entityLiving.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, entityLiving.getSoundCategory(), 1.0F, 1.0F);
        if (worldIn instanceof WorldServer) {
            double d0 = (-MathHelper.sin(entityLiving.rotationYaw * 0.017453292F));
            double d1 = MathHelper.cos(entityLiving.rotationYaw * 0.017453292F);
            ((WorldServer) worldIn).spawnParticle(EnumParticleTypes.SWEEP_ATTACK, entityLiving.posX + d0, entityLiving.posY + entityLiving.height * 0.5D, entityLiving.posZ + d1, 0, d0, 0.0D, d1, 0.0D);
        }
        stack.damageItem(2, entityLiving);
        ((EntityPlayer) entityLiving).getCooldownTracker().setCooldown(this, 25);

}
 
Example 15
@Override
	public boolean run(@NotNull World world, ModuleInstanceEffect instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
//		;
		Entity targetEntity = spell.getVictim(world);
		BlockPos targetPos = spell.getTargetPos();
//		Entity caster = spell.getCaster(world);

		if (targetPos == null) return false;

		double potency = spellRing.getAttributeValue(world, AttributeRegistry.POTENCY, spell) / 5;
//		double area = spellRing.getAttributeValue(AttributeRegistry.AREA, spell) / 2;
		double time = spellRing.getAttributeValue(world, AttributeRegistry.DURATION, spell) * 10;

		if (!spellRing.taxCaster(world, spell, true)) return false;

		world.playSound(null, targetPos, ModSounds.SLOW_MOTION_IN, SoundCategory.NEUTRAL, 1, RandUtil.nextFloat(0.1f, 0.5f));

		if (targetEntity instanceof EntityLivingBase) {
			EntityLivingBase target = (EntityLivingBase) targetEntity;
			target.addPotionEffect(new PotionEffect(MobEffects.WITHER, (int) time, (int) potency));
			target.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, (int) time, (int) potency));
		}

		if (targetPos != null) {
			// TODO: Add block decay
		}
		return true;
	}
 
Example 16
Source Project: TofuCraftReload   File: ItemRiceSeed.java    License: MIT License 4 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
    ItemStack itemstack = playerIn.getHeldItem(handIn);
    RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, true);

    if (raytraceresult == null)
    {
        return new ActionResult<ItemStack>(EnumActionResult.PASS, itemstack);
    }
    else
    {
        if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK)
        {
            BlockPos blockpos = raytraceresult.getBlockPos();

            if (!worldIn.isBlockModifiable(playerIn, blockpos) || !playerIn.canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, itemstack))
            {
                return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
            }

            BlockPos blockpos1 = blockpos.up();
            IBlockState iblockstate = worldIn.getBlockState(blockpos);

            if (iblockstate.getMaterial() == Material.WATER && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0 && worldIn.isAirBlock(blockpos1))
            {
                // special case for handling block placement with water lilies
                net.minecraftforge.common.util.BlockSnapshot blocksnapshot = net.minecraftforge.common.util.BlockSnapshot.getBlockSnapshot(worldIn, blockpos1);
                worldIn.setBlockState(blockpos1, BlockLoader.RICECROP.getDefaultState());
                if (net.minecraftforge.event.ForgeEventFactory.onPlayerBlockPlace(playerIn, blocksnapshot, net.minecraft.util.EnumFacing.UP, handIn).isCanceled())
                {
                    blocksnapshot.restore(true, false);
                    return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
                }

                worldIn.setBlockState(blockpos1, BlockLoader.RICECROP.getDefaultState(), 11);

                if (playerIn instanceof EntityPlayerMP)
                {
                    CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)playerIn, blockpos1, itemstack);
                }

                if (!playerIn.capabilities.isCreativeMode)
                {
                    itemstack.shrink(1);
                }

                playerIn.addStat(StatList.getObjectUseStats(this));
                worldIn.playSound(playerIn, blockpos, SoundEvents.BLOCK_WATERLILY_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
                return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
            }
        }

        return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemstack);
    }
}
 
Example 17
@Override
public boolean execute(World world, EntityPlayer player)
{
    ItemStack stack = EntityUtils.getHeldItemOfType(player, EnderUtilitiesItems.BUILDERS_WAND);

    if (stack.isEmpty() == false && this.wandUUID.equals(NBTUtils.getUUIDFromItemStack(stack, ItemBuildersWand.WRAPPER_TAG_NAME, false)))
    {
        ItemBuildersWand wand = (ItemBuildersWand) stack.getItem();

        for (int i = 0; i < this.blocksPerTick && this.listIndex < this.positions.size();)
        {
            if (wand.replaceBlock(world, player, stack, this.positions.get(this.listIndex)))
            {
                this.placedCount += 1;
                this.failCount = 0;
                i += 1;
            }

            this.listIndex += 1;
        }

        // Finished looping through the block positions
        if (this.listIndex >= this.positions.size())
        {
            return true;
        }
    }
    else
    {
        this.failCount += 1;
    }

    // Bail out after 10 seconds of failing to execute, or after all blocks have been placed
    if (this.failCount > 200)
    {
        world.playSound(null, player.getPosition(), SoundEvents.BLOCK_NOTE_BASEDRUM, SoundCategory.BLOCKS, 0.6f, 1.0f);
        return true;
    }

    return false;
}
 
Example 18
Source Project: TofuCraftReload   File: ItemNigari.java    License: MIT License 4 votes vote down vote up
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
	if (worldIn.isRemote)
		return new ActionResult<ItemStack>(EnumActionResult.PASS, ItemStack.EMPTY);
	RayTraceResult var4 = this.rayTrace(worldIn, playerIn, true);
	ItemStack itemStackIn = playerIn.getHeldItem(handIn);

	if (var4 == null) {
		return new ActionResult<ItemStack>(EnumActionResult.PASS, itemStackIn);
	} else {
		if (var4.typeOfHit == RayTraceResult.Type.BLOCK) {
			BlockPos targetPos = var4.getBlockPos();
			Block var11 = worldIn.getBlockState(targetPos).getBlock();
			Block var13 = null;

			if (var11 == BlockLoader.SOYMILK) {
				var13 = BlockLoader.KINUTOFU;
			} else if (var11 == BlockLoader.SOYMILKHELL) {
				var13 = BlockLoader.TOFUHELL;
			} else if (var11 == BlockLoader.ZUNDASOYMILK) {
				var13 = BlockLoader.TOFUZUNDA;
			}

			if (var13 != null) {
				worldIn.playSound(playerIn, targetPos.add(0.5, 0.5, 0.5),
						var13.getSoundType(var13.getDefaultState(), worldIn, targetPos, playerIn).getBreakSound(),
						SoundCategory.BLOCKS,
						(var13.getSoundType(var13.getDefaultState(), worldIn, targetPos, playerIn).getVolume()
								+ 1.0F) / 2.0F,
						var13.getSoundType(var13.getDefaultState(), worldIn, targetPos, playerIn).getPitch()
								* 0.8F);

				worldIn.setBlockState(targetPos, var13.getDefaultState());

				if (!playerIn.capabilities.isCreativeMode) {
					itemStackIn.shrink(1);

					ItemStack container = new ItemStack(this.getContainerItem());

					if (itemStackIn.getCount() <= 0) {
						return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, container);
					}

					if (!playerIn.inventory.addItemStackToInventory(container)) {
						playerIn.dropItem(container, false);
					}
				}
			}
		}
		return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemStackIn);
	}
}
 
Example 19
private boolean extendOneBlock(int position, FakePlayer player, boolean playPistonSoundInsteadOfPlaceSound)
{
    final int invPosition = this.isAdvanced() ? position : 0;
    World world = this.getWorld();
    BlockPos pos = this.getPos().offset(this.getFacing(), position + 1);
    ItemStack stack = this.itemHandlerDrawbridge.getStackInSlot(invPosition);
    IBlockState placementState = this.getPlacementStateForPosition(position, world, pos, player, stack);

    if (placementState != null &&
        stack.isEmpty() == false &&
        world.isBlockLoaded(pos, world.isRemote == false) &&
        world.getBlockState(pos).getBlock().isReplaceable(world, pos) &&
        world.mayPlace(placementState.getBlock(), pos, true, EnumFacing.UP, null) &&
        ((playPistonSoundInsteadOfPlaceSound && world.setBlockState(pos, placementState)) ||
         (playPistonSoundInsteadOfPlaceSound == false && BlockUtils.setBlockStateWithPlaceSound(world, pos, placementState, 3))))
    {
        // This extract will also clear the blockInfoTaken, if the slot becomes empty.
        // This will prevent item duping exploits by swapping the item to something else
        // after the drawbridge has taken the state and TE data from the world for a given block.
        stack = this.itemHandlerDrawbridge.extractItem(invPosition, 1, false);

        this.blockStatesPlaced[position] = placementState;
        this.numPlaced++;

        NBTTagCompound nbt = this.getPlacementTileNBT(position, stack);

        if (nbt != null && placementState.getBlock().hasTileEntity(placementState))
        {
            TileUtils.createAndAddTileEntity(world, pos, nbt);
        }

        if (playPistonSoundInsteadOfPlaceSound)
        {
            world.playSound(null, pos, SoundEvents.BLOCK_PISTON_EXTEND, SoundCategory.BLOCKS, 0.5f, 0.8f);
        }

        return true;
    }
    else if (stack.isEmpty() == false)
    {
        this.failedPlacements++;
    }

    return false;
}
 
Example 20
@Override
protected void playClickOnSound(World worldIn, BlockPos pos)
{
    worldIn.playSound(null, pos, content.onSound, SoundCategory.BLOCKS, 0.3F, 0.8F);
}