NBT Item Component Examples - ShaneBeee/SkBee GitHub Wiki

This wiki explains how you can use Minecraft's Item Component system to create custom items.

Table of Contents

ATTRIBUTE MODIFIER

This example shows how you can make an item with attribute modifiers.

[!TIP] See Attribute Modifier Component on McWiki for full details.

One Line Method:

set {PumpkinHelmet} to pumpkin with nbt from "{""minecraft:attribute_modifiers"":{modifiers:[{amount:10.0d,name:""blah blah blah"",operation:""add_value"",slot:""head"",type:""minecraft:generic.attack_damage"",uuid:[I;-410761057,1614499675,-1123824480,-1651913033]},{amount:5.0d,name:""blah blah blah"",operation:""add_value"",slot:""head"",type:""minecraft:generic.armor"",uuid:[I;-393082353,389891517,-1251997614,1051297152]}]}}"

Compound Method:

# Create an empty compound
set {_n} to empty nbt compound
# Get the "Minecraft:attribute_modifiers" component
set {_mod} to compound tag "minecraft:attribute_modifiers" of {_n}

# Create an empty compound for our attribute modifiers
# We're using a list var so we can create multiple modifiers
set {_mod::1} to empty nbt compound
set string tag "type" of {_mod::1} to "minecraft:generic.attack_damage"
set string tag "slot" of {_mod::1} to "head"
set uuid tag "uuid" of {_mod::1} to random uuid
set string tag "name" of {_mod::1} to "blah blah blah"
set double tag "amount" of {_mod::1} to 10
set string tag "operation" of {_mod::1} to "add_value"

set {_mod::2} to empty nbt compound
set string tag "type" of {_mod::2} to "minecraft:generic.armor"
set string tag "slot" of {_mod::2} to "head"
set uuid tag "uuid" of {_mod::2} to random uuid
set string tag "name" of {_mod::2} to "blah blah blah"
set double tag "amount" of {_mod::2} to 5
set string tag "operation" of {_mod::2} to "add_value"

# Apply our modifiers to our nbt
set compound list tag "modifiers" of {_mod} to {_mod::*}

# Create an item with our modifiers
set {PumpkinHelmet} to pumpkin with nbt {_n}

FOOD

This example shows how you can make a food item.

[!TIP] See Food Component on McWiki for full details.

One line method:

set {-ifood} to stick with nbt from "{""minecraft:food"":{eat_seconds:1.5f,effects:[{effect:{amplifier:2b,duration:200,id:""minecraft:poison"",show_icon:0b,show_particles:0b}}],nutrition:3,saturation:3.0f}}"

Compound method:

# Create an empty compound
set {_n} to empty nbt compound
# Get the "Minecraft:food" component
set {_food} to compound tag "minecraft:food" of {_n}
# Set all the food properties
set float tag "saturation" of {_food} to 3
set int tag "nutrition" of {_food} to 3
set float tag "eat_seconds" of {_food} to 1.5

# Create an empty component to put our effects in
set {_e} to empty nbt compound
set string tag "effect;id" of {_e} to "minecraft:poison"
set byte tag "effect;amplifier" of {_e} to 2
set int tag "effect;duration" of {_e} to 200
set byte tag "effect;show_particles" of {_e} to 0
set byte tag "effect;show_icon" of {_e} to 0
# Apply the effects to our food
set compound list tag "effects" of {_food} to {_e}

# Create an item with food properties
set {YummyStick} to stick with nbt {_n}

MAX DAMAGE

This example shows how you can make an item which can take damage.

[!TIP] See Max Damage Component on McWiki for full details.

One Line Method:

set {-BreakySticky} to 1 of stick with nbt from "{""minecraft:damage"":0,""minecraft:max_damage"":100,""minecraft:max_stack_size"":1,""minecraft:tool"":{rules:[]}}"

Compound method:

# Create an empty compound
set {_n} to empty nbt compound
# We will set our max damage value of our item
set int tag "minecraft:max_damage" of {_n} to 100
# We have to make sure the item can't be stacked
set int tag "minecraft:max_stack_size" of {_n} to 1
# We need to set the starter damage
set int tag "minecraft:damage" of {_n} to 0

# If the item isn't already a tool, we need to make it a tool
# This allows the item to actually take damage when breaking blocks
# You can omit this is you want to damage the item via Skript code later
set compound tag "minecraft:tool" of {_n} to nbt from "{rules:[]}"

# Apply that NBT to an item
set {BreakySticky} to 1 of stick with nbt {_n}

POTION

This example shows how you can make a potion item.

[!NOTE] This can be done in vanilla Skript, just showing component stuff

[!TIP] See Potion Contents Component on McWiki for full details.

One Line Method:

set {NightlyHastePotion} to potion with nbt from " {""minecraft:potion_contents"":{custom_color:7846721,custom_effects:[{amplifier:2b,duration:7200,id:""minecraft:night_vision"",show_icon:0b,show_particles:0b},{amplifier:2b,duration:12000,id:""minecraft:haste"",show_icon:0b,show_particles:0b}]}}"

Compound Method:

# Create an empty compound
set {_n} to empty nbt compound
# Get the "minecraft:potion_contents" component
set {_potion} to compound tag "minecraft:potion_contents" of {_n}
# Set our potion properties
set int tag "custom_color" of {_potion} to 7846721

# Create an empty compound for our potion effects
# We're using a list var so we can create multiple effects
set {_effect::1} to empty nbt compound
set string tag "id" of {_effect::1} to "minecraft:night_vision"
set byte tag "amplifier" of {_effect::1} to 2
set int tag "duration" of {_effect::1} to 7200
set byte tag "show_particles" of {_effect::1} to 0
set byte tag "show_icon" of {_effect::1} to 0

set {_effect::2} to empty nbt compound
set string tag "id" of {_effect::2} to "minecraft:haste"
set byte tag "amplifier" of {_effect::2} to 2
set int tag "duration" of {_effect::2} to 12000
set byte tag "show_particles" of {_effect::2} to 0
set byte tag "show_icon" of {_effect::2} to 0

# Apply effects to the potion
set compound list tag "custom_effects" of {_potion} to {_effect::*}

# Create an item with potion effects
set {NightlyHastePotion} to potion with nbt {_n} named "&bFancy&3Potion"

Tool

This example shows how you can make a tool item.

[!TIP] See Tool Component on McWiki for full details.

One line method:

set {MyCoolTool} to stick with nbt from "{""minecraft:damage"":0,""minecraft:max_damage"":234,""minecraft:max_stack_size"":1,""minecraft:tool"":{damage_per_block:2,default_mining_speed:3.5f,rules:[{blocks:[""minecraft:grass_block"",""minecraft:dirt_path"",""minecraft:dirt""],correct_for_drops:1b,speed:10.0f},{blocks:[""minecraft:stone"",""minecraft:cobblestone"",""minecraft:granite""],correct_for_drops:1b,speed:0.1f}]}}"

Compound method:

# Create an empty compound
set {_n} to empty nbt compound
# Get the tool component of that compound
set {_tool} to compound tag "minecraft:tool" of {_n}
# Set the tool properties
set float tag "default_mining_speed" of {_tool} to 3.5
set int tag "damage_per_block" of {_tool} to 2

# Create an empty compound for our rule
# We're using a list var so we can create multiple rules
set {_rule::1} to empty nbt compound
set string list tag "blocks" of {_rule::1} to "minecraft:grass_block", "minecraft:dirt_path" and "minecraft:dirt"
set float tag "speed" of {_rule::1} to 10
set byte tag "correct_for_drops" of {_rule::1} to 1

set {_rule::2} to empty nbt compound
set string list tag "blocks" of {_rule::2} to "minecraft:stone", "minecraft:cobblestone" and "minecraft:granite"
set float tag "speed" of {_rule::2} to 0.1
set byte tag "correct_for_drops" of {_rule::2} to 1

# Apply our rules to our tool
set compound list tag "rules" of {_tool} to {_rule::*}

# Some other stuff
# Prevent stacking of tool
set int tag "minecraft:max_stack_size" of {_n} to 1
# How much durability our tool has
set int tag "minecraft:max_damage" of {_n} to 234
# Start with 0 damage (if this is excluded, the tool won't take damage)
set int tag "minecraft:damage" of {_n} to 0


set {MiningStick} to stick with nbt {_n}