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

The following are Jave code examples for showing how to use setCurrentItemOrArmor() 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: minecraft-quiverbow   File: AI_Properties.java   View Source Code Vote up 6 votes
public static void doRepair(EntityPlayer player, Entity_AA turret, ItemStack stack)
{
	//if (this.hasArmorUpgrade) { return; }	// Already has an armor upgrade
	//this.hasArmorUpgrade = true;			// Adding one
	
	if (turret.getHealth() >= turret.getMaxHealth()) { return; }	// No repairs required
	
	turret.heal(20);
	
	// SFX
	NetHelper.sendParticleMessage(player, turret.getEntityId(), (byte) 2, (byte) 4); // Firework sparks particles (2)
	turret.worldObj.playSoundAtEntity(turret, "random.anvil_use", 0.7f, 1.0f);
	
	if (player.capabilities.isCreativeMode) { return; }	// Not deducting from creative mode players
	
	player.getHeldItem().stackSize -= 1;
	if (player.getHeldItem().stackSize <= 0) { player.setCurrentItemOrArmor(0, null); }	// Used up
}
 
Example 2
Project: minecraft-quiverbow   File: PackedUpBB.java   View Source Code Vote up 6 votes
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float sideX, float sideY, float sideZ)
   {
	if (world.isRemote) { return true; }	// Not doing this on client side
	
	Entity_BB turret = new Entity_BB(world, player);
	
	turret.setPosition(x + 0.5, y + 1 , z + 0.5);		
	world.spawnEntityInWorld(turret);
	
	// Custom name
	if (stack.hasDisplayName())	{ AI_Properties.applyNameTag(player, turret, stack, false); }
	
	if (player.capabilities.isCreativeMode) { return true; }	// Not deducting them in creative mode

	stack.stackSize -= 1;
	if (stack.stackSize <= 0)	// Used up
	{
		player.setCurrentItemOrArmor(0, null);
	}
	
	return true;
   }
 
Example 3
Project: CursedLasso   File: ItemCursedLasso.java   View Source Code Vote up 5 votes
@Override
public boolean itemInteractionForEntity(ItemStack item, EntityPlayer player, EntityLivingBase entity) {
    if (entity.worldObj.isRemote) {
        return false;
    }
    if (entity instanceof IMob) {
        if (item.hasTagCompound())
            return false;
        item.setTagCompound(new NBTTagCompound());
        NBTTagCompound mainTag = new NBTTagCompound();
        NBTTagCompound entityTag = new NBTTagCompound();
        entity.writeToNBT(entityTag);
        mainTag.setFloat("health",entity.getHealth());
        mainTag.setTag("data", entityTag);
        mainTag.setString("id", EntityList.getEntityString(entity));
        if (entity instanceof EntitySlime) {
            mainTag.setInteger("slimesize", ((EntitySlime) entity).getSlimeSize());
        }
        if(entity instanceof EntityZombie){
            mainTag.setBoolean("isBabyZombie",entity.isChild());
        }
        item.getTagCompound().setTag("entity",mainTag);
        player.setCurrentItemOrArmor(0, item);
        entity.setDead();
        return true;
    }
    return super.itemInteractionForEntity(item, player, entity);
}
 
Example 4
Project: DecompiledMinecraft   File: ItemArmor.java   View Source Code Vote up 5 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)
{
    int i = EntityLiving.getArmorPosition(itemStackIn) - 1;
    ItemStack itemstack = playerIn.getCurrentArmor(i);

    if (itemstack == null)
    {
        playerIn.setCurrentItemOrArmor(i, itemStackIn.copy());
        itemStackIn.stackSize = 0;
    }

    return itemStackIn;
}
 
Example 5
Project: DecompiledMinecraft   File: ItemArmor.java   View Source Code Vote up 5 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)
{
    int i = EntityLiving.getArmorPosition(itemStackIn) - 1;
    ItemStack itemstack = playerIn.getCurrentArmor(i);

    if (itemstack == null)
    {
        playerIn.setCurrentItemOrArmor(i, itemStackIn.copy());
        itemStackIn.stackSize = 0;
    }

    return itemStackIn;
}
 
Example 6
Project: BaseClient   File: ItemArmor.java   View Source Code Vote up 5 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)
{
    int i = EntityLiving.getArmorPosition(itemStackIn) - 1;
    ItemStack itemstack = playerIn.getCurrentArmor(i);

    if (itemstack == null)
    {
        playerIn.setCurrentItemOrArmor(i, itemStackIn.copy());
        itemStackIn.stackSize = 0;
    }

    return itemStackIn;
}
 
Example 7
Project: BaseClient   File: ItemArmor.java   View Source Code Vote up 5 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)
{
    int i = EntityLiving.getArmorPosition(itemStackIn) - 1;
    ItemStack itemstack = playerIn.getCurrentArmor(i);

    if (itemstack == null)
    {
        playerIn.setCurrentItemOrArmor(i, itemStackIn.copy());
        itemStackIn.stackSize = 0;
    }

    return itemStackIn;
}
 
Example 8
Project: minecraft-quiverbow   File: AI_Properties.java   View Source Code Vote up 5 votes
public static void applyNameTag(EntityPlayer player, Entity_AA turret, ItemStack stack, boolean consumeItem)
{
	if (stack.hasDisplayName()) { turret.setCustomNameTag(stack.getDisplayName()); }	// Applying the name
	
	if (player.capabilities.isCreativeMode) { return; }	// Not deducting from creative mode players
	if (!consumeItem) { return; }						// Don't want me to consume this thing, so probably restoring properties from the packed up AA
	
	player.getHeldItem().stackSize -= 1;
	if (player.getHeldItem().stackSize <= 0) { player.setCurrentItemOrArmor(0, null); }	// Used up
}
 
Example 9
Project: minecraft-quiverbow   File: PackedUpAA.java   View Source Code Vote up 5 votes
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float sideX, float sideY, float sideZ)
   {
	if (world.isRemote) { return true; }	// Not doing this on client side
	
	Entity_AA turret = new Entity_AA(world, player);
	
	turret.setPosition(x + 0.5, y +1 , z + 0.5);		
	world.spawnEntityInWorld(turret);
	
	// Custom name
	if (stack.hasDisplayName())	{ AI_Properties.applyNameTag(player, turret, stack, false); }
	
	// Applying upgrades
	if (stack.hasTagCompound())
	{
		if (stack.getTagCompound().getBoolean("hasArmorUpgrade")) { AI_Properties.applyArmorUpgrade(turret); }
		if (stack.getTagCompound().getBoolean("hasHeavyPlatingUpgrade")) { AI_Properties.applyPlatingUpgrade(turret); }
		if (stack.getTagCompound().getBoolean("hasMobilityUpgrade")) { AI_Properties.applyMobilityUpgrade(turret); }
		if (stack.getTagCompound().getBoolean("hasStorageUpgrade")) { AI_Properties.applyStorageUpgrade(turret); }
		if (stack.getTagCompound().getBoolean("hasWeaponUpgrade")) { AI_Properties.applyWeaponUpgrade(turret); }
		if (stack.getTagCompound().getBoolean("hasRidingUpgrade")) { AI_Properties.applyRidingUpgrade(turret); }
		if (stack.getTagCompound().getBoolean("hasCommunicationUpgrade")) { AI_Properties.applyCommunicationUpgrade(turret); }
		
		if (stack.getTagCompound().getInteger("currentHealth") > 0)	// Tracking health and reapplying it
		{
			turret.setHealth(stack.getTagCompound().getInteger("currentHealth"));
		}
	}
	
	if (player.capabilities.isCreativeMode) { return true; }	// Not deducting them in creative mode

	stack.stackSize -= 1;
	if (stack.stackSize <= 0)	// Used up
	{
		player.setCurrentItemOrArmor(0, null);
	}
	
	return true;
   }
 
Example 10
Project: CursedLasso   File: ItemCursedLasso.java   View Source Code Vote up 4 votes
@Override
public boolean onItemUse(ItemStack item, EntityPlayer player, World world, int x, int y, int z, int facing, float hitX, float hitY, float hitZ) {
    if (world.isRemote) {
        return true;
    }
    if (!item.hasTagCompound()) {
        return false;
    }
    if(player == null) {
        return false;
    }

    String entityId = item.stackTagCompound.getCompoundTag("entity").getString("id");
    Entity entityToSpawn = EntityList.createEntityByName(entityId, world);

    Block blk = world.getBlock(x,y,z);
    double spawnX = x + Facing.offsetsXForSide[facing] + 0.5;
    double spawnY = y + Facing.offsetsYForSide[facing];
    double spawnZ = z + Facing.offsetsZForSide[facing] + 0.5;
    if(facing == ForgeDirection.UP.ordinal() && (blk instanceof BlockFence || blk instanceof BlockWall)) {
        spawnY += 0.5;
    }
    if(entityToSpawn instanceof EntitySlime) {
        ((EntitySlime) entityToSpawn).setSlimeSize(item.stackTagCompound.getCompoundTag("entity").getInteger("slimesize"));
    }
    if(entityToSpawn instanceof EntityZombie){
        if(item.stackTagCompound.getCompoundTag("entity").getBoolean("isBabyZombie"))
            ((EntityZombie) entityToSpawn).setChild(true);
        else
            ((EntityZombie) entityToSpawn).setChild(false);
    }
    entityToSpawn.setLocationAndAngles(spawnX, spawnY, spawnZ, world.rand.nextFloat() * 360.0F, 0);
    world.spawnEntityInWorld(entityToSpawn);
    if(entityToSpawn instanceof EntityLiving) {
        ((EntityLiving)entityToSpawn).playLivingSound();
        ((EntityLiving)entityToSpawn).setHealth(item.stackTagCompound.getCompoundTag("entity").getFloat("health"));
    }

    Entity riddenByEntity = entityToSpawn.riddenByEntity;
    while(riddenByEntity != null) {
        riddenByEntity.setLocationAndAngles(spawnX, spawnY, spawnZ, world.rand.nextFloat() * 360.0F, 0.0F);
        world.spawnEntityInWorld(riddenByEntity);
        if(riddenByEntity instanceof EntityLiving) {
            ((EntityLiving)riddenByEntity).playLivingSound();
        }
        riddenByEntity = riddenByEntity.riddenByEntity;
    }
    item.setTagCompound(null);
    player.setCurrentItemOrArmor(0, item);
    return true;
}
 
Example 11
Project: minecraft-quiverbow   File: Entity_AA.java   View Source Code Vote up 4 votes
@Override
public boolean interact(EntityPlayer player)
   {
	if (this.worldObj.isRemote) { return true; }	// Client side. Doesn't have the same info, so makes a different decision. Ugh.
													// They'll just shoot when trying to equip this with a weapon
	if (!player.getDisplayName().equals(this.ownerName)) { return false; }	// Not the owner, so not doing this
	
	ItemStack itemstack = player.inventory.getCurrentItem();
	
	// Isn't holding anything
	if (itemstack == null) 
	{
		if (player.isSneaking())	// They're sneaking, so removing our weapon now
		{
			if (!this.hasFirstWeapon)	// Not holding a primary weapon, meaning I'm not holding anything right now. So folding myself up
			{
				AI_Storage.dropSelf(this);
			}
			else	// Holding a weapon, so dropping it and all ammo
			{
				AI_Storage.dropFirstWeapon(this);
				AI_Storage.dropSecondWeapon(this);
				AI_Storage.dropStoredItems(this);
			}
			
			return true;
		}
		else if (this.hasRidingUpgrade)	// Not sneaking and we have the riding upgrade, so the owner can giddy up
        {
			player.mountEntity(this);	
            return true;
        }
		
		return false; 
	}
	
	// Holding a weapon
	else if (itemstack.getItem() instanceof _WeaponBase) 
	{
		if (!player.capabilities.isCreativeMode) { player.setCurrentItemOrArmor(0, null); }	// Taking that
		
		if (this.hasWeaponUpgrade && player.isSneaking())
		{
			AI_WeaponHandler.setSecondWeapon(this, itemstack.copy());	// Equipping it in the second weapon slot, since we have that space
		}
		else	// Either not sneaking or doesn't have that weapon upgrade. Works for me
		{
			AI_WeaponHandler.setFirstWeapon(this, itemstack.copy());	// Equipping it
		}
		
		return true;
	}
	
	else if (itemstack.getItem() == Item.getItemFromBlock(Blocks.iron_block)) // Holding repair material
	{
		AI_Properties.doRepair(player, this, itemstack);
	}
	
	else if (itemstack.getItem() == Items.name_tag) // Holding a name tag
	{
		AI_Properties.applyNameTag(player, this, itemstack, true);
	}
	
	else	// Holding whatever
	{
		AI_Storage.addItem(player, this, itemstack);
		return true;
	}
	
	return false;
   }
 
Example 12
Project: minecraft-quiverbow   File: AI_Storage.java   View Source Code Vote up 4 votes
public static void addItem(EntityPlayer player, Entity_AA turret, ItemStack playerStack)
{
	int slot = 0;
	
	while (slot < turret.storage.length)
	{
		if (turret.storage[slot] == null)	// That spot is free
		{
			turret.storage[slot] = playerStack.copy();	// Stored
			if (!player.capabilities.isCreativeMode) { player.setCurrentItemOrArmor(0, null); }	// Empty
			
			if (playerStack.getItem() == Items.writable_book && AI_Targeting.isNameOnWhitelist(turret, Commands.cmdStayStationary))
			{
				//System.out.println("[ARMS ASSISTANT] Received a book with STAY command. Setting target position");
				turret.stationaryX = turret.posX;
				turret.stationaryY = turret.posY;
				turret.stationaryZ = turret.posZ;
			}
			
			// Informing the client about this change
			NetHelper.sendTurretInventoryMessageToPlayersInRange(turret.worldObj, turret, 
					Item.getIdFromItem(turret.storage[slot].getItem()), slot, turret.storage[slot].getItemDamage());
			
			return;	// We're done here
		}
		// else, there's something in there
		
		slot += 1;
	}
	
	// No free spot found. What about existing ones?
	slot = 0;
	
	while (slot < turret.storage.length)
	{
		if (turret.storage[slot] != null)
		{				
			boolean skip = false;
			
			if (!(turret.storage[slot].getItem() instanceof _AmmoBase)) { skip = true; }	// Not ammunition, hm?
			
			if (turret.storage[slot].getItemDamage() < turret.storage[slot].getMaxDamage()) { skip = true; }	// Not empty
			
			if (!skip)
			{					
				// Has an empty magazine in there, so replacing that now
				dropSingleItem(turret, turret.storage[slot].copy());
				turret.storage[slot] = playerStack.copy();	// Stored
				
				if (!player.capabilities.isCreativeMode) { player.setCurrentItemOrArmor(0, null); }	// Empty
				
				// Informing the client about this change
				NetHelper.sendTurretInventoryMessageToPlayersInRange(turret.worldObj, turret, 
						Item.getIdFromItem(turret.storage[slot].getItem()), slot, turret.storage[slot].getItemDamage());
				return;
			}
			// else, not a magazine
		}
		// else, no free spot found but this is null? Da fuq?
		
		slot += 1;
	}
}