From e2a8cdbfa49285e6f7856fa330ea50122b0b2de6 Mon Sep 17 00:00:00 2001 From: Marcel Konrad Date: Sun, 18 Oct 2020 15:35:53 +0200 Subject: [PATCH] Fix potential NPE and refactoring --- .../worldhandler/gui/widget/WidgetWatch.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/exopandora/worldhandler/gui/widget/WidgetWatch.java b/src/main/java/exopandora/worldhandler/gui/widget/WidgetWatch.java index d970913..8057ab6 100644 --- a/src/main/java/exopandora/worldhandler/gui/widget/WidgetWatch.java +++ b/src/main/java/exopandora/worldhandler/gui/widget/WidgetWatch.java @@ -20,15 +20,18 @@ public class WidgetWatch implements IContainerWidget final int watchX = container.getBackgroundX() + 233; final int watchY = container.getBackgroundY() + 5; - RenderUtils.drawWatchIntoGui(matrix, container, watchX, watchY, Minecraft.getInstance().world.getWorldInfo().getDayTime(), Config.getSettings().smoothWatch()); + long time = 0; - if(Config.getSettings().tooltips()) + if(Minecraft.getInstance().world != null) { - if(mouseX >= watchX && mouseX <= watchX + 9 && mouseY >= watchY && mouseY <= watchY + 9) - { - container.renderTooltip(matrix, new StringTextComponent(TextUtils.formatWorldTime(Minecraft.getInstance().world.getDayTime())), mouseX, mouseY + 9); - RenderUtils.disableLighting(); - } + time = Minecraft.getInstance().world.getWorldInfo().getDayTime(); + } + + RenderUtils.drawWatchIntoGui(matrix, container, watchX, watchY, time, Config.getSettings().smoothWatch()); + + if(Config.getSettings().tooltips() && mouseX >= watchX && mouseX <= watchX + 9 && mouseY >= watchY && mouseY <= watchY + 9) + { + container.renderTooltip(matrix, new StringTextComponent(TextUtils.formatWorldTime(time)), mouseX, mouseY + 9); } }