Want a better Minecraft server? Read about SpigotMC here!
Separate names with a comma.
Discussion in 'Spigot Plugin Development' started by Xocky, Feb 3, 2020.
How can you serialize a block to a string? Including Tile-Entities
Well since no one seems to know an answer, I can give a (may be incomplete):
You can save most of the data using the BlockData/ deserialize using Bukkit.createBlockData() and Locations.
For the Tile-entity, things are looking a little bit tricky. I don't think, that is serializable. Additionally, PersistantDataContainer provides no method to get all stored NBT's.
You have in my opinion 3 options:
1) Adapt for every TileState; getting the right Tags from every BlockState using PersistantDataContainer. This sounds like a lot (and it is), but you could probably use Polymorphism in a lot of cases since the tags are pretty common for most TileStates (everyone has the ID, location and keepPacked set)
2) Using reflection to access all values of the internal Map of CraftPersistantDataConatiner
3) Use the NMS-NBT's