public static void registerChannel(FMLContainer container, Side side) { channelPair = NetworkRegistry.INSTANCE.newChannel(container, "FML", new FMLRuntimeCodec(), new HandshakeCompletionHandler()); EmbeddedChannel embeddedChannel = channelPair.get(Side.SERVER); embeddedChannel.attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.NOWHERE); if (side == Side.CLIENT) { addClientHandlers(); } }
/** * INTERNAL fire a handshake to all channels * @param networkDispatcher The dispatcher firing * @param origin which side the dispatcher is on */ public void fireNetworkHandshake(NetworkDispatcher networkDispatcher, Side origin) { NetworkHandshakeEstablished handshake = new NetworkHandshakeEstablished(networkDispatcher, networkDispatcher.getNetHandler(), origin); for (Entry<String, FMLEmbeddedChannel> channel : channels.get(origin).entrySet()) { channel.getValue().attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.DISPATCHER); channel.getValue().attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(networkDispatcher); channel.getValue().pipeline().fireUserEventTriggered(handshake); } }
public static void registerChannel(ForgeModContainer forgeModContainer, Side side) { channelPair = NetworkRegistry.INSTANCE.newChannel(forgeModContainer, "FORGE", new ForgeRuntimeCodec()); if (side == Side.CLIENT) { addClientHandlers(); } FMLEmbeddedChannel serverChannel = channelPair.get(Side.SERVER); serverChannel.attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.NOWHERE); String handlerName = serverChannel.findChannelHandlerNameForType(ForgeRuntimeCodec.class); serverChannel.pipeline().addAfter(handlerName, "ServerToClientConnection", new ServerToClientConnectionEstablishedHandler()); }
@Override protected void channelRead0(final ChannelHandlerContext ctx, final NetworkEvent msg) throws Exception { NetUtils.executeSynchronized(ctx, () -> { // TODO asynchronous events, once needed MinecraftForge.EVENT_BUS.post(msg); msg.dispatcher = null; for (NetworkEvent reply : msg.replies) { ctx.channel().attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.REPLY); ctx.writeAndFlush(reply); } }); }
public void sendTo(EntityPlayerMP player, Packet packet) { this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.PLAYER); this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player); this.channels.get(Side.SERVER).writeAndFlush(packet); }
public static ITargetedPacketSender<EntityPlayer> createPlayerSender(Channel channel) { return new FmlTargetedPacketSender<>(channel, OutboundTarget.PLAYER); }
public static ITargetedPacketSender<Integer> createDimensionSender(Channel channel) { return new FmlTargetedPacketSender<>(channel, OutboundTarget.DIMENSION); }
public static ITargetedPacketSender<TargetPoint> createPointSender(Channel channel) { return new FmlTargetedPacketSender<>(channel, OutboundTarget.ALLAROUNDPOINT); }
public static IPacketSender createSender(Channel channel, OutboundTarget target) { return new FmlPacketSender(channel, target); }
public FmlPacketSender(Channel channel, OutboundTarget selector) { super(channel); this.selector = selector; }
public FmlTargetedPacketSender(Channel channel, OutboundTarget selector) { super(channel); this.selector = selector; }
/** * Utility method to generate a regular packet from a custom packet. Basically, it writes the packet through the * outbound side which should have a message to message codec present (such as {@link FMLIndexedMessageToMessageCodec}, * transforming from mod packets to standard {@link FMLProxyPacket}s. * * This is mostly useful in cases where vanilla expects a packet, such as the TileEntity getDescriptionPacket. * * @param object The inbound packet * @return A Packet suitable for passing to vanilla network code. */ public Packet<?> generatePacketFrom(Object object) { OutboundTarget outboundTarget = attr(FMLOutboundHandler.FML_MESSAGETARGET).getAndSet(OutboundTarget.NOWHERE); writeOutbound(object); Packet<?> pkt = (Packet<?>) outboundMessages().poll(); attr(FMLOutboundHandler.FML_MESSAGETARGET).set(outboundTarget); return pkt; }