RInventor7 Posted March 1, 2023 Posted March 1, 2023 (edited) Hi! I have a custom entity and I wish it would run some logic (e.g. play some sound) in every 2 seconds and some other logic in every half a second. For that I’m at the moment using 2 different timers. In entity baseTick function (runs every tick, 20 times per second): entity.getPersistentData().putInt("timer1", entity.getPersistentData().getInt("timer1") + 1); if (entity.getPersistentData().getInt("timer1") >= 40) {// evry 2 seconds entity.getPersistentData().putInt("timer1", 0); } if (entity.getPersistentData().getInt("timer1") == 1) { //Run logic 1 } Then I have second timer for the half second logic. Since both timers logic will run on every second it’s not very efficient. And it gets worse as I add more timers. Is there a way to replace this timer with something else that would be more efficient? Thanks. Edited March 2, 2023 by RInventor7 Quote
ChampionAsh5357 Posted March 1, 2023 Posted March 1, 2023 On 3/1/2023 at 9:33 AM, RInventor7 said: Hi! I have a custom entity and I wish it would run some logic (e.g. play some sound) in every 2 seconds and some other logic in every half a second. Expand Just use one timer and check for every 10 ticks (0.5s) and every 40 ticks (2s). Unless there is something that would desync the timers, it makes no sense to do otherwise. Additionally, just use a field on the entity itself, don't read/write from persistent data every tick. Quote
Recommended Posts
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.