Skip to content

Commit 52e4b96

Browse files
authored
[Feature] Implement displaying in-game time on the minimap (#43)
* Ignore some local files. * Implement displaying in-game time.
1 parent f85b177 commit 52e4b96

File tree

14 files changed

+261
-9
lines changed

14 files changed

+261
-9
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ src/minecraft/paulscode/
2828
!src/minecraft/net/minecraft/src/license.txt
2929
!src/minecraft/net/techbrew/
3030

31+
.java-version
3132
/temp/
3233
.gradle/
34+
.vscode/
3335
tmp/
3436
.idea/
3537
eclipse/
3638
out/
3739
journeymap.iml
3840
journeymap.ipr
39-
journeymap.iws
41+
journeymap.iws

src/main/java/journeymap/client/data/WorldData.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class WorldData extends CacheLoader<Class, WorldData>
5959
String name;
6060
int dimension;
6161
long time;
62+
long totalTime;
6263
boolean hardcore;
6364
boolean singlePlayer;
6465
Map<Feature, Boolean> features;
@@ -96,6 +97,18 @@ public static boolean isHardcoreAndMultiplayer()
9697
return world.hardcore && !world.singlePlayer;
9798
}
9899

100+
public static long getWorldTime()
101+
{
102+
WorldData world = DataCache.instance().getWorld(false);
103+
return world.time;
104+
}
105+
106+
public static long getWorldTotalTime()
107+
{
108+
WorldData world = DataCache.instance().getWorld(false);
109+
return world.totalTime;
110+
}
111+
99112
private static String getServerName()
100113
{
101114
try
@@ -344,7 +357,8 @@ public WorldData load(Class aClass) throws Exception
344357
dimension = ForgeHelper.INSTANCE.getDimension(mc.theWorld.provider);
345358
hardcore = worldInfo.isHardcoreModeEnabled();
346359
singlePlayer = !multiplayer;
347-
time = mc.theWorld.getWorldTime() % 24000L;
360+
time = mc.theWorld.getWorldTime();
361+
totalTime = mc.theWorld.getWorldInfo().getWorldTotalTime();
348362
features = FeatureManager.getAllowedFeatures();
349363

350364
mod_name = JourneymapClient.MOD_NAME;

src/main/java/journeymap/client/model/MapState.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.google.common.base.Objects;
1010
import journeymap.client.JourneymapClient;
1111
import journeymap.client.data.DataCache;
12+
import journeymap.client.data.WorldData;
1213
import journeymap.client.feature.Feature;
1314
import journeymap.client.feature.FeatureManager;
1415
import journeymap.client.forge.helper.ForgeHelper;
@@ -25,6 +26,7 @@
2526
import net.minecraft.client.Minecraft;
2627
import net.minecraft.entity.EntityLivingBase;
2728
import net.minecraft.entity.player.EntityPlayer;
29+
import net.minecraft.util.ChatComponentTranslation;
2830

2931
import java.io.File;
3032
import java.util.ArrayList;
@@ -50,6 +52,8 @@ public class MapState
5052
private File worldDir = null;
5153
private long lastRefresh = 0;
5254
private long lastMapTypeChange = 0;
55+
private long worldTime = 0L;
56+
private long worldTotalTime = 0L;
5357

5458
private boolean underground = false;
5559

@@ -111,6 +115,9 @@ public void refresh(Minecraft mc, EntityPlayer player, InGameMapProperties mapPr
111115

112116
playerBiome = DataCache.getPlayer().biome;
113117

118+
worldTime = WorldData.getWorldTime();
119+
worldTotalTime = WorldData.getWorldTotalTime();
120+
114121
updateLastRefresh();
115122

116123
refreshTimer.stop();
@@ -240,6 +247,14 @@ public String getPlayerBiome()
240247
return playerBiome;
241248
}
242249

250+
public long getWorldTime() {
251+
return worldTime;
252+
}
253+
254+
public long getWorldTotalTime() {
255+
return worldTotalTime;
256+
}
257+
243258
public List<DrawStep> getDrawSteps()
244259
{
245260
return drawStepList;

src/main/java/journeymap/client/properties/MiniMapProperties.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import journeymap.client.ui.minimap.Position;
1313
import journeymap.client.ui.minimap.ReticleOrientation;
1414
import journeymap.client.ui.minimap.Shape;
15+
import journeymap.client.ui.option.TimeFormat;
1516

1617
import java.util.concurrent.atomic.AtomicBoolean;
1718
import java.util.concurrent.atomic.AtomicInteger;
@@ -33,12 +34,18 @@ public class MiniMapProperties extends InGameMapProperties
3334
@Config(category = Inherit, key = "jm.minimap.position", defaultEnum = "TopRight")
3435
public final AtomicReference<Position> position = new AtomicReference<Position>(Position.TopRight);
3536

37+
@Config(category = Inherit, key = "jm.common.time_format", stringListProvider = TimeFormat.IdProvider.class)
38+
public final AtomicReference<String> timeFormat = new AtomicReference<String>(new TimeFormat.IdProvider().getDefaultString());
39+
3640
@Config(category = Inherit, key = "jm.minimap.show_fps", defaultBoolean = false)
3741
public final AtomicBoolean showFps = new AtomicBoolean(false);
3842

3943
@Config(category = Inherit, key = "jm.minimap.show_biome")
4044
public final AtomicBoolean showBiome = new AtomicBoolean(true);
4145

46+
@Config(category = Inherit, key = "jm.minimap.show_time")
47+
public final AtomicBoolean showTime = new AtomicBoolean(false);
48+
4249
@Config(category = Inherit, key = "jm.minimap.show_location")
4350
public final AtomicBoolean showLocation = new AtomicBoolean(true);
4451

@@ -164,6 +171,8 @@ public int hashCode()
164171
result = 31 * result + (position != null ? position.hashCode() : 0);
165172
result = 31 * result + (showFps != null ? showFps.hashCode() : 0);
166173
result = 31 * result + (showBiome != null ? showBiome.hashCode() : 0);
174+
result = 31 * result + (showTime != null ? showTime.hashCode() : 0);
175+
result = 31 * result + timeFormat.hashCode();
167176
result = 31 * result + (showLocation != null ? showLocation.hashCode() : 0);
168177
result = 31 * result + showWaypointLabels.hashCode();
169178
result = 31 * result + sizePercent.hashCode();
@@ -195,6 +204,8 @@ public String toString()
195204
.add("reticleOrientation", reticleOrientation)
196205
.add("shape", shape)
197206
.add("showBiome", showBiome)
207+
.add("showTime", showTime)
208+
.add("timeFormat", timeFormat)
198209
.add("showCompass", showCompass)
199210
.add("showFps", showFps)
200211
.add("showLocation", showLocation)

src/main/java/journeymap/client/properties/MiniMapProperties2.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public String toString()
5656
.add("position", position)
5757
.add("showFps", showFps)
5858
.add("showBiome", showBiome)
59+
.add("showTime", showTime)
60+
.add("timeFormat", timeFormat)
5961
.add("showLocation", showLocation)
6062
.add("showWaypointLabels", showWaypointLabels)
6163
.add("sizePercent", sizePercent)

src/main/java/journeymap/client/ui/fullscreen/Fullscreen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,7 @@ public void setTheme(String name)
11041104
MiniMapProperties mmp = JourneymapClient.getMiniMapProperties(JourneymapClient.getActiveMinimapId());
11051105
mmp.shape.set(Shape.Rectangle);
11061106
mmp.showBiome.set(false);
1107+
mmp.showTime.set(false);
11071108
mmp.sizePercent.set(20);
11081109
mmp.save();
11091110
Theme theme = ThemeFileHandler.getThemeByName(name);
@@ -1118,4 +1119,3 @@ public void setTheme(String name)
11181119
}
11191120
}
11201121
}
1121-

src/main/java/journeymap/client/ui/minimap/DisplayVars.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import journeymap.client.render.texture.TextureCache;
1515
import journeymap.client.render.texture.TextureImpl;
1616
import journeymap.client.ui.option.LocationFormat;
17+
import journeymap.client.ui.option.TimeFormat;
1718
import journeymap.client.ui.theme.Theme;
1819
import journeymap.client.ui.theme.ThemeCompassPoints;
1920
import journeymap.client.ui.theme.ThemeMinimapFrame;
@@ -48,18 +49,21 @@ public class DisplayVars
4849
final double reticleSegmentLength;
4950
final int fpsLabelHeight;
5051
final int locationLabelHeight;
52+
final int timeLabelHeight;
5153
final Point2D.Double centerPoint;
54+
final boolean showTime;
5255
final boolean showFps;
5356
final boolean showBiome;
5457
final boolean showLocation;
5558
final boolean showCompass;
5659
final boolean showReticle;
57-
final LabelVars labelFps, labelLocation, labelBiome, labelDebug1, labelDebug2;
60+
final LabelVars labelFps, labelLocation, labelBiome, labelTime, labelDebug1, labelDebug2;
5861
final Theme theme;
5962
final ThemeMinimapFrame minimapFrame;
6063
final ThemeCompassPoints minimapCompassPoints;
6164
final Theme.Minimap.MinimapSpec minimapSpec;
6265
final LocationFormat.LocationFormatKeys locationFormatKeys;
66+
final TimeFormat.TimeFormatKeys timeFormatKeys;
6367
final boolean locationFormatVerbose;
6468
int marginX, marginY;
6569
boolean forceUnicode;
@@ -76,6 +80,7 @@ public class DisplayVars
7680
{
7781
// Immutable member and local vars
7882
this.scaledResolution = ForgeHelper.INSTANCE.getScaledResolution();
83+
this.showTime = miniMapProperties.showTime.get();
7984
this.showFps = miniMapProperties.showFps.get();
8085
this.showBiome = miniMapProperties.showBiome.get();
8186
this.showLocation = miniMapProperties.showLocation.get();
@@ -87,6 +92,7 @@ public class DisplayVars
8792
this.displayHeight = mc.displayHeight;
8893
this.terrainAlpha = Math.max(0f, Math.min(1f, miniMapProperties.terrainAlpha.get() / 100f));
8994
this.locationFormatKeys = new LocationFormat().getFormatKeys(miniMapProperties.locationFormat.get());
95+
this.timeFormatKeys = new TimeFormat().getFormatKeys(miniMapProperties.timeFormat.get());
9096
this.locationFormatVerbose = miniMapProperties.locationFormatVerbose.get();
9197
this.theme = ThemeFileHandler.getCurrentTheme();
9298

@@ -135,6 +141,7 @@ public class DisplayVars
135141
FontRenderer fontRenderer = ForgeHelper.INSTANCE.getFontRenderer();
136142
fpsLabelHeight = (int) (DrawUtil.getLabelHeight(fontRenderer, minimapSpec.fpsLabel.shadow) * this.fontScale);
137143
locationLabelHeight = (int) (DrawUtil.getLabelHeight(fontRenderer, minimapSpec.locationLabel.shadow) * this.fontScale);
144+
timeLabelHeight = (int) (DrawUtil.getLabelHeight(fontRenderer, minimapSpec.timeLabel.shadow) * this.fontScale);
138145

139146
int compassFontScale = miniMapProperties.compassFontScale.get();
140147
int compassLabelHeight = 0;
@@ -177,10 +184,11 @@ public class DisplayVars
177184
{
178185
case BottomRight:
179186
{
180-
if (!minimapSpec.labelBottomInside && (showLocation || showBiome))
187+
if (!minimapSpec.labelBottomInside && (showLocation || showBiome || showTime))
181188
{
182189
int labels = showLocation ? 1 : 0;
183190
labels += showBiome ? 1 : 0;
191+
labels += showTime ? 1 : 0;
184192
marginY = Math.max(marginY, minimapSpec.labelBottomMargin + (labels * locationLabelHeight) + compassLabelHeight / 2);
185193
}
186194

@@ -209,10 +217,11 @@ public class DisplayVars
209217
}
210218
case BottomLeft:
211219
{
212-
if (!minimapSpec.labelBottomInside && (showLocation || showBiome))
220+
if (!minimapSpec.labelBottomInside && (showLocation || showBiome || showTime))
213221
{
214222
int labels = showLocation ? 1 : 0;
215223
labels += showBiome ? 1 : 0;
224+
labels += showTime ? 1 : 0;
216225

217226
marginY = Math.max(marginY, minimapSpec.labelBottomMargin + (labels * locationLabelHeight) + compassLabelHeight / 2);
218227
}
@@ -297,6 +306,20 @@ public class DisplayVars
297306
int labelMargin = minimapSpec.labelBottomMargin;
298307
int yOffset = minimapSpec.labelBottomInside ? -labelMargin : labelMargin;
299308

309+
if (showTime)
310+
{
311+
DrawUtil.VAlign vAlign = (minimapSpec.labelBottomInside) ? DrawUtil.VAlign.Above : DrawUtil.VAlign.Below;
312+
labelTime = new LabelVars(this, centerX, bottomY + yOffset, DrawUtil.HAlign.Center, vAlign, fontScale, minimapSpec.timeLabel);
313+
if (showLocation)
314+
{
315+
yOffset += timeLabelHeight;
316+
}
317+
}
318+
else
319+
{
320+
labelTime = null;
321+
}
322+
300323
if (showLocation)
301324
{
302325
DrawUtil.VAlign vAlign = minimapSpec.labelBottomInside ? DrawUtil.VAlign.Above : DrawUtil.VAlign.Below;

src/main/java/journeymap/client/ui/minimap/MiniMap.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public class MiniMap
6464
private String fpsLabelText;
6565
private String locationLabelText;
6666
private String biomeLabelText;
67+
private String timeLabelText;
6768

6869
private Point2D.Double centerPoint;
6970
private Rectangle2D.Double centerRect;
@@ -380,6 +381,10 @@ public void drawMap(boolean preview)
380381
{
381382
dv.labelBiome.draw(biomeLabelText);
382383
}
384+
if (dv.showTime)
385+
{
386+
dv.labelTime.draw(timeLabelText);
387+
}
383388

384389
// Return resolution to how it is normally scaled
385390
DrawUtil.sizeDisplay(dv.scaledResolution.getScaledWidth_double(), dv.scaledResolution.getScaledHeight_double());
@@ -657,8 +662,30 @@ private void updateLabels()
657662
biomeLabelText = state.getPlayerBiome();
658663
}
659664

665+
// Time key
666+
if (dv.showTime)
667+
{
668+
long worldTime = state.getWorldTime();
669+
long days = (worldTime / 24000L);
670+
long hours = (worldTime / 1000L + 6L) % 24L;
671+
long minutes = (worldTime % 1000L) * 60L / 1000L;
672+
673+
String am_pm = "AM";
674+
if (hours > 12) {
675+
hours -= 12;
676+
am_pm = "PM";
677+
} else if (hours == 12) {
678+
am_pm = "PM";
679+
}
680+
timeLabelText = dv.timeFormatKeys.format(
681+
String.format("%d", days),
682+
String.format("%02d", hours),
683+
String.format("%02d", minutes),
684+
am_pm
685+
);
686+
}
687+
660688
// Update timestamp
661689
lastLabelRefresh = System.currentTimeMillis();
662690
}
663691
}
664-

src/main/java/journeymap/client/ui/option/OptionSlotFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,11 @@ static SlotMetadata<String> getStringSlotMetadata(PropertiesBase properties, Fie
346346
button = new LocationFormat.Button(properties, property);
347347
defaultTip = Constants.getString("jm.config.default", ((LocationFormat.Button) button).getLabel(slp.getDefaultString()));
348348
}
349+
else if (slp instanceof TimeFormat.IdProvider)
350+
{
351+
button = new TimeFormat.Button(properties, property);
352+
defaultTip = Constants.getString("jm.config.default", ((TimeFormat.Button) button).getLabel(slp.getDefaultString()));
353+
}
349354
else
350355
{
351356
button = new ListPropertyButton<String>(slp.getStrings(), name, properties, property);

0 commit comments

Comments
 (0)