I have reproduced it in 1.10.2, 1.11.2, and 1.12.2. I have not tried to reproduce it in the snapshots yet.
It can easily be recreated by:
Teleport a large distance from spawn (I usually do 1000+ blocks)
Place a bed
Teleport another 1000 blocks away
Teleport back to the location the bed was placed.
Sleep
When the sleep cycle ends, you will not be able to get out of bed and will have to quit the game.
Running MC through a debugger shows that this is due to the player not being in the EntityTracker.
Further debugging showed that the player was being removed from the EntityTracker when the chunk they left unloaded.
Visual comparison of the tick() methods between 1.7.10 and 1.10.2 revealed the change in event order, which was then verified via debugger.
Finally the code in BedPatch which inserts the "missing" update prior to the chunk unload prevents the issue. Users of BedPatch have also reported that they no longer have instances of not seeing other players after installing it.
As far as all the other issues reported here, I have not tried them to see if the patch resolves them, but I will try to do that tonight.
Yes it is.
I have done some further investigation and believe I have identified the root cause of the issue itself. I have put the details in MC-92916.
This issue still exists.
We see it fairly often when a player teleports out of a chunk that gets unloaded, and then tries to sleep. Once the sleep cycle ends, the player is not able to leave their bed and must quit the game to "escape".
I believe that at some time around 1.10, a refactor changed the order of events during the tick. It appears that in earlier versions, entities received an update prior to chunks being unloaded, and now the chunks get unloaded first.
Getting the update caused updateEntityWithOptionalForce to be called, which would see that the entity was not in the chunk indicated by the entities properties. This caused the entity to be removed from the chunk, preventing it from being removed from the EntityTracker later in the tick.
Sometime after 1.7.10 a refactor appears to have inadvertently changed the order of the tick by taking what was a single method and splitting it across several subclasses. With the new order the chunks get unloaded before entities get updated, this denies the entity a chance to remove itself from the unloading chunk.
I have created a Forge mod named BedPatch that patches the Chunk.OnUnload method to look though the chunks entitylists and send a forced update to any EntityPlayers in the chunk via updateEntityWithOptionalForce prior to doing anything else. I also created a Forge PR to do the same.
I do not believe that this has to do with the check to see if the players area is loaded. I believe this is a direct result of the change in event order during the tick.
BedPatch:
https://github.com/Mordenkainen/BedPatch
Forge PR:
https://github.com/MinecraftForge/MinecraftForge/pull/4784
This is due to the player entity being removed from the entity tracker when they chunk they left unloaded.
When the player should wake up, they are looked up in the entity tracker and sent the "wake up" message. Since the player entity was removed from the tracker, they never get the message, resulting in being stuck in the bed.
Preventing the player from being removed from the tracker unless they are marked as dead avoids the issue.
Can we get this resolved? It causes some pretty serious issues.
I submitted a fix for Forge and have seen no ill side effects.
At the beginning of Chunk#onChunkUnload (func_76623_d in 1.12.2, around line 187ish) add the following:
java.util.Arrays.stream(field_76645_j).forEach(multimap -> com.google.common.collect.Lists.newArrayList(multimap.func_180215_b(net.minecraft.entity.player.EntityPlayer.class)).forEach(player -> field_76637_e.func_72866_a(player, false))); // FORGE - Fix for MC-92916
This searches the list of entities in the unloading chunk for any players, and forces them to refresh their position. This causes them to be registered with the new chunk and prevents their removal from the EntityTracker.
Seems to solve all these issues.
Can we get this issue closed once and for all?