Jump to content

[1.14.4][SOLVED] Packet handler problem


Recommended Posts

I've been trying to figure out how to work with packets, but I've hit a stumbling block. In my packet handler class I get an odd issue that may be related to intellij, but I'm not sure. if it is intellij, where would be the best place to get support? if it's something to do with minecraft/forge, I could use some help. I used EnderUnknown's post about the same topic as a framework to work off of. It is incomplete as I can't really move forward until I get this part figured out.


the issue is on the line near the bottom that contains: channel.registerMessage(id++, PacketSellButton.class, PacketSellButton::encode, PacketSellButton::decode, PacketSellButton::handle);

this seems to be the correct way to do things. I've seen other peoples packet handlers, and they all seem to do it this way.

package com.garrett.merchantcraft.network;

import com.garrett.merchantcraft.network.packets.PacketSellButton;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.network.NetworkRegistry;
import net.minecraftforge.fml.network.simple.SimpleChannel;

public final class MerchantcraftPacketHandler {

    private static final String PROTICOL_VERSION = "1";
    public static SimpleChannel channel;

    public void register() {
        channel = NetworkRegistry.newSimpleChannel(
                new ResourceLocation("merchantcraft","main")
                ,() -> PROTICOL_VERSION
                , PROTICOL_VERSION::equals
                , PROTICOL_VERSION::equals);
        int id = 0;
        channel.registerMessage(id++, PacketSellButton.class, PacketSellButton::encode, PacketSellButton::decode, PacketSellButton::handle);


The error message:



here's the packet sell button class if that matters:

package com.garrett.merchantcraft.network.packets;

import com.google.common.base.Supplier;

import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.network.NetworkEvent;

public class PacketSellButton {

    private final ItemStack item;

    public PacketSellButton(ItemStack stack) {
        this.item = stack;
    public static void encode(PacketSellButton msg, PacketBuffer buf) {
    public static PacketSellButton decode(PacketBuffer buf) {
        return new PacketSellButton(buf.readItemStack());
    public static void handle(PacketSellButton msg, Supplier<NetworkEvent.Context> ctx) {
        ctx.get().enqueueWork(() -> {
            // Work that needs to be threadsafe (most work)
            ServerPlayerEntity sender = ctx.get().getSender(); // the client that sent this packet
            // do stuff



I imported imported the wrong Supplier "com.google.common.base.Supplier;"

correct Supplier: java.util.function.Supplier 

Edited by andGarrett
Link to comment
Share on other sites

2 minutes ago, andGarrett said:

import com.google.common.base.Supplier;

You've imported the wrong Supplier you need java.util.function.Supplier

  • Thanks 1


I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use.