2013-07-26 21:18:53 -07:00
|
|
|
package tconstruct.items.tools;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
2013-12-31 11:26:08 -05:00
|
|
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
2014-01-10 21:14:54 -05:00
|
|
|
import net.minecraft.init.Items;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.item.EnumAction;
|
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2013-12-31 11:26:08 -05:00
|
|
|
import net.minecraft.util.IIcon;
|
2013-11-25 14:08:18 -05:00
|
|
|
import net.minecraft.util.StatCollector;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.world.World;
|
2014-02-05 10:28:54 -05:00
|
|
|
import tconstruct.entity.projectile.LaunchedPotion;
|
2013-07-26 21:18:53 -07:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
|
|
|
|
|
public class PotionLauncher extends Item
|
|
|
|
|
{
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
2013-12-31 11:26:08 -05:00
|
|
|
private IIcon[] icons;
|
2013-07-26 21:18:53 -07:00
|
|
|
public static final String[] textureNames = new String[] { "potionlauncher" };
|
|
|
|
|
|
2013-12-31 11:26:08 -05:00
|
|
|
public PotionLauncher()
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2013-12-31 11:26:08 -05:00
|
|
|
super();
|
2013-07-26 21:18:53 -07:00
|
|
|
this.maxStackSize = 1;
|
|
|
|
|
this.setCreativeTab(CreativeTabs.tabCombat);
|
|
|
|
|
this.setMaxDamage(3);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-17 00:31:43 -05:00
|
|
|
@Override
|
2013-07-26 21:18:53 -07:00
|
|
|
public ItemStack onEaten (ItemStack stack, World world, EntityPlayer player)
|
|
|
|
|
{
|
|
|
|
|
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
|
|
|
|
boolean loaded = tags.getBoolean("Loaded");
|
|
|
|
|
if (!loaded)
|
|
|
|
|
{
|
2014-01-10 21:14:54 -05:00
|
|
|
int slotID = getInventorySlotContainItem(Items.potionitem, player.inventory);
|
2013-07-26 21:18:53 -07:00
|
|
|
ItemStack potion = player.inventory.getStackInSlot(slotID);
|
|
|
|
|
|
|
|
|
|
NBTTagCompound potionTag = new NBTTagCompound();
|
|
|
|
|
potion.writeToNBT(potionTag);
|
2013-12-31 16:37:46 -05:00
|
|
|
tags.setTag("LoadedPotion", potionTag);
|
2013-07-26 21:18:53 -07:00
|
|
|
tags.setBoolean("Loaded", true);
|
|
|
|
|
|
|
|
|
|
if (!player.capabilities.isCreativeMode)
|
|
|
|
|
{
|
|
|
|
|
potion.stackSize--;
|
|
|
|
|
if (potion.stackSize < 1)
|
|
|
|
|
player.inventory.setInventorySlotContents(slotID, null);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-28 19:56:01 -07:00
|
|
|
world.playSoundEffect(player.posX, player.posY, player.posZ, "tinker:launcher_clank", 1.0F, (world.rand.nextFloat() - world.rand.nextFloat()) * 0.15F + 1.0F);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
return stack;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-17 00:31:43 -05:00
|
|
|
@Override
|
2013-07-26 21:18:53 -07:00
|
|
|
public void onPlayerStoppedUsing (ItemStack stack, World world, EntityPlayer player, int time)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-17 00:31:43 -05:00
|
|
|
@Override
|
2013-07-26 21:18:53 -07:00
|
|
|
public ItemStack onItemRightClick (ItemStack stack, World world, EntityPlayer player)
|
|
|
|
|
{
|
|
|
|
|
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
2014-01-10 21:14:54 -05:00
|
|
|
int slotID = getInventorySlotContainItem(Items.potionitem, player.inventory);
|
2013-07-26 21:18:53 -07:00
|
|
|
if (!tags.getBoolean("Loaded") && slotID >= 0)
|
|
|
|
|
player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
|
|
|
|
|
return stack;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* How long it takes to use or consume an item
|
|
|
|
|
*/
|
2014-02-17 00:31:43 -05:00
|
|
|
@Override
|
2013-07-26 21:18:53 -07:00
|
|
|
public int getMaxItemUseDuration (ItemStack stack)
|
|
|
|
|
{
|
|
|
|
|
return 30;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-02-16 14:23:50 -05:00
|
|
|
* returns the action that specifies what animation to play when the items
|
|
|
|
|
* is being used
|
2013-07-26 21:18:53 -07:00
|
|
|
*/
|
2014-02-17 00:31:43 -05:00
|
|
|
@Override
|
2013-07-26 21:18:53 -07:00
|
|
|
public EnumAction getItemUseAction (ItemStack stack)
|
|
|
|
|
{
|
|
|
|
|
if (!stack.getTagCompound().getCompoundTag("InfiTool").getBoolean("Loaded"))
|
|
|
|
|
return EnumAction.bow;
|
|
|
|
|
else
|
|
|
|
|
return EnumAction.none;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-17 00:31:43 -05:00
|
|
|
@Override
|
2013-07-26 21:18:53 -07:00
|
|
|
@SideOnly(Side.CLIENT)
|
2013-12-31 11:26:08 -05:00
|
|
|
public void registerIcons (IIconRegister par1IconRegister)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2013-12-31 11:26:08 -05:00
|
|
|
this.icons = new IIcon[textureNames.length];
|
2013-07-26 21:18:53 -07:00
|
|
|
|
|
|
|
|
for (int i = 0; i < this.icons.length; ++i)
|
|
|
|
|
{
|
|
|
|
|
this.icons[i] = par1IconRegister.registerIcon("tinker:" + textureNames[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-17 00:31:43 -05:00
|
|
|
@Override
|
2013-07-26 21:18:53 -07:00
|
|
|
@SideOnly(Side.CLIENT)
|
2013-12-31 14:11:05 -05:00
|
|
|
public IIcon getIconFromDamage (int meta)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
return icons[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-02-05 08:28:53 -05:00
|
|
|
public void getSubItems (Item b, CreativeTabs tabs, List list)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2013-12-31 11:26:08 -05:00
|
|
|
ItemStack stack = new ItemStack(b, 1, 0);
|
2013-07-26 21:18:53 -07:00
|
|
|
NBTTagCompound compound = new NBTTagCompound();
|
|
|
|
|
NBTTagCompound tags = new NBTTagCompound();
|
2013-12-31 16:37:46 -05:00
|
|
|
compound.setTag("InfiTool", tags);
|
2013-07-26 21:18:53 -07:00
|
|
|
|
|
|
|
|
tags.setBoolean("Loaded", false);
|
|
|
|
|
|
|
|
|
|
stack.setTagCompound(compound);
|
|
|
|
|
|
|
|
|
|
list.add(stack);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onEntitySwing (EntityLivingBase player, ItemStack stack)
|
|
|
|
|
{
|
2014-03-28 01:37:13 -04:00
|
|
|
if (stack != null && stack.hasTagCompound())
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-03-28 01:37:13 -04:00
|
|
|
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
|
|
|
|
if (tags.getBoolean("Loaded"))
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-03-28 01:37:13 -04:00
|
|
|
NBTTagCompound potionTag = tags.getCompoundTag("LoadedPotion");
|
|
|
|
|
ItemStack potion = ItemStack.loadItemStackFromNBT(potionTag);// findPotion(player);InventoryLogic
|
|
|
|
|
if (potion != null)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-03-28 01:37:13 -04:00
|
|
|
World world = player.worldObj;
|
|
|
|
|
world.playSoundAtEntity(player, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
|
|
|
|
|
|
|
|
|
|
if (!world.isRemote)
|
|
|
|
|
{
|
|
|
|
|
world.spawnEntityInWorld(new LaunchedPotion(world, player, potion));
|
|
|
|
|
}
|
|
|
|
|
tags.removeTag("LoadedPotion");
|
|
|
|
|
tags.setBoolean("Loaded", false);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
2014-03-28 01:37:13 -04:00
|
|
|
return true;
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ItemStack findPotion (EntityLivingBase living)
|
|
|
|
|
{
|
|
|
|
|
if (living instanceof EntityPlayer)
|
|
|
|
|
{
|
|
|
|
|
EntityPlayer player = (EntityPlayer) living;
|
2014-01-10 21:14:54 -05:00
|
|
|
int potionSlot = getInventorySlotContainItem(Items.potionitem, player.inventory);
|
2013-07-26 21:18:53 -07:00
|
|
|
if (potionSlot >= 0)
|
|
|
|
|
{
|
|
|
|
|
return player.inventory.getStackInSlot(potionSlot);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-10 21:14:54 -05:00
|
|
|
int getInventorySlotContainItem (Item item, InventoryPlayer inventory)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
for (int j = 0; j < inventory.mainInventory.length; ++j)
|
|
|
|
|
{
|
2014-01-10 21:14:54 -05:00
|
|
|
if (inventory.mainInventory[j] != null && inventory.mainInventory[j].getItem() == item)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
return j;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
public void addInformation (ItemStack stack, EntityPlayer player, List list, boolean par4)
|
|
|
|
|
{
|
2013-11-25 14:08:18 -05:00
|
|
|
list.add(StatCollector.translateToLocal("potionlauncher.tooltip"));
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|