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

The following are Jave code examples for showing how to use swingItem() 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: DecompiledMinecraft   File: EntityCreeper.java   View Source Code Vote up 6 votes
/**
 * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
 */
protected boolean interact(EntityPlayer player)
{
    ItemStack itemstack = player.inventory.getCurrentItem();

    if (itemstack != null && itemstack.getItem() == Items.flint_and_steel)
    {
        this.worldObj.playSoundEffect(this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D, "fire.ignite", 1.0F, this.rand.nextFloat() * 0.4F + 0.8F);
        player.swingItem();

        if (!this.worldObj.isRemote)
        {
            this.ignite();
            itemstack.damageItem(1, player);
            return true;
        }
    }

    return super.interact(player);
}
 
Example 2
Project: DecompiledMinecraft   File: ItemFishingRod.java   View Source Code Vote up 6 votes
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
    if (playerIn.fishEntity != null)
    {
        int i = playerIn.fishEntity.handleHookRetraction();
        itemStackIn.damageItem(i, playerIn);
        playerIn.swingItem();
    }
    else
    {
        worldIn.playSoundAtEntity(playerIn, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

        if (!worldIn.isRemote)
        {
            worldIn.spawnEntityInWorld(new EntityFishHook(worldIn, playerIn));
        }

        playerIn.swingItem();
        playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
    }

    return itemStackIn;
}
 
Example 3
Project: DecompiledMinecraft   File: EntityCreeper.java   View Source Code Vote up 6 votes
/**
 * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
 */
protected boolean interact(EntityPlayer player)
{
    ItemStack itemstack = player.inventory.getCurrentItem();

    if (itemstack != null && itemstack.getItem() == Items.flint_and_steel)
    {
        this.worldObj.playSoundEffect(this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D, "fire.ignite", 1.0F, this.rand.nextFloat() * 0.4F + 0.8F);
        player.swingItem();

        if (!this.worldObj.isRemote)
        {
            this.ignite();
            itemstack.damageItem(1, player);
            return true;
        }
    }

    return super.interact(player);
}
 
Example 4
Project: DecompiledMinecraft   File: ItemFishingRod.java   View Source Code Vote up 6 votes
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
    if (playerIn.fishEntity != null)
    {
        int i = playerIn.fishEntity.handleHookRetraction();
        itemStackIn.damageItem(i, playerIn);
        playerIn.swingItem();
    }
    else
    {
        worldIn.playSoundAtEntity(playerIn, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

        if (!worldIn.isRemote)
        {
            worldIn.spawnEntityInWorld(new EntityFishHook(worldIn, playerIn));
        }

        playerIn.swingItem();
        playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
    }

    return itemStackIn;
}
 
Example 5
Project: BaseClient   File: EntityCreeper.java   View Source Code Vote up 6 votes
/**
 * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
 */
protected boolean interact(EntityPlayer player)
{
    ItemStack itemstack = player.inventory.getCurrentItem();

    if (itemstack != null && itemstack.getItem() == Items.flint_and_steel)
    {
        this.worldObj.playSoundEffect(this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D, "fire.ignite", 1.0F, this.rand.nextFloat() * 0.4F + 0.8F);
        player.swingItem();

        if (!this.worldObj.isRemote)
        {
            this.ignite();
            itemstack.damageItem(1, player);
            return true;
        }
    }

    return super.interact(player);
}
 
Example 6
Project: BaseClient   File: ItemFishingRod.java   View Source Code Vote up 6 votes
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
    if (playerIn.fishEntity != null)
    {
        int i = playerIn.fishEntity.handleHookRetraction();
        itemStackIn.damageItem(i, playerIn);
        playerIn.swingItem();
    }
    else
    {
        worldIn.playSoundAtEntity(playerIn, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

        if (!worldIn.isRemote)
        {
            worldIn.spawnEntityInWorld(new EntityFishHook(worldIn, playerIn));
        }

        playerIn.swingItem();
        playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
    }

    return itemStackIn;
}
 
Example 7
Project: BaseClient   File: EntityCreeper.java   View Source Code Vote up 6 votes
/**
 * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
 */
protected boolean interact(EntityPlayer player)
{
    ItemStack itemstack = player.inventory.getCurrentItem();

    if (itemstack != null && itemstack.getItem() == Items.flint_and_steel)
    {
        this.worldObj.playSoundEffect(this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D, "fire.ignite", 1.0F, this.rand.nextFloat() * 0.4F + 0.8F);
        player.swingItem();

        if (!this.worldObj.isRemote)
        {
            this.ignite();
            itemstack.damageItem(1, player);
            return true;
        }
    }

    return super.interact(player);
}
 
Example 8
Project: BaseClient   File: ItemFishingRod.java   View Source Code Vote up 6 votes
/**
 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
 */
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
    if (playerIn.fishEntity != null)
    {
        int i = playerIn.fishEntity.handleHookRetraction();
        itemStackIn.damageItem(i, playerIn);
        playerIn.swingItem();
    }
    else
    {
        worldIn.playSoundAtEntity(playerIn, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

        if (!worldIn.isRemote)
        {
            worldIn.spawnEntityInWorld(new EntityFishHook(worldIn, playerIn));
        }

        playerIn.swingItem();
        playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
    }

    return itemStackIn;
}
 
Example 9
Project: connor41-etfuturum2   File: ServerEventHandler.java   View Source Code Vote up 6 votes
private void feedBaby(EntityAnimal animal, EntityPlayer player, ItemStack stack) {
	int currentAge = animal.getGrowingAge();
	int age = (int) (-currentAge * 0.1F);
	animal.setGrowingAge(currentAge + age);
	player.swingItem();

	Random itemRand = animal.worldObj.rand;
	for (int i = 0; i < 3; i++) {
		double d0 = itemRand.nextGaussian() * 0.02D;
		double d1 = itemRand.nextGaussian() * 0.02D;
		double d2 = itemRand.nextGaussian() * 0.02D;
		animal.worldObj.spawnParticle("happyVillager", animal.posX + itemRand.nextFloat() * 0.5, animal.posY + 0.5 + itemRand.nextFloat() * 0.5, animal.posZ + itemRand.nextFloat() * 0.5, d0, d1, d2);
	}

	if (!player.capabilities.isCreativeMode)
		if (--stack.stackSize <= 0)
			player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
}