Jump to content

[SOLVED] How to check minecrafts actual time


The_SlayerMC

Recommended Posts

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

Link to comment
Share on other sites

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! :D

Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.