fixed serialization for urbanist over the network
This commit is contained in:
parent
4b144864d6
commit
d27f8d90ab
4 changed files with 85 additions and 34 deletions
41
common/buildcraft/builders/urbanism/AnchoredBox.java
Executable file
41
common/buildcraft/builders/urbanism/AnchoredBox.java
Executable file
|
@ -0,0 +1,41 @@
|
|||
/**
|
||||
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.builders.urbanism;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import buildcraft.core.Box;
|
||||
import buildcraft.core.network.NetworkData;
|
||||
|
||||
public class AnchoredBox {
|
||||
@NetworkData
|
||||
public Box box = new Box();
|
||||
|
||||
@NetworkData
|
||||
public float x1, y1, z1;
|
||||
|
||||
public void setP2 (float x2, float y2, float z2) {
|
||||
box.initialize(x1, y1, z1, x2, y2, z2);
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
nbt.setFloat("anchorX", x1);
|
||||
nbt.setFloat("anchorY", y1);
|
||||
nbt.setFloat("anchorZ", z1);
|
||||
|
||||
box.writeToNBT(nbt);
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
x1 = nbt.getFloat("anchorX");
|
||||
y1 = nbt.getFloat("anchorY");
|
||||
z1 = nbt.getFloat("anchorZ");
|
||||
|
||||
box.initialize(nbt);
|
||||
}
|
||||
}
|
|
@ -14,7 +14,6 @@ import net.minecraft.util.ResourceLocation;
|
|||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import buildcraft.builders.urbanism.TileUrbanist.AnchoredBox;
|
||||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.render.RenderBox;
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import buildcraft.builders.blueprints.BlueprintBuilder.SchematicBuilder;
|
|||
import buildcraft.builders.filler.pattern.FillerPattern;
|
||||
import buildcraft.core.Box;
|
||||
import buildcraft.core.TileBuildCraft;
|
||||
import buildcraft.core.network.NetworkData;
|
||||
import buildcraft.core.network.RPC;
|
||||
import buildcraft.core.network.RPCHandler;
|
||||
import buildcraft.core.network.RPCSide;
|
||||
|
@ -40,31 +41,7 @@ public class TileUrbanist extends TileBuildCraft implements IInventory {
|
|||
|
||||
int p2x = 0, p2y = 0, p2z = 0;
|
||||
|
||||
public static class AnchoredBox {
|
||||
Box box = new Box();
|
||||
float x1, y1, z1;
|
||||
|
||||
public void setP2 (float x2, float y2, float z2) {
|
||||
box.initialize(x1, y1, z1, x2, y2, z2);
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
nbt.setFloat("anchorX", x1);
|
||||
nbt.setFloat("anchorY", y1);
|
||||
nbt.setFloat("anchorZ", z1);
|
||||
|
||||
box.writeToNBT(nbt);
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
x1 = nbt.getFloat("anchorX");
|
||||
y1 = nbt.getFloat("anchorY");
|
||||
z1 = nbt.getFloat("anchorZ");
|
||||
|
||||
box.initialize(nbt);
|
||||
}
|
||||
}
|
||||
|
||||
@NetworkData
|
||||
public ArrayList <AnchoredBox> frames = new ArrayList <AnchoredBox> ();
|
||||
|
||||
LinkedList <UrbanistTask> tasks = new LinkedList <UrbanistTask> ();
|
||||
|
|
|
@ -10,8 +10,6 @@ package buildcraft.core.network;
|
|||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Type;
|
||||
|
@ -20,9 +18,8 @@ import java.util.LinkedList;
|
|||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import buildcraft.core.utils.Utils;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import buildcraft.core.utils.Utils;
|
||||
|
||||
/**
|
||||
* This class implements custom class mapping. There are three advantages in
|
||||
|
@ -75,6 +72,7 @@ public class ClassMapping {
|
|||
private LinkedList<Field> booleanFields = new LinkedList<Field>();
|
||||
private LinkedList<Field> enumFields = new LinkedList<Field>();
|
||||
private LinkedList<Field> nbtFields = new LinkedList<Field>();
|
||||
private LinkedList<Field> arrayListFields = new LinkedList<Field>();
|
||||
|
||||
class FieldObject {
|
||||
public Field field;
|
||||
|
@ -143,7 +141,7 @@ public class ClassMapping {
|
|||
continue;
|
||||
}
|
||||
|
||||
Type t = f.getGenericType();
|
||||
Type t = f.getType();
|
||||
|
||||
if (t instanceof Class) {
|
||||
Class fieldClass = (Class) t;
|
||||
|
@ -162,8 +160,11 @@ public class ClassMapping {
|
|||
floatFields.add(f);
|
||||
} else if (fieldClass.equals(double.class)) {
|
||||
doubleFields.add(f);
|
||||
} else if (NBTBase.class.isAssignableFrom(fieldClass)) {
|
||||
} else if (NBTTagCompound.class.isAssignableFrom(fieldClass)) {
|
||||
nbtFields.add(f);
|
||||
} else if (ArrayList.class.isAssignableFrom(fieldClass)) {
|
||||
System.out.println ("ARRAY LIST IN MAPPING");
|
||||
arrayListFields.add(f);
|
||||
} else {
|
||||
FieldObject obj = new FieldObject();
|
||||
obj.mapping = get (fieldClass);
|
||||
|
@ -283,7 +284,7 @@ public class ClassMapping {
|
|||
}
|
||||
|
||||
for (Field f : doubleFields) {
|
||||
data.writeDouble((double) f.getDouble(obj));
|
||||
data.writeDouble(f.getDouble(obj));
|
||||
}
|
||||
|
||||
for (Field f : stringFields) {
|
||||
|
@ -308,6 +309,21 @@ public class ClassMapping {
|
|||
}
|
||||
}
|
||||
|
||||
for (Field f : arrayListFields) {
|
||||
ArrayList list = (ArrayList) f.get(obj);
|
||||
|
||||
if (list == null) {
|
||||
data.writeBoolean(false);
|
||||
} else {
|
||||
data.writeBoolean(true);
|
||||
data.writeShort(list.size());
|
||||
|
||||
for (Object o : list) {
|
||||
setDataObject(o, null, data, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (FieldObject f : objectFields) {
|
||||
Object cpt = f.field.get(obj);
|
||||
|
||||
|
@ -361,6 +377,24 @@ public class ClassMapping {
|
|||
}
|
||||
}
|
||||
|
||||
for (Field f : arrayListFields) {
|
||||
System.out.println ("RETRIEVE ARRAY LIST");
|
||||
if (data.readBoolean()) {
|
||||
int size = data.readShort();
|
||||
|
||||
ArrayList arr = new ArrayList();
|
||||
|
||||
for (int i = 0; i < size; ++i) {
|
||||
arr.add(updateFromDataObject(null, null,
|
||||
data, context));
|
||||
}
|
||||
|
||||
f.set(obj, arr);
|
||||
} else {
|
||||
f.set(obj, null);
|
||||
}
|
||||
}
|
||||
|
||||
for (Field f : nbtFields) {
|
||||
if (data.readBoolean()) {
|
||||
f.set(obj, Utils.readNBT(data));
|
||||
|
@ -654,7 +688,7 @@ public class ClassMapping {
|
|||
|
||||
Class realClass = obj.getClass();
|
||||
|
||||
if (realClass.equals(baseMapping.mappedClass)) {
|
||||
if (baseMapping != null && realClass.equals(baseMapping.mappedClass)) {
|
||||
data.writeByte(0);
|
||||
} else {
|
||||
if (context.classToId.containsKey(realClass.getCanonicalName())) {
|
||||
|
|
Loading…
Add table
Reference in a new issue