What is a predicate? A predicate is a part of a datapack. In the base game, they are used for loot tables E.G, when mobs should drop certain kinds of loot, what type of loot to generate in chests, etc. A predicate tells us whether something is true Or false. The “Something” it tells us is called a condition, and there’s a looong list of condititions that are built into Minecraft. There’s conditions for just about everything, from detecting your position in the world, checking scoreboard values, And even checking light levels! The full list of them is on the Minecraft wiki page for predicates. Predicates are often used as an alternative to having tons of scoreboards. However, there are some things that can only be done with predicates! So, when should you use a predicate? 1. When you need to detect a large number of criterias at once. 2. When you are trying to reduce the number of scoreboards in use. 3. When something can only be detected by a predicate. Let’s have a look at making one now. Given that it’s a JSON file, predicates are very easy for Computers to read, but fairly annoying to write as a human. Because of that, I’m gonna use a generator. This is a quite popular and up-to-date one. The link is misode.github.io/predicate/ and it’s in the description for you to go click on. Let’s start with a pretty common use case for predicates. Detecting if a player is sneaking! Our first condition here is called “entity properties” and it contains just about everything you can think of to do with entities. It’s got entity type, NBT, team- but what we want is Under “flags”. Click on the plus to add a “flags” condition. Then we’ll click on is_sneaking: true. Now to get our predicate into the game. I’m gonna assume you’re familiar with how to set up a basic datapack for this video (just like this one), but if you’re not, go watch my datapack tutorial after This video. While I’m shamelessly cross-promoting myself, subscribe if you want to see more quality command/datapack videos like this one! Anyway, open up your datapack folder and go into data, then create a namespace for your project if you haven’t already. Mine is called “tutorial”. Brilliant. Inside that (this is where the new stuff happens) create a folder called “predicates” spelled just like that. Inside here is where we will put the predicates. You can either copy and paste the predicate into a new json file (called something like “is_sneaking.json”), Or you can download your predicate as a json file, then move and rename it once it’s downloaded. Now we can go in game and do /reload. Our predicates are now loaded! There’s a number of different ways to use predicates in commands, and no one is truly superior to any other, so let Me show you some options. First, there’s what you came here to see: /execute if predicate. I’ll write the command /execute as @a if predicate tutorial:is_sneaking run say I’m sneaking! . What this does can be broken down into 3 parts. First, /execute as @a, run the following once for each Player. If predicate tutorial:is_sneaking, so *if* this player is sneaking, then run the say command, and say “I’m sneaking!” Let’s make this run every tick and see what we get. Nothing, until I start holding sneak, then the chat gets flooded with messages! Nice! The second way to do this would be to use the target selector form of predicate. Meaning we can use a predicate to only select certain players! For example: /execute as @a[predicate=tutorial:is_sneaking] run say I’m sneaking! This command does exactly the same thing as our last command, but the predicate is built Into the player selector, instead of using an execute if command. Is this better or worse than the previous way? Not really, it’s just different. I use this version less often, just because I don’t like how crowded it gets, and more importantly because Minecraft doesn’t let you Tab-complete your predicates this way. Get on it Mojang! Alll the cool kids let you tab complete in your player-selectors! (2nd example) Our 2nd example is using a random-chance condition to make something happen a certain percent of the time. Just choose random chance as our condition, and write a percentage as a decimal between 0 and 1. I’ll choose 0.5, giving this predicate a 50% chance of being true every time it’s checked. I’ve added the predicate to my folder and reloaded. If you forgot how to do that already then too bad the information is gone forev- wait actually I’ve just been informed this is not a Live broadcast on television, and you go back and look again. Ok good good. Now, we could check our 50% chance on just ourselves, but that’s boring. Instead I’ve recruited my friend logbog, digdog, bigbog or zigzog, eggnog, leap frog, hotdog, wigwog, tall man, colonel sand, homestuck fan, Haunted lands, big band, grand cayn, loves mans, I’ll be damned- to help with the commands. These are fake players created by the carpet mod by the way. They behave just like real players for testing purposes, but aren’t controlled by humans because this is still singleplayer. This is my command, don’t mind how long it is, basically all it does is: execute as @a[predicate=tutorial:50_percent] and also whose name is not my username. If that 50% chance condition is met, then it runs a particle command. *press* Each time I run this command, Every player basically does a coin flip. If they win the flip, then the particles go off. It won’t choose exactly 50% of people every time, but each player has a 50% chance of running the command. Our 3rd example is detecting players below a certain Y-level. I’ve gotten several comments Asking how to do this, usually for a bedwars inspired map. For this we’ll need a “location” flag which can be found under “entity properties”. Click the plus, then go down and click the plus next to “position”. Then in the Y section we want to change it from number To object, which will let us pick a range of numbers, instead of just looking for one specific number. The first number here is the minimum height we’re looking for and the second is the maximum. I’ll set these to 0 and 60 respectively. After adding it to my predicates folder, Naming it something appropriate like “is_y_less_than_60.json” and reloading in the game, we can test it with a command. Here’s my example command! /execute as @a (pretty basic) if predicate tutorial:is_y_less_than_60 run- a command that just says “My y <= 60!” Awesome, and we switch this on.
Ground level in this world is 64, so if we go more than 4 blocks down this should activate! Keep an eye on my Y coordinate in the top left. One, two, three, four- and there it is! Any lower
Than this and it’ll just keep spamming. But as soon as we go back to the surface it’ll fade away. No more new messages are getting sent. Something else we can do with the “location” condition is detect light levels! Add a “light”
Condition and set it to object. Now we can enter the min and max light we want to detect. I’ll detect 0 through 7, as that’s what Minecraft considers “dark” for mob spawning. Bim bam boom added to the game, reload, and here’s our command:
/execute as @a if predicate tutorial:is_dark run say I’m in the dark! Just like the last one! Now if we go into my spooky dungeon, we should know when we’re in the dark. Oooooooo, scary. And also very cool! There are many other cool things you can detect with predicates such as time of day,
Biome, and even scoreboard values. I’ll leave figuring those out to you as homework. If you want to know what any of the other conditions do, the first place to look is this wiki page (link in the description). It’s got a nice list of all the conditions and
What they do in pretty good detail most of the time! If you have more questions or suggestions feel free to leave them in the comments. Also subscribe so you can get more videos like this one! I’ve been Legitimoose, thank you for watching. Video Information
This video, titled ‘Minecraft /execute if PREDICATE [1.19] Command Tutorial’, was uploaded by Legitimoose on 2020-12-25 00:57:08. It has garnered views and [vid_likes] likes. The duration of the video is or seconds.
Learn how to use predicates in this Minecraft predicate tutorial for 1.19/1.18/1.17/1.16. If you’ve ever wondered what /execute if …