Jump to content

[1.7.10] [solved] Teleports 10 block lower than than the given Y value


artman41

Recommended Posts

Any help? I've been adding 10 to the newY value, but that causes unnecessary fall damage.

 

here's the code:

 

private static void teleportPlayer(EntityPlayerMP player){
	int newX = (rand.nextInt(65536)-32768);
	int newY = 60;
	int newZ = (rand.nextInt(65536)-32768);

	boolean safe = safetyCheck(player.worldObj, newX, newY, newZ);

	while(!safe){
		newY++;
		safe = safetyCheck(player.worldObj, newX, newY, newZ);
		//System.out.println("BlockExists: " + safe);
	}

	player.playerNetServerHandler.setPlayerLocation(newX, newY + 13, newZ, player.rotationYaw, player.rotationPitch);

	afterCheck(player, newX, newY, newZ);
}

 

--EDIT--

 

If you have the same problem as me, the code you need to use is

 

player.setPositionAndUpdate(newX, newY, newZ);

Link to comment
Share on other sites

EntityPlayer has the setPositionAndUpdate method. This is what I use to teleport players in my mod.

 

player.setPositionAndUpdate(loc.posX, loc.posY, loc.posZ);
player.fallDistance = 0F;

 

They end up exactly where they're supposed to be, the fallDistance = 0F gaurantees if they were previously falling through the air before teleport they won't take fall damage.

Link to comment
Share on other sites

EntityPlayer has the setPositionAndUpdate method. This is what I use to teleport players in my mod.

 

player.setPositionAndUpdate(loc.posX, loc.posY, loc.posZ);
player.fallDistance = 0F;

 

They end up exactly where they're supposed to be, the fallDistance = 0F gaurantees if they were previously falling through the air before teleport they won't take fall damage.

 

This fixed it thanks :D

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.

Announcements



×
×
  • Create New...

Important Information

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