Search in sources :

Example 1 with INetHandler

use of net.minecraft.network.INetHandler in project BuildCraft by BuildCraft.

the class ChannelHandler method decodeInto.

@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf data, Packet packet) {
    int start = data.readerIndex();
    INetHandler handler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
    packet.readData(data);
    packet.player = CoreProxy.proxy.getPlayerFromNetHandler(handler);
    int read = data.readerIndex() - start;
    recordStat(ctx, read, packet, EnumOpType.READ);
}
Also used : INetHandler(net.minecraft.network.INetHandler)

Example 2 with INetHandler

use of net.minecraft.network.INetHandler in project BuildCraft by BuildCraft.

the class PacketHandlerTransport method channelRead0.

/**
 * TODO: A lot of this is based on the player to retrieve the world. Passing a dimension id would be more
 * appropriate. More generally, it seems like a lot of these packets could be replaced with tile-based RPCs.
 */
// @Override
@Deprecated
protected void channelRead0(ChannelHandlerContext ctx, Packet packet) {
    // super.channelRead0(ctx, packet);
    try {
        INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
        EntityPlayer player = CoreProxy.proxy.getPlayerFromNetHandler(netHandler);
        // packet.getID();
        int packetID = 0;
        switch(packetID) {
            case PacketIds.PIPE_POWER:
                // onPacketPower(player, (PacketPowerUpdate) packet);
                break;
            case PacketIds.PIPE_LIQUID:
                // action will have happened already at read time
                break;
            case PacketIds.PIPE_TRAVELER:
                {
                    // onPipeTravelerUpdate(player, (PacketPipeTransportTraveler) packet);
                    break;
                }
            case PacketIds.PIPE_ITEMSTACK:
                {
                    // action will have happened already at read time
                    break;
                }
            /**
             * SERVER SIDE *
             */
            case PacketIds.DIAMOND_PIPE_SELECT:
                {
                    onDiamondPipeSelect(player, (PacketSlotChange) packet);
                    break;
                }
            case PacketIds.EMERALD_PIPE_SELECT:
                {
                    onEmeraldPipeSelect(player, (PacketSlotChange) packet);
                    break;
                }
            case PacketIds.PIPE_ITEMSTACK_REQUEST:
                {
                    ((PacketPipeTransportItemStackRequest) packet).sendDataToPlayer(player);
                    break;
                }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : INetHandler(net.minecraft.network.INetHandler) EntityPlayer(net.minecraft.entity.player.EntityPlayer) PacketSlotChange(buildcraft.core.lib.network.PacketSlotChange)

Example 3 with INetHandler

use of net.minecraft.network.INetHandler in project MinecraftForge by MinecraftForge.

the class SimpleChannelHandlerWrapper method channelRead0.

@Override
protected void channelRead0(ChannelHandlerContext ctx, REQ msg) throws Exception {
    INetHandler iNetHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
    MessageContext context = new MessageContext(iNetHandler, side);
    REPLY result = messageHandler.onMessage(msg, context);
    if (result != null) {
        ctx.channel().attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.REPLY);
        ctx.writeAndFlush(result).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
    }
}
Also used : INetHandler(net.minecraft.network.INetHandler)

Example 4 with INetHandler

use of net.minecraft.network.INetHandler in project Charset by CharsetMC.

the class PacketChannelHandler method decode.

@Override
protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception {
    INetHandler iNetHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
    Packet newMsg = registry.instantiatePacket(msg.payload().readUnsignedByte());
    if (newMsg != null) {
        newMsg.readData(iNetHandler, new PacketBuffer(msg.payload()));
        if (newMsg.isAsynchronous()) {
            newMsg.apply(iNetHandler);
        } else {
            IThreadListener listener = Packet.getThreadListener(iNetHandler);
            if (listener.isCallingFromMinecraftThread()) {
                newMsg.apply(iNetHandler);
            } else {
                listener.addScheduledTask(() -> newMsg.apply(iNetHandler));
            }
        }
    }
}
Also used : FMLProxyPacket(net.minecraftforge.fml.common.network.internal.FMLProxyPacket) INetHandler(net.minecraft.network.INetHandler) IThreadListener(net.minecraft.util.IThreadListener) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 5 with INetHandler

use of net.minecraft.network.INetHandler in project Galacticraft by micdoodle8.

the class GalacticraftPacketHandler method channelRead0.

@Override
protected void channelRead0(ChannelHandlerContext ctx, IPacket msg) throws Exception {
    INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
    Side side = ctx.channel().attr(NetworkRegistry.CHANNEL_SOURCE).get();
    EntityPlayer player = GalacticraftCore.proxy.getPlayerFromNetHandler(netHandler);
    if (player == null) {
        return;
    }
    if (side != null) {
        getQueue(side, msg.getDimensionID()).add(new PacketPlayerPair(msg, player));
        livePacketCount++;
    }
}
Also used : Side(net.minecraftforge.fml.relauncher.Side) INetHandler(net.minecraft.network.INetHandler) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Aggregations

INetHandler (net.minecraft.network.INetHandler)5 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 PacketSlotChange (buildcraft.core.lib.network.PacketSlotChange)1 PacketBuffer (net.minecraft.network.PacketBuffer)1 IThreadListener (net.minecraft.util.IThreadListener)1 FMLProxyPacket (net.minecraftforge.fml.common.network.internal.FMLProxyPacket)1 Side (net.minecraftforge.fml.relauncher.Side)1