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

Improve legacy conversion for blocks

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • Windows 7, Java 8

    • This server is running CraftBukkit version git-Spigot-69774b3-3b8f5be (MC: 1.13) (Implementing API version 1.13-R0.1-SNAPSHOT)
    • Yes

      org.bukkit.craftbukkit.util.CraftLegacy has a method:

          public static Material toLegacy(Material material) {
              if (material == null || material.isLegacy()) {
                  return material;
              }        
              return toLegacyData(material).getItemType();
          }
      

      This is used when wrapping getType() calls up for plugins that depend on the legac,y pre-1.13 Material API. There is one major problem: type loss during conversion.

      An example: Minecraft 1.13 no longer has types FURNACE and BURNING_FURNACE, only FURNACE. This is because the burning state was integrated into the FURNACE Block type, as it should be. This poses a problem: both burning furnaces and normal furnaces now return FURNACE. To properly convert this information to LEGACY_FURNACE/LEGACY_BURNING_FURNACE, the type input is inadequate.

      Instead, the method should look somewhat like this:

      public static Material getLegacyType(IBlockData blockData) {
          // body todo
          // broken, returns byte instead of MaterialData like should be the case!
          return toLegacyData(blockData).getItemType();
      }
      

      In addition, when proxying block.getType() and others during runtime re-compiling, the call should be changed to block.getNMS or similar to retrieve the IBlockData. Only IBlockData/BlockData stores all required information.

      This problem occurs for the following cases, a simple unit test I wrote shows:

      [STDERR]: Expected LEGACY_DEAD_BUSH (id=32), but got LEGACY_LONG_GRASS (id=31)
      [STDERR]: Expected LEGACY_DOUBLE_STEP (id=43), but got LEGACY_STEP (id=44)
      [STDERR]: Expected LEGACY_BURNING_FURNACE (id=62), but got LEGACY_AIR (id=0)
      [STDERR]: Expected LEGACY_WALL_SIGN (id=68), but got LEGACY_AIR (id=0)
      [STDERR]: Expected LEGACY_GLOWING_REDSTONE_ORE (id=74), but got LEGACY_REDSTONE_ORE (id=73)
      [STDERR]: Expected LEGACY_REDSTONE_TORCH_OFF (id=75), but got LEGACY_AIR (id=0)
      [STDERR]: Expected LEGACY_DIODE_BLOCK_ON (id=94), but got LEGACY_DIODE_BLOCK_OFF (id=93)
      [STDERR]: Expected LEGACY_REDSTONE_LAMP_ON (id=124), but got LEGACY_REDSTONE_LAMP_OFF (id=123)
      [STDERR]: Expected LEGACY_WOOD_DOUBLE_STEP (id=125), but got LEGACY_WOOD_STEP (id=126)
      [STDERR]: Expected LEGACY_SKULL (id=144), but got LEGACY_AIR (id=0)
      [STDERR]: Expected LEGACY_REDSTONE_COMPARATOR_ON (id=150), but got LEGACY_REDSTONE_COMPARATOR_OFF (id=149)
      [STDERR]: Expected LEGACY_WALL_BANNER (id=177), but got LEGACY_AIR (id=0)
      [STDERR]: Expected LEGACY_DAYLIGHT_DETECTOR_INVERTED (id=178), but got LEGACY_DAYLIGHT_DETECTOR (id=151)
      [STDERR]: Expected LEGACY_DOUBLE_STONE_SLAB2 (id=181), but got LEGACY_STONE_SLAB2 (id=182)
      [STDERR]: Expected LEGACY_PURPUR_DOUBLE_SLAB (id=204), but got LEGACY_PURPUR_SLAB (id=205)
      

      Most prudent are material types plugin use often, like WALL_SIGN, which will no-doubt break many plugins.

      Note however, that some edge cases are valid. For example, the LEGACY_STATIONARY_WATER and LEGACY_STATIONARY_LAVA types simply don't exist anymore on MC 1.13, so it can not be expected to work anyway.

            Unassigned Unassigned
            bergerkiller Irmo van den Berge
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: