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;
}
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);
}
Aggregations