How do I make an item break a certain block in Minecraft Java 1.14.1? [duplicate]

I am trying to build an adventure map, but I'm afraid the player will place the button in the wrong place. So I need to make a pickaxe to break just the button and not break anything else to reduce cheating and make secret ways. But none of the tutorials are for Java 1.14 or seem to work.


Solution 1:

Nothing has really changed from my knowledge, the command to make a tool break a specific block is somewhat simple

/give [Name] minecraft:wooden_pickaxe{CanDestroy:["minecraft:stone_button"]}

Just replace the [Name] section with your Minecraft username, or if you dont want it on a wooden pickaxe just replace it with any other tool (E.g: stone_pickaxe, iron_pickaxe, etc)

/give [Name] minecraft:stone_pickaxe{CanDestroy:["minecraft:stone_button"]}

/give [Name] minecraft:iron_pickaxe{CanDestroy:["minecraft:stone_button"]}

/give [Name] minecraft:diamond_pickaxe{CanDestroy:["minecraft:stone_button"]}

If you want to add more than just a stone button, like say, make it also able to destroy an oak button or something, it would be like this

/give [Name] minecraft:diamond_pickaxe{CanDestroy:["minecraft:stone_button","minecraft:oak_button"]}

The tool can also be used to break specified blocks in Adventure mode if you change the 'stone button' and 'oak button' parts to some other block. But you could also make a button that can only be placed on specific blocks

/give [Name] minecraft:stone_button{CanPlaceOn:["minecraft:stone","minecraft:cobblestone"]}

You can change out what it can be placed on by just replacing the 'stone' and 'cobblestone' with some other block like before with the buttons, but if it's broken once placed, it will no longer have the 'CanPlaceOn' specific's that allowed it to be placed on certain blocks in adventure mode.

To my knowledge, there is no way around that. But I hope I helped.

Edit: This is on Minecraft Java 1.14.1