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

Shields crash upon accessing its BlockStateMeta

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • 3132-Spigot-66f9d3c-40caacc (MC: 1.17)
    • Yes

      In the 1.17 releases of Spigot, shields seem to longer be tied to its own BlockStateMeta, making customization of the shield's base color and banner patterns impossible.

      On previous versions of Spigot, if one were to implement code such as:

      import org.bukkit.DyeColor;
      import org.bukkit.Material;
      import org.bukkit.block.Banner;
      import org.bukkit.block.BlockState;
      import org.bukkit.inventory.ItemStack;
      import org.bukkit.inventory.meta.BlockStateMeta;
      
      public class TestShield extends ItemStack { 
         public TestShield () { 
              super (Material.SHIELD); 
              // Creates a shield with a red base color 
              BlockStateMeta blockStateMeta = (BlockStateMeta) this.getItemMeta();
              BlockState blockState = blockStateMeta.getBlockState();
              Banner banner = (Banner) blockState; 
              banner.setBaseColor(DyeColor.RED); 
              banner.update(); 
              blockStateMeta.setBlockState(banner); 
              this.setItemMeta(blockStateMeta ); 
         }
      }
      

      ... one would expect to get a red shield upon generating this object in-game. However, running the same code at the 1.17 Spigot builds throws the following exception:

      java.lang.NullPointerException: Cannot invoke "net.minecraft.world.level.block.Block.getBlockData()" because the return value of "org.bukkit.craftbukkit.v1_17_R1.util.CraftMagicNumbers.getBlock(org.bukkit.Material)" is nulljava.lang.NullPointerException: Cannot invoke "net.minecraft.world.level.block.Block.getBlockData()" because the return value of "org.bukkit.craftbukkit.v1_17_R1.util.CraftMagicNumbers.getBlock(org.bukkit.Material)" is null at org.bukkit.craftbukkit.v1_17_R1.inventory.CraftMetaBlockState.getBlockState(CraftMetaBlockState.java:310) ~[spigot-1.17.jar:3132-Spigot-66f9d3c-40caacc]
      

            Unassigned Unassigned
            CompleteEdd Eric Su
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: