Minecraft Tree Tipper Command Block Error

minecraft-commandsminecraft-java-edition

I am trying to create a system that when you break any block on a tree, the whole thing will break. I successfully made that part, but ran into an error. I have it so the tree is relative to a bat named Tree1, so anywhere there's a bat named Tree1, there will be a tree. What I am having a problem with is that when ever I break a block on one tree, it affects all of the other trees. I need to know how to have the same bat under each tree(no differences what so ever), then somehow change the bat once it's tree gets chopped down. I could set it so that the player receives a scoreboard point when their holding an axe, and the tree would only fall when that player is in a certain range, but that might get messy around tress that are clumped together, and I also want to keep it as compact as possible. Here is the code:

Spawning the bat:

/summon Bat X Y Z {NoAI:1,Silent:1,CustomName:"Tree1"}

Setting the scoreboard:

/scoreboard objectives add Tree1 dummy Tree1

/scoreboard players set @e[type=Bat] Tree1 1 {CustomName:"Tree1"} (on a setblock clock)

Spawning the tree:

/execute @e[type=Bat,score_Tree1_min=1] ~ ~ ~ /fill ~ ~2 ~ ~ ~7 ~ log
/execute @e[type=Bat,score_Tree1_min=1] ~ ~ ~ /fill ~-1 ~4 ~-1 ~1 ~8 ~1 leaves 1 replace air

Testing to see if a block is broken:

/execute @e[type=Bat,score_Tree1_min=1] ~ ~ ~ /testforblock ~ ~3 ~ air (on a setblock clock)

Using a comparator to remove the tree:

/execute @e[type=Bat,score_Tree1_min=1] ~ ~ ~ /fill ~-1 ~2 ~-1 ~1 ~8 ~1 air

Spawning the dropped items:

/execute @e[type=Bat,score_Tree1_min=1] ~ ~ ~ /summon Item ~ ~2 ~ {Item:{Count:4,id:log,tag:{display:{Name:Wooden Log}}}}

Any help would be useful. Thanks.

Best Answer

Rather than having a testforblock leading onto a fill command via a comparator, you can use the detect function of execute on a clock, which will allow the same bat that detects the air to execute the fill. E.G:

execute @e[type=Bat,score_Tree1_min=1] ~ ~ ~ detect ~ ~3 ~ air 0 fill ~-1 ~2 ~-1 ~1 ~8 ~1 air

Similar thing for spawning the dropped item:

execute @e[type=Bat,score_Tree1_min=1] ~ ~ ~ detect ~ ~3 ~ air 0 summon Item ~ ~2 ~ {Item:{Count:4,id:log,tag:{display:{Name:Wooden Log}}}}

Few sidenotes:

1. You can make the bat invulnerable and invisible like so:

/summon Bat X Y Z {NoAI:1,Silent:1,CustomName:"Tree1",Invulnerable:1b,ActiveEffects:[{Id:14,Amplifier:0,Duration:2147483647,ShowParticles:0b}]}

2. Players can use a nametag to name a bat "Tree1" themselves. Exploiting this, a player could destroy bedrock or clear large areas. Thus, you may want to set the Tree1 score based off of something other than the bat's name.

3. You'll probably want to kill the bat or set its score to 0 after it has been used, otherwise they'll accumulate and keep causing lag.