Skip to content

Commit

Permalink
Fix game clock bed icon (fix #69 lol)
Browse files Browse the repository at this point in the history
Also added an option to disable the icon and fixed the alignment
  • Loading branch information
mccreery committed Aug 22, 2019
1 parent 821a456 commit d3bd572
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
24 changes: 21 additions & 3 deletions src/main/java/jobicade/betterhud/element/text/GameClock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand All @@ -37,6 +40,7 @@ public GameClock() {
protected void addSettings(List<Setting<?>> 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"));
}

Expand All @@ -45,6 +49,7 @@ public void loadDefaults() {
super.loadDefaults();

showDays.set(true);
showSleepIndicator.set(false);
requireItem.setIndex(0);
}

Expand All @@ -70,16 +75,29 @@ 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());
}
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;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/betterhud/lang/de_DE.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/betterhud/lang/du_MY.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/betterhud/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/betterhud/lang/pt_BR.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/betterhud/lang/ru_RU.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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=Формат
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/betterhud/lang/zh_CN.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d3bd572

Please sign in to comment.