Posted October 3, 20159 yr 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); if(entityplayer.isPlayerFullyAsleep()){ 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.
October 3, 20159 yr 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? http://i.imgur.com/NdrFdld.png[/img]
October 3, 20159 yr Author 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.
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.