3

I'm trying to execute a command if a mob has the Owner NBT tag, regardless of who the owner is. How would I do this, if possible?

I'd like to be able to do something like /execute as @e[nbt={Owner=""}] or /execute as @e[nbt={Owner="*"}]. Which don't work, as expected, but I'm hoping there's a way that I didn't think of or simply don't know.

I intend to make something that only affects players and tamed mobs. It doesn't matter who tamed the mob, as long as it is tamed it should be affected.

2
  • Admittedly, I don't know the specifics of the NBT format, but going by this post, it doesn't seem like this is possible. Commented Jul 25 at 1:24
  • @Hoppeduppeanut while similar, this doesn't seem to be the same thing I'm looking for. Rather the opposite, I believe? From what I understand they want to save a player's name to NBT one way or another. What I want is to check for an NBT tag that usually does mention a player (or rather, their UUID), but read it without filling in a specific player. I simply want to check the existence of the NBT on the entity, even if it's empty. I'd want to be able to do an if [entity] has [NBT container tag] then ... Commented Jul 25 at 2:00

1 Answer 1

4

Here is the command you probably want:

execute as @e if data entity @s Owner run <Command>

This will run if the if data is successful, it doesn't check for any specific value. For example, when I tested this only the entity with the Owner nbt, in my case an item, ran the command, and not the player. As I don't have the nbt on myself.

1
  • Thanks! This exactly what I was looking for. Commented Jul 27 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.