Jump to content

[FORGE 1.19.2] I can not reserve my items in my container when I leave the loading chunk


Recommended Posts

Posted

When I kill myself and return to the container's chunk, the items inside disappear. If I close the GUI and open it, the items do not disappear.

If I do not leave the loading chunk, the container works normally and does not lose anything.

This is the code of Blockentity of the container: https://github.com/bread88993/Mystiasdelight-1.19.2-Forge/blob/1.19.2/src/main/java/com/bread88993/mystiasdelight/block/entity/custom/BarbecuenetBlockEntity.java

This is the menu of the container: https://github.com/bread88993/Mystiasdelight-1.19.2-Forge/blob/1.19.2/src/main/java/com/bread88993/mystiasdelight/screen/BarbecuenetMenu.java

Posted

I haven't looked at all your code, but this doesn't look right to me?

https://github.com/bread88993/Mystiasdelight-1.19.2-Forge/blob/4729748b580fb72f94056d717c8278599fdab79d/src/main/java/com/bread88993/mystiasdelight/screen/BarbecuenetMenu.java#L37

 

Slots should be initialised to the block entity data on the server.

On the client, the slots should be backed by an empty container of the correct size ready to be filled with the data from the server.

The idea is the client side slots are just a proxy to the server data.

Instead you seem to be the using client side capability data of the block entity as the backing of the slots?

 

Maybe that is ok? But I haven't seen it done that way.

I imagine since your block entity also has code to synchronize the same data to the client, the 2 different channels could conflict with each other perhaps with inconsistent data since the networking is inherently asynchronous?

Is there some other reason why you would always synchronize the inventory the client?

The container gui processing does this for you and more efficently since it only happens when the GUI is open for that player and not everybody in range all the time.

 

You can see the basic idea of the normal way of doing it in this immersive engineering menu:

https://github.com/BluSunrize/ImmersiveEngineering/blob/1.19.2/src/main/java/blusunrize/immersiveengineering/common/gui/AlloySmelterMenu.java

  • Like 1

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted (edited)
Quote

Maybe that is ok? But I haven't seen it done that way.

Even the vanilla LecternMenu which does send the page number to the client for rendering purposes, doesn't use that client data in the menu.

The client side ContainerData that holds this data for the menu is seperate.

Edited by warjort
  • Thanks 1

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted
21 hours ago, warjort said:

即使是将页码发送到客户端以用于呈现目的的香草 LecternMenu,也不会在菜单中使用该客户端数据。

保存此菜单数据的客户端 ContainerData 是独立的。

Thanks for your help!

I have found my fault in my Blockentity file.

It is because when I save the nbt, the compound is named "inventory". But when I load the compound it will load the nbt "Inventory". It can not find "Inventory" so my slots were cleaned.

//This is the code when I save compound
@Override
    protected void saveAdditional(@NotNull CompoundTag tag) {
        tag.put("inventory", itemHandler.serializeNBT());
    }
//This is the code when I load nbt
@Override
    public void load(CompoundTag compound) {
        super.load(compound);
        itemHandler.deserializeNBT(compound.getCompound("Inventory"));
    }

 

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...

×   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.

Announcements



×
×
  • Create New...

Important Information

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