2

I'm creating a data pack where when entities go below bedrock or past the height limit you teleport to a different dimension like this:

END
Y -128 --> Y 320
Y 384 --> Y -64
OVERWORLD
Y -128 --> Y 320
Y 384 --> Y -64
NETHER

And I want to teleport with a 1:8 ratio in the Nether and End. Examples:

Overworld -821 385 511 --> End -6568 -64 4088
End 140 -128 -4843 --> Overworld 17 320 -605
Nether 3583 -128 283 --> Nothing (You can't go below the Nether)

I want it to be compatible with as many entities as possible and not be too laggy.

  • 2
    Can you please make clear how the coordinates are supposed to behave in relation to each other? I see a few examples, but they are confusing. For example it looks like you want to teleport everyone from height -128 to height 320, but why? And how do you make sure that they don't die long before reaching y=-128? And what are the exact rules for X and Z? Also: It will be laggy, no matter what you do. Whenever you teleport a player to another dimension, lots of chunks need to load around them. – Fabian Röling Dec 12 '19 at 17:16
  • 1
    When players go high up in one dimension, they teleport to the "higher" dimension. Like how the End is "above" the Overworld. When you go from the Overworld to the Nether, your coordinates divide by 8 and vice versa. When you go to the End your coordinates multiply by 8. And I will be giving players Resistance when falling into the void, so damage isn't an issue. – DaedalusMind Dec 12 '19 at 19:47
  • Alright, and what is the exact thing you currently struggle with? – Fabian Röling Dec 12 '19 at 22:53
  • 2
    Teleporting the player to the coordinates multiplied or divided by 8. I can easily teleport them to their own coordinates, but I can't divide or multiply them. – DaedalusMind Dec 13 '19 at 0:39
  • 1
    I could probably figure it out myself, but I asked here to get a probably better answer. My idea is to store the coordinates of a player in each dimension, but it would be executing ~60 commands per tick and cause some serious TPS lag. (Since every entity would summon an armor stand). – DaedalusMind Dec 13 '19 at 2:18
2

Similar to this answer you need a dummy entity whose position is stored and can be set in NBT.
All of this needs to be executed in one tick, for example as a function.

Assumtions: Player is tagged as "teleportMe", scoreboards x and z exist.

Summon dummy entity at player:

execute at @a[tag=teleportMe] run summon armor_stand ~ ~ ~ {NoGravity:1,NoAI:1,Invisible:1,Marker:1,ActiveEffects:[{Id:11,Amplifier:9,Duration:9}],Tags:["teleportHelper"]}

Get coordinates of the entity into scoreboards:

execute as @e[tag=teleportHelper] store result score @s x run data get entity @s Pos[0] 71
execute as @e[tag=teleportHelper] store result score @s z run data get entity @s Pos[2] 71

Scoreboards are always integers, so multiplying by 71 and later dividing by 71·8 gives you the best accurracy.

Put scaled coordinates back into NBT:

execute as @e[tag=teleportHelper] store result entity @s Pos[0] double 0.001760563380281690140845070422535211267605633802816901408450704225352112676056338028169014084507042253521126760563380281690140845070422535211267605633 run scoreboard players get @s x
execute as @e[tag=teleportHelper] store result entity @s Pos[2] double 0.001760563380281690140845070422535211267605633802816901408450704225352112676056338028169014084507042253521126760563380281690140845070422535211267605633 run scoreboard players get @s z

Teleport player to dummy entity coordinates, but in another dimension and higher:

execute at @e[tag=teleportHelper] in the_end run tp @a[tag=teleportMe] ~ ~512 ~

Clean up:

kill @e[tag=teleportHelper]
  • 1
    Will this work with two players in the same tick? Or when they are at the same position? – DaedalusMind Dec 20 '19 at 14:40
  • It does not work with two in the same tick, they would both arrive at the target coordinates for one of them. (Therefore the same location doesn't matter anyway.) You need to put it all into a function and execute it as and at the player who should be teleported. And replace @a[tag=teleportMe] in the second to last command with @s. You don't need execute at @a[tag=teleportMe] run at all then and you don't need to tag the player anymore. – Fabian Röling Dec 21 '19 at 0:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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