3

I have a problem I want to create a chest that will have a button inside and this button can be placed on stone block. Can someone give me the command? I was trying this: (No Error) It was placing chest with button but this button hasn't got option to place it on stone.

/setblock 776 74 363 chest 0 replace {
    Items: [
        {
            id: "stone_button",
            Slot: 13,
            Count: 1,
            CanPlaceOn: "stone"
        }
    ]
}
  • Are you on Java edition? – Peregrine Lennert Mar 13 '19 at 17:00
  • 2
    Possible duplicate of How do I tag a named item on the ground – Fabian Röling Mar 13 '19 at 18:40
  • 2
    The dupe target has been closed for being unclear, it might be better to provide an answer on this question instead, as this question is more easy to understand. Other Q might then be set as Dupe of this one. – Malco Mar 14 '19 at 14:13
  • 3
    Given that the proposed dupe target is closed and has 1 pending delete vote, I am strongly against closing this question as a duplicate. – Unionhawk Mar 14 '19 at 16:11
  • 2
    The linked question also doesn't really answer this question. Yes, someone that has some experience can glean the answer to this question from that answer, but it isn't a straight path from one to the other. – MBraedley Mar 14 '19 at 16:37
2

There are two issues in your command.

/setblock 776 74 363 chest 0 replace {
    Items: [
        {
            id: "stone_button",
            Slot: 13,
            Count: 1,
            CanPlaceOn: "stone" // specifically, this line
        }
    ]
}

1

The CanPlaceOn tag syntax specifies that it accepts an array of strings:

{CanPlaceOn:[
    "<ID>",
    "<another ID>",...
]}

(Note the pair of square brackets.) Therefore, it is necessary to enclose the block ID(s) in [].

2

The Item tag syntax is as follows:

{Item:{
    id:"<ID>",
    Damage:<int>,
    Count:<int>,
    tag:{
        <Item NBT data here>
    }
}}

The syntax specifies that you need to put NBT tags of the item within the tag: tagname. Since CanPlaceOn is an NBT tag of an item, you need to enclose it with tag:{}.

tldr

The correct command is as follows:

setblock 776 74 363 chest 0 replace {
    Items: [
        {
            id: "stone_button",
            Slot: 13,
            Count: 1,
            tag:{
                CanPlaceOn: ["minecraft:stone"]
            }
        } 
    ]
}

This has been tested in a 1.11.2 singleplayer world.

| improve this answer | |
0

I dont think you can make items with special features on them What you have to do is create the button and make it place on stone and then put the button in the chest

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.