From 3a82e265e967c76399c15cf658d70de6f1518117 Mon Sep 17 00:00:00 2001 From: Matthew Cain Date: Wed, 20 May 2020 21:25:20 +0200 Subject: [PATCH 1/4] Fix GUI element multi-renders Resolves #21 --- .../io/yooksi/daylight/gui/GuiHandler.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/yooksi/daylight/gui/GuiHandler.java b/src/main/java/io/yooksi/daylight/gui/GuiHandler.java index df6b7c6..34e3412 100644 --- a/src/main/java/io/yooksi/daylight/gui/GuiHandler.java +++ b/src/main/java/io/yooksi/daylight/gui/GuiHandler.java @@ -31,19 +31,24 @@ public class GuiHandler { @SubscribeEvent public void onPreRenderOverlay(RenderGameOverlayEvent.Pre event) { - @Nullable World world = Minecraft.getInstance().world; - @Nullable ClientPlayerEntity player = Minecraft.getInstance().player; + // Render along with ALL other other HUD elements + // otherwise we risk our GUI element rendering multiple times + if (event.getType() != RenderGameOverlayEvent.ElementType.ALL) { + return; + } + @Nullable World world = Minecraft.getInstance().world; + @Nullable ClientPlayerEntity player = Minecraft.getInstance().player; - if (world != null && player != null) - { - Biome biome = world.getBiome(player.getPosition()); - TimeCycle cycle = TimeCycle.getForBiome(biome); + if (world != null && player != null) + { + Biome biome = world.getBiome(player.getPosition()); + TimeCycle cycle = TimeCycle.getForBiome(biome); - if (cycle != null) { - cycle.updateAndDraw(world); - } - // Default to Plains biome for everything else - else Objects.requireNonNull(TimeCycle.getForBiome(Biomes.PLAINS)).updateAndDraw(world); + if (cycle != null) { + cycle.updateAndDraw(world); } + // Default to Plains biome for everything else + else Objects.requireNonNull(TimeCycle.getForBiome(Biomes.PLAINS)).updateAndDraw(world); } } +} From 90b392a912d7d5ef9661b899bdb0f7e6ab37c4bf Mon Sep 17 00:00:00 2001 From: Matthew Cain Date: Wed, 20 May 2020 21:35:07 +0200 Subject: [PATCH 2/4] Fix potential NPE error --- .../io/yooksi/daylight/gui/GuiHandler.java | 7 ++----- .../java/io/yooksi/daylight/gui/TimeCycle.java | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/yooksi/daylight/gui/GuiHandler.java b/src/main/java/io/yooksi/daylight/gui/GuiHandler.java index 34e3412..467e455 100644 --- a/src/main/java/io/yooksi/daylight/gui/GuiHandler.java +++ b/src/main/java/io/yooksi/daylight/gui/GuiHandler.java @@ -17,14 +17,11 @@ import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; -import net.minecraft.world.biome.Biomes; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import org.jetbrains.annotations.Nullable; -import java.util.Objects; - @Mod.EventBusSubscriber public class GuiHandler { @@ -47,8 +44,8 @@ public void onPreRenderOverlay(RenderGameOverlayEvent.Pre event) { if (cycle != null) { cycle.updateAndDraw(world); } - // Default to Plains biome for everything else - else Objects.requireNonNull(TimeCycle.getForBiome(Biomes.PLAINS)).updateAndDraw(world); + // Use default instance for everything else + else TimeCycle.getDefault().updateAndDraw(world); } } } diff --git a/src/main/java/io/yooksi/daylight/gui/TimeCycle.java b/src/main/java/io/yooksi/daylight/gui/TimeCycle.java index 183d5ea..9941cd5 100644 --- a/src/main/java/io/yooksi/daylight/gui/TimeCycle.java +++ b/src/main/java/io/yooksi/daylight/gui/TimeCycle.java @@ -64,6 +64,9 @@ public enum Type { public static final Dimensions DEFAULT_OFFSET = new Dimensions(5, 5); public static final Dimensions DEFAULT_SIZE = new Dimensions(90, 32); + /** Default type used when no appropriate biome found for time cycle. */ + public static Type DEFAULT_TYPE = PLAIN; + private static final Type[] VALUES = Type.values(); private final ResourceLocation location; @@ -148,6 +151,21 @@ public static void initialize() { return null; } + /** + * @return registered {@code TimeCycle} instance for the given type. Never returns {@code null} + * since all types should have an associated {@code TimeCycle} instance. + */ + public static TimeCycle getForType(Type type) { + return types.get(type); + } + + /** + * @return default type used when no appropriate biome was found for time cycle. + */ + public static TimeCycle getDefault() { + return types.get(Type.DEFAULT_TYPE); + } + /** * Recalculate time cycle UV mapping coordinates in the given world. * The calculation mainly depends on the current time in the From e16e398e8b6785f8d5138451d5f89f352ab68881 Mon Sep 17 00:00:00 2001 From: Matthew Cain Date: Wed, 20 May 2020 21:36:11 +0200 Subject: [PATCH 3/4] Change default alignment Change alignment due to compatibility issues for MMD Jam. Resolves #22 --- src/main/java/io/yooksi/daylight/gui/TimeCycle.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/yooksi/daylight/gui/TimeCycle.java b/src/main/java/io/yooksi/daylight/gui/TimeCycle.java index 9941cd5..b098db0 100644 --- a/src/main/java/io/yooksi/daylight/gui/TimeCycle.java +++ b/src/main/java/io/yooksi/daylight/gui/TimeCycle.java @@ -60,7 +60,7 @@ public enum Type { /* * These static fields contain data for creating TimeCycle instances */ - public static final Alignment DEFAULT_ALIGNMENT = Alignment.TOP_RIGHT; + public static final Alignment DEFAULT_ALIGNMENT = Alignment.TOP_LEFT; public static final Dimensions DEFAULT_OFFSET = new Dimensions(5, 5); public static final Dimensions DEFAULT_SIZE = new Dimensions(90, 32); From 29096a2b449422acf3bb6101ce5ba068a52ab3ac Mon Sep 17 00:00:00 2001 From: Matthew Cain Date: Wed, 20 May 2020 21:55:10 +0200 Subject: [PATCH 4/4] Bump mod version number --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 9a4cb0b..c6e0351 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false modId=daylight -modVersion=0.1.1 +modVersion=0.1.2 groupName=yooksi minecraftVersion=1.15.2