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);
}
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();
}
}
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);
}
}
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));
}
}
}
}
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++;
}
}
Aggregations