Jump to content

[1.14.4] Teleporting player to other dimension


Elrol_Arrowsend

Recommended Posts

So, it was brought to my attention that the way that I am teleporting the player using commands seems to cause some rather bad happenings on the server. When I first tried it, after they found the issue, I tried to teleport from the overworld to the end. When I did it had me suspended in what looked like the end, but nothing was loaded, no blocks could be seen, I couldn't move, nothing. Eventually my client disconnected, and then when I tried to log back in the server crashed saying that the server took a 60 seconds for a single tick. 

 

The way that I am attempting to teleport the player is just like how they do it in minecrafts code 

(pulled from the end portal block code)
 

entityIn.changeDimension(worldIn.dimension.getType() == DimensionType.THE_END ? DimensionType.OVERWORLD : DimensionType.THE_END);

 

What I am doing is this:
 

	public static void teleport(ServerPlayerEntity player, Location loc) {
		PlayerData data = Main.database.get(player.getUniqueID());
		data.prevLoc = getPlayerLocation(player);
		BlockPos pos = loc.getBlockPos();
		if(!player.dimension.equals(loc.getDim())) {
			if(Main.isDev()) {
				player.changeDimension(loc.getDim());
			}else {
				TextUtils.err(player.getCommandSource(), "The ability to teleport between dimensions has been disabled until it can be fixed.");
				return;
			}
		}
		player.setPositionAndUpdate((double)pos.getX() + 0.5D, (double)pos.getY(), (double)pos.getZ() + 0.5D);
	}


I feel like something I am doing must be the issue, it is normally the reason, but I was fairly certain that this would work.

  • Like 1
Link to comment
Share on other sites

Teleporting players is a messy business. ServerPlayerEntity#changeDimension() has all kinds of hardcoded stuff that assumes it was called from a vanilla portal, and therefore isn't really suited for general purpose use. You can try ServerPlayerEntity#teleport() instead. Be warned though, ServerPlayerEntity#teleport() will not work from Block#onEntityCollision(). If your are using it only in a command you should be fine.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.