Store NBT data in world blocks, is it possible?

Discussion in 'Plugin Development' started by chingo247, May 23, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    chingo247

    I was wandering if there is a way to store NBT Data in world blocks.

    I'm currently working on a plugin that places structures(schematics) into the world (with WorldEdit & AsyncWorldEdit)

    When a structure is placed it reserves a region (with worldguard). In case of a server crash or sudden interrupt the worldguard region (and my database) get out of sync with the world, meaning all structures that were not saved in the world still take in space. Which means no one can build at those spots. I only need to store 2 primitive values.

    I'm currently abusing a sign for this as workaround, but i got wandering if there exists another way to do this. Then NBT's got in my mind
     
  2. Offline

    fireblast709

    chingo247 There is no pure Bukkit way of handling custom NBT. You would either have to rely on CraftBukkit & NMS, or reflection (both with their downside of breaking with updates). Why not use YAML?

    [Addition] Not to bash on the creator of Async WE, or rather, to do so: Don't use Async WE. It changes blocks without even considering thread safety (or the last time I checked it, it simply accessed it from an async thread)
     
  3. Offline

    NathanWolf

    Not easily or via the API, no.

    You may be able to create a fake TileEntity of some kind to store the data. I'm admittedly not too familiar with the mechanics, but I'm guessing there has to be a real block somewhere the entity maps to anyway, so your Sign hack could be the best way to go.

    Could another option be to force a server save whenever a new region gets created? Not ideal, I know.
     
  4. Offline

    chingo247


    Thx for your response, but How is YAML gonna help in this situation? My current problem is that i have to store data specificly in the world and not in a database or somewhere else. Because those will get out of sync.

    Anyway ill take a look at CraftBukkit and NMS ^^
     
  5. Offline

    fireblast709

    chingo247 Assume we have a YAML file loaded to variable yc. At the start of the edit, you run
    Code:java
    1. ConfigurationSection cs = yc.createConfigurationSection("someuniqueidentifier");
    2. cs.set("world", "worldname");
    3. cs.set("otherdata", data);
    4. try
    5. {
    6. yc.save(thefile);
    7. }
    8. catch(IOException ex)
    9. {
    10. // catch exception
    11. }
    And as soon as you are done with the edit, you remove it. As long as you keep track of what you are doing at the right time, it should always be in sync.
     
  6. Offline

    chingo247

    Ye but what happends when the server crashes? The world isnt saved but i still got the yaml who is telling me that there should be data in that block. This is what i actually meant by out of sync hehe :p
    At the moment that's kinda my situation with my Database.

    What i want is for my database to compare it's values with the world, if a value is invalid/incorrect it needs to by syncronized (maybe that's the wrong word..) with the world. Meaning if my database says there is a structure in the world, but my world says there isnt. My database needs to remove the record and WorldGuard needs to remove a region
     
  7. Offline

    NathanWolf

    Just to be clear on my post -

    The short answer to your question is a firm "no". You cannot store NBT data in blocks.

    You can store NBT data in a TileEntity, though, which is how signs, chests, etc work.

    By just using a Sign you're already doing this. What you're looking for is something like an "invisible" TileEntity, or one that maps to a block that doesn't really have NBT data, or something like that.

    I think if you go that route, you'll find that Minecraft and/or Bukkit will internally drop your custom data. At least for now, may change in 1.8, and maybe eventually we'll even see an API for this, who knows.

    But for now, I may be wrong, there is not going to be a reliable way to put NBT data on a block unless that block actually has NBT data.

    Are your regions full height? Can you stick the sign at y=1 and make sure it's covered with bedrock?
     
Thread Status:
Not open for further replies.

Share This Page