BloodMagic/BM_src/WayofTime/alchemicalWizardry/common/items/EnergyBazooka.java
2014-01-17 21:43:13 +00:00

220 lines
6.9 KiB
Java

package WayofTime.alchemicalWizardry.common.items;
import WayofTime.alchemicalWizardry.common.AlchemicalWizardry;
import WayofTime.alchemicalWizardry.common.entity.projectile.EntityEnergyBazookaMainProjectile;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.Icon;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import java.util.List;
public class EnergyBazooka extends EnergyItems
{
private static Icon activeIcon;
private static Icon passiveIcon;
private static int damage;
//private static int delay;
private static final int maxDelay = 150;
public EnergyBazooka(int id)
{
super(id);
setMaxStackSize(1);
setCreativeTab(AlchemicalWizardry.tabBloodMagic);
setFull3D();
setMaxDamage(250);
this.setEnergyUsed(20000);
damage = 12;
//delay = 0;
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister)
{
this.itemIcon = iconRegister.registerIcon("AlchemicalWizardry:EnergyBazooka_activated");
this.activeIcon = iconRegister.registerIcon("AlchemicalWizardry:EnergyBazooka_activated");
this.passiveIcon = iconRegister.registerIcon("AlchemicalWizardry:SheathedItem");
}
@Override
public Icon getIcon(ItemStack stack, int renderPass, EntityPlayer player, ItemStack usingItem, int useRemaining)
{
if (stack.stackTagCompound == null)
{
stack.setTagCompound(new NBTTagCompound());
}
NBTTagCompound tag = stack.stackTagCompound;
if (tag.getBoolean("isActive"))
{
return this.activeIcon;
} else
{
return this.passiveIcon;
}
}
@Override
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
EnergyItems.checkAndSetItemOwner(par1ItemStack, par3EntityPlayer);
if (par3EntityPlayer.isSneaking())
{
this.setActivated(par1ItemStack, !getActivated(par1ItemStack));
par1ItemStack.stackTagCompound.setInteger("worldTimeDelay", (int) (par2World.getWorldTime() - 1) % 100);
return par1ItemStack;
}
if (!getActivated(par1ItemStack))
{
return par1ItemStack;
}
if (this.getDelay(par1ItemStack) > 0)
{
return par1ItemStack;
}
if (!par3EntityPlayer.capabilities.isCreativeMode)
{
this.syphonBatteries(par1ItemStack, par3EntityPlayer, this.getEnergyUsed());
}
par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
if (!par2World.isRemote)
{
//par2World.spawnEntityInWorld(new EntityEnergyBazookaMainProjectile(par2World, par3EntityPlayer, damage));
par2World.spawnEntityInWorld(new EntityEnergyBazookaMainProjectile(par2World, par3EntityPlayer, damage));
this.setDelay(par1ItemStack, maxDelay);
}
Vec3 vec = par3EntityPlayer.getLookVec();
double wantedVelocity = 3.0f;
par3EntityPlayer.motionX = -vec.xCoord * wantedVelocity;
par3EntityPlayer.motionY = -vec.yCoord * wantedVelocity;
par3EntityPlayer.motionZ = -vec.zCoord * wantedVelocity;
par2World.playSoundEffect((double) ((float) par3EntityPlayer.posX + 0.5F), (double) ((float) par3EntityPlayer.posY + 0.5F), (double) ((float) par3EntityPlayer.posZ + 0.5F), "random.fizz", 0.5F, 2.6F + (par2World.rand.nextFloat() - par2World.rand.nextFloat()) * 0.8F);
par3EntityPlayer.fallDistance = 0;
return par1ItemStack;
}
@Override
public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5)
{
if (!(par3Entity instanceof EntityPlayer))
{
return;
}
EntityPlayer par3EntityPlayer = (EntityPlayer) par3Entity;
if (par1ItemStack.stackTagCompound == null)
{
par1ItemStack.setTagCompound(new NBTTagCompound());
}
// if(par1ItemStack.stackTagCompound.getBoolean("isActive"))
// {
// EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, 1);
// }
int delay = this.getDelay(par1ItemStack);
if (!par2World.isRemote && delay > 0)
{
this.setDelay(par1ItemStack, delay - 1);
}
if (par2World.getWorldTime() % 100 == par1ItemStack.stackTagCompound.getInteger("worldTimeDelay") && par1ItemStack.stackTagCompound.getBoolean("isActive"))
{
if (!par3EntityPlayer.capabilities.isCreativeMode)
{
EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, 50);
}
}
par1ItemStack.setItemDamage(0);
return;
}
@Override
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
{
par3List.add("Boom.");
if (!(par1ItemStack.stackTagCompound == null))
{
if (par1ItemStack.stackTagCompound.getBoolean("isActive"))
{
par3List.add("Activated");
} else
{
par3List.add("Deactivated");
}
if (!par1ItemStack.stackTagCompound.getString("ownerName").equals(""))
{
par3List.add("Current owner: " + par1ItemStack.stackTagCompound.getString("ownerName"));
}
}
}
public void setActivated(ItemStack par1ItemStack, boolean newActivated)
{
NBTTagCompound itemTag = par1ItemStack.stackTagCompound;
if (itemTag == null)
{
par1ItemStack.setTagCompound(new NBTTagCompound());
}
itemTag.setBoolean("isActive", newActivated);
}
public boolean getActivated(ItemStack par1ItemStack)
{
NBTTagCompound itemTag = par1ItemStack.stackTagCompound;
if (itemTag == null)
{
par1ItemStack.setTagCompound(new NBTTagCompound());
}
return itemTag.getBoolean("isActive");
}
public void setDelay(ItemStack par1ItemStack, int newDelay)
{
NBTTagCompound itemTag = par1ItemStack.stackTagCompound;
if (itemTag == null)
{
par1ItemStack.setTagCompound(new NBTTagCompound());
}
itemTag.setInteger("delay", newDelay);
}
public int getDelay(ItemStack par1ItemStack)
{
NBTTagCompound itemTag = par1ItemStack.stackTagCompound;
if (itemTag == null)
{
par1ItemStack.setTagCompound(new NBTTagCompound());
}
return itemTag.getInteger("delay");
}
}