Jump to content

Recommended Posts

Posted

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?

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

Posted
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

Posted

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.

 

Posted
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?

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.