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

The following examples show how to use net.minecraft.entity.player.EntityPlayer#setItemInUse() . 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
Source Project: SimplyJetpacks   File: ItemJetpackFueller.java    License: MIT License 5 votes vote down vote up
@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
    MovingObjectPosition blockPos = BlockHelper.getCurrentMovingObjectPosition(player, true);
    if (blockPos != null && blockPos.sideHit >= 0) {
        player.setItemInUse(itemStack, this.getMaxItemUseDuration(itemStack));
    }
    return itemStack;
}
 
Example 2
/**
 * Called whenever this item is equipped and the right mouse button is
 * pressed. Args: itemStack, world, entityPlayer
 */
@Override
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
    par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
    return par1ItemStack;
}
 
Example 3
/**
 * Called whenever this item is equipped and the right mouse button is
 * pressed. Args: itemStack, world, entityPlayer
 */
@Override
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
	par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
	return par1ItemStack;
}
 
Example 4
@Override
public ItemStack onFocusRightClick(ItemStack wandStack, World world, EntityPlayer player, MovingObjectPosition movingobjectposition) {
    player.setItemInUse(wandStack, 2147483647);
    //WandManager.setCooldown(player, -1);
    return wandStack;
}
 
Example 5
Source Project: SimplyJetpacks   File: ItemJetpackFueller.java    License: MIT License 4 votes vote down vote up
@Override
public void onUsingTick(ItemStack itemStack, EntityPlayer player, int count) {
    MovingObjectPosition blockPos = BlockHelper.getCurrentMovingObjectPosition(player, true);
    if (blockPos == null || blockPos.sideHit < 0) {
        player.setItemInUse(null, 1);
    } else {
        player.setItemInUse(itemStack, this.getMaxItemUseDuration(itemStack));
        if (player.worldObj.isRemote) {
            return;
        }
        
        ItemStack chestplate = player.getCurrentArmor(2);
        if (chestplate == null || !(chestplate.getItem() instanceof ItemPack)) {
            return;
        }
        ItemPack packItem = (ItemPack) chestplate.getItem();
        PackBase pack = packItem.getPack(chestplate);
        if (pack == null) {
            return;
        }
        FuelType fuelType = pack.fuelType;
        
        ForgeDirection pullSide = ForgeDirection.values()[blockPos.sideHit];
        player.worldObj.getBlock(blockPos.blockX, blockPos.blockY, blockPos.blockZ);
        TileEntity tile = player.worldObj.getTileEntity(blockPos.blockX, blockPos.blockY, blockPos.blockZ);
        int toPull = Math.min(pack.fuelPerTickIn, packItem.getMaxFuelStored(chestplate) - packItem.getFuelStored(chestplate));
        int pulled = 0;
        
        if (fuelType == FuelType.ENERGY && tile instanceof IEnergyProvider) {
            IEnergyProvider energyTile = (IEnergyProvider) tile;
            pulled = energyTile.extractEnergy(pullSide, toPull, false);
            
        } else if (fuelType == FuelType.FLUID) {
            if (tile instanceof IFluidHandler) {
                IFluidHandler fluidTile = (IFluidHandler) tile;
                FluidStack fluid = fluidTile.drain(pullSide, toPull, false);
                if (fluid == null || !fluid.getFluid().getName().equals(pack.fuelFluid)) {
                    return;
                }
                fluid = fluidTile.drain(pullSide, toPull, true);
                pulled = fluid.amount;
            }
        }
        
        if (pulled > 0) {
            packItem.addFuel(chestplate, pulled, false);
        }
    }
}
 
Example 6
@Override
public ItemStack onFocusRightClick(ItemStack paramItemStack, World paramWorld, EntityPlayer paramEntityPlayer, MovingObjectPosition paramMovingObjectPosition) {
	if (isUseItem())
		paramEntityPlayer.setItemInUse(paramItemStack, Integer.MAX_VALUE);
	return paramItemStack;
}
 
Example 7
/**
 * Called whenever this item is equipped and the right mouse button is
 * pressed. Args: itemStack, world, entityPlayer
 */
@Override
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer entityplayer)
{
	/*if(!MoCreatures.isServer())
	{
		return par1ItemStack;
	}*/

	if (entityplayer.ridingEntity != null || entityplayer.riddenByEntity != null)
	{

		return par1ItemStack;
	}
	
	
		
	
   	double coordY = entityplayer.posY + (double)entityplayer.getEyeHeight();
   	double coordZ = entityplayer.posZ;
   	double coordX = entityplayer.posX;
	for (int x = 4; x < 128; x++)
	{
		
		
		double newPosY = coordY - Math.cos( (entityplayer.rotationPitch- 90F) / 57.29578F) * x;
   		double newPosX = coordX + Math.cos((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * x );
   		double newPosZ = coordZ + Math.sin((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * x );
   		int iTarget = entityplayer.worldObj.getBlockId( MathHelper.floor_double(newPosX),  MathHelper.floor_double(newPosY),  MathHelper.floor_double(newPosZ)); 
	        if (iTarget != 0)
	        {
	        	newPosY = coordY - Math.cos( (entityplayer.rotationPitch- 90F) / 57.29578F) * (x-1);
    			newPosX = coordX + Math.cos((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * (x-1) );
    			newPosZ = coordZ + Math.sin((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * (x-1) );
    			
    			if (MoCreatures.isServer())
    			{
    				EntityPlayerMP thePlayer = (EntityPlayerMP) entityplayer;
			        thePlayer.playerNetServerHandler.setPlayerLocation((double)newPosX, (double)newPosY, (double)newPosZ, entityplayer.rotationYaw, entityplayer.rotationPitch);
			        MoCTools.playCustomSound(entityplayer, "appearmagic", entityplayer.worldObj);
    			}
    			MoCreatures.proxy.teleportFX(entityplayer);
		        entityplayer.setItemInUse(par1ItemStack, 200);
		        par1ItemStack.damageItem(1, entityplayer);
			     
		        return par1ItemStack;
	        }
	}
	
	entityplayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
	
	return par1ItemStack;
}
 
Example 8
/**
* Called whenever this item is equipped and the right mouse button is
* pressed. Args: itemStack, world, entityPlayer
*/
  @Override
  public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer entityplayer)
  {
  	double coordY = entityplayer.posY + (double)entityplayer.getEyeHeight();
  	double coordZ = entityplayer.posZ;
  	double coordX = entityplayer.posX;
  	int wallBlockID = 0;
  	int newWallBlockID = 0;
  	
  	for (int x = 3; x < 128; x++)
  	{



  		double newPosY = coordY - Math.cos( (entityplayer.rotationPitch- 90F) / 57.29578F) * x;
  		double newPosX = coordX + Math.cos((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * x );
  		double newPosZ = coordZ + Math.sin((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * x );
  		newWallBlockID = entityplayer.worldObj.getBlockId( MathHelper.floor_double(newPosX),  MathHelper.floor_double(newPosY),  MathHelper.floor_double(newPosZ)); 
  		
  		if (newWallBlockID == 0)
  		{
  			wallBlockID = newWallBlockID;
  			continue;
   		}
 
  		if (newWallBlockID != 0 && wallBlockID == 0)
  		{

  			newPosY = coordY - Math.cos( (entityplayer.rotationPitch- 90F) / 57.29578F) * (x-1);
  			newPosX = coordX + Math.cos((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * (x-1) );
  			newPosZ = coordZ + Math.sin((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * (x-1) );
  			if (entityplayer.worldObj.getBlockId(MathHelper.floor_double(newPosX), MathHelper.floor_double(newPosY), MathHelper.floor_double(newPosZ)) != 0)  
  			{
  				//System.out.println("busy spot!");
  				return par1ItemStack;
  			}
      		
  			int blockInfo[] = obtainBlockAndMetadataFromBelt(entityplayer, true);
  			if (blockInfo[0] != 0)
  			{
  				if (MoCreatures.isServer())
  				{
  					entityplayer.worldObj.setBlock(MathHelper.floor_double(newPosX),  MathHelper.floor_double(newPosY),  MathHelper.floor_double(newPosZ), blockInfo[0], blockInfo[1], 3);
  					Block block = Block.blocksList[blockInfo[0]];
  					entityplayer.worldObj.playSoundEffect((double)((float)newPosX + 0.5F), (double)((float)newPosY + 0.5F), (double)((float)newPosZ + 0.5F), block.stepSound.getPlaceSound(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);
  				}
  				MoCreatures.proxy.hammerFX(entityplayer);
  				entityplayer.setItemInUse(par1ItemStack, 200);
  			}
  			return par1ItemStack;
  		}
  	}
  	return par1ItemStack;
  }
 
Example 9
/**
* Called whenever this item is equipped and the right mouse button is
* pressed. Args: itemStack, world, entityPlayer
*/
  @Override
  public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer entityplayer)
  {
  	double coordY = entityplayer.posY + (double)entityplayer.getEyeHeight();
  	double coordZ = entityplayer.posZ;
  	double coordX = entityplayer.posX;
  	int wallBlockID = 0;
  	int newWallBlockID = 0;
  	
  	for (int x = 3; x < 128; x++)
  	{



  		double newPosY = coordY - Math.cos( (entityplayer.rotationPitch- 90F) / 57.29578F) * x;
  		double newPosX = coordX + Math.cos((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * x );
  		double newPosZ = coordZ + Math.sin((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * x );
  		newWallBlockID = entityplayer.worldObj.getBlockId( MathHelper.floor_double(newPosX),  MathHelper.floor_double(newPosY),  MathHelper.floor_double(newPosZ)); 
  		
  		if (newWallBlockID == 0)
  		{
  			wallBlockID = newWallBlockID;
  			continue;
   		}
 
  		if (newWallBlockID != 0 && wallBlockID == 0)
  		{

  			newPosY = coordY - Math.cos( (entityplayer.rotationPitch- 90F) / 57.29578F) * (x-1);
  			newPosX = coordX + Math.cos((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * (x-1) );
  			newPosZ = coordZ + Math.sin((MoCTools.realAngle(entityplayer.rotationYaw- 90F) / 57.29578F)) * (Math.sin( (entityplayer.rotationPitch- 90F) / 57.29578F) * (x-1) );
  			if (entityplayer.worldObj.getBlockId(MathHelper.floor_double(newPosX), MathHelper.floor_double(newPosY), MathHelper.floor_double(newPosZ)) != 0)  
  			{
  				//System.out.println("busy spot!");
  				return par1ItemStack;
  			}
      		
  			int blockInfo[] = obtainBlockAndMetadataFromBelt(entityplayer, true);
  			if (blockInfo[0] != 0)
  			{
  				if (MoCreatures.isServer())
  				{
  					entityplayer.worldObj.setBlock(MathHelper.floor_double(newPosX),  MathHelper.floor_double(newPosY),  MathHelper.floor_double(newPosZ), blockInfo[0], blockInfo[1], 3);
  					Block block = Block.blocksList[blockInfo[0]];
  					entityplayer.worldObj.playSoundEffect((double)((float)newPosX + 0.5F), (double)((float)newPosY + 0.5F), (double)((float)newPosZ + 0.5F), block.stepSound.getPlaceSound(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);
  				}
  				MoCreatures.proxy.hammerFX(entityplayer);
  				entityplayer.setItemInUse(par1ItemStack, 200);
  			}
  			return par1ItemStack;
  		}
  	}
  	return par1ItemStack;
  }