To fix the command:
@e[type=Player]
can just be @a
- There is no air with a data value of 1, so the detect will never succeed; it should be 0
- The data value in
/fill
should come before the old block handling mode
So your command should be:
execute @a ~ ~ ~ detect ~ ~-2 ~ air 0 fill ~-2 ~-1 ~-2 ~1 ~-1 ~1 barrier 0 destroy
I'm not sure if this really does what you want it to though. There is no way to execute two separate commands in a command block, nor is there any way to have a delay in a single block.
You're in luck, because I have a function that does exactly this. I'll explain what it does then give you the commands. I'm not sure eggs are a good idea, though, because there is a chance a baby chicken could spawn.
First, a scoreboard objective is created that tracks players who have thrown eggs. Players who have thrown an egg and have held an egg (determined by tag commands at the end of the function) summons an armor stand at the closest egg without a certain tag, then tags the egg so it doesn't happen again. The armor stand is constantly teleported to the closest egg, but when it does not detect a nearby egg then it is tagged. You can then execute all armor stands who have that tag to summon creepers or whatever you want to happen, then kill the armor stand.
This is the function. I converted it into 1.13 because it was originally in 1.12, and I changed it from snowballs to eggs (named "Grenade"). Because of lack of time I haven't tested it, but I see no reason why it shouldn't work. If it doesn't work, just let me know.
scoreboard objectives add grenade minecraft.used:minecraft.egg
execute as @a[scores={grenade=1..},tag=grenade] at @e[sort=nearest,limit=1,type=egg,tag=!grenade] run summon armor_stand ~ ~ ~ {Small:1b,NoGravity:1b,CustomName:"\"grenade\"",Marker:1b,Invisible:1b}
execute as @e[type=egg,tag=grenade] at @s run tp @e[type=armor_stand,name=grenade,limit=1,sort=nearest,distance=..2] @s
tag @e[type=armor_stand,name=grenade] add boom
execute as @e[type=egg,tag=grenade] at @s run tag @e[type=armor_stand,name=grenade,limit=1,sort=nearest] remove boom
execute as @e[type=armor_stand,tag=boom] at @s run summon creeper ~ ~ ~ {Fuse:0.0b,CustomName:"\"a grenade\""}
kill @e[type=armor_stand,tag=boom]
scoreboard players reset @a grenade
tag @a remove grenade
tag @a[nbt={SelectedItem:{id:"minecraft:egg",tag:{display:{Name:"\"Grenade\""}}}}] add grenade
Best Answer
Your NBT data is malformed. You have to provide a list of attributes, even if you only want to specify one, and for each attribute you want to specify you have to give its name and base value.
{...}
.Name
andBase
.element:value
. So in this case you doName:"generic.movementSpeed"
andBase:0d
. You put thegeneric.movementSpeed
in quotation marks, because it is of type String (computer talk for text) and you put thed
behind the number because it is of type Double (computer talk for a decimal number).Overall you get:
Now that you have your attribute you have to consider that Minecraft expects an element called
Attributes
with a value that is a list of all attributes. You create a list with[...]
. Put your attribute compound into it to form a list with one element (which is your attribute compound, which itself has two elements), so you just surround your attribute with[...]
. Now put this as the value of the elementAttributes
:When checking with
nbt=...
Minecraft always expects a single NBT compound, so add another{...}
around this. If you want to check any creeper for this you can do:Or you do it split up into an
as
and anat
like you did in your first command. The second and third commands you specified would not work as expected, because you never specify anas
, thus the command will check the currently executing entity whether it is a creeper with the NBT attribute. And this is normally the player who runs the command.For doing something (like summoning a zombie) at the position of those creepers replace the
run ...
withat @s run ...
.HOWEVER, note that this will check for creepers that have this movement speed attribute, NOT for creepers that are currently moving with this speed. So to check for any still standing creepers this won't work.