2013-04-17 02:48:49 +02:00
package StevenDimDoors.mod_pocketDim.items ;
2013-02-18 03:46:16 +01:00
import java.util.List ;
2013-06-14 01:01:54 +02:00
import StevenDimDoors.mod_pocketDim.DDProperties ;
2013-04-17 02:48:49 +02:00
import StevenDimDoors.mod_pocketDim.mod_pocketDim ;
2013-08-23 10:12:56 +02:00
import StevenDimDoors.mod_pocketDim.core.NewLinkData ;
2013-08-29 08:14:24 +02:00
import StevenDimDoors.mod_pocketDim.core.PocketManager ;
2013-04-17 02:48:49 +02:00
2013-02-18 03:46:16 +01:00
import net.minecraft.block.Block ;
import net.minecraft.block.material.Material ;
2013-03-29 23:19:27 +01:00
import net.minecraft.client.renderer.texture.IconRegister ;
2013-02-18 03:46:16 +01:00
import net.minecraft.creativetab.CreativeTabs ;
import net.minecraft.entity.player.EntityPlayer ;
import net.minecraft.item.Item ;
import net.minecraft.item.ItemStack ;
2013-04-07 06:37:13 +02:00
import net.minecraft.nbt.NBTTagCompound ;
2013-02-18 03:46:16 +01:00
import net.minecraft.world.World ;
import cpw.mods.fml.relauncher.Side ;
import cpw.mods.fml.relauncher.SideOnly ;
2013-04-17 02:48:49 +02:00
public class ItemStabilizedRiftSignature extends itemLinkSignature
2013-02-18 03:46:16 +01:00
{
2013-06-14 01:01:54 +02:00
private static DDProperties properties = null ;
2013-04-17 02:48:49 +02:00
public ItemStabilizedRiftSignature ( int par )
2013-02-18 03:46:16 +01:00
{
2013-04-17 02:48:49 +02:00
super ( par ) ;
2013-02-18 03:46:16 +01:00
this . setMaxStackSize ( 1 ) ;
2013-07-13 20:13:01 +02:00
this . setCreativeTab ( mod_pocketDim . dimDoorsCreativeTab ) ;
2013-02-18 03:46:16 +01:00
this . setMaxDamage ( 0 ) ;
2013-07-13 20:13:01 +02:00
this . hasSubtypes = true ;
2013-06-14 01:01:54 +02:00
if ( properties = = null )
properties = DDProperties . instance ( ) ;
2013-02-18 03:46:16 +01:00
}
@SideOnly ( Side . CLIENT )
@Override
public boolean hasEffect ( ItemStack par1ItemStack )
{
// adds effect if item has a link stored
2013-04-07 06:37:13 +02:00
if ( par1ItemStack . hasTagCompound ( ) )
2013-02-18 03:46:16 +01:00
{
2013-04-07 06:37:13 +02:00
if ( par1ItemStack . stackTagCompound . getBoolean ( " isCreated " ) )
{
2013-02-18 03:46:16 +01:00
return true ;
2013-04-07 06:37:13 +02:00
}
2013-02-18 03:46:16 +01:00
}
2013-07-13 20:13:01 +02:00
return false ;
2013-02-18 03:46:16 +01:00
}
2013-03-29 23:19:27 +01:00
public void registerIcons ( IconRegister par1IconRegister )
{
2013-05-09 23:16:27 +02:00
this . itemIcon = par1IconRegister . registerIcon ( mod_pocketDim . modid + " : " + this . getUnlocalizedName ( ) . replace ( " item. " , " " ) ) ;
2013-03-29 23:19:27 +01:00
}
2013-02-18 03:46:16 +01:00
@Override
public boolean onItemUse ( ItemStack par1ItemStack , EntityPlayer par2EntityPlayer , World par3World , int par4 , int par5 , int par6 , int par7 , float par8 , float par9 , float par10 )
{
int key ;
2013-08-23 10:12:56 +02:00
NewLinkData linkData ;
2013-02-18 03:46:16 +01:00
int thisWorldID = par3World . provider . dimensionId ;
2013-07-13 20:13:01 +02:00
Integer [ ] linkCoords = this . readFromNBT ( par1ItemStack ) ;
2013-02-18 03:46:16 +01:00
2013-07-13 20:13:01 +02:00
int offset = 2 ;
if ( par1ItemStack . getTagCompound ( ) ! = null )
{
2013-04-07 06:37:13 +02:00
if ( par1ItemStack . getTagCompound ( ) . getBoolean ( " isCreated " ) )
2013-02-18 03:46:16 +01:00
{
2013-04-17 02:48:49 +02:00
boolean hasEnder = false ;
2013-07-13 20:13:01 +02:00
// checks to see if the item has a link stored, if so, it creates it
2013-06-14 01:01:54 +02:00
if ( par2EntityPlayer . inventory . hasItem ( Item . enderPearl . itemID ) | | par2EntityPlayer . inventory . hasItem ( properties . StableFabricItemID ) )
2013-04-17 02:48:49 +02:00
{
2013-06-14 01:01:54 +02:00
if ( ! par2EntityPlayer . inventory . consumeInventoryItem ( properties . StableFabricItemID ) )
2013-05-31 08:17:05 +02:00
{
par2EntityPlayer . inventory . consumeInventoryItem ( Item . enderPearl . itemID ) ;
}
2013-04-17 02:48:49 +02:00
hasEnder = true ;
2013-07-13 20:13:01 +02:00
}
2013-02-18 03:46:16 +01:00
if ( par3World . getBlockId ( par4 , par5 , par6 ) = = Block . snow . blockID )
{
offset = 1 ;
}
2013-04-17 02:48:49 +02:00
if ( hasEnder & & ! par3World . isRemote )
{
2013-08-29 08:14:24 +02:00
if ( PocketManager . instance . getLinkDataFromCoords ( linkCoords [ 0 ] , linkCoords [ 1 ] , linkCoords [ 2 ] , par3World ) = = null )
2013-04-17 21:59:15 +02:00
{
2013-08-29 08:14:24 +02:00
PocketManager . instance . createLink ( linkCoords [ 3 ] , par3World . provider . dimensionId , linkCoords [ 0 ] , linkCoords [ 1 ] , linkCoords [ 2 ] , par4 , par5 + offset , par6 ) ;
2013-04-17 21:59:15 +02:00
}
2013-08-29 08:14:24 +02:00
PocketManager . instance . createLink ( par3World . provider . dimensionId , linkCoords [ 3 ] , par4 , par5 + offset , par6 , linkCoords [ 0 ] , linkCoords [ 1 ] , linkCoords [ 2 ] ) ;
2013-07-15 08:45:25 +02:00
par2EntityPlayer . worldObj . playSoundAtEntity ( par2EntityPlayer , " mods.DimDoors.sfx.riftEnd " , ( float ) . 6 , 1 ) ;
2013-04-17 02:48:49 +02:00
par2EntityPlayer . sendChatToPlayer ( " Rift Created " ) ;
}
else if ( ! par3World . isRemote )
2013-02-18 03:46:16 +01:00
{
2013-04-17 02:48:49 +02:00
par2EntityPlayer . sendChatToPlayer ( " No Ender Pearls! " ) ;
}
2013-02-18 03:46:16 +01:00
}
2013-07-13 20:13:01 +02:00
}
else if ( ! par3World . isRemote )
{
if ( par3World . getBlockId ( par4 , par5 , par6 ) = = Block . snow . blockID )
{
offset = 1 ;
}
//otherwise, it creates the first half of the link. Next click will complete it.
2013-08-29 08:14:24 +02:00
key = PocketManager . instance . createUniqueInterDimLinkKey ( ) ;
2013-07-13 20:13:01 +02:00
this . writeToNBT ( par1ItemStack , par4 , par5 + offset , par6 , par3World . provider . dimensionId ) ;
2013-07-15 08:45:25 +02:00
par2EntityPlayer . worldObj . playSoundAtEntity ( par2EntityPlayer , " mods.DimDoors.sfx.riftStart " , ( float ) . 6 , 1 ) ;
2013-07-13 20:13:01 +02:00
par2EntityPlayer . sendChatToPlayer ( " Rift Signature Stored " ) ;
}
return true ;
2013-02-18 03:46:16 +01:00
}
@SideOnly ( Side . CLIENT )
/ * *
* allows items to add custom lines of information to the mouseover description
* /
public void addInformation ( ItemStack par1ItemStack , EntityPlayer par2EntityPlayer , List par3List , boolean par4 )
{
2013-04-07 06:37:13 +02:00
if ( par1ItemStack . hasTagCompound ( ) )
2013-02-18 03:46:16 +01:00
{
2013-04-07 06:37:13 +02:00
if ( par1ItemStack . stackTagCompound . getBoolean ( " isCreated " ) )
{
Integer [ ] coords = this . readFromNBT ( par1ItemStack ) ;
2013-08-29 08:14:24 +02:00
par3List . add ( String . valueOf ( " Leads to dim " + coords [ 3 ] + " with depth " + PocketManager . instance . getDimDepth ( PocketManager . instance . getDimDepth ( coords [ 3 ] ) ) ) ) ;
2013-04-14 03:15:06 +02:00
par3List . add ( " at x= " + coords [ 0 ] + " y= " + coords [ 1 ] + " z= " + coords [ 2 ] ) ;
2013-04-07 06:37:13 +02:00
}
2013-02-18 03:46:16 +01:00
}
else
{
par3List . add ( " First click stores location, " ) ;
par3List . add ( " second click creates two rifts, " ) ;
par3List . add ( " that link the first location " ) ;
par3List . add ( " with the second location " ) ;
}
}
2013-04-07 06:37:13 +02:00
public void writeToNBT ( ItemStack itemStack , int x , int y , int z , int dimID )
{
2013-07-13 20:13:01 +02:00
NBTTagCompound tag ;
2013-04-07 06:37:13 +02:00
2013-07-13 20:13:01 +02:00
if ( itemStack . hasTagCompound ( ) )
{
tag = itemStack . getTagCompound ( ) ;
}
else
{
tag = new NBTTagCompound ( ) ;
}
tag . setInteger ( " linkX " , x ) ;
tag . setInteger ( " linkY " , y ) ;
tag . setInteger ( " linkZ " , z ) ;
tag . setInteger ( " linkDimID " , dimID ) ;
tag . setBoolean ( " isCreated " , true ) ;
itemStack . setTagCompound ( tag ) ;
2013-04-07 06:37:13 +02:00
}
/ * *
* Read the stack fields from a NBT object .
* /
public Integer [ ] readFromNBT ( ItemStack itemStack )
2013-07-13 20:13:01 +02:00
{
2013-04-07 06:37:13 +02:00
NBTTagCompound tag ;
Integer [ ] linkCoords = new Integer [ 5 ] ;
if ( itemStack . hasTagCompound ( ) )
{
tag = itemStack . getTagCompound ( ) ;
if ( ! tag . getBoolean ( " isCreated " ) )
{
return null ;
}
linkCoords [ 0 ] = tag . getInteger ( " linkX " ) ;
linkCoords [ 1 ] = tag . getInteger ( " linkY " ) ;
linkCoords [ 2 ] = tag . getInteger ( " linkZ " ) ;
linkCoords [ 3 ] = tag . getInteger ( " linkDimID " ) ;
}
2013-07-13 20:13:01 +02:00
return linkCoords ;
2013-04-07 06:37:13 +02:00
}
2013-02-18 03:46:16 +01:00
@Override
public void onCreated ( ItemStack par1ItemStack , World par2World , EntityPlayer par3EntityPlayer )
{
if ( ! par2World . isRemote )
{
/ * *
//creates the first half of the link on item creation
int key = dimHelper . instance . createUniqueInterDimLinkKey ( ) ;
LinkData linkData = new LinkData ( par2World . provider . dimensionId , MathHelper . floor_double ( par3EntityPlayer . posX ) , MathHelper . floor_double ( par3EntityPlayer . posY ) , MathHelper . floor_double ( par3EntityPlayer . posZ ) ) ;
System . out . println ( key ) ;
dimHelper . instance . interDimLinkList . put ( key , linkData ) ;
par1ItemStack . setItemDamage ( key ) ;
* * /
}
}
}