Search in sources :

Example 1 with SleepResult

use of net.minecraft.entity.player.EntityPlayer.SleepResult in project Totemic by TeamTotemic.

the class BlockTipi method tipiSleep.

private boolean tipiSleep(World world, BlockPos pos, EntityPlayer player) {
    if (!world.isRemote) {
        if (world.getBiome(pos) != Biomes.HELL) {
            if (world.provider.canRespawnHere()) {
                EntityPlayer otherPlayer = null;
                for (EntityPlayer playerEntity : world.playerEntities) {
                    if (playerEntity.isPlayerSleeping()) {
                        BlockPos playerPos = new BlockPos(playerEntity.posX, playerEntity.posY, playerEntity.posZ);
                        if (playerPos.equals(pos))
                            otherPlayer = playerEntity;
                    }
                }
                if (otherPlayer != null) {
                    player.sendStatusMessage(new TextComponentTranslation("tile.bed.occupied"), true);
                    return true;
                }
                SleepResult sleepresult = player.trySleep(pos);
                if (sleepresult == SleepResult.OK)
                    return true;
                else {
                    if (sleepresult == SleepResult.NOT_POSSIBLE_NOW)
                        player.sendStatusMessage(new TextComponentTranslation("tile.bed.noSleep"), true);
                    else if (sleepresult == SleepResult.NOT_SAFE)
                        player.sendStatusMessage(new TextComponentTranslation("tile.bed.notSafe"), true);
                    return true;
                }
            } else
                player.sendStatusMessage(new TextComponentTranslation("totemicmisc.tipi.nether"), true);
        } else
            player.sendStatusMessage(new TextComponentTranslation("totemicmisc.tipi.cantSleep"), true);
    }
    return true;
}
Also used : SleepResult(net.minecraft.entity.player.EntityPlayer.SleepResult) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with SleepResult

use of net.minecraft.entity.player.EntityPlayer.SleepResult in project Cavern2 by kegare.

the class CaveEventHooks method onPlayerSleepInBed.

@SubscribeEvent
public void onPlayerSleepInBed(PlayerSleepInBedEvent event) {
    EntityPlayer player = event.getEntityPlayer();
    if (!CavernAPI.dimension.isInCaveDimensions(player)) {
        return;
    }
    SleepResult result = null;
    World world = player.world;
    if (!world.isRemote) {
        IPlayerData data = PlayerData.get(player);
        long worldTime = world.getTotalWorldTime();
        long sleepTime = data.getLastSleepTime();
        if (sleepTime <= 0L) {
            sleepTime = worldTime;
            data.setLastSleepTime(sleepTime);
        }
        long requireTime = GeneralConfig.sleepWaitTime * 20;
        if (sleepTime + requireTime > worldTime) {
            result = SleepResult.OTHER_PROBLEM;
            long remainTime = requireTime - (worldTime - sleepTime);
            int min = MathHelper.ceil(remainTime / 20 / 60 + 1);
            player.sendStatusMessage(new TextComponentTranslation("cavern.message.sleep.still", min), true);
        }
    }
    if (result == null) {
        result = PlayerHelper.trySleep(player, event.getPos());
    }
    if (!world.isRemote && result == SleepResult.OK) {
        PlayerData.get(player).setLastSleepTime(world.getTotalWorldTime());
    }
    event.setResult(result);
}
Also used : SleepResult(net.minecraft.entity.player.EntityPlayer.SleepResult) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IPlayerData(cavern.api.IPlayerData) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 SleepResult (net.minecraft.entity.player.EntityPlayer.SleepResult)2 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)2 IPlayerData (cavern.api.IPlayerData)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1