Started by
Mopru
on
Topic category: Help with Minecraft modding (Java Edition)
(2023.3) how do I teleport a player through a dimension WITHOUT spawning inside walls or above/below the dimension's "border (above y=127, below y=1)
Topic category: Help with Minecraft modding (Java Edition)
(2023.3) how do I teleport a player through a dimension WITHOUT spawning inside walls or above/below the dimension's "border (above y=127, below y=1)
The border part is easy enough; before the player teleports to a dimension with a lower world limit or world height than the dimension they're coming from, (I'm assuming you mean the Overworld), you can clamp the height between the desired levels. MCreator doesn't have a built in clamp function for some reason, so you would just check if the player's height is greater than 128, and, if it is, also teleport them to 128. (Or probably 126, since the player is two blocks tall.) Similarly, if their height is lower than 0, teleport them to y 0 while also teleporting them to the correct dimension.
Checking for an obstruction is much harder, since you would need to have both the player's current location and the corresponding location in the Nether loaded simultaneously. (You could possibly do this by teleporting an invisible entity to the other dimension to force load it, despawn the entity if the location is solid, and then immedieately teleport the player back to the overworld if it doesn't find that entity in the target location, but I'm really not sure how this would work.) You could instead try just correcting on the other end; once the player teleports, run a 'while' function that continuously teleports them upwards or downwards until air is found.
great idea! for any other people reading, here's a TL:DR;
if you need to check max or minimum coords, just clamp them (tp to x:x y:3<y<125 z:z for the nether)
if you need to not teleport inside walls, just check if (in the dimension) there is air/water, and a place to stand on. if not, check the block in a random direction.