Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-7857

BlockStateMeta: Item not the same (isSimilar fails) after deserialization cycle

XMLWordPrintable

    •  This server is running CraftBukkit version dev-Spigot-34bd42b-0cc6acb (MC: 1.21) (Implementing API version 1.21-R0.1-SNAPSHOT)
    • Yes

      Example involving a campfire item:

      public class SerializationTest implements CommandExecutor {
          public SerializationTest() {
              Test.INSTANCE.getCommand("test").setExecutor(this);
          }
          @Override
          public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
              try {
                  ItemStack item = createItemStack();
                  YamlConfiguration config = new YamlConfiguration();
                  config.set("item", item);
                  String serialized = config.saveToString();
                  sender.sendMessage("Serialized: " + serialized);
                  config.loadFromString(serialized);
                  ItemStack deserialized = config.getItemStack("item");
                  sender.sendMessage("Deserialized: " + config.saveToString());
                  sender.sendMessage("Deserialized equals original? " + item.isSimilar(deserialized));
              } catch (Exception e) {
                  sender.sendMessage("Command execution failed: " + e.getMessage());
                  Test.INSTANCE.getLogger().log(Level.SEVERE, "Command execution failed!", e);
              }
              return true;
          }
          private static ItemStack createItemStack() {
              ItemStack itemStack = new ItemStack(Material.CAMPFIRE);
              BlockDataMeta itemMeta = (BlockDataMeta) itemStack.getItemMeta();
              Campfire blockData = (Campfire) Material.CAMPFIRE.createBlockData();
              blockData.setLit(false);
              itemMeta.setBlockData(blockData);
              itemStack.setItemMeta(itemMeta);
              return itemStack;
          }
      }
      
      

      Output:

      [17:51:46] [Server thread/INFO]: Serialized: item:
      [17:51:46] [Server thread/INFO]:   ==: org.bukkit.inventory.ItemStack
      [17:51:46] [Server thread/INFO]:   v: 3953
      [17:51:46] [Server thread/INFO]:   type: CAMPFIRE
      [17:51:46] [Server thread/INFO]:   meta:
      [17:51:46] [Server thread/INFO]:     ==: ItemMeta
      [17:51:46] [Server thread/INFO]:     meta-type: TILE_ENTITY
      [17:51:46] [Server thread/INFO]:     BlockStateTag:
      [17:51:46] [Server thread/INFO]:       waterlogged: 'false'
      [17:51:46] [Server thread/INFO]:       signal_fire: 'false'
      [17:51:46] [Server thread/INFO]:       lit: 'false'
      [17:51:46] [Server thread/INFO]:       facing: north
      [17:51:46] [Server thread/INFO]:     blockMaterial: CAMPFIRE
      [17:51:46] [Server thread/INFO]:
      [17:51:46] [Server thread/INFO]: Deserialized: item:
      [17:51:46] [Server thread/INFO]:   ==: org.bukkit.inventory.ItemStack
      [17:51:46] [Server thread/INFO]:   v: 3953
      [17:51:46] [Server thread/INFO]:   type: CAMPFIRE
      [17:51:46] [Server thread/INFO]:   meta:
      [17:51:46] [Server thread/INFO]:     ==: ItemMeta
      [17:51:46] [Server thread/INFO]:     meta-type: TILE_ENTITY
      [17:51:46] [Server thread/INFO]:     BlockStateTag:
      [17:51:46] [Server thread/INFO]:       waterlogged: ''
      [17:51:46] [Server thread/INFO]:       signal_fire: ''
      [17:51:46] [Server thread/INFO]:       lit: ''
      [17:51:46] [Server thread/INFO]:       facing: north
      [17:51:46] [Server thread/INFO]:     internal: H4sIAAAAAAAA/+NiYOBi4HPKyU/Ods0rySypDElMZ2ZgrGAAAiBdCaI5GVg9S1JzixmgglUgmpuBxzk/PzszLz0kMzcVJMfCgAa4GQRhSvJLEnNwquNgYMpMYRDKzcxLTS5KTCuxSk7MLUjLLEplYAAAe+3XY58AAAA=
      [17:51:46] [Server thread/INFO]:     blockMaterial: CAMPFIRE
      [17:51:46] [Server thread/INFO]:
      [17:51:46] [Server thread/INFO]: Deserialized equals original? false

      The decoded "internal" data is as follows:

      {"BlockEntityTag":{"x":0,"y":0,"Items":[],"z":0,"CookingTimes":[I;0,0,0,0],"CookingTotalTimes":[I;0,0,0,0],"id":"minecraft:campfire"}}

            Unassigned Unassigned
            blablubbabc blablubbabc
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: