Minecraft Java Edition Commands – How to Detect Crushed Plants

minecraft-commandsminecraft-java-edition

In the map I'm making, Pvt. Rabbit (You) must try not to crush any planted carrots underfoot. If he does, I want it to be detected and then +1 to a scoreboard counting the number of times he has done it. My question is what is what would be the correct command to detect if he has crushed any planted carrots. At first I tried:

 execute @p[r=1000] ~ ~ ~ detect ~ ~0 ~ minecraft:carrot say ... 

I won't use the say command once I've figured it out, but now I'll use that. It says that "there is no such block with name minecraft:carrot" which I completely get. Any Ideas about what to do?

Best Answer

First, create a dummy objective that we'll use to track items that are carrots:

/scoreboard objectives add isCarrot dummy

Then, on a clock, in this order:

1. Set that objective to 1 for all items that are carrots:

scoreboard players set @e[type=Item] isCarrot 1 {Item:{id:"minecraft:carrot"}}

2. Have all carrots add a point to the nearest player:

execute @e[type=Item,score_isCarrot_min=1] ~ ~ ~ scoreboard players add @p carrotsCrushed 1

3. And then kill all carrot items:

kill @e[type=Item,score_isCarrot_min=1]