#Saving Inventory when closing GUI for block entity.

8 messages · Page 1 of 1 (latest)

bleak mason
#

I am trying to add functionality and crafting to the fletching table; however, when I close the GUI, it won't save the inventory. I've looked at the fabric documentation for screen handlers and block entities, and I still can't figure it out what I need to do other than the readNbt and writeNbt methods.

https://github.com/DontNeg/improved-fletching/tree/main/src/main/java/dontneg/improvedfletching

GitHub

Adds functionality to fletching table. Contribute to DontNeg/improved-fletching development by creating an account on GitHub.

burnt flax
woven rain
#

@bleak mason @burnt flax @minor citrus That video tutorial, the code in the GitHub repo or the tutorial at the wiki do not work. (https://fabricmc.net/wiki/tutorial:inventory?s[]=inventory) I wish to note that it ONLY fails for Inventories.read/writeNbt but custom data (e.g. number from the tutorial) are stored properly. And I myself am currently still unsure as of why.

bleak mason
woven rain
#

Sadly no

minor citrus
#

if the problem is that things are not removed from the client side inv after a network update then the problem is the usual one: Inventories.read/writeNbt skip empty stacks

bleak mason
# still idol Do you call `markDirty` anywhere?

Sorry for the late reply, but yes, in the onContentChanged method in the screen handler. I think the not saving was due to a few other missing things that are there now, but it won't even register an inventory bigger than 0 slots anymore.