BloodMagic/src/main/java/WayofTime/alchemicalWizardry/common/items/sigil/SigilOfWind.java
2015-07-31 11:35:05 -04:00

127 lines
4.2 KiB
Java

package WayofTime.alchemicalWizardry.common.items.sigil;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import WayofTime.alchemicalWizardry.AlchemicalWizardry;
import WayofTime.alchemicalWizardry.api.items.interfaces.ArmourUpgrade;
import WayofTime.alchemicalWizardry.api.items.interfaces.ISigil;
import WayofTime.alchemicalWizardry.common.items.BindableItems;
public class SigilOfWind extends SigilToggleable implements ArmourUpgrade, ISigil
{
public SigilOfWind()
{
super();
setEnergyUsed(250);
}
@Override
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
{
par3List.add(StatCollector.translateToLocal("tooltip.sigilofwind.desc"));
if (!(par1ItemStack.getTagCompound() == null))
{
if (this.getActivated(par1ItemStack))
{
par3List.add(StatCollector.translateToLocal("tooltip.sigil.state.activated"));
} else
{
par3List.add(StatCollector.translateToLocal("tooltip.sigil.state.deactivated"));
}
par3List.add(StatCollector.translateToLocal("tooltip.owner.currentowner") + " " + par1ItemStack.getTagCompound().getString("ownerName"));
}
}
@Override
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
if (!BindableItems.checkAndSetItemOwner(par1ItemStack, par3EntityPlayer) || par3EntityPlayer.isSneaking())
{
return par1ItemStack;
}
if (par1ItemStack.getTagCompound() == null)
{
par1ItemStack.setTagCompound(new NBTTagCompound());
}
NBTTagCompound tag = par1ItemStack.getTagCompound();
this.setActivated(par1ItemStack, !(this.getActivated(par1ItemStack)));
if (this.getActivated(par1ItemStack) && BindableItems.syphonBatteries(par1ItemStack, par3EntityPlayer, getEnergyUsed()))
{
par1ItemStack.setItemDamage(1);
tag.setInteger("worldTimeDelay", (int) (par2World.getWorldTime() - 1) % 200);
par3EntityPlayer.addPotionEffect(new PotionEffect(AlchemicalWizardry.customPotionProjProt.id, 2, 1, true, false));
} else
{
par1ItemStack.setItemDamage(par1ItemStack.getMaxDamage());
}
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.getTagCompound() == null)
{
par1ItemStack.setTagCompound(new NBTTagCompound());
}
if (this.getActivated(par1ItemStack))
{
par3EntityPlayer.addPotionEffect(new PotionEffect(AlchemicalWizardry.customPotionProjProt.id, 2, 1, true, false));
}
if (par2World.getWorldTime() % 200 == par1ItemStack.getTagCompound().getInteger("worldTimeDelay") && par1ItemStack.getTagCompound().getBoolean("isActive"))
{
if (!par3EntityPlayer.capabilities.isCreativeMode)
{
if (!BindableItems.syphonBatteries(par1ItemStack, par3EntityPlayer, getEnergyUsed()))
{
this.setActivated(par1ItemStack, false);
}
}
}
}
@Override
public void onArmourUpdate(World world, EntityPlayer player, ItemStack itemStack)
{
if (itemStack.getTagCompound() == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
player.addPotionEffect(new PotionEffect(AlchemicalWizardry.customPotionProjProt.id, 3, 1, true, false));
}
@Override
public boolean isUpgrade()
{
return true;
}
@Override
public int getEnergyForTenSeconds()
{
return 150;
}
}