Minecraft Java Edition – How to Spawn a Chest with Custom Axe Using Commands

minecraft-commandsminecraft-java-edition

I've got an axe via this command (via command blocks)

 /give @p golden_axe 1 0 {display:{Name:"Thor's Axe",Lore:["The godliest","of the godliest."]},AttributeModifiers:[{AttributeName:"generic.maxHealth",Name:"generic.maxHealth",Amount:40,Operation:0,UUIDMost:69160,UUIDLeast:521589},{AttributeName:"generic.followRange",Name:"generic.followRange",Amount:32,Operation:0,UUIDMost:99396,UUIDLeast:851924},{AttributeName:"generic.knockbackResistance",Name:"generic.knockbackResistance",Amount:500,Operation:0,UUIDMost:76900,UUIDLeast:463228},{AttributeName:"generic.movementSpeed",Name:"generic.movementSpeed",Amount:0.5,Operation:0,UUIDMost:34152,UUIDLeast:644098},{AttributeName:"generic.attackDamage",Name:"generic.attackDamage",Amount:5,Operation:0,UUIDMost:85956,UUIDLeast:818955}],Unbreakable:1}

However, my intentions were to put it into a summoned chest command. So I tried this:

/setblock ~1 ~ ~ chest 0 replace {Items:[{golden_axe 0 1 {display:{Name:"Thor's Axe",Lore:["The godliest","of the godliest."]},AttributeModifiers:[{AttributeName:"generic.maxHealth",Name:"generic.maxHealth",Amount:40,Operation:0,UUIDMost:69160,UUIDLeast:521589},{AttributeName:"generic.followRange",Name:"generic.followRange",Amount:32,Operation:0,UUIDMost:99396,UUIDLeast:851924},{AttributeName:"generic.knockbackResistance",Name:"generic.knockbackResistance",Amount:500,Operation:0,UUIDMost:76900,UUIDLeast:463228},{AttributeName:"generic.movementSpeed",Name:"generic.movementSpeed",Amount:0.5,Operation:0,UUIDMost:34152,UUIDLeast:644098},{AttributeName:"generic.attackDamage",Name:"generic.attackDamage",Amount:5,Operation:0,UUIDMost:85956,UUIDLeast:818955}],Unbreakable:1}}]}

However then I get a JSON error about seperators:

[00:04:05] Data tag parsing failed: Unable to locate name/value separator for string: golden_axe {display:{Name:"Thor's Axe",Lore:["The godliest","of the godliest."]},AttributeModifiers:[{AttributeName:"generic.maxHealth",Name:"generic.maxHealth",Amount:40,Operation:0,UUIDMost:69160,UUIDLeast:521589},{AttributeName:"generic.followRange",Name:"generic.followRange",Amount:32,Operation:0,UUIDMost:99396,UUIDLeast:851924},{AttributeName:"generic.knockbackResistance",Name:"generic.knockbackResistance",Amount:500,Operation:0,UUIDMost:76900,UUIDLeast:463228},{AttributeName:"generic.movementSpeed",Name:"generic.movementSpeed",Amount:0.5,Operation:0,UUIDMost:34152,UUIDLeast:644098},{AttributeName:"generic.attackDamage",Name:"generic.attackDamage",Amount:5,Operation:0,UUIDMost:85956,UUIDLeast:818955}],Unbreakable:1}

Now I'm stumped. I found something like the one above; but it worked – but WITHOUT the custome attributes.

Is there anyway to put the axe :

    "{golden_axe {display:{Name:"Thor's Axe",Lore:["The godliest","of the godliest."]},AttributeModifiers:[{AttributeName:"generic.maxHealth",Name:"generic.maxHealth",Amount:40,Operation:0,UUIDMost:69160,UUIDLeast:521589},{AttributeName:"generic.followRange",Name:"generic.followRange",Amount:32,Operation:0,UUIDMost:99396,UUIDLeast:851924},{AttributeName:"generic.knockbackResistance",Name:"generic.knockbackResistance",Amount:500,Operation:0,UUIDMost:76900,UUIDLeast:463228},{AttributeName:"generic.movementSpeed",Name:"generic.movementSpeed",Amount:0.5,Operation:0,UUIDMost:34152,UUIDLeast:644098},{AttributeName:"generic.attackDamage",Name:"generic.attackDamage",Amount:5,Operation:0,UUIDMost:85956,UUIDLeast:818955}],Unbreakable:1}}]"

Into the chest? (summon command or setblock)

Best Answer

You are trying to insert a command into NBT data. You need to follow the correct format for NBT; the wiki lists data for the item format here.

In particular, you need to specify an id string, Damage short, Count byte, Slot byte, and tag compound. The /give syntax reflects all except Slot:

/give <player> <id> [Count] [Damage] {tag}

Therefore, with the following /give command:

/give @p minecraft:stone_sword 1 0 {Unbreakable:1b}

The data becomes:

{
    id:"minecraft:stone_sword",
    Damage:0s,
    Count:1b,
    tag:{
        Unbreakable:1b
    }
}

Your command will follow the same format, including the Slot tag as the Items list uses that tag to determine which slot in the inventory the item is in. Fixed command:

/setblock ~ ~1 ~ minecraft:chest 0 replace {Items:[{id:"minecraft:golden_axe",Count:1b,Slot:0b,Damage:0s,tag:{display:{Name:"Thor'sAxe",Lore:["Thegodliest","ofthegodliest."]},AttributeModifiers:[{AttributeName:"generic.maxHealth",Name:"generic.maxHealth",Amount:40,Operation:0,UUIDMost:69160,UUIDLeast:521589},{AttributeName:"generic.followRange",Name:"generic.followRange",Amount:32,Operation:0,UUIDMost:99396,UUIDLeast:851924},{AttributeName:"generic.knockbackResistance",Name:"generic.knockbackResistance",Amount:500,Operation:0,UUIDMost:76900,UUIDLeast:463228},{AttributeName:"generic.movementSpeed",Name:"generic.movementSpeed",Amount:0.5,Operation:0,UUIDMost:34152,UUIDLeast:644098},{AttributeName:"generic.attackDamage",Name:"generic.attackDamage",Amount:5,Operation:0,UUIDMost:85956,UUIDLeast:818955}],Unbreakable:1}}]}