java类net.minecraftforge.fml.common.network.internal.FMLProxyPacket的实例源码

FMLOutboundHandler.java 文件源码 项目:CustomWorldGen 阅读 23 收藏 0 点赞 0 评论 0
@Override
public List<NetworkDispatcher> selectNetworks(Object args, ChannelHandlerContext context, FMLProxyPacket packet)
{
    ImmutableList.Builder<NetworkDispatcher> builder = ImmutableList.builder();
    for (EntityPlayerMP player : FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerList())
    {
        NetworkDispatcher dispatcher = player.connection.netManager.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
        if (dispatcher != null) builder.add(dispatcher);
    }
    return builder.build();
}
PacketCustom.java 文件源码 项目:CodeChickenLib 阅读 24 收藏 0 点赞 0 评论 0
public FMLProxyPacket toPacket() {

        if (incoming()) {
            throw new IllegalStateException("Tried to write an incoming packet");
        }

        if (readableBytes() > 32000 || (type & 0x80) != 0) {
            do_compress();
        }

        return new FMLProxyPacket(new PacketBuffer(copy()), channel);
    }
ARKMessagePipeline.java 文件源码 项目:ARKCraft 阅读 23 收藏 0 点赞 0 评论 0
@Override
protected void encode(ChannelHandlerContext ctx, ARKMessage msg, List<Object> out) throws Exception
{
    ByteBuf buffer = Unpooled.buffer();
    Class<? extends ARKMessage> 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);
    msg.encodeInto(ctx, buffer);
    FMLProxyPacket proxyPacket = new FMLProxyPacket((PacketBuffer) buffer, ctx.channel().attr(
            NetworkRegistry.FML_CHANNEL).get());
    out.add(proxyPacket);
}
ARKMessagePipeline.java 文件源码 项目:ARKCraft 阅读 19 收藏 0 点赞 0 评论 0
@Override
protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception
{
    ByteBuf payload = msg.payload();
    byte discriminator = payload.readByte();
    Class<? extends ARKMessage> clazz = packets.get(discriminator);
    if (clazz == null) { throw new NullPointerException("No packet registered for discriminator: "
            + discriminator); }

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

    EntityPlayer player;
    switch (FMLCommonHandler.instance().getEffectiveSide())
    {
        case CLIENT:
            player = getClientPlayer();
            pkt.handleClientSide(player);
            break;

        case SERVER:
            INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
            player = ((NetHandlerPlayServer) netHandler).playerEntity;
            pkt.handleServerSide(player);
            break;

        default:
    }

    out.add(pkt);
}
DescPacketHandler.java 文件源码 项目:Signals 阅读 14 收藏 0 点赞 0 评论 0
@Override
protected void channelRead0(ChannelHandlerContext ctx, FMLProxyPacket msg) {

    PacketDescription packet = new PacketDescription();
    packet.fromBytes(msg.payload());
    packet.handleClientSide(Signals.proxy.getPlayer());
}
NetworkRouter.java 文件源码 项目:Ambidextrous 阅读 23 收藏 0 点赞 0 评论 0
@SuppressWarnings( "unchecked" )
public void onPacketData(
        final FMLProxyPacket packet,
        final INetHandler handler )
{
    final PacketBuffer buffer = new PacketBuffer( packet.payload() );
    final ModPacket innerPacket = parsePacket( buffer );

    PacketThreadUtil.checkThreadAndEnqueue( innerPacket, handler, Minecraft.getMinecraft() );
    innerPacket.client();
}
NetworkRouter.java 文件源码 项目:Ambidextrous 阅读 23 收藏 0 点赞 0 评论 0
private FMLProxyPacket getProxyPacket(
        final ModPacket packet )
{
    final PacketBuffer buffer = new PacketBuffer( Unpooled.buffer() );

    buffer.writeByte( ModPacketTypes.getID( packet.getClass() ) );
    packet.getPayload( buffer );

    return new FMLProxyPacket( buffer, channelName );
}
FlatNet.java 文件源码 项目:Factorization 阅读 23 收藏 0 点赞 0 评论 0
public static void fx(Coord at, EnumFacing side, FlatFace face, byte type) {
    ByteBuf buff = prepare(type);
    writeCoord(buff, at);
    writeSide(buff, side);
    writeFace(buff, face);
    FMLProxyPacket packet = build(buff);
    sendAround(at.getChunk(), packet);
}
FlatNet.java 文件源码 项目:Factorization 阅读 25 收藏 0 点赞 0 评论 0
static FMLProxyPacket syncChunk(EntityPlayer player, Coord at) {
    IExtraChunkData ecd = (IExtraChunkData) at.getChunk();
    FlatChunkLayer data = ecd.getFlatLayer();
    SyncWrite writer = new SyncWrite();
    data.iterate(writer);
    writer.finish();
    return build(writer.buff);
}
FlatNet.java 文件源码 项目:Factorization 阅读 24 收藏 0 点赞 0 评论 0
static void send(EntityPlayer player, FMLProxyPacket toSend) {
    if (player.worldObj.isRemote) {
        channel.sendToServer(toSend);
    } else {
        channel.sendTo(toSend, (EntityPlayerMP) player);
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号