Finished loading savedata
This commit is contained in:
@@ -8,6 +8,7 @@ import java.util.TreeMap;
|
|||||||
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import StevenDimDoors.mod_pocketDim.DDProperties;
|
import StevenDimDoors.mod_pocketDim.DDProperties;
|
||||||
|
import StevenDimDoors.mod_pocketDim.Point3D;
|
||||||
import StevenDimDoors.mod_pocketDim.dungeon.DungeonData;
|
import StevenDimDoors.mod_pocketDim.dungeon.DungeonData;
|
||||||
import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPack;
|
import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPack;
|
||||||
import StevenDimDoors.mod_pocketDim.util.Point4D;
|
import StevenDimDoors.mod_pocketDim.util.Point4D;
|
||||||
@@ -134,7 +135,7 @@ public abstract class NewDimData
|
|||||||
IUpdateWatcher<Point4D> linkWatcher)
|
IUpdateWatcher<Point4D> linkWatcher)
|
||||||
{
|
{
|
||||||
// The isPocket flag is redundant. It's meant as an integrity safeguard.
|
// The isPocket flag is redundant. It's meant as an integrity safeguard.
|
||||||
if (isPocket != (parent != null))
|
if (isPocket && (parent == null))
|
||||||
{
|
{
|
||||||
throw new NullPointerException("Dimensions can be pocket dimensions if and only if they have a parent dimension.");
|
throw new NullPointerException("Dimensions can be pocket dimensions if and only if they have a parent dimension.");
|
||||||
}
|
}
|
||||||
@@ -347,6 +348,11 @@ public abstract class NewDimData
|
|||||||
return linkMapping.get(location);
|
return linkMapping.get(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DimLink getLink(Point3D location)
|
||||||
|
{
|
||||||
|
return linkMapping.get(new Point4D(location.getX(),location.getY(),location.getZ(),this.id));
|
||||||
|
}
|
||||||
|
|
||||||
public DimLink getLink(Point4D location)
|
public DimLink getLink(Point4D location)
|
||||||
{
|
{
|
||||||
if (location.getDimension() != id)
|
if (location.getDimension() != id)
|
||||||
|
|||||||
@@ -256,6 +256,40 @@ public class PocketManager
|
|||||||
isLoaded = true;
|
isLoaded = true;
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean registerPackedDimData(PackedDimData packedData)
|
||||||
|
{
|
||||||
|
InnerDimData dimData;
|
||||||
|
|
||||||
|
if(packedData.ID==packedData.ParentID)
|
||||||
|
{
|
||||||
|
dimData = new InnerDimData(packedData.ID, null, false, false, linkWatcher);
|
||||||
|
dimData.root=dimData;
|
||||||
|
dimData.parent=dimData;
|
||||||
|
dimData.isFilled=packedData.IsFilled;
|
||||||
|
|
||||||
|
PocketManager.rootDimensions.add(dimData);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
InnerDimData test = PocketManager.dimensionData.get(packedData.ParentID);
|
||||||
|
dimData = new InnerDimData(packedData.ID, test,true, packedData.IsDungeon, linkWatcher);
|
||||||
|
dimData.isFilled=packedData.IsFilled;
|
||||||
|
|
||||||
|
dimData.root=PocketManager.getDimensionData(packedData.RootID);
|
||||||
|
|
||||||
|
if(packedData.DungeonData!=null)
|
||||||
|
{
|
||||||
|
dimData.dungeon=DDSaveHandler.unpackDungeonData(packedData.DungeonData);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
PocketManager.dimensionData.put(dimData.id, dimData);
|
||||||
|
dimWatcher.onCreated(new ClientDimData(dimData));
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
public static boolean deletePocket(NewDimData target, boolean deleteFolder)
|
public static boolean deletePocket(NewDimData target, boolean deleteFolder)
|
||||||
{
|
{
|
||||||
// We can't delete the dimension if it's currently loaded or if it's not actually a pocket.
|
// We can't delete the dimension if it's currently loaded or if it's not actually a pocket.
|
||||||
@@ -380,7 +414,7 @@ public class PocketManager
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
System.out.println("Writing Dimensional Doors save data...");
|
System.out.println("Writing Dimensional Doors save data...");
|
||||||
if ( DDSaveHandler.saveAll(dimensionData.values()) )
|
// if ( DDSaveHandler.saveAll(dimensionData.values()) )
|
||||||
{
|
{
|
||||||
System.out.println("Saved successfully!");
|
System.out.println("Saved successfully!");
|
||||||
}
|
}
|
||||||
@@ -587,6 +621,11 @@ public class PocketManager
|
|||||||
Compactor.write(dimensionData.values(), output);
|
Compactor.write(dimensionData.values(), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isRegisteredInternally(int dimensionID)
|
||||||
|
{
|
||||||
|
return dimensionData.containsKey(dimensionID);
|
||||||
|
}
|
||||||
|
|
||||||
public static void readPacket(DataInputStream input) throws IOException
|
public static void readPacket(DataInputStream input) throws IOException
|
||||||
{
|
{
|
||||||
if (isLoaded)
|
if (isLoaded)
|
||||||
|
|||||||
@@ -7,7 +7,16 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.minecraftforge.common.DimensionManager;
|
import net.minecraftforge.common.DimensionManager;
|
||||||
|
import StevenDimDoors.mod_pocketDim.Point3D;
|
||||||
|
import StevenDimDoors.mod_pocketDim.core.DimLink;
|
||||||
|
import StevenDimDoors.mod_pocketDim.core.NewDimData;
|
||||||
|
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||||
|
import StevenDimDoors.mod_pocketDim.dungeon.DungeonData;
|
||||||
|
import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPack;
|
||||||
|
import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonType;
|
||||||
|
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
|
||||||
import StevenDimDoors.mod_pocketDim.util.FileFilters;
|
import StevenDimDoors.mod_pocketDim.util.FileFilters;
|
||||||
|
import StevenDimDoors.mod_pocketDim.util.Point4D;
|
||||||
|
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
|
|
||||||
@@ -47,14 +56,22 @@ public class DDSaveHandler
|
|||||||
for (File dataFile : dataFiles)
|
for (File dataFile : dataFiles)
|
||||||
{
|
{
|
||||||
PackedDimData packedDim = readDimension(dataFile, reader);
|
PackedDimData packedDim = readDimension(dataFile, reader);
|
||||||
//packedDims.add(packedDim);
|
packedDims.add(packedDim);
|
||||||
}
|
}
|
||||||
return unpackDimData(packedDims);
|
|
||||||
|
List<PackedLinkData> linksToUnpack = new ArrayList<PackedLinkData>();
|
||||||
|
//get the grand list of all links to unpack
|
||||||
|
for(PackedDimData packedDim : packedDims)
|
||||||
|
{
|
||||||
|
linksToUnpack.addAll(packedDim.Links);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return unpackDimData(packedDims)&&unpackLinkData(linksToUnpack);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes a list of packedDimData and rebuilds the DimData for it, as well as registering all of
|
* Takes a list of packedDimData and rebuilds the DimData for it
|
||||||
* them and their links.
|
|
||||||
* @param packedDims
|
* @param packedDims
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -62,18 +79,78 @@ public class DDSaveHandler
|
|||||||
{
|
{
|
||||||
List<PackedDimData> unpackedDims = new ArrayList<PackedDimData>();
|
List<PackedDimData> unpackedDims = new ArrayList<PackedDimData>();
|
||||||
|
|
||||||
while(!packedDims.isEmpty())
|
|
||||||
{
|
|
||||||
//Load roots
|
//Load roots
|
||||||
for(PackedDimData packedDim : packedDims)
|
for(PackedDimData packedDim : packedDims)
|
||||||
{
|
{
|
||||||
if(packedDim.ParentID==packedDim.ID)
|
if(packedDim.ParentID==packedDim.ID)
|
||||||
{
|
{
|
||||||
|
PocketManager.registerPackedDimData(packedDim);
|
||||||
|
unpackedDims.add(packedDim);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
packedDims.removeAll(unpackedDims);
|
packedDims.removeAll(unpackedDims);
|
||||||
|
unpackedDims.clear();
|
||||||
|
|
||||||
|
//Load the pockets
|
||||||
|
while(!packedDims.isEmpty())
|
||||||
|
{
|
||||||
|
for(PackedDimData packedDim : packedDims)
|
||||||
|
{
|
||||||
|
if(PocketManager.isRegisteredInternally(packedDim.ParentID))
|
||||||
|
{
|
||||||
|
PocketManager.registerPackedDimData(packedDim);
|
||||||
|
unpackedDims.add(packedDim);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//break here gracefully
|
||||||
|
}
|
||||||
|
}
|
||||||
|
packedDims.removeAll(unpackedDims);
|
||||||
|
unpackedDims.clear();
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean unpackLinkData(List<PackedLinkData> linksToUnpack)
|
||||||
|
{
|
||||||
|
Point3D fakePoint = new Point3D(-1,-1,-1);
|
||||||
|
List<PackedLinkData> unpackedLinks = new ArrayList<PackedLinkData>();
|
||||||
|
/**
|
||||||
|
* sort through the list, unpacking links that do not have parents.
|
||||||
|
*/
|
||||||
|
//TODO- what we have a loop of links?
|
||||||
|
for(PackedLinkData packedLink : linksToUnpack)
|
||||||
|
{
|
||||||
|
if(packedLink.parent.equals(fakePoint))
|
||||||
|
{
|
||||||
|
NewDimData data = PocketManager.getDimensionData(packedLink.source.getDimension());
|
||||||
|
DimLink link = data.createLink(packedLink.source, packedLink.tail.linkType, packedLink.orientation);
|
||||||
|
Point4D destination = packedLink.tail.destination;
|
||||||
|
if(destination!=null)
|
||||||
|
{
|
||||||
|
PocketManager.getDimensionData(destination.getDimension()).setDestination(link, destination.getX(),destination.getY(),destination.getZ());
|
||||||
|
}
|
||||||
|
unpackedLinks.add(packedLink);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
linksToUnpack.removeAll(unpackedLinks);
|
||||||
|
|
||||||
|
//unpack remaining children
|
||||||
|
while(!linksToUnpack.isEmpty())
|
||||||
|
{
|
||||||
|
for(PackedLinkData packedLink : linksToUnpack)
|
||||||
|
{
|
||||||
|
NewDimData data = PocketManager.getDimensionData(packedLink.source.getDimension());
|
||||||
|
if(data.getLink(packedLink.parent)!=null)
|
||||||
|
{
|
||||||
|
data.createChildLink(packedLink.source.getX(), packedLink.source.getY(), packedLink.source.getZ(), data.getLink(packedLink.parent));
|
||||||
|
}
|
||||||
|
unpackedLinks.add(packedLink);
|
||||||
|
}
|
||||||
|
linksToUnpack.removeAll(unpackedLinks);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -162,4 +239,20 @@ public class DDSaveHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO - make this more robust
|
||||||
|
public static DungeonData unpackDungeonData(PackedDungeonData packedDungeon)
|
||||||
|
{
|
||||||
|
DungeonPack pack;
|
||||||
|
DungeonType type;
|
||||||
|
|
||||||
|
for(DungeonData data : DungeonHelper.instance().getRegisteredDungeons())
|
||||||
|
{
|
||||||
|
if(data.schematicName().equals(packedDungeon.SchematicName))
|
||||||
|
{
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user