diff --git a/fml/src/main/java/cpw/mods/fml/common/FMLDummyContainer.java b/fml/src/main/java/cpw/mods/fml/common/FMLContainer.java
similarity index 95%
rename from fml/src/main/java/cpw/mods/fml/common/FMLDummyContainer.java
rename to fml/src/main/java/cpw/mods/fml/common/FMLContainer.java
index 9668ebc3b..366bff4bb 100644
--- a/fml/src/main/java/cpw/mods/fml/common/FMLDummyContainer.java
+++ b/fml/src/main/java/cpw/mods/fml/common/FMLContainer.java
@@ -16,7 +16,6 @@ import java.io.File;
import java.security.cert.Certificate;
import java.util.Arrays;
import java.util.Map;
-import java.util.Set;
import java.util.logging.Level;
import net.minecraft.nbt.NBTBase;
@@ -30,16 +29,17 @@ import com.google.common.eventbus.EventBus;
import cpw.mods.fml.client.FMLFileResourcePack;
import cpw.mods.fml.client.FMLFolderResourcePack;
import cpw.mods.fml.common.asm.FMLSanityChecker;
+import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameData;
-import cpw.mods.fml.common.registry.ItemData;
+import cpw.mods.fml.relauncher.Side;
/**
* @author cpw
*
*/
-public class FMLDummyContainer extends DummyModContainer implements WorldAccessContainer
+public class FMLContainer extends DummyModContainer implements WorldAccessContainer
{
- public FMLDummyContainer()
+ public FMLContainer()
{
super(new ModMetadata());
ModMetadata meta = getMetadata();
@@ -130,6 +130,7 @@ public class FMLDummyContainer extends DummyModContainer implements WorldAccessC
{
return FMLSanityChecker.fmlLocation;
}
+
@Override
public Class> getCustomResourcePackClass()
{
diff --git a/fml/src/main/java/cpw/mods/fml/common/network/ByteBufUtils.java b/fml/src/main/java/cpw/mods/fml/common/network/ByteBufUtils.java
new file mode 100644
index 000000000..3e32bc999
--- /dev/null
+++ b/fml/src/main/java/cpw/mods/fml/common/network/ByteBufUtils.java
@@ -0,0 +1,62 @@
+package cpw.mods.fml.common.network;
+
+import org.apache.commons.lang3.Validate;
+
+import com.google.common.base.Charsets;
+
+import io.netty.buffer.ByteBuf;
+
+public class ByteBufUtils {
+ public static int varIntByteCount(int toCount)
+ {
+ return (toCount & -128) == 0 ? 1 : ((toCount & -16384) == 0 ? 2 : ((toCount & -2097152) == 0 ? 3 : ((toCount & -268435456) == 0 ? 4 : 5)));
+ }
+ public static int readVarInt(ByteBuf buf, int maxSize)
+ {
+ Validate.isTrue(maxSize < 6 && maxSize > 0, "Varint length is between 1 and 5, not %d", maxSize);
+ int i = 0;
+ int j = 0;
+ byte b0;
+
+ do
+ {
+ b0 = buf.readByte();
+ i |= (b0 & 127) << j++ * 7;
+
+ if (j > maxSize)
+ {
+ throw new RuntimeException("VarInt too big");
+ }
+ }
+ while ((b0 & 128) == 128);
+
+ return i;
+ }
+
+ public static void writeVarInt(ByteBuf to, int toWrite, int maxSize)
+ {
+ Validate.isTrue(varIntByteCount(toWrite) < maxSize, "Integer is too big for %d bytes", maxSize);
+ while ((toWrite & -128) != 0)
+ {
+ to.writeByte(toWrite & 127 | 128);
+ toWrite >>>= 7;
+ }
+
+ to.writeByte(toWrite);
+ }
+ public static String readUTF8String(ByteBuf from)
+ {
+ int len = readVarInt(from,2);
+ String str = from.toString(from.readerIndex(), len, Charsets.UTF_8);
+ from.readerIndex(from.readerIndex() + len);
+ return str;
+ }
+
+ public static void writeUTF8String(ByteBuf to, String string)
+ {
+ byte[] utf8Bytes = string.getBytes(Charsets.UTF_8);
+ Validate.isTrue(varIntByteCount(utf8Bytes.length) < 3, "The string is too long for this encoding.");
+ writeVarInt(to, utf8Bytes.length, 2);
+ to.writeBytes(utf8Bytes);
+ }
+}
diff --git a/fml/src/main/java/cpw/mods/fml/common/network/ClientSidePacketHandler.java b/fml/src/main/java/cpw/mods/fml/common/network/ClientSidePacketHandler.java
new file mode 100644
index 000000000..262d5732e
--- /dev/null
+++ b/fml/src/main/java/cpw/mods/fml/common/network/ClientSidePacketHandler.java
@@ -0,0 +1,23 @@
+package cpw.mods.fml.common.network;
+
+import cpw.mods.fml.common.network.NetworkSide.ClientSide;
+import net.minecraft.network.play.server.S3FPacketCustomPayload;
+
+/**
+ * Handle packets from the server at the client.
+ *
+ * @author cpw
+ *
+ */
+public abstract class ClientSidePacketHandler implements IPacketHandler {
+ @Override
+ public ClientSide side()
+ {
+ return NetworkSide.CLIENT;
+ }
+ /**
+ * Handle the custompayload packet
+ * @param packet
+ */
+ public abstract void handleCustomPayload(S3FPacketCustomPayload packet);
+}
diff --git a/fml/src/main/java/cpw/mods/fml/common/network/FMLIndexedMessageToMessageCodec.java b/fml/src/main/java/cpw/mods/fml/common/network/FMLIndexedMessageToMessageCodec.java
new file mode 100644
index 000000000..b98230bd8
--- /dev/null
+++ b/fml/src/main/java/cpw/mods/fml/common/network/FMLIndexedMessageToMessageCodec.java
@@ -0,0 +1,49 @@
+package cpw.mods.fml.common.network;
+
+import java.util.List;
+
+import gnu.trove.map.hash.TByteObjectHashMap;
+import gnu.trove.map.hash.TObjectByteHashMap;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.handler.codec.MessageToMessageCodec;
+
+public abstract class FMLIndexedMessageToMessageCodec extends MessageToMessageCodec {
+ private TByteObjectHashMap> discriminators = new TByteObjectHashMap>();
+ private TObjectByteHashMap> types = new TObjectByteHashMap>();
+
+ public FMLIndexedMessageToMessageCodec addDiscriminator(byte discriminator, Class extends A> type)
+ {
+ discriminators.put(discriminator, type);
+ types.put(type, discriminator);
+ return this;
+ }
+
+ public abstract void encodeInto(ChannelHandlerContext ctx, A msg, ByteBuf target) throws Exception;
+ @Override
+ protected final void encode(ChannelHandlerContext ctx, A msg, List