Skip to content

Commit

Permalink
Improve compatibility with Travellers Map
Browse files Browse the repository at this point in the history
  • Loading branch information
matshou committed May 20, 2020
2 parents 200178c + 29096a2 commit 3436c5c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 16 additions & 14 deletions src/main/java/io/yooksi/daylight/gui/GuiHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,35 @@
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 {

@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);
}
// Use default instance for everything else
else TimeCycle.getDefault().updateAndDraw(world);
}
}
}
20 changes: 19 additions & 1 deletion src/main/java/io/yooksi/daylight/gui/TimeCycle.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ 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);

/** 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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3436c5c

Please sign in to comment.