Jump to content

[1.15.2] How to create a timer similar to Java util Timer using Forge methods


ultra_reemun

Recommended Posts

I am currently using Java's built in Timer for my code, however I am facing problems such as it still running whilst the game is paused.

Is there a built in Timer for forge?

 

In my case, I need:

A timer that runs code after a fixed time

E.g when a key is pressed, wait five seconds then do something

A timer that runs code every tick for a fixed time

E.g when a key is pressed, do something constantly for five seconds

 

Any Help would be greatly appreciated!

 

- Roman

 

Edit: This is my first mod so if anything seems too obvious, please share because I'll have learned something!

Edited by ultra_reemun
Experience
Link to comment
Share on other sites

4 minutes ago, diesieben07 said:

Note that your current code is inherently broken, because it uses a separate thread and thus will break Minecraft's single-threaded assumptions.

 

Usually when you need delays you use a tick event and count ticks.

Thanks for pointing that out, I didn't realise the implications.

I will look into Forge's tick events as I'm new to modding Minecraft.

 

Thanks for the help!

Edited by ultra_reemun
Half asleep
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.