Hi! I need to make a command which detect named mob on specific type of blocks, and I can do it:
/execute as @e[name=mob1,nbt={OnGround:1b}] at @e[name=mob1] if block ~ ~-1 ~ minecraft:stone
But, the problem starts when I want to add running command at the end: setblock ~ ~1 ~ minecraft:redstone_block, but instead of setting it above the command block, redstone block is set one block above that mob.
/execute as @e[name=mob1,nbt={OnGround:1b}] at @e[name=mob1] if block ~ ~-1 ~ minecraft:stone run setblock ~ ~1 ~ minecraft:redstone_block
I know that it just works this way, but if someone know any option to solve it, I would be grateful :3
Hi! I need to make a command which detect named mob on specific type of blocks, and I can do it:
/execute as @e[name=mob1,nbt={OnGround:1b}] at @e[name=mob1] if block ~ ~-1 ~ minecraft:stone
But, the problem starts when I want to add running command at the end: setblock ~ ~1 ~ minecraft:redstone_block, but instead of setting it above the command block, redstone block is set one block above that mob.
/execute as @e[name=mob1,nbt={OnGround:1b}] at @e[name=mob1] if block ~ ~-1 ~ minecraft:stone run setblock ~ ~1 ~ minecraft:redstone_block
I know that it just works this way, but if someone know any option to solve it, I would be grateful :3
instead of using relative coordinates, just use the coordinates of the block directly above the command block's coordinates.
So if the command block is at -11, 63, 153, use /execute as @e[name=mob1,nbt={OnGround:1b}] at @e[name=mob1] if block ~ ~-1 ~ minecraft:stone run setblock -11 64 153 minecraft:redstone_block
I know, but I have to chceck and put so many coordinates to so many command blocks instead. I make a puzzle map and this is why I wanted to find more simple way to do it.
Oh, I wouldn't have figured it out and I definitely will use it somewhere, but in this case I decided to just write absolute coordinates of block after /setblock
/execute as @e[name=mob1,nbt={OnGround:1b}] at @e[name=mob1] if block ~ ~-1 ~ minecraft:stone
When you tell the game "as @#" or "at @#", it is similar to a "For" loop, if you know a bit of programming.
Basically, the game will run all the text after "as/at @#" for each entity found that way
So how your command works looks like that :
-For each mob1 OnGround, as @s{
--For each mob1, at @s {
---Test for stone under @s
--}
-}
This means your actual command will test if there is a stone under any mob1, and repeat the same test for each entity.
For example, if you have 3 mob1 and only one on stone, here's what the log of your /execute (ran once) would be :
-block found under mob1
-block not found under mob1
-block not found under mob1
-block found under mob1
-block not found under mob1
-block not found under mob1
-block found under mob1
-block not found under mob1
-block not found under mob1
This means your /setblock will be ran 3 times per test, in that case. Would change pretty much nothing, but this can be worse in systems where you have hundreds of entities to test.
Here's a simplified command :
/execute as @e[name=mob1,nbt={OnGround:1b}] at @s if block ~ ~-1 ~ minecraft:stone
Pretty simple : I only used "at @s".
When ran from a command block, "@s" by default is that command block. However, the current @s is changed before "at @s", using "as @e[name=mob1,nbt={OnGround:1b}]"
So here would be the loop for that :
-For each mob1 OnGround as @s {
--Test for stone under @s
-}
And the command's log, for 3 mob1, only one on stone :
-block found under mob1
-block not found under mob1
-block not found under mob1
I got into chiptune music composition.
You can listen to them on my Youtube channel : https://www.youtube.com/channel/UCjWYbJGk7nvNDbnCvMlZGkw
Descriptions are in french, you'd just need some google translation copy-paste...
Also made some more or less complicated datapacks, shared here (planetminecraft).
Oh, I didn't know that I could use @s in this command, and I love to keep commands as simple as it's possible, so thank you very much! Now i'm gonna change it in my save
Also thanks for explanation of the whole command mechanism
Hi! I need to make a command which detect named mob on specific type of blocks, and I can do it:
But, the problem starts when I want to add running command at the end: setblock ~ ~1 ~ minecraft:redstone_block, but instead of setting it above the command block, redstone block is set one block above that mob.
I know that it just works this way, but if someone know any option to solve it, I would be grateful :3
instead of using relative coordinates, just use the coordinates of the block directly above the command block's coordinates.
So if the command block is at -11, 63, 153, use /execute as @e[name=mob1,nbt={OnGround:1b}] at @e[name=mob1] if block ~ ~-1 ~ minecraft:stone run setblock -11 64 153 minecraft:redstone_block
Creator of Metroid Cubed 3, a Metroid-themed mod! Become a donator today!
I know, but I have to chceck and put so many coordinates to so many command blocks instead. I make a puzzle map and this is why I wanted to find more simple way to do it.
Anyway thanks for help!
I'm no good with complicated commands, but you could change the command so it does something that doesn't matter, for instance:
/execute as @e[name=mob1,nbt={OnGround:1b}] at @e[name=mob1] if block ~ ~-1 ~ minecraft:stone run setblock 0 0 0 minecraft:bedrock
and have it facing a chained command block with:
/setblock ~ ~1 ~ minecraft:redstone_block
of course that would give you even more command blocks which might not be any better.
Just testing.
Oh, I wouldn't have figured it out and I definitely will use it somewhere, but in this case I decided to just write absolute coordinates of block after /setblock
Anyway, thanks for help :3
Just a little tip to improve your commands :
When you tell the game "as @#" or "at @#", it is similar to a "For" loop, if you know a bit of programming.
Basically, the game will run all the text after "as/at @#" for each entity found that way
So how your command works looks like that :
-For each mob1 OnGround, as @s{
--For each mob1, at @s {
---Test for stone under @s
--}
-}
This means your actual command will test if there is a stone under any mob1, and repeat the same test for each entity.
For example, if you have 3 mob1 and only one on stone, here's what the log of your /execute (ran once) would be :
Here's a simplified command :
Pretty simple : I only used "at @s".
When ran from a command block, "@s" by default is that command block. However, the current @s is changed before "at @s", using "as @e[name=mob1,nbt={OnGround:1b}]"
So here would be the loop for that :
-For each mob1 OnGround as @s {
--Test for stone under @s
-}
And the command's log, for 3 mob1, only one on stone :
-block found under mob1
-block not found under mob1
-block not found under mob1
I got into chiptune music composition.
You can listen to them on my Youtube channel :
https://www.youtube.com/channel/UCjWYbJGk7nvNDbnCvMlZGkw
Descriptions are in french, you'd just need some google translation copy-paste...
Also made some more or less complicated datapacks, shared here (planetminecraft).
Oh, I didn't know that I could use @s in this command, and I love to keep commands as simple as it's possible, so thank you very much! Now i'm gonna change it in my save
Also thanks for explanation of the whole command mechanism