Java Code Examples for net.minecraft.entity.player.EntityPlayer.playSound()

The following are Jave code examples for showing how to use playSound() of the net.minecraft.entity.player.EntityPlayer 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: PurificatiMagicae   File: ItemGlove.java   View Source Code Vote up 6 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{

    ItemStack glove = playerIn.getHeldItem(handIn);
    if (handIn == EnumHand.OFF_HAND)
    {
        ItemStack shard = playerIn.getHeldItem(EnumHand.MAIN_HAND);
        if (shard.getItem() == ItemRegistry.crystal_shard)
        {
            int shrink = playerIn.isSneaking() ? shard.getCount() : 1;
            playerIn.playSound(SoundRegistry.GLASS, 1, 1);
            if (ItemSipAmulet.checkForAmulet(playerIn))
            {
                ItemStack amulet = ItemUtils.getBauble(playerIn, BaubleType.AMULET.getValidSlots()[0]);
                amulet.getCapability(CapabilityRegistry.SIP_STORE_CAP, null).add(SipUtils.getSipInStack(shard), shrink);
                ItemUtils.setBauble(playerIn, BaubleType.AMULET.getValidSlots()[0], amulet);
            }
            playerIn.getHeldItem(EnumHand.MAIN_HAND).shrink(shrink);
            return new ActionResult<>(EnumActionResult.SUCCESS, glove);
        }
    }
    return new ActionResult<>(EnumActionResult.PASS, glove);
}
 
Example 2
Project: Backmemed   File: EntityCow.java   View Source Code Vote up 6 votes
public boolean processInteract(EntityPlayer player, EnumHand hand)
{
    ItemStack itemstack = player.getHeldItem(hand);

    if (itemstack.getItem() == Items.BUCKET && !player.capabilities.isCreativeMode && !this.isChild())
    {
        player.playSound(SoundEvents.ENTITY_COW_MILK, 1.0F, 1.0F);
        itemstack.func_190918_g(1);

        if (itemstack.func_190926_b())
        {
            player.setHeldItem(hand, new ItemStack(Items.MILK_BUCKET));
        }
        else if (!player.inventory.addItemStackToInventory(new ItemStack(Items.MILK_BUCKET)))
        {
            player.dropItem(new ItemStack(Items.MILK_BUCKET), false);
        }

        return true;
    }
    else
    {
        return super.processInteract(player, hand);
    }
}
 
Example 3
Project: CustomWorldGen   File: EntityCow.java   View Source Code Vote up 6 votes
public boolean processInteract(EntityPlayer player, EnumHand hand, @Nullable ItemStack stack)
{
    if (stack != null && stack.getItem() == Items.BUCKET && !player.capabilities.isCreativeMode && !this.isChild())
    {
        player.playSound(SoundEvents.ENTITY_COW_MILK, 1.0F, 1.0F);

        if (--stack.stackSize == 0)
        {
            player.setHeldItem(hand, new ItemStack(Items.MILK_BUCKET));
        }
        else if (!player.inventory.addItemStackToInventory(new ItemStack(Items.MILK_BUCKET)))
        {
            player.dropItem(new ItemStack(Items.MILK_BUCKET), false);
        }

        return true;
    }
    else
    {
        return super.processInteract(player, hand, stack);
    }
}
 
Example 4
Project: AdvancedCombat   File: CustomShieldHandler.java   View Source Code Vote up 6 votes
/** Fixed vanilla code */
private void damageShield(EntityPlayer owner, float damage) {
	int i = 1 + MathHelper.floor(damage);
	owner.getActiveItemStack().damageItem(i, owner);

	if (owner.getActiveItemStack().getCount() <= 0) {
		EnumHand enumhand = owner.getActiveHand();
		ForgeEventFactory.onPlayerDestroyItem(owner, owner.getActiveItemStack(), enumhand);

		if(enumhand == EnumHand.MAIN_HAND) {
			owner.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, ItemStack.EMPTY);
		} else {
			owner.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, ItemStack.EMPTY);
		}

		owner.resetActiveHand();
		owner.playSound(SoundEvents.ITEM_SHIELD_BREAK, 0.8F, 0.8F + owner.world.rand.nextFloat() * 0.4F);
	}
}
 
Example 5
Project: pnc-repressurized   File: PacketHackingEntityFinish.java   View Source Code Vote up 5 votes
@Override
public void handleClientSide(PacketHackingEntityFinish message, EntityPlayer player) {
    Entity entity = player.world.getEntityByID(message.entityId);
    if (entity != null) {
        IHackableEntity hackableEntity = HackableHandler.getHackableForEntity(entity, player);
        if (hackableEntity != null) {
            hackableEntity.onHackFinished(entity, player);
            PneumaticCraftRepressurized.proxy.getHackTickHandler().trackEntity(entity, hackableEntity);
            CommonHUDHandler.getHandlerForPlayer(player).setHackedEntity(null);
            player.playSound(Sounds.HELMET_HACK_FINISH, 1.0F, 1.0F);
        }
    }

}
 
Example 6
Project: pnc-repressurized   File: PacketHackingBlockFinish.java   View Source Code Vote up 5 votes
@Override
public void handleClientSide(PacketHackingBlockFinish message, EntityPlayer player) {
    IHackableBlock hackableBlock = HackableHandler.getHackableForCoord(player.world, message.pos, player);
    if (hackableBlock != null) {
        hackableBlock.onHackFinished(player.world, message.pos, player);
        PneumaticCraftRepressurized.proxy.getHackTickHandler().trackBlock(new WorldAndCoord(player.world, message.pos), hackableBlock);
        CommonHUDHandler.getHandlerForPlayer(player).setHackedBlock(null);
        player.playSound(Sounds.HELMET_HACK_FINISH, 1.0F, 1.0F);
    }
}
 
Example 7
Project: Bewitchment   File: ItemBrewLinger.java   View Source Code Vote up 5 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
	ItemStack itemstack = playerIn.getHeldItem(hand);
	ItemStack copy = playerIn.capabilities.isCreativeMode ? itemstack.copy() : itemstack.splitStack(1);
	playerIn.playSound(SoundEvents.ENTITY_LINGERINGPOTION_THROW, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

	if (!worldIn.isRemote) {
		EntityBrew brew = new EntityBrew(worldIn, playerIn, copy, EntityBrew.BrewDispersion.LINGER);

		brew.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, -20.0F, 0.5F, 1.0F);
		worldIn.spawnEntity(brew);
	}

	return ActionResult.newResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(hand));
}
 
Example 8
Project: Bewitchment   File: ItemBrewSplash.java   View Source Code Vote up 5 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
	ItemStack itemstack = playerIn.getHeldItem(hand);
	ItemStack copy = playerIn.capabilities.isCreativeMode ? itemstack.copy() : itemstack.splitStack(1);
	playerIn.playSound(SoundEvents.ENTITY_SPLASH_POTION_THROW, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

	if (!worldIn.isRemote) {
		EntityBrew brew = new EntityBrew(worldIn, playerIn, copy, EntityBrew.BrewDispersion.SPLASH);

		brew.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, -20.0F, 0.5F, 1.0F);
		worldIn.spawnEntity(brew);
	}

	return ActionResult.newResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(hand));
}
 
Example 9
Project: ToughExpansion   File: ItemThirstQuencher.java   View Source Code Vote up 5 votes
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World worldIn, EntityPlayer playerIn, EnumHand hand) {
	init(stack);
	if (getFluidStored(stack) >= FLUID_CAPACITY) {
		return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);
	}
	RayTraceResult ray = rayTrace(worldIn, playerIn, true);
	if (ray == null || ray.typeOfHit == null || hand == null) {
		return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);
	}
	if (ray.typeOfHit == RayTraceResult.Type.BLOCK && hand == EnumHand.MAIN_HAND && !worldIn.isRemote) {
		BlockPos blockpos = ray.getBlockPos();
		IBlockState iblockstate = worldIn.getBlockState(blockpos);
		Material material = iblockstate.getMaterial();

		if (material == Material.WATER && iblockstate.getValue(BlockLiquid.LEVEL).intValue() == 0) {
			worldIn.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 11);
			playerIn.addStat(StatList.getObjectUseStats(this));
			playerIn.playSound(SoundEvents.ITEM_BUCKET_FILL, 1.0F, 1.0F);
			addFluid(stack, 1000);
			return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
		}
		else if (iblockstate.getBlock().hasTileEntity(iblockstate) && worldIn.getTileEntity(blockpos).hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, ray.sideHit)) {
			IFluidHandler fluidHandler = worldIn.getTileEntity(blockpos).getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, ray.sideHit);
			for (IFluidTankProperties property : fluidHandler.getTankProperties()) {
				if (property.getContents().getFluid() == FluidRegistry.WATER && property.getContents().amount >= 1000 && property.canDrain()) {
					fluidHandler.drain(new FluidStack(FluidRegistry.WATER, 1000), true);
					addFluid(stack, 1000);
				}
			}
		}

	}
	return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);
}
 
Example 10
Project: Halloween   File: EntityZombieCurse.java   View Source Code Vote up 5 votes
/**
 * Revival zombie curse - fill the player's inventory with poisionous potatoes
 */
private void performRevivalCurse()
{
	EntityPlayer player = (EntityPlayer)this.victim;
	ItemStack stack = new ItemStack(Items.POISONOUS_POTATO, 16 + this.rand.nextInt(17), 0);
	EntityItem entityItem = new EntityItem(this.world, this.posX, this.posY, this.posZ, stack);

	if (player.inventory.addItemStackToInventory(stack))
	{
		ForgeEventFactory.onItemPickup(entityItem, player);
		player.playSound(SoundEvents.ENTITY_ZOMBIE_INFECT, 0.75F, (this.rand.nextFloat() * 0.2F) + 0.9F);
	}
}
 
Example 11
Project: Halloween   File: EntitySlimeCurse.java   View Source Code Vote up 5 votes
/**
 * Original KodaichiZero slime curse - fill the player's inventory with slime balls
 */
private void performLegacyCurse()
{
	EntityPlayer player = (EntityPlayer)this.victim;
	ItemStack stack = new ItemStack(Items.SLIME_BALL, 16 + this.rand.nextInt(17), 0);
	EntityItem entityItem = new EntityItem(this.world, this.posX, this.posY, this.posZ, stack);

	if (player.inventory.addItemStackToInventory(stack))
	{
		ForgeEventFactory.onItemPickup(entityItem, player);
		player.playSound(SoundEvents.ENTITY_SLIME_ATTACK, 0.75F, (this.rand.nextFloat() * 0.2F) + 0.9F);
	}
}
 
Example 12
Project: Mods   File: ItemHorn.java   View Source Code Vote up 5 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn,
		EnumHand hand) {
	ItemStack itemStackIn = playerIn.getHeldItem(hand);
	ItemStack backpack = getBackpack(playerIn);
	if (!backpack.isEmpty() && (backpack.getTagCompound().getFloat("Rage") >= 1 || playerIn.isCreative())) {
		playerIn.setActiveHand(hand);
		if (TF2Util.getTeamForDisplay(playerIn) == 1)
			playerIn.playSound(ItemFromData.getSound(backpack, PropertyType.HORN_BLU_SOUND), 0.8f, 1f);
		else
			playerIn.playSound(ItemFromData.getSound(backpack, PropertyType.HORN_RED_SOUND), 0.8f, 1f);
		return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemStackIn);
	}
	return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemStackIn);
}
 
Example 13
Project: Mods   File: ItemCloak.java   View Source Code Vote up 5 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer living, EnumHand hand) {
	ItemStack stack=living.getHeldItem(hand);
	if (living.isInvisible() || (!isFeignDeath(stack, living) && stack.getItemDamage() < 528)) {
		this.setCloak(!WeaponsCapability.get(living).isInvisible(), stack, living, world);
		return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
	}
	else if(!living.isInvisible() && this.isFeignDeath(stack, living) && stack.getItemDamage() == 0) {
		WeaponsCapability.get(living).setFeign(!WeaponsCapability.get(living).isFeign());
		if(WeaponsCapability.get(living).isFeign())
			living.playSound(getSound(stack, PropertyType.CHARGE_SOUND), 1.0f, 1.0f);
		return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
	}
	return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
}
 
Example 14
Project: CustomWorldGen   File: FluidUtil.java   View Source Code Vote up 5 votes
/**
 * Fill a container from the given fluidSource.
 *
 * @param container   The container to be filled. Will not be modified.
 * @param fluidSource The fluid handler to be drained.
 * @param maxAmount   The largest amount of fluid that should be transferred.
 * @param player      The player to make the filling noise. Pass null for no noise.
 * @param doFill      true if the container should actually be filled, false if it should be simulated.
 * @return The filled container or null if the liquid couldn't be taken from the tank.
 */
public static ItemStack tryFillContainer(ItemStack container, IFluidHandler fluidSource, int maxAmount, @Nullable EntityPlayer player, boolean doFill)
{
    container = container.copy(); // do not modify the input
    container.stackSize = 1;
    IFluidHandler containerFluidHandler = getFluidHandler(container);
    if (containerFluidHandler != null)
    {
        FluidStack simulatedTransfer = tryFluidTransfer(containerFluidHandler, fluidSource, maxAmount, false);
        if (simulatedTransfer != null)
        {
            if (doFill)
            {
                tryFluidTransfer(containerFluidHandler, fluidSource, maxAmount, true);
                if (player != null)
                {
                    SoundEvent soundevent = simulatedTransfer.getFluid().getFillSound(simulatedTransfer);
                    player.playSound(soundevent, 1f, 1f);
                }
            }
            else
            {
                containerFluidHandler.fill(simulatedTransfer, true);
            }
            return container;
        }
    }
    return null;
}
 
Example 15
Project: CustomWorldGen   File: FluidUtil.java   View Source Code Vote up 5 votes
/**
 * Takes a filled container and tries to empty it into the given tank.
 *
 * @param container        The filled container. Will not be modified.
 * @param fluidDestination The fluid handler to be filled by the container.
 * @param maxAmount        The largest amount of fluid that should be transferred.
 * @param player           Player for making the bucket drained sound. Pass null for no noise.
 * @param doDrain          true if the container should actually be drained, false if it should be simulated.
 * @return The empty container if successful, null if the fluid handler couldn't be filled.
 *         NOTE The empty container will have a stackSize of 0 when a filled container is consumable,
 *              i.e. it has a "null" empty container but has successfully been emptied.
 */
@Nullable
public static ItemStack tryEmptyContainer(ItemStack container, IFluidHandler fluidDestination, int maxAmount, @Nullable EntityPlayer player, boolean doDrain)
{
    container = container.copy(); // do not modify the input
    container.stackSize = 1;
    IFluidHandler containerFluidHandler = getFluidHandler(container);
    if (containerFluidHandler != null)
    {
        FluidStack simulatedTransfer = tryFluidTransfer(fluidDestination, containerFluidHandler, maxAmount, false);
        if (simulatedTransfer != null)
        {
            if (doDrain)
            {
                tryFluidTransfer(fluidDestination, containerFluidHandler, maxAmount, true);
                if (player != null)
                {
                    SoundEvent soundevent = simulatedTransfer.getFluid().getEmptySound(simulatedTransfer);
                    player.playSound(soundevent, 1f, 1f);
                }
            }
            else
            {
                containerFluidHandler.drain(simulatedTransfer, true);
            }
            return container;
        }
    }
    return null;
}
 
Example 16
Project: harshencastle   File: MessagePacketRingUpdate.java   View Source Code Vote up 4 votes
@Override
public void onReceived(MessagePacketRingUpdate message, EntityPlayer player) {
	if(message.ringType < 2)
	{
		ArrayList<Item> ringTypeItem = new ArrayList<Item>();
		ringTypeItem.add(HarshenItems.TELERING);
		ringTypeItem.add(HarshenItems.MINERING);
		if(HarshenUtils.containsItem(player,ringTypeItem.get(message.ringType)))
		{
			World world = player.world;
			Vec3d vec = new Vec3d(player.posX + (player.getLookVec().x * 4f),
					player.posY + (player.getLookVec().y * 4f), player.posZ + (player.getLookVec().z* 4f));
			BlockPos blockpos = message.ringType == 0? HarshenUtils.getTopBlock(world, vec) : HarshenUtils.getBottomBlockAir(world, vec);
			Vec3d vecPos = new Vec3d(blockpos).addVector(0.5, 0, 0.5);
			if(blockpos.getY() != -1 && player.getFoodStats().getFoodLevel() > 0)
			{
				((EntityPlayerMP)player).velocityChanged = true;
				((EntityPlayerMP)player).fallDistance = 0;
				HarshenNetwork.sendToPlayer(player, new MessagePacketPlayerTeleportEffects(vecPos));
				((EntityPlayerMP)player).setPositionAndUpdate(vecPos.x, vecPos.y, vecPos.z);
				world.playSound((EntityPlayer)null, player.posX, player.posY, player.posZ, SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, SoundCategory.PLAYERS, 1.0F, 1.0F);
                player.playSound(SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, 1.0F, 1.0F);
                player.addExhaustion(0.5F);
                HarshenUtils.damageFirstOccuringItem(player, ringTypeItem.get(message.ringType));
			}
		}			
	}
	else if(message.ringType == 2 && HarshenUtils.containsItem(player, HarshenItems.COMBAT_PENDANT))
	{
		EntityLivingBase entityToAttack = HarshenUtils.getFirstEntityInDirection(player.world, player.getPositionVector(), player.getLookVec().normalize(), 5, EntityLivingBase.class);
		if(entityToAttack == null)
		{
			List<EntityLivingBase> list = player.world.getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(player.posX - 4d, player.posY - 4d, player.posZ - 4d, player.posX + 4d, player.posY + 4d, player.posZ + 4d));
			if(!list.isEmpty())
				entityToAttack = list.get(0);
		}
		if(!player.equals(entityToAttack) && (entityToAttack != null || (entityToAttack instanceof EntityPlayerMP && player.canAttackPlayer((EntityPlayerMP)entityToAttack)
				&& HarshenUtils.toArray(GameType.SURVIVAL, GameType.ADVENTURE).contains(((EntityPlayerMP)entityToAttack).interactionManager.getGameType()))))
		{
			Vec3d position = entityToAttack.getPositionVector();
			Vec3d playerPosNoY = position.addVector(movePos(), 0, movePos());
			Vec3d pos = new Vec3d(playerPosNoY.x, HarshenUtils.getTopBlock(player.world, new BlockPos(playerPosNoY)).getY(), playerPosNoY.z);
			double d0 = position.x - pos.x;
            double d1 = position.y - (pos.y + (double)player.getEyeHeight() - entityToAttack.height / 2f + 0.1f);
            double d2 = position.z - pos.z;
            double d3 = (double)MathHelper.sqrt(d0 * d0 + d2 * d2);
            float yaw = (float)(MathHelper.atan2(d2, d0) * (180D / Math.PI)) - 90.0F;
            float pitch = (float)(-(MathHelper.atan2(d1, d3) * (180D / Math.PI)));
			((EntityPlayerMP)player).velocityChanged = true;
			((EntityPlayerMP)player).connection.setPlayerLocation(pos.x, pos.y, pos.z, yaw, pitch);
		}
	}
}
 
Example 17
Project: Backmemed   File: ItemBucket.java   View Source Code Vote up 4 votes
public ActionResult<ItemStack> onItemRightClick(World itemStackIn, EntityPlayer worldIn, EnumHand playerIn)
{
    boolean flag = this.containedBlock == Blocks.AIR;
    ItemStack itemstack = worldIn.getHeldItem(playerIn);
    RayTraceResult raytraceresult = this.rayTrace(itemStackIn, worldIn, flag);

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

        if (!itemStackIn.isBlockModifiable(worldIn, blockpos))
        {
            return new ActionResult(EnumActionResult.FAIL, itemstack);
        }
        else if (flag)
        {
            if (!worldIn.canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, itemstack))
            {
                return new ActionResult(EnumActionResult.FAIL, itemstack);
            }
            else
            {
                IBlockState iblockstate = itemStackIn.getBlockState(blockpos);
                Material material = iblockstate.getMaterial();

                if (material == Material.WATER && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
                {
                    itemStackIn.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 11);
                    worldIn.addStat(StatList.getObjectUseStats(this));
                    worldIn.playSound(SoundEvents.ITEM_BUCKET_FILL, 1.0F, 1.0F);
                    return new ActionResult(EnumActionResult.SUCCESS, this.fillBucket(itemstack, worldIn, Items.WATER_BUCKET));
                }
                else if (material == Material.LAVA && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
                {
                    worldIn.playSound(SoundEvents.ITEM_BUCKET_FILL_LAVA, 1.0F, 1.0F);
                    itemStackIn.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 11);
                    worldIn.addStat(StatList.getObjectUseStats(this));
                    return new ActionResult(EnumActionResult.SUCCESS, this.fillBucket(itemstack, worldIn, Items.LAVA_BUCKET));
                }
                else
                {
                    return new ActionResult(EnumActionResult.FAIL, itemstack);
                }
            }
        }
        else
        {
            boolean flag1 = itemStackIn.getBlockState(blockpos).getBlock().isReplaceable(itemStackIn, blockpos);
            BlockPos blockpos1 = flag1 && raytraceresult.sideHit == EnumFacing.UP ? blockpos : blockpos.offset(raytraceresult.sideHit);

            if (!worldIn.canPlayerEdit(blockpos1, raytraceresult.sideHit, itemstack))
            {
                return new ActionResult(EnumActionResult.FAIL, itemstack);
            }
            else if (this.tryPlaceContainedLiquid(worldIn, itemStackIn, blockpos1))
            {
                worldIn.addStat(StatList.getObjectUseStats(this));
                return !worldIn.capabilities.isCreativeMode ? new ActionResult(EnumActionResult.SUCCESS, new ItemStack(Items.BUCKET)) : new ActionResult(EnumActionResult.SUCCESS, itemstack);
            }
            else
            {
                return new ActionResult(EnumActionResult.FAIL, itemstack);
            }
        }
    }
}
 
Example 18
Project: CustomWorldGen   File: ItemBucket.java   View Source Code Vote up 4 votes
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand)
{
    boolean flag = this.containedBlock == Blocks.AIR;
    RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, flag);
    ActionResult<ItemStack> ret = net.minecraftforge.event.ForgeEventFactory.onBucketUse(playerIn, worldIn, itemStackIn, raytraceresult);
    if (ret != null) return ret;

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

        if (!worldIn.isBlockModifiable(playerIn, blockpos))
        {
            return new ActionResult(EnumActionResult.FAIL, itemStackIn);
        }
        else if (flag)
        {
            if (!playerIn.canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, itemStackIn))
            {
                return new ActionResult(EnumActionResult.FAIL, itemStackIn);
            }
            else
            {
                IBlockState iblockstate = worldIn.getBlockState(blockpos);
                Material material = iblockstate.getMaterial();

                if (material == Material.WATER && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
                {
                    worldIn.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 11);
                    playerIn.addStat(StatList.getObjectUseStats(this));
                    playerIn.playSound(SoundEvents.ITEM_BUCKET_FILL, 1.0F, 1.0F);
                    return new ActionResult(EnumActionResult.SUCCESS, this.fillBucket(itemStackIn, playerIn, Items.WATER_BUCKET));
                }
                else if (material == Material.LAVA && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
                {
                    playerIn.playSound(SoundEvents.ITEM_BUCKET_FILL_LAVA, 1.0F, 1.0F);
                    worldIn.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 11);
                    playerIn.addStat(StatList.getObjectUseStats(this));
                    return new ActionResult(EnumActionResult.SUCCESS, this.fillBucket(itemStackIn, playerIn, Items.LAVA_BUCKET));
                }
                else
                {
                    return new ActionResult(EnumActionResult.FAIL, itemStackIn);
                }
            }
        }
        else
        {
            boolean flag1 = worldIn.getBlockState(blockpos).getBlock().isReplaceable(worldIn, blockpos);
            BlockPos blockpos1 = flag1 && raytraceresult.sideHit == EnumFacing.UP ? blockpos : blockpos.offset(raytraceresult.sideHit);

            if (!playerIn.canPlayerEdit(blockpos1, raytraceresult.sideHit, itemStackIn))
            {
                return new ActionResult(EnumActionResult.FAIL, itemStackIn);
            }
            else if (this.tryPlaceContainedLiquid(playerIn, worldIn, blockpos1))
            {
                playerIn.addStat(StatList.getObjectUseStats(this));
                return !playerIn.capabilities.isCreativeMode ? new ActionResult(EnumActionResult.SUCCESS, new ItemStack(Items.BUCKET)) : new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
            }
            else
            {
                return new ActionResult(EnumActionResult.FAIL, itemStackIn);
            }
        }
    }
}