#Is there a difference between these 2?
1 messages · Page 1 of 1 (latest)
as sets the execution context to the target entity: whatever commands you run after as @e[type=wither] will run as if the wither ran them
if entity runs the rest of the command if the target entity exists, but without changing the execution context
which one you should use depends on the context, but they are not at all the same no.
I want to execute the command if there is a wither in my world, I think using if entity would be a better option
I start thinking that my datapack is very bad for optimization because I don't know much about it, i'm afraid that the server would be bad because of this
yup, if entity should be the correct option for that case
If you do want to measure it, this guide can help. There are more tools and tricks that I am sure we can help with if you found something is causing significant lag/issues.
omg thank you
execute as @a if data entity @s Inventory[the item that i search]
here, should I use execute if data entity @a ?
wait I think i just did a better option before
checking the nbt would be better than checking data entity?
execute if entity @a[nbt={Inventory:[
that depends on your goal, do you want to run something as the player with that item or can any player have that item for some server-wide function to run?
as for inventory checks, we also have if items entity <target> <slots> for inventory checks where container.* would be the equivalent of the entire Inventory array.
-# note that both solutions do not check the offhand and armor slots as those are stored separately
hmmm for this one, I need to check if someone has it anywhere in inventory to launch another function
In that case your first command does just that, unless you have to also check the offhand.
I don't think that I have to, it's an item that you buy to a custom villager
I dont think that you can buy and put it instantly in offhand, and it's not a big deal
note that on the topic of optimization, any data operations/tests should be avoided where possible. here you could instead use a predicate or if items as quimoth mentioned
and if you just want to test if someone has made this trade with a villager, you could potentially optimize even further and just use an advancement with the villager_trade trigger
that's a good idea, thank you both for your help, i'm very grateful