Skip to content

Supports block state for adventure tags (item meta)#8128

Closed
Lulu13022002 wants to merge 1 commit into
PaperMC:masterfrom
Lulu13022002:fix/metastate
Closed

Supports block state for adventure tags (item meta)#8128
Lulu13022002 wants to merge 1 commit into
PaperMC:masterfrom
Lulu13022002:fix/metastate

Conversation

@Lulu13022002
Copy link
Copy Markdown
Contributor

Closes #6719

This allow block data into the CanDestroyOn and CanPlaceOn tags for vanilla state.
The deprecated material and namespaced key will now be backed into a block data with default state (internal)
The getters now check both tags, data and namespaced keys.

Examples:

	ItemStack stack = new ItemStack(Material.DIAMOND_PICKAXE);
        ItemMeta meta = stack.getItemMeta();
        meta.setCanDestroy(Set.of(Material.CHEST));
        stack.setItemMeta(meta);

        ItemStack stack2 = new ItemStack(Material.DIAMOND_PICKAXE);
        ItemMeta meta2 = stack2.getItemMeta();
        meta2.setDestroyableKeys(Set.of(Material.CHEST.getKey()));
        stack2.setItemMeta(meta2);

        ItemStack stack3 = new ItemStack(Material.DIAMOND_PICKAXE);
        ItemMeta meta3 = stack3.getItemMeta();
        meta3.setDestroyableDatas(Set.of(Material.CHEST.createBlockData("[facing=north]")));
        stack3.setItemMeta(meta3);

        e.getPlayer().getInventory().setItem(0, stack);
        e.getPlayer().getInventory().setItem(1, stack2);
        e.getPlayer().getInventory().setItem(2, stack3);

@Lulu13022002 Lulu13022002 requested a review from a team as a code owner July 12, 2022 13:55
Copy link
Copy Markdown
Member

@Machine-Maker Machine-Maker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cannot use BlockData to accurately represent the tags in CanPlaceOn and CanDestroy. If I have minecraft:chest[waterlogged=true] in a CanPlaceOn tag, that means the block can be placed on any chest, facing any direction as long as its waterlogged. The BlockData instance returned in item meta does not reflect that. If I do

// ["minecraft:chest[waterlogged=true]"]
BlockData data = itemMeta.getPlaceOnDatas().iterator().next();
((Chest) data).getFacing(); // this will return NORTH which is wrong
itemMeta.setPlaceableData(Set.of(data)); // will correctly serialize to "minecraft:chest[waterlogged=true]" because of the parsedStates BUT

itemStack.setItemMeta(itemMeta);
itemMeta = itemStack.getItemMeta();

Chest chest = (Chest) itemMeta.getPlaceableData().iterator().next();
// a plugin wants to know if this place on tag is only for chests facing north
if (chest.getFacing() == NORTH) {
  // the plugin incorrectly thinks this itemstack can only be placed on chests facing north
}

@Lulu13022002
Copy link
Copy Markdown
Contributor Author

Lulu13022002 commented Jul 12, 2022

Yep i have forgot the default values on uninitialized keys so i need to create a new class i think ? or is there any api already present in paper/bukkit ? also this breaks only for plugin, the serialization work well

@Machine-Maker
Copy link
Copy Markdown
Member

Machine-Maker commented Jul 12, 2022

#7223
with this PR, you'd just create a new class that implemented PropertiesHolder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pre-softspoon status: blocked Issue or Request is waiting on some other issue or change.

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

ItemMeta CanPlaceOn and CanDestroy lose block state/tile state info

3 participants