BiomesOPlenty/common/biomesoplenty/items/ItemDartBlower.java

87 lines
2.5 KiB
Java
Raw Normal View History

package biomesoplenty.items;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import biomesoplenty.BiomesOPlenty;
import biomesoplenty.api.Items;
2013-07-03 07:51:39 +00:00
import biomesoplenty.entities.projectiles.EntityDart;
import biomesoplenty.entities.projectiles.EntityDart.DartType;
public class ItemDartBlower extends Item
{
2013-05-31 10:34:02 +00:00
public ItemDartBlower(int par1)
{
super(par1);
maxStackSize = 1;
2013-05-08 12:39:12 +00:00
this.setMaxDamage(63);
2013-05-31 10:34:02 +00:00
setCreativeTab(BiomesOPlenty.tabBiomesOPlenty);
}
2013-05-31 10:34:02 +00:00
@Override
public void registerIcons(IconRegister iconRegister)
{
itemIcon = iconRegister.registerIcon("biomesoplenty:dartblower");
2013-05-31 10:34:02 +00:00
}
/**
* Returns True is the item is renderer in full 3D when hold.
*/
@Override
public boolean isFull3D()
{
return true;
}
2013-05-31 10:34:02 +00:00
@Override
public ItemStack onItemRightClick(ItemStack itemStack, World par2World, EntityPlayer par3EntityPlayer)
{
boolean flag = par3EntityPlayer.capabilities.isCreativeMode;
2013-05-31 10:34:02 +00:00
if (flag || par3EntityPlayer.inventory.hasItem(Items.dart.get().itemID))
{
2013-07-02 11:30:11 +00:00
EntityDart entityDart = new EntityDart(par2World, par3EntityPlayer, 1.0F);
2013-05-31 10:34:02 +00:00
itemStack.damageItem(1, par3EntityPlayer);
par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 2.0F / (1.0F * 0.4F + 1.2F) + 1.0F * 0.5F);
int slot = -1;
if (par3EntityPlayer.inventory.hasItemStack(new ItemStack(Items.dart.get().itemID, 1, 1)))
{
entityDart.setDartType(DartType.POISON);
for (int k = 0; k < par3EntityPlayer.inventory.mainInventory.length; ++k)
if (par3EntityPlayer.inventory.mainInventory[k] != null && par3EntityPlayer.inventory.mainInventory[k].itemID == Items.dart.get().itemID && par3EntityPlayer.inventory.mainInventory[k].getItemDamage() == 1)
{
slot = k;
break;
}
}
else if (par3EntityPlayer.inventory.hasItemStack(new ItemStack(Items.dart.get().itemID, 1, 0)))
{
entityDart.setDartType(DartType.NORMAL);
for (int k = 0; k < par3EntityPlayer.inventory.mainInventory.length; ++k)
if (par3EntityPlayer.inventory.mainInventory[k] != null && par3EntityPlayer.inventory.mainInventory[k].itemID == Items.dart.get().itemID && par3EntityPlayer.inventory.mainInventory[k].getItemDamage() == 0)
{
slot = k;
break;
}
}
2013-07-02 11:30:11 +00:00
if (!par2World.isRemote)
{
2013-05-31 10:34:02 +00:00
par2World.spawnEntityInWorld(entityDart);
}
if (!flag && slot >= 0) {
par3EntityPlayer.inventory.decrStackSize(slot, 1);
}
}
return itemStack;
}
}