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

The following are Jave code examples for showing how to use isUsingItem() 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: ItemInWorldManager.java   View Source Code Vote up 4 votes
/**
 * Attempts to right-click use an item by the given EntityPlayer in the given World
 */
public boolean tryUseItem(EntityPlayer player, World worldIn, ItemStack stack)
{
    if (this.gameType == WorldSettings.GameType.SPECTATOR)
    {
        return false;
    }
    else
    {
        int i = stack.stackSize;
        int j = stack.getMetadata();
        ItemStack itemstack = stack.useItemRightClick(worldIn, player);

        if (itemstack != stack || itemstack != null && (itemstack.stackSize != i || itemstack.getMaxItemUseDuration() > 0 || itemstack.getMetadata() != j))
        {
            player.inventory.mainInventory[player.inventory.currentItem] = itemstack;

            if (this.isCreative())
            {
                itemstack.stackSize = i;

                if (itemstack.isItemStackDamageable())
                {
                    itemstack.setItemDamage(j);
                }
            }

            if (itemstack.stackSize == 0)
            {
                player.inventory.mainInventory[player.inventory.currentItem] = null;
            }

            if (!player.isUsingItem())
            {
                ((EntityPlayerMP)player).sendContainerToPlayer(player.inventoryContainer);
            }

            return true;
        }
        else
        {
            return false;
        }
    }
}
 
Example 2
Project: DecompiledMinecraft   File: ItemInWorldManager.java   View Source Code Vote up 4 votes
/**
 * Attempts to right-click use an item by the given EntityPlayer in the given World
 */
public boolean tryUseItem(EntityPlayer player, World worldIn, ItemStack stack)
{
    if (this.gameType == WorldSettings.GameType.SPECTATOR)
    {
        return false;
    }
    else
    {
        int i = stack.stackSize;
        int j = stack.getMetadata();
        ItemStack itemstack = stack.useItemRightClick(worldIn, player);

        if (itemstack != stack || itemstack != null && (itemstack.stackSize != i || itemstack.getMaxItemUseDuration() > 0 || itemstack.getMetadata() != j))
        {
            player.inventory.mainInventory[player.inventory.currentItem] = itemstack;

            if (this.isCreative())
            {
                itemstack.stackSize = i;

                if (itemstack.isItemStackDamageable())
                {
                    itemstack.setItemDamage(j);
                }
            }

            if (itemstack.stackSize == 0)
            {
                player.inventory.mainInventory[player.inventory.currentItem] = null;
            }

            if (!player.isUsingItem())
            {
                ((EntityPlayerMP)player).sendContainerToPlayer(player.inventoryContainer);
            }

            return true;
        }
        else
        {
            return false;
        }
    }
}
 
Example 3
Project: BaseClient   File: ItemInWorldManager.java   View Source Code Vote up 4 votes
/**
 * Attempts to right-click use an item by the given EntityPlayer in the given World
 */
public boolean tryUseItem(EntityPlayer player, World worldIn, ItemStack stack)
{
    if (this.gameType == WorldSettings.GameType.SPECTATOR)
    {
        return false;
    }
    else
    {
        int i = stack.stackSize;
        int j = stack.getMetadata();
        ItemStack itemstack = stack.useItemRightClick(worldIn, player);

        if (itemstack != stack || itemstack != null && (itemstack.stackSize != i || itemstack.getMaxItemUseDuration() > 0 || itemstack.getMetadata() != j))
        {
            player.inventory.mainInventory[player.inventory.currentItem] = itemstack;

            if (this.isCreative())
            {
                itemstack.stackSize = i;

                if (itemstack.isItemStackDamageable())
                {
                    itemstack.setItemDamage(j);
                }
            }

            if (itemstack.stackSize == 0)
            {
                player.inventory.mainInventory[player.inventory.currentItem] = null;
            }

            if (!player.isUsingItem())
            {
                ((EntityPlayerMP)player).sendContainerToPlayer(player.inventoryContainer);
            }

            return true;
        }
        else
        {
            return false;
        }
    }
}
 
Example 4
Project: BaseClient   File: ItemInWorldManager.java   View Source Code Vote up 4 votes
/**
 * Attempts to right-click use an item by the given EntityPlayer in the given World
 */
public boolean tryUseItem(EntityPlayer player, World worldIn, ItemStack stack)
{
    if (this.gameType == WorldSettings.GameType.SPECTATOR)
    {
        return false;
    }
    else
    {
        int i = stack.stackSize;
        int j = stack.getMetadata();
        ItemStack itemstack = stack.useItemRightClick(worldIn, player);

        if (itemstack != stack || itemstack != null && (itemstack.stackSize != i || itemstack.getMaxItemUseDuration() > 0 || itemstack.getMetadata() != j))
        {
            player.inventory.mainInventory[player.inventory.currentItem] = itemstack;

            if (this.isCreative())
            {
                itemstack.stackSize = i;

                if (itemstack.isItemStackDamageable())
                {
                    itemstack.setItemDamage(j);
                }
            }

            if (itemstack.stackSize == 0)
            {
                player.inventory.mainInventory[player.inventory.currentItem] = null;
            }

            if (!player.isUsingItem())
            {
                ((EntityPlayerMP)player).sendContainerToPlayer(player.inventoryContainer);
            }

            return true;
        }
        else
        {
            return false;
        }
    }
}
 
Example 5
Project: minecraft-quiverbow   File: EnderBow.java   View Source Code Vote up 4 votes
@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5) 
{		
	if (stack.stackTagCompound == null) 
	{
		stack.stackTagCompound = new NBTTagCompound();
		
		stack.stackTagCompound.setBoolean("isZoomed", false);
		stack.stackTagCompound.setInteger("defaultFOV", 0);	// FOV is now using full numbers. We're recording the current default FOV here
	}

	// let's check zoom here
	if (entity instanceof EntityPlayer) 	// Step 1, is this a player?
       {
		EntityPlayer entityplayer = (EntityPlayer)entity;

		if (entityplayer.inventory.getCurrentItem() != null && entityplayer.inventory.getCurrentItem() == stack)	// Step 2, are they holding the bow?
		{
			if (entityplayer.isUsingItem()) // step 3, are they using the bow?
			{
				this.setCurrentZoom(stack, true); // We need to zoom in!
				
				if (world.isRemote)
				{ 
					//System.out.println("[ENDER BOW] Current FOV: " + Minecraft.getMinecraft().gameSettings.fovSetting);
			    	
			    	// We're gonna zoom in each tick. Is it bigger than the max zoom? Then keep zooming.
			    	if (Minecraft.getMinecraft().gameSettings.fovSetting > ZoomMax) 
			    	{
			    		// FOV is now using full numbers. 70 is 70, 120 is 120. Nice of them.
			    		Minecraft.getMinecraft().gameSettings.fovSetting -= 2;	// 2 less, until we've reached zoomMax
			    	}
				}	
				// else, server side. Has no deal with game settings
				
			}
			else // Not using this item currently
			{
				if (this.isCurrentlyZoomed(stack)) 			// Are we currently zoomed in?
				{
					this.setCurrentZoom(stack, false);
					if (world.isRemote) { this.restoreFOV(stack); }	// Begone with that then
				}
				// else, not zoomed in currently
			}
		}
		else // Not holding the bow
		{
			if (this.isCurrentlyZoomed(stack)) 				// Are we currently zoomed in?
			{
				this.setCurrentZoom(stack, false);
				if (world.isRemote) { this.restoreFOV(stack); } 	// Begone with that then
					
			}
		}
		
		// step 0, recording the current zoom level, if we're not zoomed in. Need to do this AFTER we reset
		if (!this.isCurrentlyZoomed(stack))	// Not zoomed in currently
		{				
			if (world.isRemote) { this.recordCurrentFOV(stack); } // Client side only
		}
	}
	// else, not a player holding this thing
}