Block Serialization

Discussion in 'Plugin Development' started by mythcaptor, May 2, 2013.

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

    mythcaptor

    Hey! In a plugin I'm working on, I need to store any blocks that are broken in an area to a file to be later restored. This could feasibly include signs, chests, and other blocks with inventories.

    Can anyone point me towards a good resource for block serialization? If no such resource exists, anyone have any pointers or tips? What are all the things I need to consider when writing my serialization code?
     
  2. Offline

    chasechocolate

    Well pretty much everything essential from a block that can be saved would be the world name, x, y, z, block id and the data.
     
  3. Offline

    mythcaptor

    The data from block.getData() is a byte. It doesn't cover block inventories, sign text, and what have you. I can store location, id and data fine, but I need advice on how best to approach the other information I need to store.
     
  4. Offline

    chasechocolate

    Well, for other blocks it will be a bit trickier. Regarding blocks with inventories, search on how to serialize inventories. For signs, just save the sign.getLine(0), sign.getLine(1), etc.
     
  5. Offline

    mythcaptor

    Well I'm disappointed. I was hoping someone had developed a class to serialize any block. I may have to make one myself. Is there anything else I should consider, save the obvious (location type data), inventories, and sign contents? Any other information stored in blocks I need to serialize?

    edit: any way to serialize and reapply container names?
     
  6. Offline

    desht

    What you're basically after is a way of saving schematics, including the associated tile entities for blocks such as signs, inventory holders, etc. WorldEdit can do it - you can either look at their code and copy it (bearing in mind that WorldEdit is GPL-licensed so if you copy their code, your plugin needs to be GPL too), or hook into the WorldEdit API (which obviously requires the WorldEdit plugin to be present on the server).

    I wrote a convenience wrapper to WorldEdit for saving & loading regions: http://forums.bukkit.org/threads/terrainmanager-backing-up-restoring-terrain-made-easier.84160
     
  7. Offline

    mythcaptor

    Ah, well thank you very much, I think your code is just what I was looking for. It's a shame that i'll have to depend worldedit for it to work, but not a big deal, and it drastically simplifies what I'm trying to do.
     
Thread Status:
Not open for further replies.

Share This Page