My goal is that in my adventure mode map a player starts with a stack of diamond blocks that have NBT properties allowing them to be placed in the world and picked with a specially given pickaxe. This is all working fine.
The problem is that once the player breaks the blocks they placed, they cannot replace them as the NBT properties of the mined blocks that are picked back up are defaulted. So a workaround I thought of was that if I can "detect" when they break their placed diamond blocks, I can execute a command to give them a replacement block with the correct properties.
A better way, in my opinion, would be to replace the entity data of the mined block (as an item before it is picked up). You can do this by running this command:
execute as @e[type=Item,nbt=nbt={Item:{id:"minecraft:diamond_block"}}]] run data merge entity @s {Item:{tag:{CanPlaceOn:["minecraft:air","minecraft:stone"]}}}
Put this into a repeating command block followed by chain ones: (this works for when you break a diamond_block with a diamond_pickaxe)
execute at @a[nbt={SelectedItem:{id:'minecraft:diamond_pickaxe'}}},scores={UsedDiaPick=1..}] at @e[nbt={Item:{id:\'minecraft:diamond_block\'},Age:0s},sort=nearest,limit=1] run summon area_effect_cloud ~ ~ ~ {Tags:[\'BrokenBlock\'],Duration:2147483647}
scoreboard players reset @a UsedDiaPick
You can get the position using:
execute at @e[tag=BrokenBlock] run setblock ~ ~ ~ red_concrete
My goal is that in my adventure mode map a player starts with a stack of diamond blocks that have NBT properties allowing them to be placed in the world and picked with a specially given pickaxe. This is all working fine.
The problem is that once the player breaks the blocks they placed, they cannot replace them as the NBT properties of the mined blocks that are picked back up are defaulted. So a workaround I thought of was that if I can "detect" when they break their placed diamond blocks, I can execute a command to give them a replacement block with the correct properties.
So this command works great:
/give @p diamond_block 1 0 {"minecraft:can_place_on":{"blocks":["stone","cobblestone","stained_glass","grass","dirt","carpet", "iron_block","smooth_stone"
,"brick_block","stonebrick", "end_stone","concrete","nether_brick"]}}
But how do I preface it with the condition of "IF player mines diamond_block, then give...." I just don't know how to do the mine detection part.
A better way, in my opinion, would be to replace the entity data of the mined block (as an item before it is picked up). You can do this by running this command:
Funny I just finished a system that uses this. I've done many tests on this one and theres no way you can bug into it.
First add one objective:
Put this into a repeating command block followed by chain ones: (this works for when you break a diamond_block with a diamond_pickaxe)
You can get the position using: