Posted May 22, 20241 yr 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 May 22, 20241 yr by sfxprt2
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.