2013-07-26 21:18:53 -07:00
|
|
|
package tconstruct.items.tools;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
2023-01-28 18:04:28 -08:00
|
|
|
|
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;
|
2023-09-24 22:57:55 +02:00
|
|
|
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;
|
2023-09-24 22:57:55 +02:00
|
|
|
import net.minecraft.item.EnumAction;
|
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2023-09-24 22:57:55 +02:00
|
|
|
import net.minecraft.util.IIcon;
|
|
|
|
|
import net.minecraft.util.StatCollector;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.world.World;
|
2023-01-28 18:04:28 -08:00
|
|
|
|
2023-05-15 15:07:18 +09:00
|
|
|
import tconstruct.tools.entity.LaunchedPotion;
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2022-09-22 19:51:23 +01:00
|
|
|
public class PotionLauncher extends Item {
|
2023-01-28 18:04:28 -08:00
|
|
|
|
2013-07-26 21:18:53 -07:00
|
|
|
@SideOnly(Side.CLIENT)
|
2013-12-31 11:26:08 -05:00
|
|
|
private IIcon[] icons;
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2022-09-22 19:51:23 +01:00
|
|
|
public static final String[] textureNames = new String[] { "potionlauncher" };
|
|
|
|
|
|
|
|
|
|
public PotionLauncher() {
|
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
|
2022-09-22 19:51:23 +01:00
|
|
|
public ItemStack onEaten(ItemStack stack, World world, EntityPlayer player) {
|
2013-07-26 21:18:53 -07:00
|
|
|
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
|
|
|
|
boolean loaded = tags.getBoolean("Loaded");
|
2022-09-22 19:51:23 +01:00
|
|
|
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);
|
|
|
|
|
|
2022-09-22 19:51:23 +01:00
|
|
|
if (!player.capabilities.isCreativeMode) {
|
2013-07-26 21:18:53 -07:00
|
|
|
potion.stackSize--;
|
2022-09-22 19:51:23 +01:00
|
|
|
if (potion.stackSize < 1) player.inventory.setInventorySlotContents(slotID, null);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
2022-09-22 19:51:23 +01: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
|
2022-09-22 19:51:23 +01:00
|
|
|
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer player, int time) {}
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2014-02-17 00:31:43 -05:00
|
|
|
@Override
|
2022-09-22 19:51:23 +01:00
|
|
|
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
|
2013-07-26 21:18:53 -07:00
|
|
|
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
2014-01-10 21:14:54 -05:00
|
|
|
int slotID = getInventorySlotContainItem(Items.potionitem, player.inventory);
|
2022-09-22 19:51:23 +01:00
|
|
|
if (!tags.getBoolean("Loaded") && slotID >= 0) player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
|
2013-07-26 21:18:53 -07:00
|
|
|
return stack;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* How long it takes to use or consume an item
|
|
|
|
|
*/
|
2014-02-17 00:31:43 -05:00
|
|
|
@Override
|
2022-09-22 19:51:23 +01:00
|
|
|
public int getMaxItemUseDuration(ItemStack stack) {
|
2013-07-26 21:18:53 -07:00
|
|
|
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
|
2022-09-22 19:51:23 +01:00
|
|
|
public EnumAction getItemUseAction(ItemStack stack) {
|
|
|
|
|
if (stack != null && stack.hasTagCompound()
|
|
|
|
|
&& !stack.getTagCompound().getCompoundTag("InfiTool").getBoolean("Loaded"))
|
|
|
|
|
return EnumAction.bow;
|
|
|
|
|
else return EnumAction.none;
|
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
|
|
|
@SideOnly(Side.CLIENT)
|
2022-09-22 19:51:23 +01:00
|
|
|
public void registerIcons(IIconRegister par1IconRegister) {
|
2013-12-31 11:26:08 -05:00
|
|
|
this.icons = new IIcon[textureNames.length];
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2022-09-22 19:51:23 +01:00
|
|
|
for (int i = 0; i < this.icons.length; ++i) {
|
2013-07-26 21:18:53 -07:00
|
|
|
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)
|
2022-09-22 19:51:23 +01:00
|
|
|
public IIcon getIconFromDamage(int meta) {
|
2013-07-26 21:18:53 -07:00
|
|
|
return icons[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-09-22 19:51:23 +01:00
|
|
|
public void getSubItems(Item b, CreativeTabs tabs, List list) {
|
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
|
2022-09-22 19:51:23 +01:00
|
|
|
public boolean onEntitySwing(EntityLivingBase player, ItemStack stack) {
|
|
|
|
|
if (stack != null && stack.hasTagCompound()) {
|
2014-03-28 01:37:13 -04:00
|
|
|
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
2022-09-22 19:51:23 +01:00
|
|
|
if (tags.getBoolean("Loaded")) {
|
2014-03-28 01:37:13 -04:00
|
|
|
NBTTagCompound potionTag = tags.getCompoundTag("LoadedPotion");
|
2022-09-22 19:51:23 +01:00
|
|
|
ItemStack potion = ItemStack.loadItemStackFromNBT(potionTag); // findPotion(player);InventoryLogic
|
|
|
|
|
if (potion != null) {
|
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));
|
|
|
|
|
|
2022-09-22 19:51:23 +01:00
|
|
|
if (!world.isRemote) {
|
2014-03-28 01:37:13 -04:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-22 19:51:23 +01:00
|
|
|
ItemStack findPotion(EntityLivingBase living) {
|
|
|
|
|
if (living instanceof EntityPlayer) {
|
2013-07-26 21:18:53 -07:00
|
|
|
EntityPlayer player = (EntityPlayer) living;
|
2014-01-10 21:14:54 -05:00
|
|
|
int potionSlot = getInventorySlotContainItem(Items.potionitem, player.inventory);
|
2022-09-22 19:51:23 +01:00
|
|
|
if (potionSlot >= 0) {
|
2013-07-26 21:18:53 -07:00
|
|
|
return player.inventory.getStackInSlot(potionSlot);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-22 19:51:23 +01:00
|
|
|
int getInventorySlotContainItem(Item item, InventoryPlayer inventory) {
|
|
|
|
|
for (int j = 0; j < inventory.mainInventory.length; ++j) {
|
|
|
|
|
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)
|
2022-09-22 19:51:23 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|