2013-06-10 23:03:52 +02:00
package StevenDimDoors.mod_pocketDim.helpers ;
2013-02-18 03:46:16 +01:00
/ * *
* This class regulates all the operations involving the storage and manipulation of dimensions . It handles saving dim data , teleporting the player , and
* creating / registering new dimensions as well as loading old dimensions on startup
* @Return
* /
import java.io.File ;
import java.io.FileInputStream ;
import java.io.FileOutputStream ;
import java.io.ObjectOutputStream ;
import java.util.ArrayList ;
import java.util.HashMap ;
import java.util.Iterator ;
import java.util.Random ;
import java.util.Set ;
import net.minecraft.block.Block ;
2013-03-10 05:04:20 +01:00
import net.minecraft.entity.Entity ;
import net.minecraft.entity.EntityList ;
2013-02-18 03:46:16 +01:00
import net.minecraft.entity.player.EntityPlayer ;
import net.minecraft.entity.player.EntityPlayerMP ;
import net.minecraft.item.ItemStack ;
2013-03-10 05:04:20 +01:00
import net.minecraft.nbt.NBTTagCompound ;
import net.minecraft.network.packet.Packet41EntityEffect ;
import net.minecraft.network.packet.Packet43Experience ;
import net.minecraft.network.packet.Packet9Respawn ;
import net.minecraft.potion.PotionEffect ;
2013-02-18 03:46:16 +01:00
import net.minecraft.tileentity.TileEntity ;
import net.minecraft.util.MathHelper ;
import net.minecraft.world.World ;
import net.minecraft.world.WorldServer ;
import net.minecraft.world.chunk.Chunk ;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage ;
import net.minecraftforge.common.DimensionManager ;
2013-06-14 01:01:54 +02:00
import StevenDimDoors.mod_pocketDim.DDProperties ;
import StevenDimDoors.mod_pocketDim.DimData ;
import StevenDimDoors.mod_pocketDim.LinkData ;
import StevenDimDoors.mod_pocketDim.ObjectSaveInputStream ;
import StevenDimDoors.mod_pocketDim.PacketHandler ;
2013-06-25 20:28:11 +02:00
import StevenDimDoors.mod_pocketDim.Point3D ;
2013-07-30 19:58:14 +02:00
import StevenDimDoors.mod_pocketDim.SchematicLoader ;
2013-06-14 01:01:54 +02:00
import StevenDimDoors.mod_pocketDim.TileEntityRift ;
import StevenDimDoors.mod_pocketDim.mod_pocketDim ;
2013-08-02 13:48:44 +02:00
import StevenDimDoors.mod_pocketDim.schematic.BlockRotator ;
2013-06-14 01:01:54 +02:00
import StevenDimDoors.mod_pocketDim.world.LimboProvider ;
2013-07-26 11:31:59 +02:00
import StevenDimDoors.mod_pocketDim.world.PocketProvider ;
2013-02-18 03:46:16 +01:00
import cpw.mods.fml.common.FMLCommonHandler ;
2013-04-07 06:37:13 +02:00
import cpw.mods.fml.common.registry.GameRegistry ;
2013-02-18 03:46:16 +01:00
import cpw.mods.fml.relauncher.Side ;
public class dimHelper extends DimensionManager
{
2013-05-05 00:58:51 +02:00
/ * *
* hashMap for the private pocket dimensions
* /
public static HashMap < String , DimData > privatePockets = new HashMap < String , DimData > ( ) ;
2013-02-18 03:46:16 +01:00
/ * *
* HashMap containing all the dims registered with DimDoors , sorted by dim ID . loaded on startup
* @Return
* /
public static HashMap < Integer , DimData > dimList = new HashMap < Integer , DimData > ( ) ;
public static boolean isSaving = false ;
/ * *
* ArrayList containing any blocks in limbo that have been placed by the player . Cycled through in the common tick manager
* @Return
* /
2013-06-25 20:28:11 +02:00
public static ArrayList < Point3D > blocksToDecay = new ArrayList < Point3D > ( ) ;
2013-02-18 03:46:16 +01:00
/ * *
* instance of the dimHelper
* @Return
* /
public static dimHelper instance = new dimHelper ( ) ;
/ * *
2013-06-14 01:01:54 +02:00
* HashMap for temporary storage of Link Signature damage hash values . See itemLinkSignature for more details
2013-02-18 03:46:16 +01:00
* @Return
* /
public HashMap < Integer , LinkData > interDimLinkList = new HashMap < Integer , LinkData > ( ) ;
/ * *
* ArrayList containing all link data not sorted for easy random access , used for random doors and for recreating rifts if they have a block placed over them .
2013-06-14 01:01:54 +02:00
* See the common tick manager and the Chaos door for details on usage
2013-02-18 03:46:16 +01:00
* @Return
* /
2013-04-01 09:15:16 +02:00
//public ArrayList<LinkData> linksForRendering =new ArrayList<LinkData>();
2013-02-18 03:46:16 +01:00
Random rand = new Random ( ) ;
2013-08-02 00:01:42 +02:00
public static final int DEFAULT_POCKET_SIZE = 39 ;
public static final int DEFAULT_POCKET_WALL_THICKNESS = 5 ;
public static final int MAX_WORLD_HEIGHT = 254 ;
2013-02-18 03:46:16 +01:00
public int getDimDepth ( int DimID )
{
2013-06-18 04:26:39 +02:00
if ( dimList . containsKey ( DimID ) )
2013-02-18 03:46:16 +01:00
{
2013-06-18 04:26:39 +02:00
return dimList . get ( DimID ) . depth ;
2013-02-18 03:46:16 +01:00
}
else return 1 ;
}
2013-03-10 23:39:17 +01:00
private Entity teleportEntity ( World oldWorld , Entity entity , LinkData link ) //this beautiful teleport method is based off of xCompWiz's teleport function.
2013-03-10 05:04:20 +01:00
{
2013-05-01 02:52:57 +02:00
Entity cart = entity . ridingEntity ;
2013-03-10 23:39:17 +01:00
if ( entity . riddenByEntity ! = null )
{
2013-05-01 02:52:57 +02:00
return this . teleportEntity ( oldWorld , entity . riddenByEntity , link ) ;
2013-03-10 23:39:17 +01:00
}
2013-05-01 02:52:57 +02:00
if ( entity . ridingEntity ! = null )
{
entity . mountEntity ( null ) ;
cart = teleportEntity ( oldWorld , cart , link ) ;
2013-03-10 23:39:17 +01:00
}
2013-04-06 22:57:51 +02:00
WorldServer newWorld ;
2013-03-10 05:04:20 +01:00
2013-07-31 18:09:47 +02:00
if ( DimensionManager . getWorld ( link . destDimID ) = = null )
2013-03-10 05:04:20 +01:00
{
2013-07-31 18:09:47 +02:00
DimensionManager . initDimension ( link . destDimID ) ;
2013-03-10 05:04:20 +01:00
}
2013-03-10 23:39:17 +01:00
boolean difDest = link . destDimID ! = link . locDimID ;
if ( difDest )
{
2013-07-31 18:09:47 +02:00
newWorld = DimensionManager . getWorld ( link . destDimID ) ;
2013-03-10 23:39:17 +01:00
}
else
{
2013-04-06 22:57:51 +02:00
newWorld = ( WorldServer ) oldWorld ;
2013-03-10 23:39:17 +01:00
}
2013-07-31 02:15:55 +02:00
mod_pocketDim . teleporter . placeInPortal ( entity , newWorld , link ) ;
2013-05-01 02:52:57 +02:00
2013-03-10 05:04:20 +01:00
if ( ( entity instanceof EntityPlayerMP ) )
{
EntityPlayerMP player = ( EntityPlayerMP ) entity ;
2013-03-10 23:39:17 +01:00
if ( difDest )
2013-03-10 05:04:20 +01:00
{
2013-07-30 23:56:59 +02:00
GameRegistry . onPlayerChangedDimension ( ( EntityPlayer ) entity ) ;
2013-03-10 05:04:20 +01:00
player . dimension = link . destDimID ;
player . playerNetServerHandler . sendPacketToPlayer ( new Packet9Respawn ( player . dimension , ( byte ) player . worldObj . difficultySetting , newWorld . getWorldInfo ( ) . getTerrainType ( ) , newWorld . getHeight ( ) , player . theItemInWorldManager . getGameType ( ) ) ) ;
2013-04-06 22:57:51 +02:00
WorldServer . class . cast ( oldWorld ) . removeEntity ( player ) ;
player . isDead = false ;
oldWorld . playerEntities . remove ( player ) ;
WorldServer . class . cast ( oldWorld ) . getPlayerManager ( ) . removePlayer ( player ) ;
newWorld . getPlayerManager ( ) . addPlayer ( player ) ;
player . theItemInWorldManager . setWorld ( ( WorldServer ) newWorld ) ;
player . mcServer . getConfigurationManager ( ) . updateTimeAndWeatherForPlayer ( player , ( WorldServer ) newWorld ) ;
player . mcServer . getConfigurationManager ( ) . syncPlayerInventory ( player ) ;
for ( Object potionEffect : player . getActivePotionEffects ( ) )
{
PotionEffect effect = ( PotionEffect ) potionEffect ;
player . playerNetServerHandler . sendPacketToPlayer ( new Packet41EntityEffect ( player . entityId , effect ) ) ;
}
2013-04-17 02:48:49 +02:00
player . playerNetServerHandler . sendPacketToPlayer ( new Packet43Experience ( player . experience , player . experienceTotal , player . experienceLevel ) ) ;
2013-03-10 05:04:20 +01:00
}
2013-07-31 02:15:55 +02:00
}
2013-03-10 23:39:17 +01:00
if ( difDest )
2013-03-10 05:04:20 +01:00
{
2013-03-10 23:39:17 +01:00
int entX = entity . chunkCoordX ;
int entZ = entity . chunkCoordZ ;
if ( ( entity . addedToChunk ) & & ( oldWorld . getChunkProvider ( ) . chunkExists ( entX , entZ ) ) )
2013-03-10 05:04:20 +01:00
{
2013-03-10 23:39:17 +01:00
oldWorld . getChunkFromChunkCoords ( entX , entZ ) . removeEntity ( entity ) ;
oldWorld . getChunkFromChunkCoords ( entX , entZ ) . isModified = true ;
2013-03-10 05:04:20 +01:00
}
oldWorld . releaseEntitySkin ( entity ) ;
if ( ! ( entity instanceof EntityPlayer ) )
{
NBTTagCompound entityNBT = new NBTTagCompound ( ) ;
entity . isDead = false ;
entity . addEntityID ( entityNBT ) ;
entity . isDead = true ;
entity = EntityList . createEntityFromNBT ( entityNBT , newWorld ) ;
2013-03-10 23:39:17 +01:00
2013-03-10 05:04:20 +01:00
if ( entity = = null )
{
2013-03-10 23:39:17 +01:00
2013-03-10 05:04:20 +01:00
}
}
newWorld . spawnEntityInWorld ( entity ) ;
entity . setWorld ( newWorld ) ;
}
2013-03-11 00:10:03 +01:00
entity . worldObj . updateEntityWithOptionalForce ( entity , false ) ;
2013-05-01 02:52:57 +02:00
if ( ( entity ! = null ) & & ( cart ! = null ) )
{
2013-05-09 21:28:32 +02:00
if ( ( entity instanceof EntityPlayerMP ) )
{
entity . worldObj . updateEntityWithOptionalForce ( entity , true ) ;
}
2013-07-31 02:15:55 +02:00
entity . mountEntity ( cart ) ;
2013-05-01 02:52:57 +02:00
}
if ( entity instanceof EntityPlayerMP )
{
2013-06-10 05:56:31 +02:00
WorldServer . class . cast ( newWorld ) . getChunkProvider ( ) . loadChunk ( MathHelper . floor_double ( entity . posX ) > > 4 , MathHelper . floor_double ( entity . posZ ) > > 4 ) ;
2013-05-01 02:52:57 +02:00
}
2013-07-31 02:15:55 +02:00
mod_pocketDim . teleporter . placeInPortal ( entity , newWorld , link ) ;
2013-06-14 01:01:54 +02:00
return entity ;
2013-03-10 05:04:20 +01:00
}
2013-06-14 01:01:54 +02:00
2013-02-18 03:46:16 +01:00
/ * *
2013-06-14 01:01:54 +02:00
* Primary function used to teleport the player using doors . Performs numerous null checks , and also generates the destination door / pocket if it has not done so already .
2013-02-18 03:46:16 +01:00
* Also ensures correct orientation relative to the door using the pocketTeleporter .
* @param world - world the player is currently in
* @param linkData - the link the player is using to teleport , sends the player to its dest information .
* @param player - the instance of the player to be teleported
* @param orientation - the orientation of the door used to teleport , determines player orientation and door placement on arrival
* @Return
* /
2013-08-01 01:34:08 +02:00
public void traverseDimDoor ( World world , LinkData linkData , Entity entity )
2013-02-18 03:46:16 +01:00
{
2013-06-14 01:01:54 +02:00
DDProperties properties = DDProperties . instance ( ) ;
if ( world . isRemote )
2013-06-10 06:16:49 +02:00
{
return ;
}
2013-06-14 01:01:54 +02:00
if ( linkData ! = null )
2013-02-18 03:46:16 +01:00
{
int destinationID = linkData . destDimID ;
2013-03-29 02:34:38 +01:00
2013-07-31 18:09:47 +02:00
if ( dimHelper . dimList . containsKey ( destinationID ) & & dimHelper . dimList . containsKey ( world . provider . dimensionId ) )
2013-02-18 03:46:16 +01:00
{
this . generatePocket ( linkData ) ;
2013-07-31 02:15:55 +02:00
2013-04-07 08:33:11 +02:00
if ( mod_pocketDim . teleTimer = = 0 | | entity instanceof EntityPlayer )
{
mod_pocketDim . teleTimer = 2 + rand . nextInt ( 2 ) ;
}
else
{
return ;
2013-07-31 02:15:55 +02:00
}
2013-06-02 15:57:05 +02:00
if ( ! world . isRemote )
2013-06-10 23:03:52 +02:00
{
2013-05-28 04:45:21 +02:00
entity = this . teleportEntity ( world , entity , linkData ) ;
2013-07-31 02:15:55 +02:00
}
2013-06-10 23:03:52 +02:00
entity . worldObj . playSoundEffect ( entity . posX , entity . posY , entity . posZ , " mob.endermen.portal " , 1 . 0F , 1 . 0F ) ;
2013-07-31 02:15:55 +02:00
2013-06-10 23:03:52 +02:00
int playerXCoord = MathHelper . floor_double ( entity . posX ) ;
int playerYCoord = MathHelper . floor_double ( entity . posY ) ;
int playerZCoord = MathHelper . floor_double ( entity . posZ ) ;
2013-08-01 01:34:08 +02:00
if ( ! entity . worldObj . isBlockOpaqueCube ( playerXCoord , playerYCoord - 1 , playerZCoord ) & & dimHelper . instance . getDimData ( linkData . locDimID ) . isDimRandomRift & & ! linkData . hasGennedDoor )
2013-06-10 23:03:52 +02:00
{
for ( int count = 0 ; count < 20 ; count + + )
{
if ( entity . worldObj . isBlockOpaqueCube ( playerXCoord , playerYCoord - 1 - count , playerZCoord ) )
{
break ;
}
if ( count = = 19 )
{
2013-06-14 01:01:54 +02:00
entity . worldObj . setBlock ( playerXCoord , playerYCoord - 1 , playerZCoord , properties . FabricBlockID ) ;
2013-06-10 23:03:52 +02:00
}
}
2013-07-31 02:15:55 +02:00
}
2013-06-10 23:03:52 +02:00
if ( entity . worldObj . getBlockId ( playerXCoord , playerYCoord - 1 , playerZCoord ) = = Block . lavaStill . blockID )
{
2013-06-14 01:01:54 +02:00
entity . worldObj . setBlock ( playerXCoord , playerYCoord - 1 , playerZCoord , properties . FabricBlockID ) ;
2013-06-10 23:03:52 +02:00
}
this . generateDoor ( world , linkData ) ;
2013-07-31 02:15:55 +02:00
2013-08-03 12:12:56 +02:00
//FIXME: Why are we checking blockList.length? Not necessary. getBlockId() can't return an ID past the end of the block list.
//Plus even if the check is necessary, it's still wrong since it should be less than, not less than or equal to.
2013-06-10 23:03:52 +02:00
if ( Block . blocksList . length > = entity . worldObj . getBlockId ( playerXCoord , playerYCoord + 1 , playerZCoord ) & & ! entity . worldObj . isAirBlock ( playerXCoord , playerYCoord + 1 , playerZCoord ) )
{
2013-08-03 12:12:56 +02:00
if ( Block . blocksList [ entity . worldObj . getBlockId ( playerXCoord , playerYCoord + 1 , playerZCoord ) ] . isOpaqueCube ( ) & &
! mod_pocketDim . blockRift . isBlockImmune ( entity . worldObj , playerXCoord + 1 , playerYCoord , playerZCoord ) )
2013-06-10 23:03:52 +02:00
{
entity . worldObj . setBlock ( playerXCoord , playerYCoord + 1 , playerZCoord , 0 ) ;
}
}
2013-08-03 12:12:56 +02:00
if ( Block . blocksList . length > = entity . worldObj . getBlockId ( playerXCoord , playerYCoord , playerZCoord ) & & ! entity . worldObj . isAirBlock ( playerXCoord , playerYCoord , playerZCoord ) )
2013-06-10 23:03:52 +02:00
{
2013-08-03 12:12:56 +02:00
if ( Block . blocksList [ entity . worldObj . getBlockId ( playerXCoord , playerYCoord , playerZCoord ) ] . isOpaqueCube ( ) & &
! mod_pocketDim . blockRift . isBlockImmune ( entity . worldObj , playerXCoord , playerYCoord , playerZCoord ) )
2013-06-10 23:03:52 +02:00
{
entity . worldObj . setBlock ( playerXCoord , playerYCoord , playerZCoord , 0 ) ;
}
}
2013-02-18 03:46:16 +01:00
}
}
2013-07-31 18:09:47 +02:00
//FIXME: Wtf? This code is useless. It doesn't seem to do anything! If that's the case, it should be removed. ~SenseiKiwi
else if ( ! dimHelper . dimList . containsKey ( world . provider . dimensionId ) )
2013-05-28 23:15:40 +02:00
{
2013-07-26 11:31:59 +02:00
if ( ! ( world . provider instanceof PocketProvider | | world . provider instanceof LimboProvider ) )
2013-05-28 23:15:40 +02:00
{
DimData data = new DimData ( world . provider . dimensionId , false , 0 , 0 , world . getSpawnPoint ( ) . posX , world . getSpawnPoint ( ) . posY , world . getSpawnPoint ( ) . posZ ) ;
}
}
2013-05-01 02:52:57 +02:00
return ;
2013-02-18 03:46:16 +01:00
}
2013-07-31 02:15:55 +02:00
2013-02-18 03:46:16 +01:00
/ * *
* Creates a link at the location , pointing to the destination . Does NOT create a pair , so must be called twice .
* @param locationDimID
* @param destinationDimID
* @param locationXCoord
* @param locationYCoord
* @param locationZCoord
* @param destinationXCoord
* @param destinationYCoord
* @param destinationZCoord
* @return
* /
public LinkData createLink ( int locationDimID , int destinationDimID , int locationXCoord , int locationYCoord , int locationZCoord , int destinationXCoord , int destinationYCoord , int destinationZCoord )
{
if ( this . getLinkDataFromCoords ( locationXCoord , locationYCoord , locationZCoord , locationDimID ) ! = null )
{
return this . createLink ( locationDimID , destinationDimID , locationXCoord , locationYCoord , locationZCoord , destinationXCoord , destinationYCoord , destinationZCoord , this . getLinkDataFromCoords ( locationXCoord , locationYCoord , locationZCoord , locationDimID ) . linkOrientation ) ;
}
2013-03-10 17:49:29 +01:00
else
{
return this . createLink ( locationDimID , destinationDimID , locationXCoord , locationYCoord , locationZCoord , destinationXCoord , destinationYCoord , destinationZCoord , - 10 ) ;
}
2013-02-18 03:46:16 +01:00
}
/ * *
* Creates a link at the location , pointing to the destination . Does NOT create a pair , so must be called twice .
* @param locationDimID
* @param destinationDimID
* @param locationXCoord
* @param locationYCoord
* @param locationZCoord
* @param destinationXCoord
* @param destinationYCoord
* @param destinationZCoord
* @param linkOrientation
* @return
* /
public LinkData createLink ( int locationDimID , int destinationDimID , int locationXCoord , int locationYCoord , int locationZCoord , int destinationXCoord , int destinationYCoord , int destinationZCoord , int linkOrientation )
{
2013-05-04 01:34:01 +02:00
LinkData linkData = new LinkData ( locationDimID , destinationDimID , locationXCoord , locationYCoord , locationZCoord , destinationXCoord , destinationYCoord , destinationZCoord , false , linkOrientation ) ;
2013-02-18 03:46:16 +01:00
return this . createLink ( linkData ) ;
2013-07-31 02:15:55 +02:00
}
2013-02-18 03:46:16 +01:00
public LinkData createLink ( LinkData link )
{
2013-06-14 01:01:54 +02:00
DDProperties properties = DDProperties . instance ( ) ;
2013-07-31 18:09:47 +02:00
if ( ! dimHelper . dimList . containsKey ( link . locDimID ) )
2013-02-18 03:46:16 +01:00
{
DimData locationDimData = new DimData ( link . locDimID , false , 0 , link . locDimID , link . locXCoord , link . locYCoord , link . locZCoord ) ;
2013-07-31 18:09:47 +02:00
dimHelper . dimList . put ( link . locDimID , locationDimData ) ;
2013-02-18 03:46:16 +01:00
link . isLocPocket = false ;
2013-03-29 02:34:38 +01:00
}
if ( ! dimList . containsKey ( link . destDimID ) )
{
dimHelper . dimList . put ( link . destDimID , new DimData ( link . destDimID , false , 0 , link . locDimID , link . locXCoord , link . locYCoord , link . locZCoord ) ) ;
2013-02-18 03:46:16 +01:00
}
2013-08-01 01:34:08 +02:00
DimData locationDimData = dimHelper . instance . getDimData ( link . locDimID ) ;
2013-02-18 03:46:16 +01:00
link . isLocPocket = locationDimData . isPocket ;
locationDimData . addLinkToDim ( link ) ;
2013-08-03 12:12:56 +02:00
World world = dimHelper . getWorld ( link . locDimID ) ;
if ( world ! = null )
2013-02-18 03:46:16 +01:00
{
2013-08-03 12:12:56 +02:00
if ( ! mod_pocketDim . blockRift . isBlockImmune ( world , link . locXCoord , link . locYCoord , link . locZCoord ) )
2013-02-18 03:46:16 +01:00
{
2013-08-03 12:12:56 +02:00
world . setBlock ( link . locXCoord , link . locYCoord , link . locZCoord , properties . RiftBlockID ) ;
2013-02-18 03:46:16 +01:00
}
}
//Notifies other players that a link has been created.
if ( FMLCommonHandler . instance ( ) . getEffectiveSide ( ) = = Side . SERVER )
2013-07-31 02:15:55 +02:00
{
2013-02-18 03:46:16 +01:00
PacketHandler . onLinkCreatedPacket ( link ) ;
2013-07-31 02:15:55 +02:00
}
2013-02-18 03:46:16 +01:00
return link ;
}
public int getDestOrientation ( LinkData link )
{
if ( link ! = null )
{
LinkData destLink = this . getLinkDataFromCoords ( link . destXCoord , link . destYCoord , link . destZCoord , link . destDimID ) ;
if ( destLink ! = null )
{
return destLink . linkOrientation ;
}
else
{
//System.out.println("Cant find destination link");
return 0 ;
}
}
else
{
// System.out.println("sending link is null");
return 0 ;
}
}
public void removeLink ( LinkData link )
{
this . removeLink ( link . locDimID , link . locXCoord , link . locYCoord , link . locZCoord ) ;
}
/ * *
* properly deletes a link at the given coordinates . used by the rift remover . Also notifies clients of change .
* @param locationDimID
* @param locationXCoord
* @param locationYCoord
* @param locationZCoord
* /
public void removeLink ( int locationDimID , int locationXCoord , int locationYCoord , int locationZCoord )
{
2013-07-31 18:09:47 +02:00
if ( ! dimHelper . dimList . containsKey ( locationDimID ) )
2013-02-18 03:46:16 +01:00
{
DimData locationDimData = new DimData ( locationDimID , false , 0 , locationDimID , locationXCoord , locationYCoord , locationZCoord ) ;
2013-07-31 18:09:47 +02:00
dimHelper . dimList . put ( locationDimID , locationDimData ) ;
2013-02-18 03:46:16 +01:00
}
LinkData link = this . getLinkDataFromCoords ( locationXCoord , locationYCoord , locationZCoord , locationDimID ) ;
2013-08-01 01:34:08 +02:00
dimHelper . instance . getDimData ( locationDimID ) . removeLinkAtCoords ( link ) ;
2013-02-18 03:46:16 +01:00
//updates clients that a rift has been removed
if ( FMLCommonHandler . instance ( ) . getEffectiveSide ( ) = = Side . SERVER )
{
PacketHandler . onLinkRemovedPacket ( link ) ;
this . save ( ) ;
2013-07-31 02:15:55 +02:00
}
2013-02-18 03:46:16 +01:00
}
public LinkData findNearestRift ( World world , int x , int y , int z , int range )
{
2013-08-01 01:34:08 +02:00
return dimHelper . instance . getDimData ( world ) . findNearestRift ( world , range , x , y , z ) ;
2013-02-18 03:46:16 +01:00
}
/ * *
* generates a door based on what door was used to teleport . Only funtions once per linking .
* @param world - door
2013-05-04 02:42:11 +02:00
* @param incLink
2013-02-18 03:46:16 +01:00
* /
2013-05-04 02:42:11 +02:00
public void generateDoor ( World world , LinkData incLink )
2013-02-18 03:46:16 +01:00
{
2013-05-04 02:42:11 +02:00
int locX = incLink . locXCoord ;
int locY = incLink . locYCoord ;
int locZ = incLink . locZCoord ;
2013-02-18 03:46:16 +01:00
2013-05-04 02:42:11 +02:00
int destX = incLink . destXCoord ;
int destY = incLink . destYCoord ;
int destZ = incLink . destZCoord ;
2013-02-18 03:46:16 +01:00
2013-06-14 01:01:54 +02:00
DDProperties properties = DDProperties . instance ( ) ;
2013-05-04 02:42:11 +02:00
if ( ! incLink . hasGennedDoor )
2013-02-18 03:46:16 +01:00
{
2013-05-04 02:42:11 +02:00
int destinationID = incLink . destDimID ;
2013-02-18 03:46:16 +01:00
int id = world . getBlockId ( locX , locY , locZ ) ;
2013-06-14 01:01:54 +02:00
if ( id = = properties . WarpDoorID | | id = = properties . DimensionalDoorID | | id = = properties . TransientDoorID )
2013-02-18 03:46:16 +01:00
{
int doorTypeToPlace = id ;
2013-07-31 18:09:47 +02:00
if ( DimensionManager . getWorld ( destinationID ) = = null )
2013-02-18 03:46:16 +01:00
{
2013-07-31 18:09:47 +02:00
DimensionManager . initDimension ( destinationID ) ;
2013-02-18 03:46:16 +01:00
}
2013-05-04 02:42:11 +02:00
LinkData destLink = this . getLinkDataFromCoords ( destX , destY , destZ , destinationID ) ;
2013-07-31 18:09:47 +02:00
int destOrientation = 0 ;
2013-05-04 02:42:11 +02:00
if ( destLink ! = null )
{
destOrientation = destLink . linkOrientation ;
destLink . hasGennedDoor = true ;
}
2013-07-31 18:09:47 +02:00
int blockToReplace = DimensionManager . getWorld ( destinationID ) . getBlockId ( destX , destY , destZ ) ;
2013-06-14 01:01:54 +02:00
if ( blockToReplace ! = properties . DimensionalDoorID & & blockToReplace ! = properties . WarpDoorID & & blockToReplace ! = properties . TransientDoorID )
2013-02-18 03:46:16 +01:00
{
2013-07-31 18:09:47 +02:00
DimensionManager . getWorld ( destinationID ) . setBlock ( destX , destY - 1 , destZ , doorTypeToPlace , destOrientation , 2 ) ;
DimensionManager . getWorld ( destinationID ) . setBlock ( destX , destY , destZ , doorTypeToPlace , 8 , 2 ) ;
2013-02-18 03:46:16 +01:00
}
2013-05-04 02:42:11 +02:00
incLink . hasGennedDoor = true ;
2013-02-18 03:46:16 +01:00
}
}
}
/ * *
* Generates the black pocket out of fabric of reality blocks . Placement of the pocket is based off of the orignial doors orientation . Kind of a clunky method ,
2013-07-31 18:09:47 +02:00
* but is necessary to maintain a one to one relationship with the overworld . Is called every teleport , but checks if the dim has been filled first and is a pocket .
2013-02-18 03:46:16 +01:00
* Also responsible for generation the random dungeons .
* @param world - id of the world TO BE FILLED
* @param x
* @param y
* @param z
* @param orientation
* @return
* /
public void generatePocket ( LinkData incomingLink )
{
2013-06-14 01:01:54 +02:00
DDProperties properties = DDProperties . instance ( ) ;
2013-05-31 08:17:05 +02:00
try
2013-02-18 03:46:16 +01:00
{
2013-07-31 18:09:47 +02:00
if ( DimensionManager . getWorld ( incomingLink . destDimID ) = = null )
2013-05-31 08:17:05 +02:00
{
2013-07-31 18:09:47 +02:00
DimensionManager . initDimension ( incomingLink . destDimID ) ;
2013-05-31 08:17:05 +02:00
}
2013-07-31 18:09:47 +02:00
if ( DimensionManager . getWorld ( incomingLink . destDimID ) . provider = = null )
2013-05-31 08:17:05 +02:00
{
2013-07-31 18:09:47 +02:00
DimensionManager . initDimension ( incomingLink . destDimID ) ;
2013-05-31 08:17:05 +02:00
}
2013-02-18 03:46:16 +01:00
}
2013-05-31 08:17:05 +02:00
catch ( Exception E )
2013-02-18 03:46:16 +01:00
{
2013-05-31 08:17:05 +02:00
E . printStackTrace ( ) ;
return ;
2013-02-18 03:46:16 +01:00
}
// World world = this.getWorld(incomingLink.destDimID);
2013-08-01 01:34:08 +02:00
DimData data = dimHelper . instance . getDimData ( incomingLink . destDimID ) ;
2013-02-18 03:46:16 +01:00
if ( ! data . hasBeenFilled & & data . isPocket & & ! data . isDimRandomRift )
{
data . hasBeenFilled = true ;
//System.out.println("genning pocket");
int x = incomingLink . destXCoord ;
int y = incomingLink . destYCoord ;
int z = incomingLink . destZCoord ;
int orientation = ( incomingLink . linkOrientation ) ;
int depth = this . getDimDepth ( incomingLink . locDimID ) ;
//x=x*depth;
//y=y*depth;
//z=z*depth;
y = y + 13 ;
if ( orientation = = 0 )
{
x = x + 15 ;
2013-07-30 23:56:59 +02:00
//this.getWorld(incomingLink.destDimID).provider.setSpawnPoint(x-1, y, z);
2013-05-28 23:15:40 +02:00
2013-02-18 03:46:16 +01:00
}
else if ( orientation = = 1 )
{
z = z + 15 ;
2013-07-30 23:56:59 +02:00
//this.getWorld(incomingLink.destDimID).provider.setSpawnPoint(x, y, z-1);
2013-05-28 23:15:40 +02:00
2013-02-18 03:46:16 +01:00
}
else if ( orientation = = 2 )
{
x = x - 15 ;
2013-07-30 23:56:59 +02:00
//this.getWorld(incomingLink.destDimID).provider.setSpawnPoint(x+1, y, z);
2013-05-28 23:15:40 +02:00
2013-02-18 03:46:16 +01:00
}
else if ( orientation = = 3 )
{
z = z - 15 ;
2013-07-30 23:56:59 +02:00
//this.getWorld(incomingLink.destDimID).provider.setSpawnPoint(x, y, z+1);
2013-05-28 23:15:40 +02:00
2013-02-18 03:46:16 +01:00
}
int searchRadius = 19 ;
2013-07-31 18:09:47 +02:00
if ( ! DimensionManager . getWorld ( incomingLink . destDimID ) . isRemote )
2013-02-18 03:46:16 +01:00
{
int xCount = - searchRadius ;
int yCount = - searchRadius ;
int zCount = - searchRadius ;
while ( xCount < = searchRadius )
{
while ( yCount < = searchRadius )
{
while ( zCount < = searchRadius )
{
2013-07-31 18:09:47 +02:00
if ( ( Math . abs ( xCount ) > = 15 | | Math . abs ( yCount ) > = 15 | | Math . abs ( zCount ) > = 15 ) & & DimensionManager . getWorld ( incomingLink . destDimID ) . isAirBlock ( x + xCount , y + yCount , z + zCount ) & & ( ( yCount + y ) > 0 ) )
2013-02-18 03:46:16 +01:00
{
if ( Math . abs ( xCount ) > = 19 | | Math . abs ( yCount ) > = 19 | | Math . abs ( zCount ) > = 19 )
{
2013-07-31 18:09:47 +02:00
dimHelper . setBlockDirectly ( DimensionManager . getWorld ( incomingLink . destDimID ) , x + xCount , y + yCount , z + zCount , properties . PermaFabricBlockID , 0 ) ;
2013-02-18 03:46:16 +01:00
}
else
{
2013-07-31 18:09:47 +02:00
dimHelper . setBlockDirectly ( DimensionManager . getWorld ( incomingLink . destDimID ) , x + xCount , y + yCount , z + zCount , properties . FabricBlockID , 0 ) ;
2013-06-14 01:01:54 +02:00
if ( properties . TNFREAKINGT_Enabled )
2013-02-18 03:46:16 +01:00
{
2013-06-14 01:01:54 +02:00
if ( ( Math . abs ( xCount ) > = 16 | | Math . abs ( yCount ) > = 16 | | Math . abs ( zCount ) > = 16 ) & & rand . nextInt ( properties . NonTntWeight + 1 ) = = 0 )
2013-02-18 03:46:16 +01:00
{
2013-07-31 18:09:47 +02:00
DimensionManager . getWorld ( incomingLink . destDimID ) . setBlock ( x + xCount , y + yCount , z + zCount , Block . tnt . blockID ) ;
2013-02-18 03:46:16 +01:00
}
}
}
}
zCount + + ;
}
zCount = - searchRadius ;
yCount + + ;
}
yCount = - searchRadius ;
xCount + + ;
}
}
}
2013-07-31 18:09:47 +02:00
else if ( ! data . hasBeenFilled & & data . isPocket & & data . isDimRandomRift )
2013-02-18 03:46:16 +01:00
{
2013-07-30 19:58:14 +02:00
SchematicLoader . generateDungeonPocket ( incomingLink , properties ) ;
2013-02-18 03:46:16 +01:00
data . hasBeenFilled = true ;
}
}
/ * *
* simple method called on startup to register all dims saved in the dim list . Only tries to register pocket dims , though . Also calls load ( )
* @return
* /
public void initPockets ( )
{
2013-06-14 01:01:54 +02:00
DDProperties properties = DDProperties . instance ( ) ;
2013-02-18 03:46:16 +01:00
mod_pocketDim . hasInitDims = true ;
this . load ( ) ;
2013-07-30 19:58:14 +02:00
if ( ! dimHelper . dimList . isEmpty ( ) )
2013-02-18 03:46:16 +01:00
{
2013-07-31 18:09:47 +02:00
Set < Integer > allDimIds = dimList . keySet ( ) ;
//FIXME: ...Wat. Why aren't we using a foreach loop here instead of manipulating an explicit iterator? ;-; ~SenseiKiwi
Iterator < Integer > itr = allDimIds . iterator ( ) ;
2013-02-18 03:46:16 +01:00
while ( itr . hasNext ( ) )
{
DimData dimData = ( DimData ) dimList . get ( itr . next ( ) ) ;
if ( dimData . isPocket )
{
try
{
2013-07-31 18:09:47 +02:00
DimensionManager . getNextFreeDimId ( ) ;
2013-06-14 01:01:54 +02:00
registerDimension ( dimData . dimID , properties . PocketProviderID ) ;
2013-02-18 03:46:16 +01:00
}
catch ( Exception e )
{
if ( dimData . isPocket )
{
System . out . println ( " Warning- could not register dim " + dimData . depth + " . Probably caused by a version update/save data corruption/other mods. " ) ;
}
2013-03-29 02:34:38 +01:00
else
{
e . printStackTrace ( ) ;
}
2013-02-18 03:46:16 +01:00
}
}
}
}
2013-06-24 07:40:56 +02:00
}
2013-06-25 20:28:11 +02:00
public boolean resetPocket ( DimData dimData )
2013-06-24 07:40:56 +02:00
{
2013-06-26 02:54:58 +02:00
if ( ! dimData . isPocket | | getWorld ( dimData . dimID ) ! = null )
2013-06-24 07:40:56 +02:00
{
2013-06-25 20:28:11 +02:00
return false ;
2013-06-24 07:40:56 +02:00
}
2013-06-25 20:28:11 +02:00
File save = new File ( getCurrentSaveRootDirectory ( ) + " /DimensionalDoors/pocketDimID " + dimData . dimID ) ;
2013-06-24 07:40:56 +02:00
DeleteFolder . deleteFolder ( save ) ;
2013-06-25 20:28:11 +02:00
dimData . hasBeenFilled = false ;
dimData . hasDoor = false ;
2013-07-12 02:42:57 +02:00
for ( LinkData link : dimData . getLinksInDim ( ) )
2013-06-24 07:40:56 +02:00
{
2013-06-25 20:28:11 +02:00
link . hasGennedDoor = false ;
LinkData linkOut = this . getLinkDataFromCoords ( link . destXCoord , link . destYCoord , link . destZCoord , link . destDimID ) ;
if ( linkOut ! = null )
2013-06-24 07:40:56 +02:00
{
2013-06-25 20:28:11 +02:00
linkOut . hasGennedDoor = false ;
2013-06-24 07:40:56 +02:00
}
}
2013-06-25 20:28:11 +02:00
return true ;
2013-02-18 03:46:16 +01:00
}
2013-06-25 20:28:11 +02:00
2013-06-26 02:54:58 +02:00
public boolean pruneDimension ( DimData dimData , boolean deleteFolder )
{
2013-07-31 02:15:55 +02:00
2013-06-26 02:54:58 +02:00
//TODO: All the logic for checking that this is an isolated pocket should be moved in here.
2013-07-31 02:15:55 +02:00
if ( ! dimData . isPocket | | getWorld ( dimData . dimID ) ! = null ) //Checks to see if the pocket is loaded or isnt actually a pocket.
2013-06-26 02:54:58 +02:00
{
return false ;
}
dimList . remove ( dimData . dimID ) ;
if ( deleteFolder )
{
File save = new File ( getCurrentSaveRootDirectory ( ) + " /DimensionalDoors/pocketDimID " + dimData . dimID ) ;
DeleteFolder . deleteFolder ( save ) ;
}
return true ;
}
2013-02-18 03:46:16 +01:00
/ * *
2013-06-25 20:28:11 +02:00
* method called when the client disconnects / server stops to unregister dims .
2013-02-18 03:46:16 +01:00
* @Return
* /
public void unregsisterDims ( )
{
2013-07-31 18:09:47 +02:00
if ( ! dimHelper . dimList . isEmpty ( ) )
2013-02-18 03:46:16 +01:00
{
Set allDimIds = dimList . keySet ( ) ;
Iterator itr = allDimIds . iterator ( ) ;
while ( itr . hasNext ( ) )
{
DimData dimData = ( DimData ) dimList . get ( itr . next ( ) ) ;
if ( dimData . isPocket )
{
try
{
2013-07-31 18:09:47 +02:00
DimensionManager . unregisterDimension ( dimData . dimID ) ;
2013-02-18 03:46:16 +01:00
}
catch ( Exception e )
{
System . out . println ( " Dim- " + String . valueOf ( dimData . dimID ) + " is already unregistered, ok? Enough with it already. " ) ;
}
// initDimension(dimData.dimID);
2013-07-31 02:15:55 +02:00
}
2013-02-18 03:46:16 +01:00
}
}
}
/ * *
* Used to associate a damage value on a Rift Signature with a link pair . See LinkSignature for details .
* @return
* /
public int createUniqueInterDimLinkKey ( )
{
int linkKey ;
Random rand = new Random ( ) ;
do
{
linkKey = rand . nextInt ( 30000 ) ;
}
while ( this . interDimLinkList . containsKey ( linkKey ) ) ;
return linkKey ;
}
/ * *
* Method used to create and register a new pocket dimension . Called on door placement and rift generation . It does NOT actually generate the structure of the dim , just
* registers it with the dimension manager and adds the necessary links and dim info to the dimlist / linklists .
* Also registers existing dims with the dimList , so link data can be stored for them .
*
* Handles the randomization associated with depth as well , going far enough causes the next dims exit link to be randomized .
*
* @param world - World currently occupied , the parent of the pocket dim to be created .
* @param x
* @param y
* @param z
* @param isGoingDown
* @param isRandomRift
* @param orientation - determines the orientation of the entrance link to this dim . Should be the metaData of the door occupying the rift . - 1 if no door .
* @return
* /
public LinkData createPocket ( LinkData link , boolean isGoingDown , boolean isRandomRift )
{
2013-06-14 01:01:54 +02:00
DDProperties properties = DDProperties . instance ( ) ;
2013-06-25 15:15:19 +02:00
if ( dimHelper . getWorld ( 0 ) = = null )
{
return link ;
}
2013-06-14 01:01:54 +02:00
if ( dimHelper . getWorld ( link . locDimID ) = = null )
2013-02-21 22:27:51 +01:00
{
2013-06-14 01:01:54 +02:00
dimHelper . initDimension ( link . locDimID ) ;
2013-02-21 22:27:51 +01:00
}
2013-02-18 03:46:16 +01:00
int dimensionID ;
int depth = this . getDimDepth ( link . locDimID ) ;
dimensionID = getNextFreeDimId ( ) ;
2013-06-14 01:01:54 +02:00
registerDimension ( dimensionID , properties . PocketProviderID ) ;
2013-02-18 03:46:16 +01:00
DimData locationDimData ;
DimData destDimData ;
2013-08-02 00:01:42 +02:00
2013-07-31 18:09:47 +02:00
if ( dimHelper . dimList . containsKey ( link . locDimID ) & & ! DimensionManager . getWorld ( link . locDimID ) . isRemote ) //checks to see if dim is already registered. If not, it creates a DimData entry for it later
2013-02-18 03:46:16 +01:00
{
//randomizes exit if deep enough
2013-07-31 18:09:47 +02:00
locationDimData = dimList . get ( DimensionManager . getWorld ( link . locDimID ) . provider . dimensionId ) ;
2013-02-18 03:46:16 +01:00
if ( depth > 5 )
{
if ( depth > = 12 )
{
depth = 11 ;
}
if ( rand . nextInt ( 13 - depth ) = = 0 )
{
2013-08-02 00:01:42 +02:00
LinkData link1 = getRandomLinkData ( false ) ;
2013-02-18 03:46:16 +01:00
}
}
if ( locationDimData . isPocket ) //determines the qualites of the pocket dim being created, based on parent dim.
{
if ( isGoingDown )
{
destDimData = new DimData ( dimensionID , true , locationDimData . depth + 1 , locationDimData . exitDimLink ) ;
}
else
{
destDimData = new DimData ( dimensionID , true , locationDimData . depth - 1 , locationDimData . exitDimLink ) ;
}
}
else
{
destDimData = new DimData ( dimensionID , true , 1 , link . locDimID , link . locXCoord , link . locYCoord , link . locZCoord ) ;
}
}
else
{
locationDimData = new DimData ( link . locDimID , false , 0 , link . locDimID , link . locXCoord , link . locYCoord , link . locZCoord ) ;
destDimData = new DimData ( dimensionID , true , 1 , link . locDimID , link . locXCoord , link . locYCoord , link . locZCoord ) ;
}
destDimData . isDimRandomRift = isRandomRift ;
2013-07-31 18:09:47 +02:00
dimHelper . dimList . put ( DimensionManager . getWorld ( link . locDimID ) . provider . dimensionId , locationDimData ) ;
dimHelper . dimList . put ( dimensionID , destDimData ) ;
2013-02-18 03:46:16 +01:00
if ( FMLCommonHandler . instance ( ) . getEffectiveSide ( ) = = Side . SERVER ) //sends packet to clients notifying them that a new dim has been created.
{
PacketHandler . onDimCreatedPacket ( destDimData ) ;
}
2013-08-02 00:01:42 +02:00
link = this . createLink ( DimensionManager . getWorld ( link . locDimID ) . provider . dimensionId , dimensionID , link . locXCoord , link . locYCoord , link . locZCoord , link . destXCoord , constrainPocketY ( link . destYCoord ) , link . destZCoord , link . linkOrientation ) ; //creates and registers the two rifts that link the parent and pocket dim.
2013-08-02 13:48:44 +02:00
this . createLink ( dimensionID , DimensionManager . getWorld ( link . locDimID ) . provider . dimensionId , link . destXCoord , constrainPocketY ( link . destYCoord ) , link . destZCoord , link . locXCoord , link . locYCoord , link . locZCoord , BlockRotator . transformMetadata ( link . linkOrientation , 2 , Block . doorWood . blockID ) ) ;
2013-06-04 02:56:15 +02:00
return link ;
2013-02-18 03:46:16 +01:00
}
2013-08-02 00:01:42 +02:00
public static int constrainPocketY ( int entranceDoorYPos )
{
if ( entranceDoorYPos + DEFAULT_POCKET_SIZE - DEFAULT_POCKET_WALL_THICKNESS > = MAX_WORLD_HEIGHT )
{
return entranceDoorYPos - DEFAULT_POCKET_SIZE + DEFAULT_POCKET_WALL_THICKNESS ;
}
if ( entranceDoorYPos - 1 - DEFAULT_POCKET_WALL_THICKNESS < = 0 )
{
return entranceDoorYPos + DEFAULT_POCKET_WALL_THICKNESS ;
}
else return entranceDoorYPos ;
2013-02-18 03:46:16 +01:00
2013-08-02 00:01:42 +02:00
}
2013-02-18 03:46:16 +01:00
/ * *
* function that saves all dim data in a hashMap . Calling too often can cause Concurrent modification exceptions , so be careful .
* @return
* /
//TODO change from saving serialized objects to just saving data for compatabilies sake.
2013-06-18 04:26:39 +02:00
//TODO If saving is multithreaded as the concurrent modification exception implies, you should be synchronizing access. ~SenseiKiwi
2013-02-18 03:46:16 +01:00
public void save ( )
{
2013-07-31 18:09:47 +02:00
if ( dimHelper . isSaving ) return ;
2013-06-07 04:22:23 +02:00
World world = DimensionManager . getWorld ( 0 ) ;
if ( world = = null | | world . isRemote ) return ;
2013-07-31 18:09:47 +02:00
if ( DimensionManager . getCurrentSaveRootDirectory ( ) ! = null )
2013-02-18 03:46:16 +01:00
{
2013-06-07 04:22:23 +02:00
//System.out.println("saving");
2013-02-18 03:46:16 +01:00
2013-07-31 18:09:47 +02:00
dimHelper . isSaving = true ;
2013-06-07 04:22:23 +02:00
HashMap comboSave = new HashMap ( ) ;
2013-07-31 18:09:47 +02:00
comboSave . put ( " dimList " , dimHelper . dimList ) ;
2013-06-07 04:22:23 +02:00
comboSave . put ( " interDimLinkList " , this . interDimLinkList ) ;
2013-07-31 18:09:47 +02:00
comboSave . put ( " blocksToDecay " , dimHelper . blocksToDecay ) ;
2013-02-18 03:46:16 +01:00
FileOutputStream saveFile = null ;
try
{
2013-06-02 03:43:56 +02:00
//World world=FMLCommonHandler.instance().getMinecraftServerInstance().worldServers[0];
2013-07-31 18:09:47 +02:00
String saveFileName = DimensionManager . getCurrentSaveRootDirectory ( ) + " /DimensionalDoorsDataTEMP " ;
2013-02-18 03:46:16 +01:00
saveFile = new FileOutputStream ( saveFileName ) ;
ObjectOutputStream save = new ObjectOutputStream ( saveFile ) ;
save . writeObject ( comboSave ) ;
save . close ( ) ;
saveFile . close ( ) ;
2013-07-31 18:09:47 +02:00
if ( new File ( DimensionManager . getCurrentSaveRootDirectory ( ) + " /DimensionalDoorsDataOLD " ) . exists ( ) )
2013-02-18 03:46:16 +01:00
{
2013-07-31 18:09:47 +02:00
new File ( DimensionManager . getCurrentSaveRootDirectory ( ) + " /DimensionalDoorsDataOLD " ) . delete ( ) ;
2013-02-18 03:46:16 +01:00
}
2013-07-31 18:09:47 +02:00
new File ( DimensionManager . getCurrentSaveRootDirectory ( ) + " /DimensionalDoorsData " ) . renameTo ( new File ( DimensionManager . getCurrentSaveRootDirectory ( ) + " /DimensionalDoorsDataOLD " ) ) ;
2013-02-18 03:46:16 +01:00
2013-07-31 18:09:47 +02:00
new File ( saveFileName ) . renameTo ( new File ( DimensionManager . getCurrentSaveRootDirectory ( ) + " /DimensionalDoorsData " ) ) ;
2013-02-18 03:46:16 +01:00
}
catch ( Exception e )
{
e . printStackTrace ( ) ;
System . out . println ( " Could not save data-- SEVERE " ) ;
}
2013-07-31 18:09:47 +02:00
dimHelper . isSaving = false ;
2013-02-18 03:46:16 +01:00
}
}
/ * *
* loads the dim data from the saved hashMap . Also handles compatabilty with old saves , see OldSaveHandler
* @return
* /
//TODO change to loading vars instead of objects
2013-07-31 18:09:47 +02:00
@SuppressWarnings ( " unchecked " )
2013-02-18 03:46:16 +01:00
public void load ( )
{
boolean firstRun = false ;
System . out . println ( " Loading DimDoors data " ) ;
FileInputStream saveFile = null ;
2013-07-31 18:09:47 +02:00
if ( ! DimensionManager . getWorld ( 0 ) . isRemote & & DimensionManager . getCurrentSaveRootDirectory ( ) ! = null )
2013-06-04 02:56:15 +02:00
{
2013-02-18 03:46:16 +01:00
try
{
2013-07-31 18:09:47 +02:00
File dataStore = new File ( DimensionManager . getCurrentSaveRootDirectory ( ) + " /DimensionalDoorsData " ) ;
2013-02-18 03:46:16 +01:00
if ( ! dataStore . exists ( ) )
{
2013-07-31 18:09:47 +02:00
if ( ! new File ( DimensionManager . getCurrentSaveRootDirectory ( ) + " /DimensionalDoorsDataOLD " ) . exists ( ) )
2013-02-18 03:46:16 +01:00
{
firstRun = true ;
}
}
2013-03-10 17:49:29 +01:00
2013-02-18 03:46:16 +01:00
saveFile = new FileInputStream ( dataStore ) ;
ObjectSaveInputStream save = new ObjectSaveInputStream ( saveFile ) ;
2013-07-31 18:09:47 +02:00
HashMap comboSave = ( ( HashMap ) save . readObject ( ) ) ;
2013-02-18 03:46:16 +01:00
try
{
2013-07-31 18:09:47 +02:00
this . interDimLinkList = ( HashMap < Integer , LinkData > ) comboSave . get ( " interDimLinkList " ) ;
2013-02-18 03:46:16 +01:00
}
catch ( Exception e )
{
System . out . println ( " Could not load Link Signature list. Link Sig items will loose restored locations. " ) ;
}
try
{
2013-07-31 18:09:47 +02:00
dimHelper . dimList = ( HashMap < Integer , DimData > ) comboSave . get ( " dimList " ) ;
2013-02-18 03:46:16 +01:00
}
catch ( Exception e )
{
System . out . println ( " Could not load pocket dim list. Saves probably lost, but repairable. Move the files from indivual pocket dim files to active ones. See MC thread for details. " ) ;
}
2013-04-01 09:15:16 +02:00
2013-02-18 03:46:16 +01:00
try
{
2013-07-31 18:09:47 +02:00
dimHelper . blocksToDecay = ( ArrayList < Point3D > ) comboSave . get ( " blocksToDecay " ) ;
2013-02-18 03:46:16 +01:00
}
catch ( Exception e )
{
System . out . println ( " Could not load list of blocks to decay in Limbo. Probably because you updated versions, in which case this is normal. " ) ;
}
save . close ( ) ;
saveFile . close ( ) ;
}
catch ( Exception e4 )
{
try
{
if ( ! firstRun )
{
System . out . println ( " Save data damaged, trying backup... " ) ;
}
World world = FMLCommonHandler . instance ( ) . getMinecraftServerInstance ( ) . worldServers [ 0 ] ;
File dataStore = new File ( world . getSaveHandler ( ) . getMapFileFromName ( " idcounts " ) . getParentFile ( ) . getParent ( ) + " /DimensionalDoorsDataOLD " ) ;
saveFile = new FileInputStream ( dataStore ) ;
ObjectSaveInputStream save = new ObjectSaveInputStream ( saveFile ) ;
HashMap comboSave = ( ( HashMap ) save . readObject ( ) ) ;
try
{
2013-07-31 18:09:47 +02:00
this . interDimLinkList = ( HashMap < Integer , LinkData > ) comboSave . get ( " interDimLinkList " ) ;
2013-02-18 03:46:16 +01:00
}
catch ( Exception e )
{
System . out . println ( " Could not load Link Signature list. Link Sig items will loose restored locations. " ) ;
}
try
{
2013-07-31 18:09:47 +02:00
dimHelper . dimList = ( HashMap < Integer , DimData > ) comboSave . get ( " dimList " ) ;
2013-02-18 03:46:16 +01:00
}
catch ( Exception e )
{
System . out . println ( " Could not load pocket dim list. Saves probably lost, but repairable. Move the files from indivual pocket dim files to active ones. See MC thread for details. " ) ;
}
2013-04-01 09:15:16 +02:00
2013-02-18 03:46:16 +01:00
try
{
2013-07-31 18:09:47 +02:00
dimHelper . blocksToDecay = ( ArrayList < Point3D > ) comboSave . get ( " blocksToDecay " ) ;
2013-02-18 03:46:16 +01:00
}
catch ( Exception e )
{
System . out . println ( " Could not load list of blocks to decay in Limbo. Probably because you updated versions, in which case this is normal. " ) ;
}
save . close ( ) ;
saveFile . close ( ) ;
}
catch ( Exception e2 )
{
if ( ! firstRun )
{
e2 . printStackTrace ( ) ;
System . out . println ( " Could not read data-- SEVERE " ) ;
}
}
2013-06-04 02:56:15 +02:00
}
2013-02-18 03:46:16 +01:00
}
2013-04-01 09:15:16 +02:00
2013-02-18 03:46:16 +01:00
}
2013-04-01 09:15:16 +02:00
public LinkData getRandomLinkData ( boolean allowInPocket )
{
boolean foundRandomDest = false ;
int i = 0 ;
int size = dimHelper . dimList . size ( ) ;
while ( ! foundRandomDest & & size > 0 & & i < 100 )
{
i + + ;
2013-04-01 22:43:11 +02:00
DimData dimData ;
2013-07-31 18:09:47 +02:00
ArrayList < LinkData > linksInDim = new ArrayList < LinkData > ( ) ;
2013-05-27 14:10:07 +02:00
for ( size - - ; size > 0 ; )
2013-04-01 22:43:11 +02:00
{
2013-08-01 01:34:08 +02:00
dimData = dimHelper . instance . getDimData ( ( Integer ) dimList . keySet ( ) . toArray ( ) [ rand . nextInt ( dimList . keySet ( ) . size ( ) ) ] ) ;
2013-04-01 22:43:11 +02:00
if ( dimData = = null )
{
break ;
}
2013-07-12 02:42:57 +02:00
linksInDim = dimData . getLinksInDim ( ) ;
2013-04-01 22:43:11 +02:00
if ( ! linksInDim . isEmpty ( ) )
{
break ;
}
}
2013-04-01 09:15:16 +02:00
2013-04-01 22:43:11 +02:00
if ( linksInDim . isEmpty ( ) )
{
break ;
}
2013-04-01 09:15:16 +02:00
LinkData link1 = ( LinkData ) linksInDim . get ( rand . nextInt ( linksInDim . size ( ) ) ) ;
if ( link1 ! = null )
{
if ( ! link1 . isLocPocket | | allowInPocket )
{
foundRandomDest = true ;
return link1 ;
}
}
}
2013-02-18 03:46:16 +01:00
2013-04-01 09:15:16 +02:00
return null ;
}
2013-04-01 22:43:11 +02:00
2013-08-01 01:34:08 +02:00
/ * *
* Gets a link at the destination of the link provided . Returns null if none exists .
* @param link
* @return
* /
public LinkData getLinkDataAtDestination ( LinkData link )
{
return this . getLinkDataFromCoords ( link . destXCoord , link . destYCoord , link . destZCoord , link . destDimID ) ;
}
/ * *
* Moves the location of the link passed in to the provided coords . Does not change the links destination coords .
* The boolean flag determines whether or not to update other links that point to this link - true causes all links that pointed to this link to be updated
* to point to the new link location .
*
* Return true if there was an actual link to be moved .
*
* @param link
* @param x
* @param y
* @param z
* @param dimID
* @param updateLinksPointingHere
* @return
* /
public boolean moveLinkDataLocation ( LinkData link , int x , int y , int z , int dimID , boolean updateLinksPointingHere )
{
LinkData linkToMove = this . getLinkDataFromCoords ( link . locXCoord , link . locYCoord , link . locZCoord , link . locDimID ) ;
if ( linkToMove ! = null )
{
2013-08-02 00:01:42 +02:00
int oldX = linkToMove . locXCoord ;
int oldY = linkToMove . locYCoord ;
int oldZ = linkToMove . locZCoord ;
int oldDimID = linkToMove . locDimID ;
2013-08-01 01:34:08 +02:00
if ( updateLinksPointingHere )
{
ArrayList < LinkData > incomingLinks = new ArrayList < LinkData > ( ) ;
for ( DimData dimData : dimHelper . dimList . values ( ) )
{
for ( LinkData allLink : dimData . getLinksInDim ( ) )
{
if ( this . getLinkDataAtDestination ( allLink ) = = linkToMove )
{
this . moveLinkDataDestination ( allLink , x , y , z , dimID , false ) ;
}
}
}
}
linkToMove . locDimID = dimID ;
linkToMove . locXCoord = x ;
linkToMove . locYCoord = y ;
linkToMove . locZCoord = z ;
2013-08-02 00:01:42 +02:00
if ( this . getLinkDataFromCoords ( oldX , oldY , oldZ , oldDimID ) ! = null )
{
// this.removeLink(this.getLinkDataFromCoords(oldX,oldY,oldZ,oldDimID));
}
this . createLink ( linkToMove ) ;
LinkData linkTest = dimHelper . instance . getLinkDataFromCoords ( x , y , z , dimID ) ;
linkTest . printLinkData ( ) ;
2013-08-01 01:34:08 +02:00
return true ;
}
return false ;
}
/ * *
* Changes the destination coords of the link passed in if it exists to the provided coords .
* @param link
* @param x
* @param y
* @param z
* @param dimID
* @param updateLinksAtDestination
* @return
* /
public boolean moveLinkDataDestination ( LinkData link , int x , int y , int z , int dimID , boolean updateLinksAtDestination )
{
LinkData linkToMove = this . getLinkDataFromCoords ( link . locXCoord , link . locYCoord , link . locZCoord , link . locDimID ) ;
if ( linkToMove ! = null )
{
if ( updateLinksAtDestination )
{
LinkData linkAtDestination = this . getLinkDataAtDestination ( linkToMove ) ;
if ( linkAtDestination ! = null )
{
this . moveLinkDataLocation ( linkAtDestination , x , y , z , dimID , false ) ;
}
}
linkToMove . destDimID = dimID ;
linkToMove . destXCoord = x ;
linkToMove . destYCoord = y ;
linkToMove . destZCoord = z ;
2013-08-02 00:01:42 +02:00
this . createLink ( linkToMove ) ;
LinkData testLink = this . getLinkDataFromCoords ( link . locXCoord , link . locYCoord , link . locZCoord , link . locDimID ) ;
2013-08-01 01:34:08 +02:00
return true ;
}
return false ;
}
2013-02-18 03:46:16 +01:00
/ * *
* gets a link based on coords and a world object
* @param x
* @param y
* @param z
* @param par1World
* @return
* /
public LinkData getLinkDataFromCoords ( int x , int y , int z , World par1World )
{
return this . getLinkDataFromCoords ( x , y , z , par1World . provider . dimensionId ) ;
}
/ * *
* gets a link based on coords and a world ID
* @param x
* @param y
* @param z
* @param worldID
* @return
* /
public LinkData getLinkDataFromCoords ( int x , int y , int z , int worldID )
{
2013-07-31 18:09:47 +02:00
if ( dimHelper . dimList . containsKey ( worldID ) )
2013-02-18 03:46:16 +01:00
{
2013-08-01 01:34:08 +02:00
DimData dimData = dimHelper . instance . getDimData ( worldID ) ;
2013-02-18 03:46:16 +01:00
return dimData . findLinkAtCoords ( x , y , z ) ;
}
return null ;
}
/ * *
* function called by rift tile entities and the rift remover to find and spread between rifts . Does not actually de - register the rift data , see deleteRift for that .
* @param world
* @param x
* @param y
* @param z
* @param range
* @param player
* @param item
* @return
* /
public static boolean removeRift ( World world , int x , int y , int z , int range , EntityPlayer player , ItemStack item )
{
2013-06-14 01:01:54 +02:00
DDProperties properties = DDProperties . instance ( ) ;
2013-02-18 03:46:16 +01:00
LinkData nearest = null ;
float distance = range + 1 ;
int i = - range ;
int j = - range ;
int k = - range ;
while ( i < range )
{
while ( j < range )
{
while ( k < range )
{
2013-06-14 01:01:54 +02:00
if ( world . getBlockId ( x + i , y + j , z + k ) = = properties . RiftBlockID & & MathHelper . abs ( i ) + MathHelper . abs ( j ) + MathHelper . abs ( k ) < distance )
2013-02-18 03:46:16 +01:00
{
if ( MathHelper . abs ( i ) + MathHelper . abs ( j ) + MathHelper . abs ( k ) ! = 0 | | range = = 1 )
{
nearest = dimHelper . instance . getLinkDataFromCoords ( x + i , y + j , z + k , world . provider . dimensionId ) ;
distance = MathHelper . abs ( i ) + MathHelper . abs ( j ) + MathHelper . abs ( k ) ;
}
}
k + + ;
}
k = - range ;
j + + ;
}
j = - range ;
i + + ;
}
if ( nearest ! = null )
{
if ( world . getBlockTileEntity ( nearest . locXCoord , nearest . locYCoord , nearest . locZCoord ) ! = null )
{
TileEntity tile = world . getBlockTileEntity ( nearest . locXCoord , nearest . locYCoord , nearest . locZCoord ) ;
TileEntityRift tilerift = ( TileEntityRift ) tile ;
tilerift . shouldClose = true ;
//System.out.println("erasing rift");
item . damageItem ( 1 , player ) ;
return true ;
}
}
return false ;
}
public static void setBlockDirectly ( World world , int x , int y , int z , int id , int metadata )
{
int cX = x > > 4 ;
int cZ = z > > 4 ;
int cY = y > > 4 ;
Chunk chunk ;
int chunkX = ( x % 16 ) < 0 ? ( ( x ) % 16 ) + 16 : ( ( x ) % 16 ) ;
int chunkY = y ;
int chunkZ = ( ( z ) % 16 ) < 0 ? ( ( z ) % 16 ) + 16 : ( ( z ) % 16 ) ;
// this.chunk=new EmptyChunk(world,cX, cZ);
try
{
chunk = world . getChunkFromChunkCoords ( cX , cZ ) ;
if ( chunk . getBlockStorageArray ( ) [ cY ] = = null ) {
chunk . getBlockStorageArray ( ) [ cY ] = new ExtendedBlockStorage ( cY < < 4 , ! world . provider . hasNoSky ) ;
}
chunk . getBlockStorageArray ( ) [ cY ] . setExtBlockID ( chunkX , ( y ) & 15 , chunkZ , id ) ;
chunk . getBlockStorageArray ( ) [ cY ] . setExtBlockMetadata ( chunkX , ( y ) & 15 , chunkZ , metadata ) ;
}
catch ( Exception e )
{
e . printStackTrace ( ) ;
}
}
public void addDimData ( DimData dimData )
{
2013-07-31 18:09:47 +02:00
dimHelper . dimList . put ( dimData . dimID , dimData ) ;
2013-02-18 03:46:16 +01:00
}
2013-03-18 23:42:56 +01:00
public void createDimData ( World world )
{
2013-07-31 18:09:47 +02:00
dimHelper . dimList . put ( world . provider . dimensionId , new DimData ( world . provider . dimensionId , false , 0 , 0 , world . provider . getSpawnPoint ( ) . posX , world . provider . getSpawnPoint ( ) . posY , world . provider . getSpawnPoint ( ) . posZ ) ) ;
2013-03-18 23:42:56 +01:00
}
2013-07-31 02:15:55 +02:00
public DimData getDimData ( World world )
2013-08-01 01:34:08 +02:00
{
return dimHelper . instance . getDimData ( world . provider . dimensionId ) ;
2013-07-31 02:15:55 +02:00
}
public DimData getDimData ( int dimID )
{
2013-07-31 18:09:47 +02:00
if ( dimHelper . dimList . containsKey ( dimID ) )
2013-07-31 02:15:55 +02:00
{
2013-07-31 18:09:47 +02:00
return dimHelper . dimList . get ( dimID ) ;
2013-07-31 02:15:55 +02:00
}
else
{
return null ;
}
}
2013-02-18 03:46:16 +01:00
2013-06-07 04:22:23 +02:00
}