Minecraft – Select entity by certian attributes Minecraft Bedrock Edition

minecraft-bedrock-editionminecraft-commands

I'm currently making a factions map for realms to put up on Planet Minecraft. In the map I have it so that a thrown egg teleports you to spawn (get it? spawn egg). The thing is that execute @e[type=item,name=Spawn] ~~~ doesn't seem to work right.

I obviously don't want every thrown egg to send you back to spawn, but I also like the idea of a spawn egg and it's easier for pocket edition players to throw an egg rather than have to drop something else.

Can I take the egg by some other attribute other than name?

I made it so that dropped eggs will just summon a thrown egg above it and then die themselves, but I'm hoping for a better solution to this.

Best Answer

I think it would be easier to execute players who have thrown a specific type of egg instead of executing the egg itself. Since I don't know Bedrock Edition commands, I'll use PC commands and hopefully you can edit them to your liking, or someone else can edit them in this answer.

Add an objective that tracks players who throw eggs:

/scoreboard objectives add egg minecaft.used:minecraft.egg

Then have these commands running in a repeating chain:

tp @a[tag=egg,scores={egg=1}] <write your spawnpoint coordinates here>
tag @a remove egg
tag @a[nbt={SelectedItem:{id:"minecraft:egg",tag:{display:{Name:"\"Spawnpoint\""}}}}] add egg
scoreboard players reset @a egg

What this does is:

  • Teleports all players who have thrown an egg with the egg tag to the spawnpoint.
  • Removes the egg tag of all players, then adds it for those who are holding the specific egg. In the next tick, if they had held this egg before throwing it, they will be tped. The reason why I added the tag after the tp command is because they wouldn't have had the egg anymore so tagging them would have been impossible.
  • Resets their egg score.

That system was for 1.13 commands. If you're using 1.12, use these commands instead.

tp @a[tag=egg,score_egg_min=1] <write your spawnpoint coordinates here>
tag @a remove egg
tag @a add egg {SelectedItem:{id:"minecraft:egg",tag:{display:{Name:"Spawnpoint"}}}}
scoreboard players reset @a egg
Related Topic