net.minecraft.network.INetHandler Java Examples

The following examples show how to use net.minecraft.network.INetHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PacketPipeline.java    From NBTEdit with GNU General Public License v3.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: MCPacketHandler.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void channelRead0(ChannelHandlerContext ctx, PacketAbstract packet) throws Exception {
	INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();

	switch (FMLCommonHandler.instance().getEffectiveSide()) {
		case CLIENT:
			packet.handleClientSide(NovaMinecraft.proxy.getClientPlayer());
			break;
		case SERVER:
			packet.handleServerSide(((NetHandlerPlayServer) netHandler).playerEntity);
			break;
		default:
			break;
	}

}
 
Example #3
Source File: MCPacketHandler.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void channelRead0(ChannelHandlerContext ctx, PacketAbstract packet) throws Exception {
	INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();

	switch (FMLCommonHandler.instance().getEffectiveSide()) {
		case CLIENT:
			FMLClientHandler.instance().getClient().addScheduledTask(() -> packet.handleClientSide(NovaMinecraft.proxy.getClientPlayer()));
			break;
		case SERVER:
			FMLCommonHandler.instance().getMinecraftServerInstance().addScheduledTask(() -> packet.handleServerSide(((NetHandlerPlayServer) netHandler).playerEntity));
			break;
		default:
			break;
	}

}
 
Example #4
Source File: MCPacketHandler.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void channelRead0(ChannelHandlerContext ctx, PacketAbstract packet) throws Exception {
	INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();

	switch (FMLCommonHandler.instance().getEffectiveSide()) {
		case CLIENT:
			FMLClientHandler.instance().getClient().addScheduledTask(() -> packet.handleClientSide(NovaMinecraft.proxy.getClientPlayer()));
			break;
		case SERVER:
			FMLCommonHandler.instance().getMinecraftServerInstance().addScheduledTask(() -> packet.handleServerSide(((NetHandlerPlayServer) netHandler).player));
			break;
		default:
			break;
	}

}
 
Example #5
Source File: PacketCustomChannelBuilder.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent
public void onClientPayload(NetworkEvent.LoginPayloadEvent event) {
    PacketCustom packet = new PacketCustom(event.getPayload());
    NetworkEvent.Context ctx = event.getSource().get();
    INetHandler netHandler = ctx.getNetworkManager().getNetHandler();
    ctx.setPacketHandled(true);
    if (netHandler instanceof ClientLoginNetHandler) {
        ClientLoginNetHandler nh = (ClientLoginNetHandler) netHandler;
        packetHandler.handleLoginPacket(packet, Minecraft.getInstance(), nh, ctx);
        //For _some_ reason sending this response packet in FML is private. So just spoof the packet :D
        ctx.getPacketDispatcher().sendPacket(new ResourceLocation("fml:handshake"), new PacketBuffer(Unpooled.buffer().writeByte(99)));
    }
}
 
Example #6
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void handle(final INetHandler netHandler, final String channel, final PacketCustom packet) {
    if (netHandler instanceof INetHandlerPlayClient) {
        Minecraft mc = Minecraft.getMinecraft();
        if (!mc.isCallingFromMinecraftThread())
            mc.addScheduledTask(new Runnable() {
                public void run() {
                    handle(netHandler, channel, packet);
                }
            });
        else
            handler.handlePacket(packet, mc, (INetHandlerPlayClient) netHandler);
    } else
        System.err.println("Invalid INetHandler for PacketCustom on channel: " + channel);
}
 
Example #7
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void handle(final INetHandler netHandler, final String channel, final PacketCustom packet) {
    if (netHandler instanceof NetHandlerPlayServer) {
        MinecraftServer mc = MinecraftServer.getServer();
        if (!mc.isCallingFromMinecraftThread())
            mc.addScheduledTask(new Runnable() {
                public void run() {
                    handle(netHandler, channel, packet);
                }
            });
        else
            handler.handlePacket(packet, ((NetHandlerPlayServer) netHandler).playerEntity, (INetHandlerPlayServer) netHandler);
    } else
        System.err.println("Invalid INetHandler for PacketCustom on channel: " + channel);
}
 
Example #8
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof NetworkHandshakeEstablished) {
        INetHandler netHandler = ((NetworkDispatcher) ctx.channel().attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).get()).getNetHandler();
        if (netHandler instanceof NetHandlerPlayServer)
            handler.handshakeRecieved((NetHandlerPlayServer) netHandler);
    } else
        ctx.fireUserEventTriggered(evt);
}
 
Example #9
Source File: PacketCustomChannelBuilder.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent
public void onServerPayload(NetworkEvent.ClientCustomPayloadEvent event) {
    PacketCustom packet = new PacketCustom(event.getPayload());
    NetworkEvent.Context ctx = event.getSource().get();
    INetHandler netHandler = ctx.getNetworkManager().getNetHandler();
    ctx.setPacketHandled(true);
    if (netHandler instanceof ServerPlayNetHandler) {
        ServerPlayNetHandler nh = (ServerPlayNetHandler) netHandler;
        ctx.enqueueWork(() -> packetHandler.handlePacket(packet, nh.player, nh));
    }
}
 
Example #10
Source File: PacketCustomChannelBuilder.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent
public void onClientPayload(NetworkEvent.ServerCustomPayloadEvent event) {
    if (event instanceof NetworkEvent.ServerCustomPayloadLoginEvent) {
        return;
    }
    PacketCustom packet = new PacketCustom(event.getPayload());
    NetworkEvent.Context ctx = event.getSource().get();
    INetHandler netHandler = ctx.getNetworkManager().getNetHandler();
    ctx.setPacketHandled(true);
    if (netHandler instanceof ClientPlayNetHandler) {
        ClientPlayNetHandler nh = (ClientPlayNetHandler) netHandler;
        ctx.enqueueWork(() -> packetHandler.handlePacket(packet, Minecraft.getInstance(), nh));
    }
}
 
Example #11
Source File: MixinPacketUtil.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Inject(method = "onProcessPacket", at = @At(value = "RETURN"))
private static void postOnProcessPacket(Packet packetIn, INetHandler netHandler,
    CallbackInfo info) {
    if (packetIn instanceof ITransformablePacket) {
        ITransformablePacket transformPacket = (ITransformablePacket) packetIn;
        transformPacket.doPostProcessing((NetHandlerPlayServer) netHandler, true);
    }
}
 
Example #12
Source File: MixinPacketUtil.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Inject(method = "onProcessPacket", at = @At(value = "HEAD"))
private static void preOnProcessPacket(Packet packetIn, INetHandler netHandler,
    CallbackInfo info) {
    if (packetIn instanceof ITransformablePacket) {
        ITransformablePacket transformPacket = (ITransformablePacket) packetIn;
        transformPacket.doPreProcessing((NetHandlerPlayServer) netHandler, true);
    }
}
 
Example #13
Source File: NetworkEventCodec.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception {
	final Channel channel = ctx.channel();
	final Side side = channel.attr(NetworkRegistry.CHANNEL_SOURCE).get();

	final PacketBuffer payload = new PacketBuffer(msg.payload());
	final int typeId = payload.readVarInt();
	final NetworkEventEntry type = CommonRegistryCallbacks.getEntryIdMap(registry).inverse().get(typeId);

	final EventDirection validator = type.getDirection();
	Preconditions.checkState(validator != null && validator.validateReceive(side),
			"Invalid direction: receiving packet %s on side %s", msg.getClass(), side);

	final NetworkEvent event = type.createPacket();
	event.readFromStream(payload);
	event.dispatcher = msg.getDispatcher();

	event.side = side;

	final INetHandler handler = msg.handler();
	if (handler != null) event.sender = OpenMods.proxy.getPlayerFromHandler(handler);

	final int bufferJunkSize = payload.readableBytes();
	if (bufferJunkSize > 0) Log.warn("%s junk bytes left in buffer, event %s", bufferJunkSize, event);

	out.add(event);
	payload.release();
}
 
Example #14
Source File: OpenClientProxy.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
public EntityPlayer getPlayerFromHandler(INetHandler handler) {
	if (handler instanceof NetHandlerPlayServer) return ((NetHandlerPlayServer)handler).player;

	if (handler instanceof NetHandlerPlayClient) return getThePlayer();

	return null;
}
 
Example #15
Source File: WrapperINetHandler.java    From ClientBase with MIT License 4 votes vote down vote up
public INetHandler unwrap() {
    return this.real;
}
 
Example #16
Source File: RpcCallCodec.java    From OpenModsLib with MIT License 4 votes vote down vote up
protected EntityPlayer getPlayer(FMLProxyPacket msg) {
	INetHandler handler = msg.handler();
	EntityPlayer player = OpenMods.proxy.getPlayerFromHandler(handler);
	Preconditions.checkNotNull(player, "Can't get player from handler %s", handler);
	return player;
}
 
Example #17
Source File: OpenServerProxy.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public EntityPlayer getPlayerFromHandler(INetHandler handler) {
	if (handler instanceof NetHandlerPlayServer) return ((NetHandlerPlayServer)handler).player;

	return null;
}
 
Example #18
Source File: ASMessagePipeline.java    From archimedes-ships with MIT License 4 votes vote down vote up
@Override
protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception
{
	ByteBuf payload = msg.payload();
	byte discriminator = payload.readByte();
	Class<? extends ASMessage> clazz = packets.get(discriminator);
	if (clazz == null)
	{
		throw new NullPointerException("No packet registered for discriminator: " + discriminator);
	}
	
	EntityPlayer player = null;
	Side side = FMLCommonHandler.instance().getEffectiveSide();
	switch (side)
	{
	case CLIENT:
		player = getClientPlayer();
		break;
	case SERVER:
		INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
		player = ((NetHandlerPlayServer) netHandler).playerEntity;
		break;
	default:
	}
	
	ASMessage pkt = clazz.newInstance();
	try
	{
		pkt.decodeInto(ctx, payload.slice(), player);
	} catch (IOException e)
	{
		e.printStackTrace();
		throw e;
	}
	
	switch (side)
	{
	case CLIENT:
		pkt.handleClientSide(player);
		break;
	case SERVER:
		pkt.handleServerSide(player);
		break;
	default:
	}
	
	out.add(pkt);
}
 
Example #19
Source File: FakeNetServerHandler.java    From Gadomancy with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public INetHandler getNetHandler() {
    return null;
}
 
Example #20
Source File: FakeNetServerHandler.java    From Gadomancy with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setNetHandler(INetHandler p_150719_1_) {
}
 
Example #21
Source File: PacketReceivedEvent.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
public Packet<INetHandler> getPacket() {
    return packet;
}
 
Example #22
Source File: PacketReceivedEvent.java    From Hyperium with GNU Lesser General Public License v3.0 4 votes vote down vote up
public PacketReceivedEvent(Packet<INetHandler> packet) {
    this.packet = packet;
}
 
Example #23
Source File: WrapperINetHandler.java    From ClientBase with MIT License 4 votes vote down vote up
public WrapperINetHandler(INetHandler var1) {
    this.real = var1;
}
 
Example #24
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 votes vote down vote up
public void handle(INetHandler handler, String channel, PacketCustom packet); 
Example #25
Source File: IOpenModsProxy.java    From OpenModsLib with MIT License votes vote down vote up
public EntityPlayer getPlayerFromHandler(INetHandler handler);