// Example of working with ItemDyeableComponent functiondemonstrateItemDyeableComponent() { constplayer = world.getAllPlayers()[0]; if (!player) return;
// Get the item in the player's main hand constmainHandItem = player.getComponent("minecraft:inventory")?.container?.getItem(player.selectedSlotIndex);
if (mainHandItem) { // Check if the item has a dyeable component constdyeableComponent = mainHandItem.getComponent("minecraft:dyeable") asItemDyeableComponent;
if (dyeableComponent) { console.log("Item is dyeable!");
// Get the current color constcurrentColor = dyeableComponent.color; console.log(`Current color - R: ${currentColor.red}, G: ${currentColor.green}, B: ${currentColor.blue}`);
// Get the default color constdefaultColor = dyeableComponent.defaultColor; console.log(`Default color - R: ${defaultColor.red}, G: ${defaultColor.green}, B: ${defaultColor.blue}`);
// Example: Change the item color to red constredColor: RGB = { red:255, green:0, blue:0 }; dyeableComponent.color = redColor; console.log("Changed item color to red!");
// Example: Reset to default color dyeableComponent.color = dyeableComponent.defaultColor; console.log("Reset item color to default!"); } else { console.log(`Item ${mainHandItem.typeId} is not dyeable`); } } else { console.log("No item in main hand"); } }
// Example: Create dyeable items with specific colors functioncreateDyeableItems() { constplayer = world.getAllPlayers()[0]; if (!player) return;
// Create a leather helmet with custom color constleatherHelmet = newItemStack("minecraft:leather_helmet", 1); consthelmetDyeable = leatherHelmet.getComponent("minecraft:dyeable") asItemDyeableComponent;
if (helmetDyeable) { // Set to bright blue constblueColor: RGB = { red:0, green:100, blue:255 }; helmetDyeable.color = blueColor;
// Give to player constinventory = player.getComponent("minecraft:inventory"); if (inventory?.container) { inventory.container.addItem(leatherHelmet); console.log("Gave player blue leather helmet!"); } }
// Create leather boots with custom color constleatherBoots = newItemStack("minecraft:leather_boots", 1); constbootsDyeable = leatherBoots.getComponent("minecraft:dyeable") asItemDyeableComponent;
if (bootsDyeable) { // Set to bright green constgreenColor: RGB = { red:0, green:255, blue:0 }; bootsDyeable.color = greenColor;
// Give to player constinventory = player.getComponent("minecraft:inventory"); if (inventory?.container) { inventory.container.addItem(leatherBoots); console.log("Gave player green leather boots!"); } } }
This property can't be read in early-execution mode.
ReadonlyisValid
isValid:boolean
Remarks
Returns whether the component is valid. A component is
considered valid if its owner is valid, in addition to any
addition to any additional validation required by the
component.
World Ready
This property can't be read in early-execution mode.
ReadonlytypeId
typeId:string
Remarks
Identifier of the component.
World Ready
This property can't be read in early-execution mode.
When present on an item, this item can be dyed.
Example: itemDyeableExample.ts