Deserializing Savedata completed
This commit is contained in:
@@ -333,8 +333,9 @@ public class PocketManager
|
||||
*/
|
||||
private static void loadInternal()
|
||||
{
|
||||
if (FMLCommonHandler.instance().getSide().isServer()&&
|
||||
DimensionManager.getCurrentSaveRootDirectory() != null)
|
||||
System.out.println(!FMLCommonHandler.instance().getSide().isClient());
|
||||
|
||||
if (DimensionManager.getCurrentSaveRootDirectory() != null)
|
||||
{
|
||||
// Load and register blacklisted dimension IDs
|
||||
|
||||
|
||||
@@ -9,12 +9,15 @@ import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import scala.Char;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import StevenDimDoors.mod_pocketDim.Point3D;
|
||||
@@ -41,14 +44,32 @@ public class DimDataProcessor extends BaseConfigurationProcessor<PackedDimData>
|
||||
@Override
|
||||
public PackedDimData readFromStream(InputStream inputStream)
|
||||
throws ConfigurationProcessingException
|
||||
{
|
||||
return null;
|
||||
{
|
||||
try
|
||||
{
|
||||
JsonReader reader = new JsonReader(new InputStreamReader(inputStream, "UTF-8"));
|
||||
PackedDimData data = this.createDImDataFromJson(reader);
|
||||
return data;
|
||||
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
throw new ConfigurationProcessingException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(OutputStream outputStream, PackedDimData data)
|
||||
throws ConfigurationProcessingException
|
||||
{
|
||||
/** Print out dimData using the GSON built in serializer. I dont feel bad doing this because
|
||||
* 1- We can read it
|
||||
* 2- We are manually reading the data in.
|
||||
* 3- The error messages tell us exactly where its failing, so its easy to fix
|
||||
*/
|
||||
|
||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||
Gson gson = gsonBuilder.setPrettyPrinting().create();
|
||||
|
||||
@@ -59,10 +80,190 @@ public class DimDataProcessor extends BaseConfigurationProcessor<PackedDimData>
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
// not sure if this is kosher, we need it to explode, but not by throwing the IO exception.
|
||||
throw new ConfigurationProcessingException();
|
||||
}
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
/**
|
||||
* Nightmare method that takes a JsonReader pointed at a serialized instance of PackedDimData
|
||||
* @param reader
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public PackedDimData createDImDataFromJson(JsonReader reader) throws IOException
|
||||
{
|
||||
int ID;
|
||||
boolean IsDungeon;
|
||||
boolean IsFilled;
|
||||
int Depth;
|
||||
int PackDepth;
|
||||
int ParentID;
|
||||
int RootID;
|
||||
Point3D Origin;
|
||||
int Orientation;
|
||||
List<Integer> ChildIDs;
|
||||
List<PackedLinkData> Links;
|
||||
List<PackedLinkTail> Tails = new ArrayList<PackedLinkTail>();
|
||||
|
||||
reader.beginObject();
|
||||
|
||||
reader.nextName();
|
||||
ID = reader.nextInt();
|
||||
|
||||
reader.nextName();
|
||||
IsDungeon = reader.nextBoolean();
|
||||
|
||||
reader.nextName();
|
||||
IsFilled = reader.nextBoolean();
|
||||
|
||||
reader.nextName();
|
||||
Depth = reader.nextInt();
|
||||
|
||||
reader.nextName();
|
||||
PackDepth = reader.nextInt();
|
||||
|
||||
reader.nextName();
|
||||
ParentID=reader.nextInt();
|
||||
|
||||
reader.nextName();
|
||||
RootID= reader.nextInt();
|
||||
|
||||
reader.nextName();
|
||||
Origin = createPointFromJson(reader);
|
||||
|
||||
reader.nextName();
|
||||
Orientation = reader.nextInt();
|
||||
|
||||
reader.nextName();
|
||||
ChildIDs = this.createIntListFromJson(reader);
|
||||
|
||||
reader.nextName();
|
||||
Links = this.createLinksListFromJson(reader);
|
||||
|
||||
return new PackedDimData(ID, Depth, PackDepth, ParentID, RootID, Orientation, IsDungeon, IsFilled, Origin, ChildIDs, Links, Tails);
|
||||
}
|
||||
|
||||
private Point3D createPointFromJson(JsonReader reader) throws IOException
|
||||
{
|
||||
reader.beginObject();
|
||||
|
||||
reader.nextName();
|
||||
int x = reader.nextInt();
|
||||
|
||||
reader.nextName();
|
||||
int y = reader.nextInt();
|
||||
|
||||
reader.nextName();
|
||||
int z = reader.nextInt();
|
||||
|
||||
reader.endObject();
|
||||
|
||||
return new Point3D(x,y,z);
|
||||
}
|
||||
|
||||
private Point4D createPoint4DFromJson(JsonReader reader) throws IOException
|
||||
{
|
||||
reader.beginObject();
|
||||
|
||||
reader.nextName();
|
||||
int x = reader.nextInt();
|
||||
|
||||
reader.nextName();
|
||||
int y = reader.nextInt();
|
||||
|
||||
reader.nextName();
|
||||
int z = reader.nextInt();
|
||||
|
||||
reader.nextName();
|
||||
int dimension = reader.nextInt();
|
||||
|
||||
reader.endObject();
|
||||
|
||||
return new Point4D(x,y,z,dimension);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private List<PackedLinkData> createLinksListFromJson(JsonReader reader) throws IOException
|
||||
{
|
||||
List<PackedLinkData> list = new ArrayList<PackedLinkData>();
|
||||
|
||||
reader.beginArray();
|
||||
|
||||
while(reader.peek()!= JsonToken.END_ARRAY)
|
||||
{
|
||||
list.add(createLinkDataFromJson(reader));
|
||||
}
|
||||
reader.endArray();
|
||||
return list;
|
||||
}
|
||||
|
||||
private PackedLinkData createLinkDataFromJson(JsonReader reader) throws IOException
|
||||
{
|
||||
Point4D source;
|
||||
Point3D parent;
|
||||
PackedLinkTail tail;
|
||||
int orientation;
|
||||
List<Point3D> children = new ArrayList<Point3D>();
|
||||
|
||||
reader.beginObject();
|
||||
|
||||
reader.nextName();
|
||||
source = this.createPoint4DFromJson(reader);
|
||||
|
||||
reader.nextName();
|
||||
parent = this.createPointFromJson(reader);
|
||||
|
||||
reader.nextName();
|
||||
tail = this.createLinkTailFromJson(reader);
|
||||
|
||||
reader.nextName();
|
||||
orientation = reader.nextInt();
|
||||
|
||||
reader.nextName();
|
||||
reader.beginArray();
|
||||
|
||||
while(reader.peek() != JsonToken.END_ARRAY)
|
||||
{
|
||||
children.add(this.createPointFromJson(reader));
|
||||
}
|
||||
reader.endArray();
|
||||
reader.endObject();
|
||||
|
||||
return new PackedLinkData(source, parent, tail, orientation, children);
|
||||
}
|
||||
|
||||
private PackedLinkTail createLinkTailFromJson(JsonReader reader) throws IOException
|
||||
{
|
||||
Point4D destination=null;
|
||||
int linkType;
|
||||
reader.beginObject();
|
||||
reader.nextName();
|
||||
|
||||
JsonToken test =reader.peek();
|
||||
if(reader.peek()==JsonToken.BEGIN_OBJECT)
|
||||
{
|
||||
destination = this.createPoint4DFromJson(reader);
|
||||
reader.nextName();
|
||||
}
|
||||
|
||||
linkType = reader.nextInt();
|
||||
reader.endObject();
|
||||
|
||||
return new PackedLinkTail(destination, linkType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,7 +355,7 @@ public class TileEntityRift extends TileEntity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(INetworkManager net, Packet132TileEntityData pkt)
|
||||
public void onDataPacket(INetworkManager net, Packet132TileEntityData pkt)
|
||||
{
|
||||
readFromNBT(pkt.customParam1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user