1.15.2 Serializing a block

Discussion in 'Spigot Plugin Development' started by Xocky, Feb 3, 2020.

  1. How can you serialize a block to a string? Including Tile-Entities
     
  2. 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