2

I'm trying to do my own portal gun with only command blocks, and it is going pretty well.
But, the thing is, I can't make the teleport system work correctly.
What I'm trying to do is if you're in a certain distance from the armor stand with the name "blue", you're teleported to 2 blocks in front of the armor stand with the name "orange" and also make the same but reverse (orange to blue). Everything I tried either didn't work, or made so you're teleported exactly where the armor stand is, making you stuck in a TP loop.

How could I make it work correctly?

2
  • I suppose this is Minecraft Java
    – pinckerman
    Commented Jul 21, 2022 at 0:08
  • 1
    You can take a look at how nether portal works! They have a flag that gets set to true once you teleport and that prevents you from being teleported again; The flag only goes away if you are away from the portal.
    – BunnyMerz
    Commented Jul 21, 2022 at 18:55

1 Answer 1

2

To do a teleporter, we need to add some sort of cooldown so that it won't activate on the other side; Or you could do what you suggest which is put the player on a place that it wouldn't trigger the teleport.

We will have two cooldown tags, refering to each armorstand. Our steps will be:


  • If the player is close enough and doesn't have the tag for that armor_stand:

    1. Add the cooldown tag of the other armor_stand
    2. Telport to the other armor_stand
  • If the player is far enough of said armor_stand, remove their own cooldown tag.


Which translates to:

execute at @e[type=minecraft:armor_stand,tag=orange] as @a[distance=..1] unless entity @s[tag=ignore_orange] run tag @s add ignore_blue
execute at @e[type=minecraft:armor_stand,tag=orange] as @a[distance=..1] unless entity @s[tag=ignore_orange] run tp @s @e[limit=1,type=armor_stand,tag=blue]
execute at @e[type=minecraft:armor_stand,tag=orange] as @a[tag=ignore_orange, distance=1..] run tag @s remove ignore_orange

execute at @e[type=minecraft:armor_stand,tag=blue] as @a[distance=..1] unless entity @s[tag=ignore_blue] run tag @s add ignore_orange
execute at @e[type=minecraft:armor_stand,tag=blue] as @a[distance=..1] unless entity @s[tag=ignore_blue] run tp @s @e[limit=1,type=armor_stand,tag=orange]
execute at @e[type=minecraft:armor_stand,tag=blue] as @a[tag=ignore_blue, distance=1..] run tag @s remove ignore_blue

You must log in to answer this question.

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