Add forge network handling support

Updated FML:
MinecraftForge/FML@4922e90d81 Separate network mod config from setup. Allows for Forge Packet Handler nicety
This commit is contained in:
Christian 2013-05-20 21:50:54 -04:00
parent 7f5fa36fcf
commit 75e99e2150
6 changed files with 125 additions and 2 deletions

View file

@ -3,12 +3,17 @@ package net.minecraftforge.common;
import java.io.File; import java.io.File;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map; import java.util.Map;
import java.util.logging.Level;
import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.management.PlayerInstance; import net.minecraft.server.management.PlayerInstance;
import net.minecraft.world.storage.SaveHandler; import net.minecraft.world.storage.SaveHandler;
import net.minecraft.world.storage.WorldInfo; 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.EventBus;
import com.google.common.eventbus.Subscribe; 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.Loader;
import cpw.mods.fml.common.ModMetadata; import cpw.mods.fml.common.ModMetadata;
import cpw.mods.fml.common.WorldAccessContainer; 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.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent; 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.*; 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 class ForgeDummyContainer extends DummyModContainer implements WorldAccessContainer
{ {
public static int clumpingThreshold = 64; public static int clumpingThreshold = 64;
@ -83,7 +92,7 @@ public class ForgeDummyContainer extends DummyModContainer implements WorldAcces
clumpingThreshold = 64; clumpingThreshold = 64;
prop.set(64); prop.set(64);
} }
prop = config.get(Configuration.CATEGORY_GENERAL, "legacyFurnaceOutput", false); 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."; 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); legacyFurnaceSides = prop.getBoolean(false);
@ -123,6 +132,21 @@ public class ForgeDummyContainer extends DummyModContainer implements WorldAcces
return true; 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 @Subscribe
public void preInit(FMLPreInitializationEvent evt) public void preInit(FMLPreInitializationEvent evt)
{ {

View file

@ -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)
{
}
}

View file

@ -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;
}
}

View file

@ -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)
{
}
}

View file

@ -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)
{
}
}

2
fml

@ -1 +1 @@
Subproject commit a3a920437f3ede6841ae2c449a38975b02b28088 Subproject commit 4922e90d81d8b8b9374c4d04858a06c5bf03965c