Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

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?

  • 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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.