BloodMagic/src/main/java/WayofTime/alchemicalWizardry/common/items/sigil/SigilCompress.java

143 lines
4.6 KiB
Java
Raw Normal View History

package WayofTime.alchemicalWizardry.common.items.sigil;
import java.util.List;
2015-05-18 18:33:23 -04:00
import WayofTime.alchemicalWizardry.api.items.interfaces.ISigil;
import net.minecraft.entity.Entity;
2014-11-20 08:27:53 -05:00
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
2014-11-20 08:27:53 -05:00
import WayofTime.alchemicalWizardry.api.compress.CompressionRegistry;
import WayofTime.alchemicalWizardry.api.items.interfaces.ArmourUpgrade;
import WayofTime.alchemicalWizardry.api.items.interfaces.IHolding;
2015-07-30 17:24:20 -04:00
import WayofTime.alchemicalWizardry.common.items.BindableItems;
2015-07-31 11:35:05 -04:00
public class SigilCompress extends SigilToggleable implements IHolding, ArmourUpgrade, ISigil
{
2015-07-31 11:35:05 -04:00
public SigilCompress()
{
super();
2014-11-20 10:19:45 -05:00
setEnergyUsed(200);
}
@Override
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
{
par3List.add(StatCollector.translateToLocal("tooltip.packratsigil.desc"));
2015-01-16 10:00:50 -05:00
if (!(par1ItemStack.getTagCompound() == null))
{
2015-07-31 11:35:05 -04:00
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)
{
2015-07-30 17:24:20 -04:00
if (!BindableItems.checkAndSetItemOwner(par1ItemStack, par3EntityPlayer) || par3EntityPlayer.isSneaking())
{
return par1ItemStack;
}
2015-01-16 10:00:50 -05:00
if (par1ItemStack.getTagCompound() == null)
{
par1ItemStack.setTagCompound(new NBTTagCompound());
}
2015-01-16 10:00:50 -05:00
NBTTagCompound tag = par1ItemStack.getTagCompound();
2015-07-31 11:35:05 -04:00
this.setActivated(par1ItemStack, !(this.getActivated(par1ItemStack)));
2015-07-31 11:35:05 -04:00
if (this.getActivated(par1ItemStack))
{
par1ItemStack.setItemDamage(1);
tag.setInteger("worldTimeDelay", (int) (par2World.getWorldTime() - 1) % 200);
if (!par3EntityPlayer.capabilities.isCreativeMode)
{
2015-07-30 17:24:20 -04:00
if (!BindableItems.syphonBatteries(par1ItemStack, par3EntityPlayer, getEnergyUsed()))
{
2015-07-31 11:35:05 -04:00
this.setActivated(par1ItemStack, 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) || par2World.isRemote)
{
return;
}
EntityPlayer par3EntityPlayer = (EntityPlayer) par3Entity;
2015-01-16 10:00:50 -05:00
if (par1ItemStack.getTagCompound() == null)
{
par1ItemStack.setTagCompound(new NBTTagCompound());
}
2015-07-31 11:35:05 -04:00
if (this.getActivated(par1ItemStack))
{
2014-11-20 10:19:45 -05:00
ItemStack stack = CompressionRegistry.compressInventory(par3EntityPlayer.inventory.mainInventory, par2World);
if(stack != null)
{
EntityItem entityItem = new EntityItem(par2World, par3EntityPlayer.posX, par3EntityPlayer.posY, par3EntityPlayer.posZ, stack);
par2World.spawnEntityInWorld(entityItem);
}
}
2015-07-31 11:35:05 -04:00
if (par2World.getWorldTime() % 200 == par1ItemStack.getTagCompound().getInteger("worldTimeDelay") && this.getActivated(par1ItemStack))
{
if (!par3EntityPlayer.capabilities.isCreativeMode)
{
2015-07-30 17:24:20 -04:00
if(!BindableItems.syphonBatteries(par1ItemStack, par3EntityPlayer, getEnergyUsed()))
{
2015-07-31 11:35:05 -04:00
this.setActivated(par1ItemStack, false);
}
}
}
}
@Override
public void onArmourUpdate(World world, EntityPlayer player, ItemStack thisItemStack)
{
if(world.isRemote)
{
return;
}
2014-11-20 10:19:45 -05:00
ItemStack stack = CompressionRegistry.compressInventory(player.inventory.mainInventory, world);
if(stack != null)
{
EntityItem entityItem = new EntityItem(world, player.posX, player.posY, player.posZ, stack);
world.spawnEntityInWorld(entityItem);
}
}
@Override
public boolean isUpgrade()
{
return true;
}
@Override
public int getEnergyForTenSeconds()
{
2014-11-20 10:19:45 -05:00
return 200;
}
}