Mazes #117
@@ -10,7 +10,7 @@ import java.util.Iterator;
|
|||||||
|
|
||||||
import net.minecraft.util.MathHelper;
|
import net.minecraft.util.MathHelper;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
@Deprecated
|
||||||
public class DimData implements Serializable
|
public class DimData implements Serializable
|
||||||
{
|
{
|
||||||
public int dimID;
|
public int dimID;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPack;
|
|||||||
import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonType;
|
import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonType;
|
||||||
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
|
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public class DungeonGenerator implements Serializable
|
public class DungeonGenerator implements Serializable
|
||||||
{
|
{
|
||||||
//This static field is hax so that I don't have to add an instance field to DungeonGenerator to support DungeonType.
|
//This static field is hax so that I don't have to add an instance field to DungeonGenerator to support DungeonType.
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package StevenDimDoors.mod_pocketDim;
|
package StevenDimDoors.mod_pocketDim;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
@Deprecated
|
||||||
public class LinkData implements Serializable
|
public class LinkData implements Serializable
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import java.util.LinkedList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import StevenDimDoors.mod_pocketDim.util.Point4D;
|
import StevenDimDoors.mod_pocketDim.util.Point4D;
|
||||||
|
@Deprecated
|
||||||
public abstract class DimLink
|
public abstract class DimLink
|
||||||
{
|
{
|
||||||
protected Point4D source;
|
protected Point4D source;
|
||||||
|
|||||||
@@ -372,6 +372,18 @@ public class PocketManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for(Integer dimID : dimensionIDBlackList)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
DimensionManager.unregisterDimension(dimID);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
System.err.println("An unexpected error occurred while unregistering blacklisted dim #" + dimID + ":");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -384,7 +396,8 @@ public class PocketManager
|
|||||||
File saveDir = DimensionManager.getCurrentSaveRootDirectory();
|
File saveDir = DimensionManager.getCurrentSaveRootDirectory();
|
||||||
if (saveDir != null)
|
if (saveDir != null)
|
||||||
{
|
{
|
||||||
// Load and register blacklisted dimension IDs
|
//Try to import data from old DD versions
|
||||||
|
//TODO - remove this code in a few versions
|
||||||
File oldSaveData = new File(saveDir+"/DimensionalDoorsData");
|
File oldSaveData = new File(saveDir+"/DimensionalDoorsData");
|
||||||
if(oldSaveData.exists())
|
if(oldSaveData.exists())
|
||||||
{
|
{
|
||||||
@@ -395,7 +408,6 @@ public class PocketManager
|
|||||||
oldSaveData.delete();
|
oldSaveData.delete();
|
||||||
|
|
||||||
System.out.println("Import Succesful!");
|
System.out.println("Import Succesful!");
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -436,7 +448,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(),dimensionIDBlackList) )
|
||||||
{
|
{
|
||||||
System.out.println("Saved successfully!");
|
System.out.println("Saved successfully!");
|
||||||
}
|
}
|
||||||
@@ -648,6 +660,15 @@ public class PocketManager
|
|||||||
return dimensionData.containsKey(dimensionID);
|
return dimensionData.containsKey(dimensionID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void createAndRegisterBlacklist(List<Integer> blacklist)
|
||||||
|
{
|
||||||
|
//TODO - create a special blacklist provider
|
||||||
|
for(Integer dimID : blacklist)
|
||||||
|
{
|
||||||
|
PocketManager.dimensionIDBlackList.add(dimID);
|
||||||
|
DimensionManager.registerDimension(dimID, DDProperties.instance().PocketProviderID);
|
||||||
|
}
|
||||||
|
}
|
||||||
public static void readPacket(DataInputStream input) throws IOException
|
public static void readPacket(DataInputStream input) throws IOException
|
||||||
{
|
{
|
||||||
if (isLoaded)
|
if (isLoaded)
|
||||||
|
|||||||
@@ -1,17 +1,23 @@
|
|||||||
package StevenDimDoors.mod_pocketDim.helpers;
|
package StevenDimDoors.mod_pocketDim.helpers;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.common.DimensionManager;
|
||||||
import net.minecraftforge.common.ForgeChunkManager;
|
import net.minecraftforge.common.ForgeChunkManager;
|
||||||
import net.minecraftforge.common.ForgeChunkManager.LoadingCallback;
|
import net.minecraftforge.common.ForgeChunkManager.LoadingCallback;
|
||||||
import net.minecraftforge.common.ForgeChunkManager.Ticket;
|
import net.minecraftforge.common.ForgeChunkManager.Ticket;
|
||||||
import StevenDimDoors.mod_pocketDim.IChunkLoader;
|
import StevenDimDoors.mod_pocketDim.IChunkLoader;
|
||||||
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
|
||||||
|
import StevenDimDoors.mod_pocketDim.core.NewDimData;
|
||||||
|
import StevenDimDoors.mod_pocketDim.core.PocketManager;
|
||||||
import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoorGold;
|
import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoorGold;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.event.FMLServerStartingEvent;
|
||||||
|
|
||||||
|
|
||||||
public class ChunkLoaderHelper implements LoadingCallback
|
public class ChunkLoaderHelper implements LoadingCallback
|
||||||
{
|
{
|
||||||
@@ -29,4 +35,27 @@ public class ChunkLoaderHelper implements LoadingCallback
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void loadChunkForcedWorlds(FMLServerStartingEvent event)
|
||||||
|
{
|
||||||
|
for(NewDimData data : PocketManager.getDimensions())
|
||||||
|
{
|
||||||
|
if(data.isPocketDimension())
|
||||||
|
{
|
||||||
|
String chunkDir = DimensionManager.getCurrentSaveRootDirectory()+"/DimensionalDoors/pocketDimID" + data.id();
|
||||||
|
|
||||||
|
File file = new File(chunkDir);
|
||||||
|
|
||||||
|
if(file.exists())
|
||||||
|
{
|
||||||
|
if(ForgeChunkManager.savedWorldHasForcedChunkTickets(file))
|
||||||
|
{
|
||||||
|
PocketManager.loadDimension(data.id());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -424,5 +424,7 @@ public class mod_pocketDim
|
|||||||
CommandCreatePocket.instance().register(event);
|
CommandCreatePocket.instance().register(event);
|
||||||
CommandTeleportPlayer.instance().register(event);
|
CommandTeleportPlayer.instance().register(event);
|
||||||
|
|
||||||
|
|
||||||
|
ChunkLoaderHelper.loadChunkForcedWorlds(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
76
StevenDimDoors/mod_pocketDim/saving/BlacklistProcessor.java
Normal file
76
StevenDimDoors/mod_pocketDim/saving/BlacklistProcessor.java
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
package StevenDimDoors.mod_pocketDim.saving;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.stream.JsonReader;
|
||||||
|
import com.google.gson.stream.JsonToken;
|
||||||
|
|
||||||
|
import StevenDimDoors.mod_pocketDim.util.BaseConfigurationProcessor;
|
||||||
|
import StevenDimDoors.mod_pocketDim.util.ConfigurationProcessingException;
|
||||||
|
|
||||||
|
public class BlacklistProcessor extends BaseConfigurationProcessor<List<Integer>>
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Integer> readFromStream(InputStream inputStream) throws ConfigurationProcessingException
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
JsonReader reader = new JsonReader(new InputStreamReader(inputStream, "UTF-8"));
|
||||||
|
List<Integer> data = this.createBlacklistFromJson(reader);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new ConfigurationProcessingException("Could not read blacklist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Integer> createBlacklistFromJson(JsonReader reader) throws IOException
|
||||||
|
{
|
||||||
|
List<Integer> blacklist;
|
||||||
|
blacklist = this.createIntListFromJson(reader);
|
||||||
|
return blacklist;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToStream(OutputStream outputStream, List<Integer> data) throws ConfigurationProcessingException
|
||||||
|
{
|
||||||
|
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||||
|
Gson gson = gsonBuilder.setPrettyPrinting().create();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
outputStream.write(gson.toJson(data).getBytes("UTF-8"));
|
||||||
|
outputStream.close();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
// not sure if this is kosher, we need it to explode, but not by throwing the IO exception.
|
||||||
|
throw new ConfigurationProcessingException("Incorrectly formatted save data");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Integer> createIntListFromJson(JsonReader reader) throws IOException
|
||||||
|
{
|
||||||
|
List<Integer> list = new ArrayList<Integer>();
|
||||||
|
reader.beginArray();
|
||||||
|
|
||||||
|
while(reader.peek()!= JsonToken.END_ARRAY)
|
||||||
|
{
|
||||||
|
list.add(reader.nextInt());
|
||||||
|
}
|
||||||
|
reader.endArray();
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package StevenDimDoors.mod_pocketDim.saving;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
import java.io.FileFilter;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -16,6 +17,7 @@ import StevenDimDoors.mod_pocketDim.dungeon.DungeonData;
|
|||||||
import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPack;
|
import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonPack;
|
||||||
import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonType;
|
import StevenDimDoors.mod_pocketDim.dungeon.pack.DungeonType;
|
||||||
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
|
import StevenDimDoors.mod_pocketDim.helpers.DungeonHelper;
|
||||||
|
import StevenDimDoors.mod_pocketDim.util.ConfigurationProcessingException;
|
||||||
import StevenDimDoors.mod_pocketDim.util.FileFilters;
|
import StevenDimDoors.mod_pocketDim.util.FileFilters;
|
||||||
import StevenDimDoors.mod_pocketDim.util.Point4D;
|
import StevenDimDoors.mod_pocketDim.util.Point4D;
|
||||||
|
|
||||||
@@ -46,7 +48,14 @@ public class DDSaveHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load the dimension blacklist
|
// Load the dimension blacklist
|
||||||
// --insert code here--
|
File blacklistFile = new File(basePath+"blacklist.txt");
|
||||||
|
|
||||||
|
if(blacklistFile.exists())
|
||||||
|
{
|
||||||
|
BlacklistProcessor blacklistReader = new BlacklistProcessor();
|
||||||
|
List<Integer> blacklist = readBlacklist(blacklistFile,blacklistReader);
|
||||||
|
PocketManager.createAndRegisterBlacklist(blacklist);
|
||||||
|
}
|
||||||
|
|
||||||
// List any dimension data files and read each dimension
|
// List any dimension data files and read each dimension
|
||||||
DimDataProcessor reader = new DimDataProcessor();
|
DimDataProcessor reader = new DimDataProcessor();
|
||||||
@@ -179,7 +188,7 @@ public class DDSaveHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean saveAll(Iterable<? extends IPackable<PackedDimData>> dimensions) throws IOException
|
public static boolean saveAll(Iterable<? extends IPackable<PackedDimData>> dimensions, List<Integer> blacklist) throws IOException
|
||||||
{
|
{
|
||||||
// Create the data directory for our dimensions
|
// Create the data directory for our dimensions
|
||||||
// Don't catch exceptions here. If we can't create this folder,
|
// Don't catch exceptions here. If we can't create this folder,
|
||||||
@@ -190,6 +199,9 @@ public class DDSaveHandler
|
|||||||
Files.createParentDirs(basePathFile);
|
Files.createParentDirs(basePathFile);
|
||||||
basePathFile.mkdir();
|
basePathFile.mkdir();
|
||||||
|
|
||||||
|
BlacklistProcessor blacklistReader = new BlacklistProcessor();
|
||||||
|
writeBlacklist(blacklist, blacklistReader,basePath);
|
||||||
|
|
||||||
FileFilter dataFileFilter = new FileFilters.RegexFileFilter("dim_-?\\d+\\.txt");
|
FileFilter dataFileFilter = new FileFilters.RegexFileFilter("dim_-?\\d+\\.txt");
|
||||||
|
|
||||||
//TODO Deal with temp files correctly
|
//TODO Deal with temp files correctly
|
||||||
@@ -212,6 +224,25 @@ public class DDSaveHandler
|
|||||||
return succeeded;
|
return succeeded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean writeBlacklist(List<Integer> blacklist, BlacklistProcessor writer, String basePath)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File tempFile = new File(basePath + "blacklist.tmp");
|
||||||
|
File saveFile = new File(basePath + "blacklist.txt");
|
||||||
|
writer.writeToFile(tempFile, blacklist);
|
||||||
|
saveFile.delete();
|
||||||
|
tempFile.renameTo(saveFile);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
System.err.println("Could not save blacklist. The following error occurred:");
|
||||||
|
printException(e, true);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
private static boolean writeDimension(IPackable<PackedDimData> dimension, DimDataProcessor writer, String basePath)
|
private static boolean writeDimension(IPackable<PackedDimData> dimension, DimDataProcessor writer, String basePath)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -262,16 +293,28 @@ public class DDSaveHandler
|
|||||||
//TODO - make this more robust
|
//TODO - make this more robust
|
||||||
public static DungeonData unpackDungeonData(PackedDungeonData packedDungeon)
|
public static DungeonData unpackDungeonData(PackedDungeonData packedDungeon)
|
||||||
{
|
{
|
||||||
DungeonPack pack;
|
|
||||||
DungeonType type;
|
|
||||||
|
|
||||||
for(DungeonData data : DungeonHelper.instance().getRegisteredDungeons())
|
for(DungeonData data : DungeonHelper.instance().getRegisteredDungeons())
|
||||||
{
|
{
|
||||||
if(data.schematicName().equals(packedDungeon.SchematicName))
|
if(data.schematicName().equals(packedDungeon.SchematicName))
|
||||||
{
|
{
|
||||||
//return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<Integer> readBlacklist(File blacklistFile, BlacklistProcessor reader)
|
||||||
|
{
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return reader.readFromFile(blacklistFile);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,8 +68,6 @@ public class DimDataProcessor extends BaseConfigurationProcessor<PackedDimData>
|
|||||||
// not sure if this is kosher, we need it to explode, but not by throwing the IO exception.
|
// not sure if this is kosher, we need it to explode, but not by throwing the IO exception.
|
||||||
throw new ConfigurationProcessingException("Incorrectly formatted save data");
|
throw new ConfigurationProcessingException("Incorrectly formatted save data");
|
||||||
}
|
}
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Nightmare method that takes a JsonReader pointed at a serialized instance of PackedDimData
|
* Nightmare method that takes a JsonReader pointed at a serialized instance of PackedDimData
|
||||||
|
|||||||
6
StevenDimDoors/mod_pocketDim/world/ItemWorldThread.java
Normal file
6
StevenDimDoors/mod_pocketDim/world/ItemWorldThread.java
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package StevenDimDoors.mod_pocketDim.world;
|
||||||
|
|
||||||
|
public class ItemWorldThread
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user