Posted May 3, 201411 yr Hey, I'm wondering how I get the actual time (in 12 hour time) like the clock, but text instead of a texture. For example, ingame the sun would just be rising, so it would be 7:00AM Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods
May 3, 201411 yr World#getCurrentDate() gives you a Calendar object, which you can use to get the actual time. http://i.imgur.com/NdrFdld.png[/img]
May 3, 201411 yr Author I've currently got this: protected String getTime() { String time = ""; for (int j = 0; j < MinecraftServer.getServer().worldServers.length; j++) { time = StringUtils.ticksToElapsedTime((int)(MinecraftServer.getServer().worldServers[j].getWorldTime())); } return time; } Which is giving me this: http://prntscr.com/3fo3mv It seems to work well, but it isnt all that accurate. I type: "/time set 23000" which makes it 6:00AM (according to the MC wiki) but it says its 19:10 Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods
May 3, 201411 yr Author Never mind!! I fixed it using this: public void renderTick() { Minecraft mc = Minecraft.getMinecraft(); if(mc.currentScreen instanceof GuiChat) { GuiIngame gig = mc.ingameGUI; FontRenderer f = mc.fontRenderer; ScaledResolution s = new ScaledResolution(mc.gameSettings, mc.displayWidth, mc.displayHeight);; int h = s.getScaledHeight(); int w = s.getScaledWidth(); Long time = Long.valueOf(mc.theWorld.provider.getWorldTime()); String t = "TIME: " + formatTime(time); gig.drawString(f, t, w - f.getStringWidth(t) - 10, h - 20, 16777215); } } protected String getTime() { String time = ""; for (int j = 0; j < MinecraftServer.getServer().worldServers.length; j++) { time = StringUtils.ticksToElapsedTime((int)(MinecraftServer.getServer().worldServers[j].getWorldTime())); } return time; } public static String formatTime(Long time) { int hours24 = (int)(time.longValue() / 1000L + 6L) % 24; int hours = hours24 % 12; int minutes = (int)((float)time.longValue() / 16.666666F % 60.0F); String Time = String.format("%02d:%02d %s", new Object[] { Integer.valueOf(hours < 1 ? 12 : hours), Integer.valueOf(minutes), hours24 < 12 ? "AM" : "PM" }); return Time; } Took me a while, but i got it! Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.