Example usage for net.minecraftforge.event.entity.player PlayerSleepInBedEvent PlayerSleepInBedEvent

List of usage examples for net.minecraftforge.event.entity.player PlayerSleepInBedEvent PlayerSleepInBedEvent

Introduction

In this page you can find the example usage for net.minecraftforge.event.entity.player PlayerSleepInBedEvent PlayerSleepInBedEvent.

Prototype

public PlayerSleepInBedEvent(PlayerEntity player, Optional<BlockPos> pos) 

Source Link

Usage

From source file:com.lothrazar.cyclicmagic.item.sleep.ItemSleepingMat.java

License:Open Source License

/**
 * hack in the vanilla sleep test, or at least something similar
 * //from   w w  w  .  ja  v a  2s .c om
 * @param player
 * @param world
 * @return
 */
private SleepResult canPlayerSleep(EntityPlayer player, World world) {
    if (player.isEntityAlive() == false) {
        return EntityPlayer.SleepResult.OTHER_PROBLEM;
    }
    if (world.isDaytime()) {
        return EntityPlayer.SleepResult.NOT_POSSIBLE_NOW;
    }
    PlayerSleepInBedEvent event = new PlayerSleepInBedEvent(player, player.getPosition());
    MinecraftForge.EVENT_BUS.post(event);
    if (event.getResultStatus() != null) {
        return event.getResultStatus();
    }
    return EntityPlayer.SleepResult.OK;
}