Jump to content

[1.7.10] Strange Bed Coordinate Behavior Help

The Kaividian

Recommended Posts

Running on the WorldTickEvent and using the world.playerEntities ArrayList to cycle through players.


When I have a player that is in a bed who is FullyAsleep(entityplayer.isPlayerFullyAsleep()), I get their coordinates using x = posX etc..

I wake up the player, then put them back to bed with sleepinBedAt(x,y,z). Although this works on servers, in SinglePlayer or Multiplayer via "Open To LAN", the x coordinate is 1 integer larger. This causes players to be shifted off of their bed when they are fullyAsleep. Assuming it was a bug with forge or Minecraft, I decided to work around it by using Minecraft.getMinecraft().isSingleplayer() to alter the x coordinate based on the type of server that was running the mod, however this causes a crash on servers when that line is run.


for(int i = 0; i < players.size(); i++){
		entityplayer = (EntityPlayer) players.get(i);
			int x;
			if(Minecraft.getMinecraft().isSingleplayer()) x = (int) entityplayer.posX - 1;
			else x = (int) entityplayer.posX;
			int y = (int) entityplayer.posY;
			int z = (int) entityplayer.posZ;

			entityplayer.wakeUpPlayer(true, false, true);
			entityplayer.sleepInBedAt(x, y, z);


Any help with this issue would be appreciated.

Link to comment
Share on other sites

The Minecraft class is CLIENT side only, and the player returned by Minecraft.getMinecraft().thePlayer is the client player - of course this is crashing when you try to run it on the SERVER.


I'm not sure why the x coordinate would be off by one only in single player, but I can imagine that it may instead have to do with the player's position and the bed position not matching entirely: a bed is 2 blocks and may be oriented along either the x or z axis, whereas the player position will only ever give you 1 block coordinate.


Given that, I don't find it hard to believe that the player position will sometimes not be exactly what you'd expect the bed to be. Why don't you use EntityPlayer#getBedLocation to get their bed's actual location, rather than expecting the player's position to match perfectly?

Link to comment
Share on other sites

I totally missed the Minecraft class being CLIENT only, thank you for pointing that out to me.


The x coordinate thing is still very strange to me. I have tested it with all bed orientations and the x offset stayed consistent.

I've switched over to getBedLocation and it appears to be working. Other than the player alternating beds if they're in the same chunk, it works now.


Thanks for your help.

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.

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.