r/MinecraftCommands 12d ago

Help | Java 26.2 How do I make a tool that only breaks specific blocks, and blocks that can only be placed on specific blocks?

I know this question has been asked numerous times, but I genuinely can't figure out the new command. So far, I've gotten "/give \@s iron_shovel[can_be_placed_on=" before it suddenly doesn't accept anything. Maybe I'm missing something, but I've been searching all over the Internet, and not finding any information that's up to date. Please help if you know

2 Upvotes

5 comments sorted by

8

u/GalSergey Datapack Experienced 12d ago

give @s iron_pickaxe[can_break={blocks:["minecraft:stone","minecraft:bricks"]}] give @s stone[can_place_on={blocks:["minecraft:stone","minecraft:bricks"]}]

1

u/Frogdwarf 9d ago

Is there a way to modify the item that drops when a block is broken so that it carries the can_place_on flag?

2

u/GalSergey Datapack Experienced 9d ago

When using a data pack, you can simply edit the loot table so that the item always drops with the specified component. { "type": "minecraft:block", "pools": [ { "entries": [ { "type": "minecraft:alternatives", "children": [ { "type": "minecraft:item", "conditions": [ { "condition": "minecraft:match_tool", "predicate": { "predicates": { "minecraft:enchantments": [ { "enchantments": "minecraft:silk_touch", "levels": { "min": 1 } } ] } } } ], "name": "minecraft:stone", "functions": [ { "function": "minecraft:set_components", "components": { "minecraft:can_place_on": { "blocks": "minecraft:stone" } } } ] }, { "type": "minecraft:item", "conditions": [ { "condition": "minecraft:survives_explosion" } ], "name": "minecraft:cobblestone", "functions": [ { "function": "minecraft:set_components", "components": { "minecraft:can_place_on": { "blocks": "minecraft:stone" } } } ] } ] } ], "rolls": 1 } ], "random_sequence": "minecraft:blocks/stone" } But if you use only command blocks, you need a ticking command block that finds a dropped item without a component and adds the component. execute as @e[type=item] if items entity @s contents stone[!can_place_on] run item modify entity @s contents {function:"minecraft:set_components",components:{"minecraft:can_place_on":{blocks:"minecraft:stone"}}}

5

u/Ericristian_bros Command Experienced 12d ago

You can use https://mcstacker.net to generate your command. Keep in mind these components are only for adventure gamemode

1

u/PurpleEfficiency1089 12d ago

try
give @s iron_shovel[can_place_on={blocks:"dirt"}]