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

Block#getType() returns "AIR" for 1.13 Material types

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • Icon: Minor Minor
    • None
    • None
    • git-Spigot-1dc156c-b b6f384 (MC: 1.13.2)
    • Yes

      This issue is produced when running:

      block.getType(); // From org.bukkit.block.Block
      

      on a 1.13 block (such as Coral, for example).

       

      I've conducted a few tests to determine what happens. I can't seem to discover why this happens because everything on the CB side appears to be correct.

      // Our Bukkit Block from wherever (in my case from event#getClickedBlock() in the player interact event)
      Block block = event.getClickedBlock();
      // Get the CraftBlock from the org.bukkit.block.Block
      CraftBlock craftBlock = (CraftBlock) block;
      // Get the NMS Block from the CraftBlock
      net.minecraft.server.v1_13_R2.Block nmsBlock = craftBlock.getNMS().getBlock();
      
      // Get the key of the block (minecraft ID)
      String key = IRegistry.BLOCK.getKey(nmsBlock).getKey().toUpperCase(Locale.ROOT);
      System.out.println(key); // Yields "DEAD_TUBE_CORAL_BLOCK" as it should
      
      // Standard Bukkit API method
      Material m0 = block.getType();
      System.out.println(m0); // Yields "LEGACY_AIR"
      
      // Mimicking the "getType()" method from block with the nms block we created
      Material m1 = CraftMagicNumbers.getMaterial(nmsBlock);
      System.out.println(m0); // Yields "LEGACY_AIR"
      
      // Directly accessing the hash map "BLOCK_MATERIAL" in CraftMagicNumbers
      Field field = CraftMagicNumbers.class.getDeclaredField("BLOCK_MATERIAL");
      field.setAccessible(true);
      Map<net.minecraft.server.v1_13_R2.Block, Material> map = (Map) field.get(null);
      
      // Simple retrieval from the map using the NMS block we created above
      Material m2 = map.get(nmsBlock);
      System.out.println(m2); // Yields "DEAD_TUBE_CORAL_BLOCK" as it should??
      

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

              Created:
              Updated:
              Resolved: