From afc9ce619e3fafed7e967700dfc7e72791770faf Mon Sep 17 00:00:00 2001
From: SpaceToad <spacetoadcraft@gmail.com>
Date: Mon, 23 Jun 2014 08:31:56 +0200
Subject: [PATCH] Fixed writing of polymorphic classes. Fixes #1903 and
 probably many others.

---
 .../core/network/serializers/ClassMapping.java   | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/common/buildcraft/core/network/serializers/ClassMapping.java b/common/buildcraft/core/network/serializers/ClassMapping.java
index 8d9a4a91..b1a5b7ab 100644
--- a/common/buildcraft/core/network/serializers/ClassMapping.java
+++ b/common/buildcraft/core/network/serializers/ClassMapping.java
@@ -253,10 +253,12 @@ public class ClassMapping extends ClassSerializer {
 		Class realClass = obj.getClass();
 
 		if (realClass.equals(this.mappedClass)) {
-			data.writeByte(0);
+			data.writeBoolean(true);
 		} else {
+			data.writeBoolean(false);
 			NetworkIdRegistry.write(data, realClass.getCanonicalName());
 			ClassMapping delegateMapping = (ClassMapping) get(realClass);
+			delegateMapping.writeClass(obj, data, context);
 
 			return;
 		}
@@ -303,16 +305,12 @@ public class ClassMapping extends ClassSerializer {
 		Object obj = objI;
 
 		// The data layout for an object is the following:
-		// [boolean] does the object exist (e.g. non-null)
-		// {false} exit
-		// [int] what is the object real class?
-		// {0} the same as the declared class
-		// {1-x} the network id of the class
+		// [boolean] what is the object real class?
+		// {false} the same as the declared class
+		// {true} the network id of the class
 		// [bytes] the actual contents
 
-		int index = data.readByte();
-
-		if (index != 0) {
+		if (!data.readBoolean()) {
 			String className = NetworkIdRegistry.read(data);
 			Class cls = Class.forName(className);
 			ClassMapping delegateMapping = (ClassMapping) get(cls);