From 75e99e21507afdb0a44d09b32a6721e461441169 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 20 May 2013 21:50:54 -0400 Subject: [PATCH] Add forge network handling support Updated FML: MinecraftForge/FML@4922e90d81d8b8b9374c4d04858a06c5bf03965c Separate network mod config from setup. Allows for Forge Packet Handler nicety --- .../common/ForgeDummyContainer.java | 26 +++++++++- .../network/ForgeConnectionHandler.java | 49 +++++++++++++++++++ .../common/network/ForgeNetworkHandler.java | 19 +++++++ .../common/network/ForgePacketHandler.java | 16 ++++++ .../network/ForgeTinyPacketHandler.java | 15 ++++++ fml | 2 +- 6 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 common/net/minecraftforge/common/network/ForgeConnectionHandler.java create mode 100644 common/net/minecraftforge/common/network/ForgeNetworkHandler.java create mode 100644 common/net/minecraftforge/common/network/ForgePacketHandler.java create mode 100644 common/net/minecraftforge/common/network/ForgeTinyPacketHandler.java diff --git a/common/net/minecraftforge/common/ForgeDummyContainer.java b/common/net/minecraftforge/common/ForgeDummyContainer.java index adadd83b6..3123f379b 100644 --- a/common/net/minecraftforge/common/ForgeDummyContainer.java +++ b/common/net/minecraftforge/common/ForgeDummyContainer.java @@ -3,12 +3,17 @@ package net.minecraftforge.common; import java.io.File; import java.util.Arrays; import java.util.Map; +import java.util.logging.Level; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.server.management.PlayerInstance; import net.minecraft.world.storage.SaveHandler; import net.minecraft.world.storage.WorldInfo; +import net.minecraftforge.common.network.ForgeConnectionHandler; +import net.minecraftforge.common.network.ForgeNetworkHandler; +import net.minecraftforge.common.network.ForgePacketHandler; +import net.minecraftforge.common.network.ForgeTinyPacketHandler; import com.google.common.eventbus.EventBus; import com.google.common.eventbus.Subscribe; @@ -19,11 +24,15 @@ import cpw.mods.fml.common.LoadController; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.ModMetadata; import cpw.mods.fml.common.WorldAccessContainer; +import cpw.mods.fml.common.event.FMLConstructionEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.network.FMLNetworkHandler; +import cpw.mods.fml.common.network.NetworkMod; import static net.minecraftforge.common.ForgeVersion.*; +@NetworkMod(channels="FORGE",connectionHandler=ForgeConnectionHandler.class,packetHandler=ForgePacketHandler.class,tinyPacketHandler=ForgeTinyPacketHandler.class) public class ForgeDummyContainer extends DummyModContainer implements WorldAccessContainer { public static int clumpingThreshold = 64; @@ -83,7 +92,7 @@ public class ForgeDummyContainer extends DummyModContainer implements WorldAcces clumpingThreshold = 64; prop.set(64); } - + prop = config.get(Configuration.CATEGORY_GENERAL, "legacyFurnaceOutput", false); prop.comment = "Controls the sides of vanilla furnaces for Forge's ISidedInventroy, Vanilla defines the output as the bottom, but mods/Forge define it as the sides. Settings this to true will restore the old side relations."; legacyFurnaceSides = prop.getBoolean(false); @@ -123,6 +132,21 @@ public class ForgeDummyContainer extends DummyModContainer implements WorldAcces return true; } + @Subscribe + public void modConstruction(FMLConstructionEvent evt) + { + FMLLog.info("Registering Forge Packet Handler"); + try + { + FMLNetworkHandler.instance().registerNetworkMod(new ForgeNetworkHandler(this)); + FMLLog.info("Succeeded registering Forge Packet Handler"); + } + catch (Exception e) + { + FMLLog.log(Level.SEVERE, e, "Failed to register packet handler for Forge"); + } + } + @Subscribe public void preInit(FMLPreInitializationEvent evt) { diff --git a/common/net/minecraftforge/common/network/ForgeConnectionHandler.java b/common/net/minecraftforge/common/network/ForgeConnectionHandler.java new file mode 100644 index 000000000..eae6d19f5 --- /dev/null +++ b/common/net/minecraftforge/common/network/ForgeConnectionHandler.java @@ -0,0 +1,49 @@ +package net.minecraftforge.common.network; + +import net.minecraft.network.INetworkManager; +import net.minecraft.network.NetLoginHandler; +import net.minecraft.network.packet.NetHandler; +import net.minecraft.network.packet.Packet1Login; +import net.minecraft.server.MinecraftServer; +import cpw.mods.fml.common.network.IConnectionHandler; +import cpw.mods.fml.common.network.Player; + +public class ForgeConnectionHandler implements IConnectionHandler { + + @Override + public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager) + { + + } + + @Override + public String connectionReceived(NetLoginHandler netHandler, INetworkManager manager) + { + return null; + } + + @Override + public void connectionOpened(NetHandler netClientHandler, String server, int port, INetworkManager manager) + { + + } + + @Override + public void connectionOpened(NetHandler netClientHandler, MinecraftServer server, INetworkManager manager) + { + + } + + @Override + public void connectionClosed(INetworkManager manager) + { + + } + + @Override + public void clientLoggedIn(NetHandler clientHandler, INetworkManager manager, Packet1Login login) + { + + } + +} diff --git a/common/net/minecraftforge/common/network/ForgeNetworkHandler.java b/common/net/minecraftforge/common/network/ForgeNetworkHandler.java new file mode 100644 index 000000000..fbcbc47fe --- /dev/null +++ b/common/net/minecraftforge/common/network/ForgeNetworkHandler.java @@ -0,0 +1,19 @@ +package net.minecraftforge.common.network; + +import net.minecraftforge.common.ForgeDummyContainer; +import cpw.mods.fml.common.network.NetworkMod; +import cpw.mods.fml.common.network.NetworkModHandler; + +public class ForgeNetworkHandler extends NetworkModHandler { + public ForgeNetworkHandler(ForgeDummyContainer container) + { + super(container,container.getClass().getAnnotation(NetworkMod.class)); + configureNetworkMod(container); + } + + @Override + public boolean acceptVersion(String version) + { + return true; + } +} diff --git a/common/net/minecraftforge/common/network/ForgePacketHandler.java b/common/net/minecraftforge/common/network/ForgePacketHandler.java new file mode 100644 index 000000000..90c36b83a --- /dev/null +++ b/common/net/minecraftforge/common/network/ForgePacketHandler.java @@ -0,0 +1,16 @@ +package net.minecraftforge.common.network; + +import net.minecraft.network.INetworkManager; +import net.minecraft.network.packet.Packet250CustomPayload; +import cpw.mods.fml.common.network.IPacketHandler; +import cpw.mods.fml.common.network.Player; + +public class ForgePacketHandler implements IPacketHandler { + + @Override + public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) + { + + } + +} diff --git a/common/net/minecraftforge/common/network/ForgeTinyPacketHandler.java b/common/net/minecraftforge/common/network/ForgeTinyPacketHandler.java new file mode 100644 index 000000000..8121f681b --- /dev/null +++ b/common/net/minecraftforge/common/network/ForgeTinyPacketHandler.java @@ -0,0 +1,15 @@ +package net.minecraftforge.common.network; + +import net.minecraft.network.packet.NetHandler; +import net.minecraft.network.packet.Packet131MapData; +import cpw.mods.fml.common.network.ITinyPacketHandler; + +public class ForgeTinyPacketHandler implements ITinyPacketHandler { + + @Override + public void handle(NetHandler handler, Packet131MapData mapData) + { + + } + +} diff --git a/fml b/fml index a3a920437..4922e90d8 160000 --- a/fml +++ b/fml @@ -1 +1 @@ -Subproject commit a3a920437f3ede6841ae2c449a38975b02b28088 +Subproject commit 4922e90d81d8b8b9374c4d04858a06c5bf03965c