BiomesOPlenty/common/biomesoplenty/items/ItemJarEmpty.java

123 lines
4 KiB
Java
Raw Normal View History

2013-11-15 02:56:00 +00:00
package biomesoplenty.items;
import net.minecraft.client.renderer.texture.IconRegister;
2013-11-17 05:50:30 +00:00
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
2013-11-15 02:56:00 +00:00
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
2013-11-16 01:46:21 +00:00
import net.minecraft.util.EnumMovingObjectType;
import net.minecraft.util.MovingObjectPosition;
2013-11-15 02:56:00 +00:00
import net.minecraft.world.World;
2013-11-17 05:50:30 +00:00
import net.minecraftforge.common.FakePlayer;
2013-11-15 02:56:00 +00:00
import biomesoplenty.BiomesOPlenty;
2013-11-16 01:46:21 +00:00
import biomesoplenty.api.Fluids;
import biomesoplenty.api.Items;
2013-11-17 05:50:30 +00:00
import biomesoplenty.entities.EntityPixie;
2013-11-15 02:56:00 +00:00
public class ItemJarEmpty extends Item
{
public ItemJarEmpty(int par1)
{
super(par1);
setCreativeTab(BiomesOPlenty.tabBiomesOPlenty);
}
@Override
public void registerIcons(IconRegister iconRegister)
{
itemIcon = iconRegister.registerIcon("biomesoplenty:jarempty");
}
2013-11-16 01:46:21 +00:00
/**
* 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)
{
MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, true);
if (movingobjectposition == null)
{
return par1ItemStack;
}
else
{
if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE)
{
int i = movingobjectposition.blockX;
int j = movingobjectposition.blockY;
int k = movingobjectposition.blockZ;
if (!par2World.canMineBlock(par3EntityPlayer, i, j, k))
{
return par1ItemStack;
}
if (!par3EntityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, par1ItemStack))
{
return par1ItemStack;
}
if (par2World.getBlockId(i, j, k) == Fluids.honey.get().blockID && par2World.getBlockMetadata(i, j, k) == 7)
{
--par1ItemStack.stackSize;
par2World.setBlockToAir(i, j, k);
if (par1ItemStack.stackSize <= 0)
{
return new ItemStack(Items.jarFilled.get(), 1, 0);
}
if (!par3EntityPlayer.inventory.addItemStackToInventory(new ItemStack(Items.jarFilled.get(), 1, 0)))
{
par3EntityPlayer.dropPlayerItem(new ItemStack(Items.jarFilled.get(), 1, 0));
}
}
}
return par1ItemStack;
}
}
2013-11-17 05:50:30 +00:00
/**
* Returns true if the item can be used on the given entity, e.g. shears on sheep.
*/
public boolean itemInteractionForEntity(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, EntityLivingBase par3EntityLivingBase)
{
if (par3EntityLivingBase instanceof EntityPixie)
{
EntityPixie entitypixie = (EntityPixie)par3EntityLivingBase;
entitypixie.setDead();
--par1ItemStack.stackSize;
if (par2EntityPlayer.inventory.getFirstEmptyStack() >= 0)
{
EntityItem entityitem = new EntityItem(par2EntityPlayer.worldObj, par2EntityPlayer.posX, par2EntityPlayer.posY, par2EntityPlayer.posZ, new ItemStack(Items.jarFilled.get(), 1, 2));
if (!par2EntityPlayer.worldObj.isRemote)
{
par2EntityPlayer.worldObj.spawnEntityInWorld(entityitem);
if (!(par2EntityPlayer instanceof FakePlayer))
{
entityitem.onCollideWithPlayer(par2EntityPlayer);
}
}
}
else
{
par2EntityPlayer.dropPlayerItem(new ItemStack(Items.jarFilled.get(), 1, 2));
}
return true;
}
else
{
return false;
}
}
2013-11-15 02:56:00 +00:00
}