2014-01-17 19:12:49 +00:00
package WayofTime.alchemicalWizardry.common.items.sigil ;
2014-01-17 21:54:16 +00:00
import WayofTime.alchemicalWizardry.AlchemicalWizardry ;
2014-01-17 21:54:58 +00:00
import WayofTime.alchemicalWizardry.ModBlocks ;
2014-01-17 21:05:38 +00:00
import WayofTime.alchemicalWizardry.common.ArmourUpgrade ;
import WayofTime.alchemicalWizardry.common.items.EnergyItems ;
import cpw.mods.fml.relauncher.Side ;
import cpw.mods.fml.relauncher.SideOnly ;
2014-01-17 19:12:49 +00:00
import net.minecraft.block.Block ;
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.world.World ;
2014-01-17 21:05:38 +00:00
import java.util.List ;
2014-01-17 21:43:13 +00:00
public class SigilOfTheBridge extends EnergyItems implements ArmourUpgrade
{
2014-01-17 19:12:49 +00:00
private static Icon activeIcon ;
private static Icon passiveIcon ;
private int tickDelay = 200 ;
public SigilOfTheBridge ( int id )
{
super ( id ) ;
this . maxStackSize = 1 ;
//setMaxDamage(1000);
setEnergyUsed ( 100 ) ;
setCreativeTab ( AlchemicalWizardry . tabBloodMagic ) ;
// TODO Auto-generated constructor stub
}
@Override
public void addInformation ( ItemStack par1ItemStack , EntityPlayer par2EntityPlayer , List par3List , boolean par4 )
{
par3List . add ( " Activate to create a bridge " ) ;
par3List . add ( " beneath your feet. " ) ;
if ( ! ( par1ItemStack . stackTagCompound = = null ) )
{
if ( par1ItemStack . stackTagCompound . getBoolean ( " isActive " ) )
{
par3List . add ( " Activated " ) ;
2014-01-17 21:05:38 +00:00
} else
2014-01-17 19:12:49 +00:00
{
par3List . add ( " Deactivated " ) ;
}
par3List . add ( " Current owner: " + par1ItemStack . stackTagCompound . getString ( " ownerName " ) ) ;
}
}
@Override
@SideOnly ( Side . CLIENT )
public void registerIcons ( IconRegister iconRegister )
{
this . itemIcon = iconRegister . registerIcon ( " AlchemicalWizardry:BridgeSigil_deactivated " ) ;
this . activeIcon = iconRegister . registerIcon ( " AlchemicalWizardry:BridgeSigil_activated " ) ;
this . passiveIcon = iconRegister . registerIcon ( " AlchemicalWizardry:BridgeSigil_deactivated " ) ;
}
@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 ;
2014-01-17 21:05:38 +00:00
} else
2014-01-17 19:12:49 +00:00
{
return this . passiveIcon ;
}
}
@Override
@SideOnly ( Side . CLIENT )
public Icon getIconFromDamage ( int par1 )
{
if ( par1 = = 1 )
{
return this . activeIcon ;
2014-01-17 21:05:38 +00:00
} else
2014-01-17 19:12:49 +00:00
{
return this . passiveIcon ;
}
}
// @Override
// public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
// {
//
// if(applyBonemeal(par1ItemStack,par3World,par4,par5,par6,par2EntityPlayer))
// {
// if (par3World.isRemote)
// {
// par3World.playAuxSFX(2005, par4, par5, par6, 0);
// EnergyItems.syphonBatteries(par1ItemStack, par2EntityPlayer, getEnergyUsed());
// return true;
// }
// return true;
// }
// return false;
// }
@Override
public ItemStack onItemRightClick ( ItemStack par1ItemStack , World par2World , EntityPlayer par3EntityPlayer )
{
EnergyItems . checkAndSetItemOwner ( par1ItemStack , par3EntityPlayer ) ;
if ( par3EntityPlayer . isSneaking ( ) )
{
return par1ItemStack ;
}
if ( par1ItemStack . stackTagCompound = = null )
{
par1ItemStack . setTagCompound ( new NBTTagCompound ( ) ) ;
}
NBTTagCompound tag = par1ItemStack . stackTagCompound ;
tag . setBoolean ( " isActive " , ! ( tag . getBoolean ( " isActive " ) ) ) ;
if ( tag . getBoolean ( " isActive " ) )
{
par1ItemStack . setItemDamage ( 1 ) ;
2014-01-17 21:05:38 +00:00
tag . setInteger ( " worldTimeDelay " , ( int ) ( par2World . getWorldTime ( ) - 1 ) % tickDelay ) ;
2014-01-17 19:12:49 +00:00
if ( ! par3EntityPlayer . capabilities . isCreativeMode )
{
EnergyItems . syphonBatteries ( par1ItemStack , par3EntityPlayer , getEnergyUsed ( ) ) ;
}
2014-01-17 21:05:38 +00:00
} else
2014-01-17 19:12:49 +00:00
{
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 ;
}
2014-01-17 21:05:38 +00:00
EntityPlayer par3EntityPlayer = ( EntityPlayer ) par3Entity ;
2014-01-17 19:12:49 +00:00
if ( par1ItemStack . stackTagCompound = = null )
{
par1ItemStack . setTagCompound ( new NBTTagCompound ( ) ) ;
}
if ( par1ItemStack . stackTagCompound . getBoolean ( " isActive " ) )
{
if ( par2World . getWorldTime ( ) % tickDelay = = par1ItemStack . stackTagCompound . getInteger ( " worldTimeDelay " ) & & par3Entity instanceof EntityPlayer )
{
2014-01-17 21:05:38 +00:00
EnergyItems . syphonBatteries ( par1ItemStack , ( EntityPlayer ) par3Entity , this . getLPUsed ( par1ItemStack ) ) ;
2014-01-17 19:12:49 +00:00
this . setLPUsed ( par1ItemStack , 0 ) ;
}
// if(par2World.isRemote)
// {
// return;
// }
if ( ! par3EntityPlayer . onGround & & ! par3EntityPlayer . isSneaking ( ) )
{
return ;
}
int range = 2 ;
int verticalOffset = - 1 ;
if ( par3EntityPlayer . isSneaking ( ) )
{
verticalOffset - - ;
}
if ( par2World . isRemote )
{
verticalOffset - - ;
}
2014-01-17 21:05:38 +00:00
int posX = ( int ) Math . round ( par3Entity . posX - 0 . 5f ) ;
int posY = ( int ) par3Entity . posY ;
int posZ = ( int ) Math . round ( par3Entity . posZ - 0 . 5f ) ;
2014-01-17 19:12:49 +00:00
int incremented = 0 ;
for ( int ix = posX - range ; ix < = posX + range ; ix + + )
{
for ( int iz = posZ - range ; iz < = posZ + range ; iz + + )
{
//for(int iy=posY-verticalRange;iy<=posY+verticalRange;iy++)
{
int id = par2World . getBlockId ( ix , posY + verticalOffset , iz ) ;
Block block = Block . blocksList [ id ] ;
if ( par2World . isAirBlock ( ix , posY + verticalOffset , iz ) )
{
2014-01-17 21:05:38 +00:00
par2World . setBlock ( ix , posY + verticalOffset , iz , ModBlocks . spectralBlock . blockID , 0 , 3 ) ;
2014-01-17 19:12:49 +00:00
if ( par2World . rand . nextInt ( 2 ) = = 0 )
{
incremented + + ;
}
}
}
}
}
this . incrimentLPUSed ( par1ItemStack , incremented ) ;
}
return ;
}
public int getLPUsed ( ItemStack par1ItemStack )
{
if ( par1ItemStack . stackTagCompound = = null )
{
par1ItemStack . setTagCompound ( new NBTTagCompound ( ) ) ;
}
return par1ItemStack . stackTagCompound . getInteger ( " LPUsed " ) ;
}
public void incrimentLPUSed ( ItemStack par1ItemStack , int addedLP )
{
if ( par1ItemStack . stackTagCompound = = null )
{
par1ItemStack . setTagCompound ( new NBTTagCompound ( ) ) ;
}
par1ItemStack . stackTagCompound . setInteger ( " LPUsed " , par1ItemStack . stackTagCompound . getInteger ( " LPUsed " ) + addedLP ) ;
}
public void setLPUsed ( ItemStack par1ItemStack , int newLP )
{
if ( par1ItemStack . stackTagCompound = = null )
{
par1ItemStack . setTagCompound ( new NBTTagCompound ( ) ) ;
}
par1ItemStack . stackTagCompound . setInteger ( " LPUsed " , newLP ) ;
}
@Override
public void onArmourUpdate ( World world , EntityPlayer player , ItemStack thisItemStack )
{
if ( ! player . onGround & & ! player . isSneaking ( ) )
{
return ;
}
int range = 2 ;
int verticalOffset = - 1 ;
if ( player . isSneaking ( ) )
{
verticalOffset - - ;
}
2014-01-17 21:05:38 +00:00
int posX = ( int ) Math . round ( player . posX - 0 . 5f ) ;
int posY = ( int ) player . posY ;
int posZ = ( int ) Math . round ( player . posZ - 0 . 5f ) ;
2014-01-17 19:12:49 +00:00
//int incremented = 0;
for ( int ix = posX - range ; ix < = posX + range ; ix + + )
{
for ( int iz = posZ - range ; iz < = posZ + range ; iz + + )
{
//for(int iy=posY-verticalRange;iy<=posY+verticalRange;iy++)
{
int id = world . getBlockId ( ix , posY + verticalOffset , iz ) ;
Block block = Block . blocksList [ id ] ;
if ( world . isAirBlock ( ix , posY + verticalOffset , iz ) )
{
2014-01-17 21:05:38 +00:00
world . setBlock ( ix , posY + verticalOffset , iz , ModBlocks . spectralBlock . blockID , 0 , 3 ) ;
2014-01-17 19:12:49 +00:00
}
}
}
}
}
@Override
public boolean isUpgrade ( )
{
// TODO Auto-generated method stub
return true ;
}
@Override
public int getEnergyForTenSeconds ( )
{
// TODO Auto-generated method stub
return 100 ;
}
}