The following code worked on previous versions to set a shield's base color, but doesn't seem to work anymore as of 1.20.5/6:
ItemStack shield = new ItemStack(Material.SHIELD);
BlockStateMeta stateMeta = (BlockStateMeta) shield.getItemMeta();
Banner banner = (Banner) stateMeta.getBlockState();
banner.setBaseColor(DyeColor.BLUE);
stateMeta.setBlockState(banner);
shield.setItemMeta(stateMeta);
player.getInventory().addItem(shield);
A blue shield crafted in a crafting table is: {count: 1, Slot: 1b, components: {"minecraft:base_color": "blue", "minecraft:banner_patterns": [], "minecraft:block_entity_data": {components:
{"minecraft:base_color": "blue"}, x: 0, y: 0, z: 0, id: "minecraft:banner"}}, id: "minecraft:shield"}
The shield the code above creates is: {count: 1, Slot: 0b, components: {"minecraft:banner_patterns": [], "minecraft:block_entity_data": {x: 0, y: 0, z: 0, id: "minecraft:banner"}}, id: "minecraft:shield"}
It seems like shield base color is stored in it's own component now as opposed to a banner block state on the item, especially seeing as one crafted in Vanilla is: {count: 1, Slot: 0b, components:
{"minecraft:base_color": "blue"}, id: "minecraft:shield"}
All the item data was grabbed with /data get entity @s Inventory[<slot>]
- causes
-
SPIGOT-7812 Crafting colored shields broken
-
- Resolved
-