Can you make a repeating command in minecraft with /data command, that only affects any entity once?

by markoatonc   Last Updated June 29, 2020 23:14 PM

I am trying to make a command block command for server I am playing at, that would make any creeper near it not explode. As they still somehow spawn where they shouldnt and keep blowing up behind people when they use public chests. With the terrible and messy info on wiki I was able to come up with this:

/data modify entity @e[type=minecraft:creeper,distance=0..50,limit=1] ExplosionRadius set value 0

But it just keeps editing single nearest creeper, so I tried to make it ignore ones that already have it set to 0, but it seems to still only affect one creper repeatedly if try to do this this way:

/data modify entity @e[type=minecraft:creeper,nbt=!{ExplosionRadius:0},distance=0..50,limit=1] ExplosionRadius set value 0

So then I thought that I could just add a tag to it named like "noexplode" or something. but it seems to only allow you to edit one value with single command...

/data modify entity @e[type=minecraft:creeper,tag=!{noexplode},distance=0..50,limit=1]ExplosionRadius merge value 0 //and here I dont know how to make it also add a tag to it.

Answers 1

/data modify entity @e[type=minecraft:creeper,nbt=!{ExplosionRadius:0},distance=0..50,limit=1] ExplosionRadius set value 0

This doesn't work because the ExplosionRadius tag is a byte, and you're testing for it as an integer. /data modify entity @e[type=minecraft:creeper,nbt=!{ExplosionRadius:0b},distance=0..50,limit=1] ExplosionRadius set value 0 would work.

Your third idea could be done with two commands: /data modify entity @e[type=minecraft:creeper,tag=!noexplode,distance=0..50,limit=1] ExplosionRadius set value 0 and then /tag add @e[type=creeper,distance=0..50] add noexplode configured to run after it using a chain command block or function.

However, this entire hack is unnecessary, since you can just apply the tag to all creepers in the area in one fell swoop with /execute as @e[type=minecraft:creeper,distance=0..50] run data modify entity @s ExplosionRadius set value 0, obviating the need to check which creepers already have been modified entirely.

June 29, 2020 23:05 PM

Related Questions

How to detect score increase?

Updated May 31, 2020 16:14 PM

How do servers allow right-click events?

Updated May 29, 2020 19:14 PM