1

I'm wanting to teleport entities that have a name, just like when you use tags to name a creature in Minecraft, and I wanted to teleport any and all entities that have a name, whatever it may be, is it possible to do this? would work as a filter, I teleport the entity that has a name, ignoring those that don't.

I tried different ways, but my knowledge is very vague, below are some examples.

/tp @e[type=!minecraft:player,name=""] @p

/tp @e[type=!minecraft:player,nbt={CustomName:""] @p

/tp @e[type=!minecraft:player,nbt={CustomName: '{"text":""}'}] @p

I'm currently testing on version 1.16.5

1
  • I guess you need a common denominator and filter using that (e.g. 'animal' or 'mob'). Have you looked through the existing questions here (like e.g. this)? This might give you a solution, for example.
    – Joachim
    Commented Mar 2 at 14:43

1 Answer 1

2

You can select entities that have a specific NBT tag, regardless of value, with /execute, like so.

/execute as <selector> if data entity @s <tag> run <command>

Replace <selector> with a selector for the entities you want to test, <tag> with the NBT tag to check for, and <command> with the command that will be run for every entity with the specified tag, as that entity.

For your specific example of teleporting all entities with a custom name to the player, this command should do what you want.

/execute as @e[type=!player] if data entity @s CustomName run tp @p

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .