Jump to content

Displaying world time in a MM:HH format [SOLVED] [1.7.10]


Recommended Posts

Posted

Okay, so I am trying to display the world time in a gui, and I know that I can get the world time with world.getWorldTime()

 

But I want to display the time in a HH:MM format. Now I know that an hour in mc is 1000 ticks, so I just devide the time by 1000 to get the hour, and I have a simple if statement to put a 0 on the front if it is less than 10 (if it is a single digit), now I am struggling with the MM bit though, I do know that one minute in mc is 16.666666667 ticks (after some calculations) and so I can also display that after the ":" and it looks fine up until it goes past 00:59, when it passes that point it is 01:60, then 01:61, then 01:62  etc, you get the point, I want it to go back to 0 after an hour has passed, and I have tried doing this by:

if (time >= 60) {
time == 0;
}

but the problem with that, is that it stays at 0. it doesn't tick up again.

 

Also, I have noticed that minecrafts time system doesn't reset back to 0 after 23999 ticks, it goes on past 24000. And this is kind of a problem for my solar panel, because it checks if the time is > 0, and < 12000 it is day, and can generate, and if the time >= 12000 and less than 24000 and there is a lunar upgrade it can generate. and so this only works for the first mc day, or untill I relog the world.

 

What can I do?

 

Thanks.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted
    public static int getWorldMinutes(World world) {
        int time = (int) Math.abs((world.getWorldTime() + 6000) % 24000);
        return (time % 1000) * 6 / 100;
    }

    public static int getWorldHours(World world) {
        int time = (int)Math.abs((world.getWorldTime()+ 6000) % 24000);
        return (int)((float)time / 1000F);
    }

Posted

Can I please have a bit of explanation? I understand half of it, I sort of understand the % symbol, cant remember what it is called, but doesn't it check if a number is a multiple of another number? not entirely sure though, and I don't know what Math.abs(arg1); does though.

 

 

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

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.