package JAKJ . RedstoneInMotion ;

public class TeleportativeSpectreEntity extends MotiveSpectreEntity
{
	public boolean Source ;

	public int ShiftX ;
	public int ShiftY ;
	public int ShiftZ ;

	@Override
	public void WriteCommonRecord ( net . minecraft . nbt . NBTTagCompound TagCompound )
	{
		super . WriteCommonRecord ( TagCompound ) ;

		TagCompound . setBoolean ( "Source" , Source ) ;

		TagCompound . setInteger ( "ShiftX" , ShiftX ) ;
		TagCompound . setInteger ( "ShiftY" , ShiftY ) ;
		TagCompound . setInteger ( "ShiftZ" , ShiftZ ) ;
	}

	@Override
	public void ReadCommonRecord ( net . minecraft . nbt . NBTTagCompound TagCompound )
	{
		super . ReadCommonRecord ( TagCompound ) ;

		Source = TagCompound . getBoolean ( "Source" ) ;

		ShiftX = TagCompound . getInteger ( "ShiftX" ) ;
		ShiftY = TagCompound . getInteger ( "ShiftY" ) ;
		ShiftZ = TagCompound . getInteger ( "ShiftZ" ) ;
	}

	public void AbsorbSource ( CarriagePackage Package )
	{
		Source = true ;

		MotionDirection = Directions . values ( ) [ 0 ] ;

		RenderCacheKey = Package . RenderCacheKey ;

		DriveRecord = new BlockRecord ( Package . DriveRecord ) ;

		{
			Body = new BlockRecordSet ( ) ;

			for ( BlockRecord Record : Package . Blocks )
			{
				Body . add ( new BlockRecord ( Record ) ) ;
			}
		}

		PendingBlockUpdates = new net . minecraft . nbt . NBTTagList ( ) ;
	}

	public void AbsorbSink ( CarriagePackage Package )
	{
		Absorb ( Package ) ;

		ShiftX = - DriveRecord . X + Package . Translocator . xCoord ;
		ShiftY = - DriveRecord . Y + Package . Translocator . yCoord ;
		ShiftZ = - DriveRecord . Z + Package . Translocator . zCoord ;

		DriveRecord = new BlockRecord ( Package . Translocator . xCoord , Package . Translocator . yCoord , Package . Translocator . zCoord ) ;

		MotionDirection = Directions . values ( ) [ 0 ] ;
	}

	@Override
	public void ShiftBlockPosition ( BlockRecord Record )
	{
		Record . X += ShiftX ;
		Record . Y += ShiftY ;
		Record . Z += ShiftZ ;
	}

	@Override
	public void ShiftPipeItemPosition ( Object Position ) throws Throwable
	{
		ModInteraction . BC_Position_x . set ( Position , ( ( Double ) ModInteraction . BC_Position_x . get ( Position ) ) + ShiftX ) ;
		ModInteraction . BC_Position_y . set ( Position , ( ( Double ) ModInteraction . BC_Position_y . get ( Position ) ) + ShiftY ) ;
		ModInteraction . BC_Position_z . set ( Position , ( ( Double ) ModInteraction . BC_Position_z . get ( Position ) ) + ShiftZ ) ;
	}

	@Override
	public void ScheduleShiftedBlockUpdate ( net . minecraft . nbt . NBTTagCompound PendingBlockUpdateRecord )
	{
		worldObj . scheduleBlockUpdateFromLoad
		(
			PendingBlockUpdateRecord . getInteger ( "X" ) + ShiftX ,
			PendingBlockUpdateRecord . getInteger ( "Y" ) + ShiftY ,
			PendingBlockUpdateRecord . getInteger ( "Z" ) + ShiftZ ,

			PendingBlockUpdateRecord . getInteger ( "Id" ) ,

			PendingBlockUpdateRecord . getInteger ( "Delay" ) ,

			PendingBlockUpdateRecord . getInteger ( "Priority" )
		) ;
	}

	public static int TeleportationDuration = 20 * 8 ;

	@Override
	public void updateEntity ( )
	{
		TicksExisted ++ ;

		if ( worldObj . isRemote )
		{
			return ;
		}

		if ( TicksExisted < TeleportationDuration )
		{
			return ;
		}

		if ( Source )
		{
			try
			{
				( ( CarriageTranslocatorEntity ) worldObj . getBlockTileEntity ( DriveRecord . X , DriveRecord . Y , DriveRecord . Z ) ) . ToggleActivity ( ) ;
			}
			catch ( Throwable Throwable )
			{
				Throwable . printStackTrace ( ) ;
			}

			for ( BlockRecord Record : Body )
			{
				WorldUtil . ClearBlock ( worldObj , Record . X , Record . Y , Record . Z ) ;
			}

			return ;
		}

		Release ( ) ;
	}
}
