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

BlockDataMeta issue with ItemStacks

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • macOS 10.14.5

      java version "1.8.0_201"

      Java(TM) SE Runtime Environment (build 1.8.0_201-b09)

      Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

    • git-Spigot-d05d3c1-a2275f1
    • Just my test plugin "RecipeTest"
    • Yes

      I was trying to set a custom campfire block to be placed unlit. Choco gave me a piece of code a while back that should work, but it seems to not work as it should be working. He suggested I make an issue on Jira regarding this.

      Here is the code:

       

      ItemStack campfire = new ItemStack(Material.CAMPFIRE);
       BlockDataMeta meta = (BlockDataMeta) campfire.getItemMeta();
       BlockData data = Material.CAMPFIRE.createBlockData();
       ((Campfire) data).setLit(false);
       meta.setBlockData(data);
       campfire.setItemMeta(meta);
      

      The idea behind it was setting the block data for the item, making it so when placing the campfire on the ground, it would place unlit (rather than its vanilla state as lit)

       

      Just to state, the vanilla command `/give @p campfire{BlockStateTag:{lit:"false"}}` does work. So it appears that it is possible to place an unlit campfire.

       

      Here is the full code I have tested (in a command) I have included a jar file as well as a simple test (simple run the command /test and it will give you the campfire item, which should be placed unlit, but it is placing normally. 

       

      @Override
      public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
          if (sender instanceof Player) {
              Player player = (Player) sender;
      
              ItemStack campfire = new ItemStack(Material.CAMPFIRE);
              BlockDataMeta meta = (BlockDataMeta) campfire.getItemMeta();
              BlockData data = Material.CAMPFIRE.createBlockData();
              ((Campfire) data).setLit(false);
              meta.setBlockData(data);
              campfire.setItemMeta(meta);
      
              player.getInventory().addItem(campfire);
          }
          return true;
      }
      

      For testing purposes, I tested doing similar with a lit furnace, just to see if other items/blocks were affected, and they seem to be affected just the same.

       

      I tested this on both Spigot and Craftbukkit, both have the same outcome. Obviously this can not be tested on a vanilla server.

            Unassigned Unassigned
            ShaneBee Shane Bee
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: