Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[1.14.4][SOLVED] Packet handler problem

Featured Replies

Posted

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:

error.png.1caadcf5eebdcf51428b4ca3bb31a9d1.png

 

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) {
        buf.writeItemStack(msg.item);
    }
    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
        });
        ctx.get().setPacketHandled(true);
    }
}

 

[SOLUTION]

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

correct Supplier: java.util.function.Supplier 

Edited by andGarrett

2 minutes ago, andGarrett said:

import com.google.common.base.Supplier;

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

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

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.

  • Author
1 hour ago, Animefan8888 said:

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

You know I love you right?

 

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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.