"/execute," not to be confused with "/kill"
is a very useful command.
While not used to vanquish your enemies,
it can be used to get someone else to vanquish your enemies for you.
Interested?
Here's the deets.
If you run the command "/help execute,"
you will be greeted with an unhelpful, and rather uninformative, block of text.
So... you navigate your way to the Minecraft wiki page for "/execute,"
and woah!
You're greeted with an extremely informative wall of text
that is somehow even less helpful than the "help" command was.
And (chuckles) wait a second
Do these examples even work?
No, they do not!
"C" was replaced by "count" when all the commands got remade.
Oh! Yeah, the commands got redone a while back,
so if you used to know what "/execute" did, think again!
Everything is different now.
Nothing is the same.
The first thing you need to know is that execute is not a command on its own,
but rather the beginning of a series of sub-commands.
What are sub-commands? What do they do?
We'll get there.
There are two categories of sub-commands:
Modify sub-commands, and condition sub-commands
If you're a tech-man like me, you might have an idea what these are.
But wait, there are also two sub-commands that fall outside these two categories.
One of them is extremely complex, and could take up a whole video by itself.
And the other one is so simple I'll tell you what it is now.
"/execute run" is the simplest possible execute command.
It simply runs a command.
If I type execute run, you may notice this is exactly what usually pops up in the tab menu.
So if I do "/execute run" and then the "say" command and then type
something super important
you'll see that I just, I run the command
like normal
as if I had just done "/say."
Now that is pretty boring, but wait, it gets more exciting when we learn
about "/execute as."
Yes, this is our first modify sub-command.
"Execute as" changes the person who sent the command
to whatever player or entity you choose.
So if I execute as @s
that would do exactly the same thing, that's just for the player who runs the command
You're executing the command as the player who runs the command
that does nothing.
So, instead, we're gonna execute as @e
run say hi.
And look at that, every entity has just said "hi."
Armor stand, three paintings, four sheep, four chickens,
an egg, Legitermoose, and... one more egg.
So, this is useful for a handful of reasons
but honestly 90% of the time I use "execute as"
is when I forget that it's not "/execute at."
This is actually a trick people use for building sometimes,
this can actually be useful in the state that I'm about to teach it to you.
So "/execute at" changes where the command is run.
As in, the relative coordinates will be different.
You guys know relative coordinates
"TP, tilde, tilde, tilde,"
that'll teleport you to where you are.
If I change it to "tilde, tilde 100," that'll be 100 blocks up.
You know the deal.
So "execute at" changes the coordinates the command is being run at.
Let's first write something very basic.
"Execute, run, setblock, tilde, tilde minus one, tilde," to
lime terracotta. Beautiful!
We run that, and unsurprisingly, it shows up right below the command block.
Now, if we run "execute as Legitermoose"
and then the same "run", set the block below to lime terracotta,
it doesn't appear below me, it still appears below the command block,
because even though it's supposedly being run quote on quote "as me,"
it is actually still running at the location of the command block.
So if we change "as" to "at," then that will run the command relative to my coordinates.
Check it out- bam. Whenever we activate it, we get a lime concrete right below us.
Now, I said this was useful for building, what does that mean?
Well, I'll show you real quick.
If I set this to an always active repeating command block, so it's running twenty times per second, every second,
all of a sudden, if I just run around,
it goes below me. I can just- I can fly all over the place
and build a big ol' thing, like I'm a crayon man,
I don't know.
Like I'm a- Like I'm a living magic marker.
Now we just turn that back to "needs redstone," and to an "impulse" command block
(chuckles) Very nice.
Those last two sub-commands that we've just learned are what's known as "modify" sub-commands,
because they modify where the command is being run.
Now, if you look at the tab complete, there are actually quite a few of them.
All of these sub-commands are in the "modify" category,
except for "if," "unless," "run," and "store."
So let's see what we got, let's do a speed round, because most of these are really weird.
"Align" aligns things to, like, the nearest axis,
normally a coordinate would be in the center of the block, but if you run "align,"
it'll line it up with a corner of the block, or something like that.
I don't know when that's useful.
"Execute anchored" changes whether it's being run from the eyes or the feet of the entity that is running the command.
"Execute as" and "execute at" we've covered.
"Execute facing" is pretty straightforward, you just enter the entity or coordinates that you wanna match
the pitch and yaw of, these two coordinates, right there.
"Execute if" is what we're gonna cover in a moment.
"Execute in" is kinda cool, it chooses the dimension that you're gonna execute it in, so by default,
Overworld, the End, and the Nether,
but as of 1.16, you can actually add your own dimensions to Minecraft,
and that's pretty cool.
And if you wanted to get to one of those dimensions, you would need to use "execute in."
Next up there's "execute positioned" which- it executes something at the coordinates of an entity or block,
but not including rotation data, or what dimension they're in,
so, use that when you need it, I guess.
Then there's "/execute rotated," which lets you set the rotation as either two coordinates
or as an entity.
And that is all of the "modify" execute sub-commands.
Ya-hoo! Let's move on to the good stuff.
Conditionals.
Aww yeah, this is where it gets fun
"/execute if" "block," "blocks," "data," "entity," "predicate," and "score."
"Predicate" and "score" are a little scary, so let's start with "block."
"Execute if block,"
one block below my feet, "is a grass block."
So it's used like this, "execute if tilde, tilde minus one, tilde, Minecraft grass block,
so if the block below me is a grass block, then run the command "/say I am standing on grass"
I am standing on grass!
What if I stand on lime terracotta?
Nothing happens.
It's beautiful.
So you could put this in a command block, and say "execute at Legitermoose if the block one block below,"
now we're at Legitermoose so the block one block below me, "is a grass block, then say I am standing on grass"
But note that the command block will say "I am standing on grass" not me.
I'll leave it up to you to figure out why that is.
Just a quick side note, um, you should never use "/say" in a finished product
I know that you can, it would work, but just learn how to use "/tellraw"
It's a better command, "/say is only useful for debugging.
Now I'm gonna show you a quick variation, instead of saying "if" the block me is grass,
we can change it to "unless" the block below me is grass, run this command.
So in this case, we'll change our text to say "I am not standing on grass."
And run it, and hey! I'm standing on lime terracotta!
Now if I run onto some grass and run it,
nothing happens.
"If" and "unless" they're just the opposite of each other.
Now, what about those other conditionals?
Well actually every single conditional is the same between "if" and "unless,"
and that's all of them. So you can only do "if" or "unless"
"block," "blocks," "data," "entity," "predicate," "score." We've been over this.
To save myself from going overly in-depth during this tutorial,
I'm just gonna quickly explain what these are.
"Execute if block," well we just learned that one, it detects a block at certain coordinates.
"Blocks" will compare two areas, so, similar to "/fill,"
if two areas match, that command will run.
"Data" is for JSON tags and NBT data, so if the block, entity, or some kind of inventory storage
matches a certain data tag, then it will run this command.
If you don't know what that means, you need not concern yourself with it.
And "entity" will execute if a certain entity exists.
So, if there is "@e type equals pig," run "say pig exists"
No pig exists, so nothing is run.
If we spawn a pig
Pig exists!
And then there's "run if predicate," which is far too complicated to get into,
and then there's "run if score," which, if you're using scoreboards and you're getting to a point
where you need to like, carefully calculate scoreboards and do math, and inequalities, and whatnot.
Just write a plugin.
And that's all of the conditionals. That's "execute unless" and "execute if"
The only thing left is "execute store,"
and boy oh boy, "execute store" is a doozy of a command.
I am not gonna explain it to you. Yet. Maybe I will someday.
But for today, that's the basics. That's all you need to know to get started with "/execute."
Okay, now that we're nearing the end of the video, you guys wanna see something really cool?
Alright, for each three block neo I do, you guys gotta subscribe or unsubscribe, okay?
It's gonna be like a little children's game.
Alright, one, that means you guys gotta subscribe. Okay, we're good, we're good,
it's all going well. Ohh, two!
Okay, you guys gotta unsubscribe, hold on, I gotta make this next one.
Oh, shoot, shoot, shoot!
Oh, no, that's not gonna- that's not gonna fly.
Let's do a- no cuts-
That's three! You guys gotta subscribe! You guys have to- you guys gotta smash sub.
Okay, okay, hold on, hold on, hold on, how many can I do?
How many can I do?
We're going crazy, alright, four, four, okay
Alright, that's fine, we can make this one. I'm so good. I'm so good!
NO! Frick! Augh! It's rigged! It's rigged! System's rigged! (shouting)
