Posted June 3, 20232 yr If I have, for example, a Minecraft:cake item with an nbt on it, and I'd like to be able to place the cake block in the world, and have that nbt available when interacting with the block or to put back on the item if the block is broken and retrieved, can it be done? If I understand correctly, I can only put nbts on a block entity, but is there some way I can sneakily get similar functionality on a block? Maybe storing its information into metadata on the chunk when its placed or something like that?
June 5, 20232 yr chunks canhold data, yes. respond to ChunkDataEvent.Load event and ChunkDataEvent.Save event. events have getData method which returns a nbt tag. or you can save your structure (map or list of small records) into world save data. https://forge.gemwire.uk/wiki/Saved_Data
June 5, 20232 yr On 6/2/2023 at 8:34 PM, TaeoG said: Maybe storing its information into metadata on the chunk when its placed or something like that? Yup, exactly like that. You can add a capability to the level or levelchunk which you store nbt data on add and write to item stack on break.
June 6, 20232 yr Author 14 hours ago, ChampionAsh5357 said: Yup, exactly like that. You can add a capability to the level or levelchunk which you store nbt data on add and write to item stack on break. what are the pitfalls? I'm worried there is infinite edge cases from block placer/breaker machines from various mods like create that would make this approach untenable
June 6, 20232 yr if you keep things simple, there likely won't be issues. i wouldn't attach this to a chunk because it doesn't logically belong to a chunk. for example a flag saying whether players have visited a chunk, whether your retrogen is finished on a chunk, whether your special slimes should spawn in a chunk? that i would store with a chunk. in short, things i would access in "entity enters section" event. your list of special block positions belongs to the world - either use world saved data (use this for simple and private data) or world capabilities (more convoluted but nice inter-mod interaction). you keep the data in memory (for example a list of locations (BlockPos) or some map), you tell the game how to write it into a given nbt and that's that. when you change the data, you mark is as dirty but the game won't write it to hard drive then. only later (usually when you hit esc to get the menu), will the data be written to storage. again, you just maintain you list/map and not worry about storage.
June 8, 20232 yr Author On 6/6/2023 at 4:13 AM, MFMods said: if you keep things simple, there likely won't be issues. i wouldn't attach this to a chunk because it doesn't logically belong to a chunk. for example a flag saying whether players have visited a chunk, whether your retrogen is finished on a chunk, whether your special slimes should spawn in a chunk? that i would store with a chunk. in short, things i would access in "entity enters section" event. your list of special block positions belongs to the world - either use world saved data (use this for simple and private data) or world capabilities (more convoluted but nice inter-mod interaction). you keep the data in memory (for example a list of locations (BlockPos) or some map), you tell the game how to write it into a given nbt and that's that. when you change the data, you mark is as dirty but the game won't write it to hard drive then. only later (usually when you hit esc to get the menu), will the data be written to storage. again, you just maintain you list/map and not worry about storage. The proof of concept works! Thank you both for the advice. My only complaint is that since the data is server side, If I want to cancel a RightClickBlock event based on the stored data, its only blocked serverside and the right click appears to work for just a moment before it syncs up again. Is there some way I can make it work properly on both sides?
June 9, 20232 yr Author I guess the more straightforward question is, is there a way to sync the SavedData from the server to the client?
June 9, 20232 yr https://forge.gemwire.uk/wiki/SimpleChannel https://forge.gemwire.uk/wiki/Sending_Packets
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.