Java 类cpw.mods.fml.common.network.internal.FMLProxyPacket 实例源码

项目:ExtraUtilities    文件:PacketSplitter.java   
public static List<XUPacketSplit> splitPacket(final FMLProxyPacket packet) {
    final List<XUPacketSplit> out = new ArrayList<XUPacketSplit>();
    final ByteBuf buf = packet.payload().copy();
    int n = buf.readableBytes() / 2007136;
    if (n * 2007136 < buf.readableBytes()) {
        ++n;
    }
    ++PacketSplitter.curSendingIndex;
    LogHelper.debug("Splitting packet to " + n + " packets", new Object[0]);
    for (int i = 0; i < n; ++i) {
        final int s = (buf.readableBytes() < 2007136) ? buf.readableBytes() : 2007136;
        final ByteBuf o = Unpooled.buffer(s);
        buf.readBytes(o, s);
        out.add(new XUPacketSplit(buf, PacketSplitter.curSendingIndex, i, n));
    }
    return out;
}
项目:TRHS_Club_Mod_2016    文件:FMLEventChannel.java   
@Override
FMLNetworkEvent.CustomPacketEvent<?> make(FMLProxyPacket msg)
{
    FMLNetworkEvent.CustomPacketEvent<?> event = null;
    if (msg.handler() instanceof NetHandlerPlayClient)
    {
        NetHandlerPlayClient client = (NetHandlerPlayClient) msg.handler();
        event = new FMLNetworkEvent.ClientCustomPacketEvent(client.func_147298_b(), msg);
    }
    else if (msg.handler() instanceof NetHandlerPlayServer)
    {
        NetHandlerPlayServer server = (NetHandlerPlayServer) msg.handler();
        event = new FMLNetworkEvent.ServerCustomPacketEvent(server.func_147362_b(), msg);
    }
    return event;
}
项目:TRHS_Club_Mod_2016    文件:ChannelRegistrationHandler.java   
@Override
protected void channelRead0(ChannelHandlerContext ctx, FMLProxyPacket msg) throws Exception
{
    Side side = msg.getTarget();
    NetworkManager manager = msg.getOrigin();
    if (msg.channel().equals("REGISTER") || msg.channel().equals("UNREGISTER"))
    {
        byte[] data = new byte[msg.payload().readableBytes()];
        msg.payload().readBytes(data);
        String channels = new String(data,Charsets.UTF_8);
        String[] split = channels.split("\0");
        Set<String> channelSet = ImmutableSet.copyOf(split);
        FMLCommonHandler.instance().fireNetRegistrationEvent(manager, channelSet, msg.channel(), side);
    }
    else
    {
        ctx.fireChannelRead(msg);
    }
}
项目:TRHS_Club_Mod_2016    文件:FMLOutboundHandler.java   
@SuppressWarnings("unchecked")
@Override
public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet)
{
    int dimension = (Integer)args;
    ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.<NetworkDispatcher>builder();
    for (EntityPlayerMP player : (List<EntityPlayerMP>)FMLCommonHandler.instance().getMinecraftServerInstance().func_71203_ab().field_72404_b)
    {
        if (dimension == player.field_71093_bK)
        {
            NetworkDispatcher dispatcher = player.field_71135_a.field_147371_a.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
            // Null dispatchers may exist for fake players - skip them
            if (dispatcher != null) builder.add(dispatcher);
        }
    }
    return builder.build();
}
项目:TRHS_Club_Mod_2016    文件:FMLOutboundHandler.java   
@SuppressWarnings("unchecked")
@Override
public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet)
{
    TargetPoint tp = (TargetPoint)args;
    ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.<NetworkDispatcher>builder();
    for (EntityPlayerMP player : (List<EntityPlayerMP>)FMLCommonHandler.instance().getMinecraftServerInstance().func_71203_ab().field_72404_b)
    {
        if (player.field_71093_bK == tp.dimension)
        {
            double d4 = tp.x - player.field_70165_t;
            double d5 = tp.y - player.field_70163_u;
            double d6 = tp.z - player.field_70161_v;

            if (d4 * d4 + d5 * d5 + d6 * d6 < tp.range * tp.range)
            {
                NetworkDispatcher dispatcher = player.field_71135_a.field_147371_a.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
                if (dispatcher != null) builder.add(dispatcher);
            }
        }
    }
    return builder.build();
}
项目:TRHS_Club_Mod_2016    文件:FMLIndexedMessageToMessageCodec.java   
@Override
protected final void encode(ChannelHandlerContext ctx, A msg, List<Object> out) throws Exception
{
    ByteBuf buffer = Unpooled.buffer();
    @SuppressWarnings("unchecked") // Stupid unnecessary cast I can't seem to kill
    Class<? extends A> clazz = (Class<? extends A>) msg.getClass();
    byte discriminator = types.get(clazz);
    buffer.writeByte(discriminator);
    encodeInto(ctx, msg, buffer);
    FMLProxyPacket proxy = new FMLProxyPacket(buffer.copy(), ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get());
    WeakReference<FMLProxyPacket> ref = ctx.attr(INBOUNDPACKETTRACKER).get().get();
    FMLProxyPacket old = ref == null ? null : ref.get();
    if (old != null)
    {
        proxy.setDispatcher(old.getDispatcher());
    }
    out.add(proxy);
}
项目:TRHS_Club_Mod_2016    文件:FMLIndexedMessageToMessageCodec.java   
@Override
protected final void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception
{
    testMessageValidity(msg);
    ByteBuf payload = msg.payload();
    byte discriminator = payload.readByte();
    Class<? extends A> clazz = discriminators.get(discriminator);
    if(clazz == null)
    {
        throw new NullPointerException("Undefined message for discriminator " + discriminator + " in channel " + msg.channel());
    }
    A newMsg = clazz.newInstance();
    ctx.attr(INBOUNDPACKETTRACKER).get().set(new WeakReference<FMLProxyPacket>(msg));
    decodeInto(ctx, payload.slice(), newMsg);
    out.add(newMsg);
}
项目:FairyFactions    文件:FairyEventListener.java   
protected void handlePacket(FMLProxyPacket proxyPacket, EntityPlayerMP player) {
    final ByteBuf payload = proxyPacket.payload();
    if( payload.readableBytes() > 0 ) {
        final PacketBuffer buf = new PacketBuffer(payload);

        final byte id = buf.readByte();
        final PacketType type = PacketType.get(id);
        if( type == null ) {
            FairyFactions.LOGGER.error("Got unknown packet type "+id);
            return;
        }

        final FairyPacket packet;
        try {
            packet = type.packet_class.newInstance();
        } catch (Exception e) {
            // ERROR, unable to actually process
            e.printStackTrace();
            return;
        }

        packet.init(buf);
        packet.handle(proxyPacket.getOrigin());
    }
}
项目:LookingGlass    文件:PacketCreateView.java   
@SideOnly(Side.CLIENT)
public static FMLProxyPacket createPacket(WorldView worldview) {
    // This line may look like black magic (and, well, it is), but it's actually just returning a class reference for this class. Copy-paste safe.
    ByteBuf data = PacketHandlerBase.createDataBuffer((Class<? extends PacketHandlerBase>) new Object() {}.getClass().getEnclosingClass());

    int x = 0;
    int y = -1;
    int z = 0;
    if (worldview.coords != null) {
        x = worldview.coords.posX >> 4;
        y = worldview.coords.posY >> 4;
        z = worldview.coords.posZ >> 4;
    }

    data.writeInt(worldview.getWorldObj().provider.dimensionId);
    data.writeInt(x);
    data.writeInt(y);
    data.writeInt(z);
    data.writeByte(Math.min(ModConfigs.renderDistance, Minecraft.getMinecraft().gameSettings.renderDistanceChunks));

    return buildPacket(data);
}
项目:CauldronGit    文件:FMLEventChannel.java   
@Override
FMLNetworkEvent.CustomPacketEvent<?> make(FMLProxyPacket msg)
{
    FMLNetworkEvent.CustomPacketEvent<?> event = null;
    if (msg.handler() instanceof NetHandlerPlayClient)
    {
        NetHandlerPlayClient client = (NetHandlerPlayClient) msg.handler();
        event = new FMLNetworkEvent.ClientCustomPacketEvent(client.getNetworkManager(), msg);
    }
    else if (msg.handler() instanceof NetHandlerPlayServer)
    {
        NetHandlerPlayServer server = (NetHandlerPlayServer) msg.handler();
        event = new FMLNetworkEvent.ServerCustomPacketEvent(server.func_147362_b(), msg);
    }
    return event;
}
项目:CauldronGit    文件:ChannelRegistrationHandler.java   
@Override
protected void channelRead0(ChannelHandlerContext ctx, FMLProxyPacket msg) throws Exception
{
    Side side = msg.getTarget();
    NetworkManager manager = msg.getOrigin();
    if (msg.channel().equals("REGISTER") || msg.channel().equals("UNREGISTER"))
    {
        byte[] data = new byte[msg.payload().readableBytes()];
        msg.payload().readBytes(data);
        String channels = new String(data,Charsets.UTF_8);
        String[] split = channels.split("\0");
        Set<String> channelSet = ImmutableSet.copyOf(split);
        FMLCommonHandler.instance().fireNetRegistrationEvent(manager, channelSet, msg.channel(), side);
    }
    else
    {
        ctx.fireChannelRead(msg);
    }
}
项目:CauldronGit    文件:FMLOutboundHandler.java   
@SuppressWarnings("unchecked")
@Override
public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet)
{
    int dimension = (Integer)args;
    ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.<NetworkDispatcher>builder();
    for (EntityPlayerMP player : (List<EntityPlayerMP>)FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().playerEntityList)
    {
        if (dimension == player.dimension)
        {
            NetworkDispatcher dispatcher = player.playerNetServerHandler.netManager.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
            // Null dispatchers may exist for fake players - skip them
            if (dispatcher != null) builder.add(dispatcher);
        }
    }
    return builder.build();
}
项目:CauldronGit    文件:FMLOutboundHandler.java   
@SuppressWarnings("unchecked")
@Override
public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet)
{
    TargetPoint tp = (TargetPoint)args;
    ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.<NetworkDispatcher>builder();
    for (EntityPlayerMP player : (List<EntityPlayerMP>)FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().playerEntityList)
    {
        if (player.dimension == tp.dimension)
        {
            double d4 = tp.x - player.posX;
            double d5 = tp.y - player.posY;
            double d6 = tp.z - player.posZ;

            if (d4 * d4 + d5 * d5 + d6 * d6 < tp.range * tp.range)
            {
                NetworkDispatcher dispatcher = player.playerNetServerHandler.netManager.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
                if (dispatcher != null) builder.add(dispatcher);
            }
        }
    }
    return builder.build();
}
项目:CauldronGit    文件:FMLIndexedMessageToMessageCodec.java   
@Override
protected final void encode(ChannelHandlerContext ctx, A msg, List<Object> out) throws Exception
{
    ByteBuf buffer = Unpooled.buffer();
    @SuppressWarnings("unchecked") // Stupid unnecessary cast I can't seem to kill
    Class<? extends A> clazz = (Class<? extends A>) msg.getClass();
    byte discriminator = types.get(clazz);
    buffer.writeByte(discriminator);
    encodeInto(ctx, msg, buffer);
    FMLProxyPacket proxy = new FMLProxyPacket(buffer.copy(), ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get());
    WeakReference<FMLProxyPacket> ref = ctx.attr(INBOUNDPACKETTRACKER).get().get();
    FMLProxyPacket old = ref == null ? null : ref.get();
    if (old != null)
    {
        proxy.setDispatcher(old.getDispatcher());
    }
    out.add(proxy);
}
项目:CauldronGit    文件:FMLIndexedMessageToMessageCodec.java   
@Override
protected final void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception
{
    testMessageValidity(msg);
    ByteBuf payload = msg.payload();
    byte discriminator = payload.readByte();
    Class<? extends A> clazz = discriminators.get(discriminator);
    if(clazz == null)
    {
        throw new NullPointerException("Undefined message for discriminator " + discriminator + " in channel " + msg.channel());
    }
    A newMsg = clazz.newInstance();
    ctx.attr(INBOUNDPACKETTRACKER).get().set(new WeakReference<FMLProxyPacket>(msg));
    decodeInto(ctx, payload.slice(), newMsg);
    out.add(newMsg);
}
项目:amunra    文件:ConnectionPacketAR.java   
public static FMLProxyPacket createConfigPacket()
{
    ByteBuf payload = Unpooled.buffer();

    payload.writeByte(ID_CONFIG_OVERRIDE);

    NBTTagCompound nbt = AmunRa.config.getServerOverrideData();

    try {
        NetworkUtil.writeNBTTagCompound(nbt, payload);
    } catch (IOException e) {
        e.printStackTrace();
    }

    return new FMLProxyPacket(payload, CHANNEL);
}
项目:amunra    文件:ConnectionPacketAR.java   
public static FMLProxyPacket createMothershipPacket()
{
    ByteBuf payload = Unpooled.buffer();

    payload.writeByte(ID_MOTHERSHIP_LIST);

    NBTTagCompound nbt = new NBTTagCompound ();
    TickHandlerServer.mothershipData.writeToNBT(nbt);

    try {
        NetworkUtil.writeNBTTagCompound(nbt, payload);
    } catch (IOException e) {
        e.printStackTrace();
    }

    return new FMLProxyPacket(payload, CHANNEL);
}
项目:Cauldron    文件:FMLOutboundHandler.java   
@SuppressWarnings("unchecked")
@Override
public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet)
{
    int dimension = (Integer)args;
    ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.<NetworkDispatcher>builder();
    for (EntityPlayerMP player : (List<EntityPlayerMP>)FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().playerEntityList)
    {
        if (dimension == player.dimension)
        {
            NetworkDispatcher dispatcher = player.playerNetServerHandler.netManager.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
            // Null dispatchers may exist for fake players - skip them
            if (dispatcher != null) builder.add(dispatcher);
        }
    }
    return builder.build();
}
项目:StellarForge    文件:PacketPipeline.java   
@Override
protected void encode (ChannelHandlerContext ctx, AbstractPacket msg, List<Object> out) throws Exception
{
    ByteBuf buffer = Unpooled.buffer();
    Class<? extends AbstractPacket> clazz = msg.getClass();
    if (!this.packets.contains(msg.getClass()))
    {
        throw new NullPointerException("No Packet Registered for: " + msg.getClass().getCanonicalName());
    }

    byte discriminator = (byte) this.packets.indexOf(clazz);
    buffer.writeByte(discriminator);
    msg.encodeInto(ctx, buffer);
    FMLProxyPacket proxyPacket = new FMLProxyPacket(buffer.copy(), ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get());
    out.add(proxyPacket);
}
项目:Corruption    文件:CorruptionDataHelper.java   
public static void removeCorruptionEffectForPlayer(EntityPlayer entityPlayer, String name) {
    NBTTagCompound corruptionData = getCorruptionDataForPlayer(entityPlayer);
    NBTTagList corrEffects = corruptionData.getTagList("CorruptionEffects", 8);
    if (corrEffects != null && corrEffects.tagCount() > 0) {
        NBTTagList copy = (NBTTagList) corrEffects.copy();
        for (int i = 0; i < copy.tagCount(); i++) {
            if (name.equals(copy.getStringTagAt(i))) {
                corrEffects.removeTag(i);
                break;
            }
        }
    }
    corruptionData.setTag("CorruptionEffects", corrEffects);

    FMLProxyPacket packet = PacketEventHandler.getCorruptionEffectPacket(entityPlayer.getCommandSenderName(), name, false, false);
    Corruption.eventChannel.sendToAll(packet);
}
项目:Blockbender    文件:NewNetworkHandler.java   
@Override
protected void channelRead0(ChannelHandlerContext ctx, FMLProxyPacket packet) throws Exception {
    if(count == 0) first = System.currentTimeMillis();
    count++;
    if(count % 1000 == 0){
        double delta = System.currentTimeMillis() - last;
        last = System.currentTimeMillis();
        if(first != last && delta != 0) System.out.println(count + "packets received. approx " + (1000000D/delta) + "/sec. Avg:" + (count/(last-first)) + "/sec");          
    }
    Side side = FMLCommonHandler.instance().getEffectiveSide();
    if (side == Side.CLIENT) {
        onClientPacketData(packet);
    }
    else {
        onServerPacketData(packet);
    }
}
项目:Cauldron    文件:ChannelRegistrationHandler.java   
@Override
protected void channelRead0(ChannelHandlerContext ctx, FMLProxyPacket msg) throws Exception
{
    Side side = msg.getTarget();
    NetworkManager manager = msg.getOrigin();
    if (msg.channel().equals("REGISTER") || msg.channel().equals("UNREGISTER"))
    {
        byte[] data = new byte[msg.payload().readableBytes()];
        msg.payload().readBytes(data);
        String channels = new String(data,Charsets.UTF_8);
        String[] split = channels.split("\0");
        Set<String> channelSet = ImmutableSet.copyOf(split);
        FMLCommonHandler.instance().fireNetRegistrationEvent(manager, channelSet, msg.channel(), side);
    }
    else
    {
        ctx.fireChannelRead(msg);
    }
}
项目:Cauldron    文件:FMLOutboundHandler.java   
@SuppressWarnings("unchecked")
@Override
public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet)
{
    TargetPoint tp = (TargetPoint)args;
    ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.<NetworkDispatcher>builder();
    for (EntityPlayerMP player : (List<EntityPlayerMP>)FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().playerEntityList)
    {
        if (player.dimension == tp.dimension)
        {
            double d4 = tp.x - player.posX;
            double d5 = tp.y - player.posY;
            double d6 = tp.z - player.posZ;

            if (d4 * d4 + d5 * d5 + d6 * d6 < tp.range * tp.range)
            {
                NetworkDispatcher dispatcher = player.playerNetServerHandler.netManager.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
                if (dispatcher != null) builder.add(dispatcher);
            }
        }
    }
    return builder.build();
}
项目:Cauldron    文件:FMLOutboundHandler.java   
@SuppressWarnings("unchecked")
@Override
public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet)
{
    int dimension = (Integer)args;
    ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.<NetworkDispatcher>builder();
    for (EntityPlayerMP player : (List<EntityPlayerMP>)FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().playerEntityList)
    {
        if (dimension == player.dimension)
        {
            NetworkDispatcher dispatcher = player.playerNetServerHandler.netManager.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
            // Null dispatchers may exist for fake players - skip them
            if (dispatcher != null) builder.add(dispatcher);
        }
    }
    return builder.build();
}
项目:Cauldron    文件:FMLOutboundHandler.java   
@SuppressWarnings("unchecked")
@Override
public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet)
{
    TargetPoint tp = (TargetPoint)args;
    ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.<NetworkDispatcher>builder();
    for (EntityPlayerMP player : (List<EntityPlayerMP>)FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().playerEntityList)
    {
        if (player.dimension == tp.dimension)
        {
            double d4 = tp.x - player.posX;
            double d5 = tp.y - player.posY;
            double d6 = tp.z - player.posZ;

            if (d4 * d4 + d5 * d5 + d6 * d6 < tp.range * tp.range)
            {
                NetworkDispatcher dispatcher = player.playerNetServerHandler.netManager.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
                if (dispatcher != null) builder.add(dispatcher);
            }
        }
    }
    return builder.build();
}
项目:archimedes-ships    文件:ASMessagePipeline.java   
@Override
protected void encode(ChannelHandlerContext ctx, ASMessage msg, List<Object> out) throws Exception
{
    ByteBuf buffer = Unpooled.buffer();
    Class<? extends ASMessage> clazz = msg.getClass();
    if (!packets.contains(msg.getClass()))
    {
        throw new NullPointerException("No Packet Registered for: " + msg.getClass().getCanonicalName());
    }

    byte discriminator = (byte) packets.indexOf(clazz);
    buffer.writeByte(discriminator);
    try
    {
        msg.encodeInto(ctx, buffer);
    } catch (IOException e)
    {
        e.printStackTrace();
        throw e;
    }
    FMLProxyPacket proxyPacket = new FMLProxyPacket(buffer, ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get());
    out.add(proxyPacket);
}
项目:NBTEdit    文件:PacketPipeline.java   
@Override
protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception {
    ByteBuf payload = msg.payload();
    byte discriminator = payload.readByte();
    Class<? extends AbstractPacket> clazz = this.packets.get(discriminator);

    AbstractPacket pkt = clazz.newInstance();
    pkt.decodeInto(ctx, payload.slice());

    switch (FMLCommonHandler.instance().getEffectiveSide()) {
        case CLIENT:
            pkt.handleClientSide(this.getClientPlayer());
            break;
        case SERVER:
            INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
            pkt.handleServerSide(((NetHandlerPlayServer) netHandler).playerEntity);
            break;
        default:
            break;
    }

    out.add(pkt);
}
项目:Cauldron    文件:FMLEventChannel.java   
@Override
FMLNetworkEvent.CustomPacketEvent<?> make(FMLProxyPacket msg)
{
    FMLNetworkEvent.CustomPacketEvent<?> event = null;
    if (msg.handler() instanceof NetHandlerPlayClient)
    {
        NetHandlerPlayClient client = (NetHandlerPlayClient) msg.handler();
        event = new FMLNetworkEvent.ClientCustomPacketEvent(client.getNetworkManager(), msg);
    }
    else if (msg.handler() instanceof NetHandlerPlayServer)
    {
        NetHandlerPlayServer server = (NetHandlerPlayServer) msg.handler();
        event = new FMLNetworkEvent.ServerCustomPacketEvent(server.func_147362_b(), msg);
    }
    return event;
}
项目:Cauldron    文件:FMLIndexedMessageToMessageCodec.java   
@Override
protected final void encode(ChannelHandlerContext ctx, A msg, List<Object> out) throws Exception
{
    ByteBuf buffer = Unpooled.buffer();
    @SuppressWarnings("unchecked") // Stupid unnecessary cast I can't seem to kill
    Class<? extends A> clazz = (Class<? extends A>) msg.getClass();
    byte discriminator = types.get(clazz);
    buffer.writeByte(discriminator);
    encodeInto(ctx, msg, buffer);
    FMLProxyPacket proxy = new FMLProxyPacket(buffer.copy(), ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get());
    WeakReference<FMLProxyPacket> ref = ctx.attr(INBOUNDPACKETTRACKER).get().get();
    FMLProxyPacket old = ref == null ? null : ref.get();
    if (old != null)
    {
        proxy.setDispatcher(old.getDispatcher());
    }
    out.add(proxy);
}
项目:Cauldron    文件:FMLIndexedMessageToMessageCodec.java   
@Override
protected final void encode(ChannelHandlerContext ctx, A msg, List<Object> out) throws Exception
{
    ByteBuf buffer = Unpooled.buffer();
    @SuppressWarnings("unchecked") // Stupid unnecessary cast I can't seem to kill
    Class<? extends A> clazz = (Class<? extends A>) msg.getClass();
    byte discriminator = types.get(clazz);
    buffer.writeByte(discriminator);
    encodeInto(ctx, msg, buffer);
    FMLProxyPacket proxy = new FMLProxyPacket(buffer.copy(), ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get());
    WeakReference<FMLProxyPacket> ref = ctx.attr(INBOUNDPACKETTRACKER).get().get();
    FMLProxyPacket old = ref == null ? null : ref.get();
    if (old != null)
    {
        proxy.setDispatcher(old.getDispatcher());
    }
    out.add(proxy);
}
项目:4Space-5    文件:ConnectionPacket.java   
public static FMLProxyPacket createDimPacket(Integer[] dims)
{
    ArrayList<Integer> data = new ArrayList();
    for (int i = 0; i < dims.length; i++)
        data.add(dims[i]);
    return createPacket((byte) 101, data);
}
项目:4Space-5    文件:ConnectionPacket.java   
public static FMLProxyPacket createSSPacket(Integer[] dims)
{
    ArrayList<Integer> data = new ArrayList();
    for (int i = 0; i < dims.length; i++)
        data.add(dims[i]);
    return createPacket((byte) 102, data);
}
项目:4Space-5    文件:ConnectionPacket.java   
public static FMLProxyPacket createPacket(byte packetId, Collection<Integer> data)
{
    ByteBuf payload = Unpooled.buffer();

    payload.writeByte(packetId);
    payload.writeInt(data.size());
    for (Integer i : data)
    {
        payload.writeInt(i.intValue());
    }
    payload.writeInt(3519); //signature
    return new FMLProxyPacket(payload, CHANNEL);
}
项目:4Space-5    文件:ConnectionPacket.java   
public static FMLProxyPacket createConfigPacket(List<Object> data)
{
    ByteBuf payload = Unpooled.buffer();
    payload.writeByte(103);
       try
       {
        NetworkUtil.encodeData(payload, data);
       }
       catch (IOException e)
       {
           e.printStackTrace();
       }
    payload.writeInt(3519); //signature
    return new FMLProxyPacket(payload, CHANNEL);
}
项目:4Space-5    文件:ConnectionPacket.java   
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onPacketData(FMLNetworkEvent.ClientCustomPacketEvent event)
{
    FMLProxyPacket pkt = event.packet;

    onFMLProxyPacketData(event.manager, pkt, Minecraft.getMinecraft().thePlayer);
}
项目:4Space-5    文件:ConnectionPacket.java   
@SubscribeEvent
public void onPacketData(FMLNetworkEvent.ServerCustomPacketEvent event)
{
    FMLProxyPacket pkt = event.packet;

    onFMLProxyPacketData(event.manager, pkt, ((NetHandlerPlayServer)event.handler).playerEntity);
}
项目:4Space-5    文件:ConnectionPacket.java   
public void onFMLProxyPacketData(NetworkManager manager, FMLProxyPacket packet, EntityPlayer player)
{
    try {
        if ((packet == null) || (packet.payload() == null)) throw new RuntimeException("Empty packet sent to Galacticraft channel");
        ByteBuf data = packet.payload();
        this.handle(data, player);
    } catch (Exception e) {
        GCLog.severe("GC login packet handler: Failed to read packet");
        GCLog.severe(e.toString());
        e.printStackTrace();
    }
}
项目:4Space-5    文件:PacketCustom.java   
@Override
protected void channelRead0(ChannelHandlerContext ctx, FMLProxyPacket msg) throws Exception {
    handlers.get(ctx.channel().attr(NetworkRegistry.CHANNEL_SOURCE).get())
            .handle(ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(),
                    ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get(),
                    new PacketCustom(msg.payload()));
}
项目:4Space-5    文件:PacketCustom.java   
public FMLProxyPacket toPacket() {
    if (incoming())
        throw new IllegalStateException("Tried to write an incoming packet");

    if (byteBuf.readableBytes() > 32000 || (type & 0x80) != 0)
        do_compress();

    //FML packet impl returns the whole of the backing array, copy used portion of array to another ByteBuf
    return new FMLProxyPacket(byteBuf.copy(), channel);
}
项目:TRHS_Club_Mod_2016    文件:FMLEventChannel.java   
@Override
FMLNetworkEvent.CustomPacketEvent<?> make(FMLProxyPacket msg)
{
    FMLNetworkEvent.CustomPacketEvent<?> event = null;
    if (msg.handler() instanceof NetHandlerPlayServer)
    {
        NetHandlerPlayServer server = (NetHandlerPlayServer) msg.handler();
        event = new FMLNetworkEvent.ServerCustomPacketEvent(server.func_147362_b(), msg);
    }
    return event;
}