0
\$\begingroup\$

I'm working on a mod for Minecraft in Java. How can I make something happen every half tick? If I run my code in the tick function, my code is called 20 times a second. I want my code to be called 40 times a second, or even 60 or 80. How would I do this?

Any answer, whether in Forge, MCP, or even plain Java would help.

EDIT: I'm still keeping this question up, but the rest of the game only ticks at 20. Doing 1 task at 60 wont make a difference if everything else ticks at 20.

\$\endgroup\$
5
  • \$\begingroup\$ What is the intent of calling your code more than once? What do you want to do more often than once per tick? \$\endgroup\$
    – Vaillancourt
    Oct 8 '21 at 18:16
  • \$\begingroup\$ Anything really. The example I had was spamming a mouse button. Like clicking exactly 13 or 14 cps which required more precision than 1 tick. \$\endgroup\$
    – Day Trip
    Oct 8 '21 at 18:22
  • \$\begingroup\$ Let's just assume I have a function called clickMouse() \$\endgroup\$
    – Day Trip
    Oct 8 '21 at 18:22
  • \$\begingroup\$ I'm not sure but, if everything else is running at 20 ticks per second, do you know if the rest of the game will be able to handle your commands more frequently than this? \$\endgroup\$
    – Vaillancourt
    Oct 8 '21 at 20:57
  • 1
    \$\begingroup\$ Oh! I completely didn't think about that! Your absolutely right. If I call something 60 times a second, the game will in fact only process it at 20. Thank you for pointing that out. \$\endgroup\$
    – Day Trip
    Oct 8 '21 at 21:01
1
\$\begingroup\$

It's really easy to call your function twice each tick, but that's calling it twice every 20th of a second, not once every 60th of a second which is what you seem to want.

Without wading into multithreading and worrying about API access and thread-safe interactions in your code, you're not going to be able to get this behavior without increasing the tick rate of the engine.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .