[SPIGOT-5146] BlockDataMeta issue with ItemStacks Created: 06/Jul/19  Updated: 09/Jul/19  Resolved: 09/Jul/19

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Shane Bee Assignee: Unassigned
Resolution: Fixed Votes: 1
Labels: 1.14.3, BlockDataMeta
Environment:

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)


Attachments: File RecipeTest.jar    
Version: git-Spigot-d05d3c1-a2275f1
Plugin: Just my test plugin "RecipeTest"
Guidelines Read: Yes

 Description   

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.



 Comments   
Comment by Shane Bee [ 06/Jul/19 ]

Ahhh good to know, thank you for informing me!

Comment by md_5 [ 06/Jul/19 ]

The implementation is completely wrong, it needs to be rewritten.

Generated at Tue Apr 15 11:10:18 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.