Skip to content

Commit

Permalink
Add forge network handling support
Browse files Browse the repository at this point in the history
Updated FML:
MinecraftForge/FML@4922e90 Separate network mod config from setup. Allows for Forge Packet Handler nicety
  • Loading branch information
cpw committed May 21, 2013
1 parent 7f5fa36 commit 75e99e2
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 2 deletions.
26 changes: 25 additions & 1 deletion common/net/minecraftforge/common/ForgeDummyContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
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;
Expand All @@ -19,11 +24,15 @@
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;
Expand Down Expand Up @@ -83,7 +92,7 @@ public ForgeDummyContainer()
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);
Expand Down Expand Up @@ -123,6 +132,21 @@ public boolean registerBus(EventBus bus, LoadController controller)
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)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
{

}

}
19 changes: 19 additions & 0 deletions common/net/minecraftforge/common/network/ForgeNetworkHandler.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
16 changes: 16 additions & 0 deletions common/net/minecraftforge/common/network/ForgePacketHandler.java
Original file line number Diff line number Diff line change
@@ -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)
{

}

}
Original file line number Diff line number Diff line change
@@ -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 changes: 1 addition & 1 deletion fml

0 comments on commit 75e99e2

Please sign in to comment.