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.

[SOLVED] 1.18.2 Items added through packet doesn't instantly show up on client

Featured Replies

Posted

SOLVED EDIT: The fix was to ensure AbstractContainerMenu#stillValid returned true IF the container/menu is being accessed. I guess it was some kind of sync race condition where the screen would be inactive but the container still active causing the packet to wait and ensure container was also closed. Since opening the inventory opens a new container that race condition would be met. Idk if its true just my guess

EDIT: Item instantly pops up if i open and then close the inventory.

I have a screen that sends a packet, that packet then calls a method that simply gives the player a gold ingot. In game the screen works fine and the packet does get sent but the item doesnt show up in my inventory. If I press Q the item will drop on the floor and when i pick it back up it still wont show in the inventory. The item usually shows up after 30-40 seconds or if i put it in a hopper/chest than back into my inventory.

ModMessages.sendToServer(new VillagerScreenC2S(1)); //send packet

public class VillagerScreenC2S {
    private int id;
    public VillagerScreenC2S(int rV) {
        this.id = rV;
    }

    public void encode(FriendlyByteBuf buffer) {
        buffer.writeInt(this.id);
    }

    public static VillagerScreenC2S decode(FriendlyByteBuf buffer) {
        return new VillagerScreenC2S(buffer.readInt());
    }

    public static void handle(VillagerScreenC2S msg, Supplier<NetworkEvent.Context> ctx) {
        AtomicBoolean success = new AtomicBoolean(false);
        ctx.get().enqueueWork(() -> {
            ServerPlayer p = ctx.get().getSender();
            if(msg.id == 1){
                DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> success.set(ClientAccess.villagerGetQuest(p)));
            }
        });
        ctx.get().setPacketHandled(success.get());
    }
}

public class ClientAccess {
    public static boolean villagerGetQuest(ServerPlayer p){
        AtomicBoolean success = new AtomicBoolean(false);
        p.addItem(new ItemStack(Items.GOLD_INGOT));
        return success.get();
    }
}

 

Edited by sfxprt2

  • sfxprt2 changed the title to [SOLVED] 1.18.2 Items added through packet doesn't instantly show up on client

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.