Add a utility method for finding the channel handler name based on type. Should fix naming weirdnesses.

This commit is contained in:
Christian committed 2014-01-03 22:57:36 -05:00
1 parent 6f1da6550e
commit 5317672631
2 files changed
+21 -7

No files matched your search

@@ -1,5 +1,6 @@
package cpw.mods.fml.common.network;
import java.util.Map.Entry;
import net.minecraft.network.Packet;
import io.netty.channel.ChannelHandler;
import io.netty.channel.embedded.EmbeddedChannel;
@@ -7,6 +8,7 @@ import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ModContainer;
import cpw.mods.fml.common.network.FMLOutboundHandler.OutboundTarget;
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
import cpw.mods.fml.common.network.internal.FMLRuntimeCodec;
import cpw.mods.fml.relauncher.Side;
/**
@@ -49,4 +51,18 @@ public class FMLEmbeddedChannel extends EmbeddedChannel {
attr(FMLOutboundHandler.FML_MESSAGETARGET).set(outboundTarget);
return pkt;
}
public String findChannelHandlerNameForType(Class<? extends ChannelHandler> type)
{
String targetName = null;
for (Entry<String, ChannelHandler> entry : pipeline())
{
if (FMLRuntimeCodec.class.isInstance(entry.getValue()))
{
targetName = entry.getKey();
break;
}
}
return targetName;
}
}
@@ -12,14 +12,13 @@
package cpw.mods.fml.common.network.internal;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.embedded.EmbeddedChannel;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
@@ -28,11 +27,8 @@ import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.server.management.ServerConfigurationManager;
import net.minecraft.world.World;
import org.apache.logging.log4j.core.helpers.Integers;
import com.google.common.collect.Lists;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.FMLContainer;
import cpw.mods.fml.common.FMLLog;
@@ -149,8 +145,10 @@ public class FMLNetworkHandler
@SideOnly(Side.CLIENT)
private static void addClientHandlers()
{
channelPair.get(Side.CLIENT).pipeline().addAfter("FMLRuntimeCodec#0", "GuiHandler", new OpenGuiHandler());
channelPair.get(Side.CLIENT).pipeline().addAfter("FMLRuntimeCodec#0", "EntitySpawnHandler", new EntitySpawnHandler());
ChannelPipeline pipeline = channelPair.get(Side.CLIENT).pipeline();
String targetName = channelPair.get(Side.CLIENT).findChannelHandlerNameForType(FMLRuntimeCodec.class);
pipeline.addAfter(targetName, "GuiHandler", new OpenGuiHandler());
pipeline.addAfter(targetName, "EntitySpawnHandler", new EntitySpawnHandler());
}
public static void registerChannel(FMLContainer container, Side side)
{