diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 54f589cf..145268e9 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,8 +1,12 @@ # Changelog ## [1.4.1] +### Added +- Option to disable sleep indicator on game clock ### Removed - Block viewer NBT storage (#51, #53, #57, #58, #61, #66) +### Fixed +- Sleep icon using `World#isDaytime` on client and never showing ## [1.4] - 2019-04-04 ### Added diff --git a/src/main/java/jobicade/betterhud/element/text/GameClock.java b/src/main/java/jobicade/betterhud/element/text/GameClock.java index 17c45fbb..b483009d 100644 --- a/src/main/java/jobicade/betterhud/element/text/GameClock.java +++ b/src/main/java/jobicade/betterhud/element/text/GameClock.java @@ -12,6 +12,8 @@ import net.minecraft.client.resources.I18n; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; +import net.minecraft.world.WorldProvider.WorldSleepResult; +import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.fml.common.eventhandler.Event; import jobicade.betterhud.element.settings.DirectionOptions; import jobicade.betterhud.element.settings.Setting; @@ -23,9 +25,10 @@ import jobicade.betterhud.geom.Point; public class GameClock extends Clock { - private static final ItemStack BED = new ItemStack(Items.BED); + private static final ItemStack BED = new ItemStack(Items.BED, 1, 14); private SettingBoolean showDays; + private SettingBoolean showSleepIndicator; private SettingChoose requireItem; public GameClock() { @@ -37,6 +40,7 @@ public GameClock() { protected void addSettings(List> settings) { super.addSettings(settings); settings.add(showDays = new SettingBoolean("showDays").setValuePrefix(SettingBoolean.VISIBLE)); + settings.add(showSleepIndicator = new SettingBoolean("showSleepIndicator").setValuePrefix(SettingBoolean.VISIBLE)); settings.add(requireItem = new SettingChoose("requireItem", "disabled", "inventory", "hand")); } @@ -45,6 +49,7 @@ public void loadDefaults() { super.loadDefaults(); showDays.set(true); + showSleepIndicator.set(false); requireItem.setIndex(0); } @@ -70,9 +75,10 @@ public boolean shouldRender(Event event) { @Override public Rect render(Event event) { Rect bounds = super.render(event); + float partialTicks = ((RenderGameOverlayEvent)event).getPartialTicks(); - if(!MC.world.isDaytime()) { - Direction bedAnchor = DirectionOptions.WEST_EAST.apply(position.getContentAlignment()); + if(showSleepIndicator(partialTicks)) { + Direction bedAnchor = DirectionOptions.WEST_EAST.apply(position.getContentAlignment().mirrorCol()); Rect bed = new Rect(16, 16).anchor(bounds, bedAnchor); GlUtil.renderSingleItem(BED, bed.getPosition()); @@ -80,6 +86,18 @@ public Rect render(Event event) { return bounds; } + private boolean showSleepIndicator(float partialTicks) { + return showSleepIndicator.get() + && MC.world.provider.canSleepAt(MC.player, MC.player.getPosition()) == WorldSleepResult.ALLOW + // Taken from EntityPlayer#trySleep, ignores enemies and bed position + && !MC.player.isPlayerSleeping() + && MC.player.isEntityAlive() + && MC.world.provider.isSurfaceWorld() + // World#isDayTime is server only + //&& !MC.world.isDaytime(); + && MC.world.calculateSkylightSubtracted(partialTicks) >= 4; + } + @Override protected Date getDate() { long worldTime = MC.world.getWorldTime() + 6000; diff --git a/src/main/resources/assets/betterhud/lang/de_DE.lang b/src/main/resources/assets/betterhud/lang/de_DE.lang index a1e38b0f..cd89121c 100644 --- a/src/main/resources/assets/betterhud/lang/de_DE.lang +++ b/src/main/resources/assets/betterhud/lang/de_DE.lang @@ -177,6 +177,7 @@ betterHud.setting.scale=Skala betterHud.setting.24hr=24 Stunden betterHud.setting.showSeconds=Zeige Sekunden #betterHud.setting.showDays=Days +#betterHud.setting.showSleepIndicator=Sleep Indicator betterHud.setting.fullYear=Volles Jahr #betterHud.setting.dateType=Format diff --git a/src/main/resources/assets/betterhud/lang/du_MY.lang b/src/main/resources/assets/betterhud/lang/du_MY.lang index 50c9b8ad..ff35315f 100644 --- a/src/main/resources/assets/betterhud/lang/du_MY.lang +++ b/src/main/resources/assets/betterhud/lang/du_MY.lang @@ -177,6 +177,7 @@ #betterHud.setting.24hr=24 Hour #betterHud.setting.showSeconds=Seconds #betterHud.setting.showDays=Days +#betterHud.setting.showSleepIndicator=Sleep Indicator #betterHud.setting.fullYear=Full Year #betterHud.setting.dateType=Format diff --git a/src/main/resources/assets/betterhud/lang/en_US.lang b/src/main/resources/assets/betterhud/lang/en_US.lang index 00693136..6096c856 100644 --- a/src/main/resources/assets/betterhud/lang/en_US.lang +++ b/src/main/resources/assets/betterhud/lang/en_US.lang @@ -177,6 +177,7 @@ betterHud.value.hand=In Hand betterHud.setting.24hr=24 Hour betterHud.setting.showSeconds=Seconds betterHud.setting.showDays=Days +betterHud.setting.showSleepIndicator=Sleep Indicator betterHud.setting.fullYear=Full Year betterHud.setting.dateType=Format diff --git a/src/main/resources/assets/betterhud/lang/pt_BR.lang b/src/main/resources/assets/betterhud/lang/pt_BR.lang index 94b66c99..c535cafb 100644 --- a/src/main/resources/assets/betterhud/lang/pt_BR.lang +++ b/src/main/resources/assets/betterhud/lang/pt_BR.lang @@ -177,6 +177,7 @@ betterHud.value.hand=Na Mão betterHud.setting.24hr=24 horas betterHud.setting.showSeconds=Segundos betterHud.setting.showDays=Dias +#betterHud.setting.showSleepIndicator=Sleep Indicator betterHud.setting.fullYear=Ano inteiro betterHud.setting.dateType=Formato diff --git a/src/main/resources/assets/betterhud/lang/ru_RU.lang b/src/main/resources/assets/betterhud/lang/ru_RU.lang index a653b884..34d5845d 100644 --- a/src/main/resources/assets/betterhud/lang/ru_RU.lang +++ b/src/main/resources/assets/betterhud/lang/ru_RU.lang @@ -177,6 +177,7 @@ betterHud.value.hand=В руке betterHud.setting.24hr=24 часа betterHud.setting.showSeconds=Секунды betterHud.setting.showDays=Дни +#betterHud.setting.showSleepIndicator=Sleep Indicator betterHud.setting.fullYear=Целый год betterHud.setting.dateType=Формат diff --git a/src/main/resources/assets/betterhud/lang/zh_CN.lang b/src/main/resources/assets/betterhud/lang/zh_CN.lang index 6c18c001..4e1c5d54 100644 --- a/src/main/resources/assets/betterhud/lang/zh_CN.lang +++ b/src/main/resources/assets/betterhud/lang/zh_CN.lang @@ -177,6 +177,7 @@ betterHud.setting.scale=缩放 betterHud.setting.24hr=24小时计时法 betterHud.setting.showSeconds=显示秒数 #betterHud.setting.showDays=Days +#betterHud.setting.showSleepIndicator=Sleep Indicator betterHud.setting.fullYear=年全称 #betterHud.setting.dateType=Format