Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

Posted

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

  • Author
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

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.