I need to detect if there are mobs nearby when a user tries to access a bed and have set up an event handler for PlayerSleepInBedEvent.
On a single player world, if a player tries to sleep in a bed, the event is fired. Even if there are mobs nearby, or if it is day time etc.
When connecting to a server (which has the mod) and using the client the event will only fire if they are successful in sleeping. Is this intended or a forge bug or something else?
Corresponding Code:
public class PlayerBedEventHandler
{
@SubscribeEvent
public void onPlayerSleepInBedEvent (PlayerSleepInBedEvent event)
{
FMLLog.log(Reference.MOD_NAME, Level.INFO, "PlayerSleepInBedEvent");
List<EntityMob> list = NearbyMobHelper.findNearbyMobs(event.entityPlayer, event.x, event.y, event.z);
if (Settings.enableNearbyMobCheckAtBed && !list.isEmpty() && !event.entityPlayer.worldObj.isDaytime() && !(Math.abs(event.entityPlayer.posX - (double)event.x) > 3.0D || Math.abs(event.entityPlayer.posY - (double)event.y) > 2.0D || Math.abs(event.entityPlayer.posZ - (double)event.z) > 3.0D))
{
TickHandler.playerRequesting = event.entityPlayer;
TickHandler.nearbyMobList = list;
}
}
}
The FMLLog is how I am detecting if it works and it does not log anything when trying to access a bed if there are monsters nearby. However it will fire when successfully sleeping in a bed. The FMLLog works in all cases in single player.
NOTE: This may be an actual forge bug so if it is, a moderator or likewise can move it to bug reports. However, I am not sure if it's a bug so here it remains.
EDIT: Using Forge 10.13.2.1230