Jump to content

Assigning NBT to a block in the world


TaeoG

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • It will be about medeaival times
    • the mods are crashing and I'm not sure why so heres everything  crash log https://pastebin.com/RxLKbMNR  L2 Library (12library) has failed to load correctly java.lang.NoClassDefFoundError: org/antarcticgardens/newage/content/energiser/EnergiserBlock L2 Screen Tracker (12screentracker) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.12library.base.L2Registrate Create: Interiors (interiors) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.tterrag.registrate.AbstractRegistrate L2 Damage Tracker (12damagetracker) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.l2library.base.L2Registrate Create Enchantment Industry (create_enchantment_industry) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.foundation.data.Createfiegistrate Create Crafts & Additions (createaddition) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.foundation.data.CreateRegistrate Create Slice & Dice (sliceanddice) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.foundation.data.CreateRegistrate L2 Tabs (12tabs) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.l2library.base.L2Registrate Modular Golems (modulargolems) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.l2library.base.L2Registrate Create: Steam 'n' FRails (railways) has failed to load correctly java.lang.NoClassDefFoundError : Could not initialize class com.simibubi.create.foundation.data.Createfregistrate Cuisine Delight (cuisinedelight) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.12library.base.L2Registrate Create (create) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.Create Guardian Beam Defense (creategbd) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.foundation.data.CreateRegistrate L2 Item Selector (12itemselector) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.l2library.base.L2Registrate
    • hey there, I have been using Forge for years without any problems, but for some time now I have been getting this error message when I click on “Installer” under the downloads. This happens on all versions. I have tried various things but have not gotten any results. If anyone has a solution, I would be very grateful!
    • I don't have mcreator installed.
    • the session has expired, what if the modified LAN Server displays the same screen after logging in as after logging in to the premium server from a non-premium account? Minecraft Forge 1.20.1 CurseForge. I also use Mod LAN World Plug n Play
  • Topics

×
×
  • Create New...

Important Information

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