Search in sources :

Example 1 with OutboundTarget

use of net.minecraftforge.fml.common.network.FMLOutboundHandler.OutboundTarget in project MinecraftForge by MinecraftForge.

the class FMLEmbeddedChannel method generatePacketFrom.

/**
     * 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;
}
Also used : OutboundTarget(net.minecraftforge.fml.common.network.FMLOutboundHandler.OutboundTarget) Packet(net.minecraft.network.Packet) FMLProxyPacket(net.minecraftforge.fml.common.network.internal.FMLProxyPacket)

Aggregations

Packet (net.minecraft.network.Packet)1 OutboundTarget (net.minecraftforge.fml.common.network.FMLOutboundHandler.OutboundTarget)1 FMLProxyPacket (net.minecraftforge.fml.common.network.internal.FMLProxyPacket)1