aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/polyfrost/oneconfig/utils/TickDelay.java
diff options
context:
space:
mode:
authornextdaydelivery <12willettsh@gmail.com>2022-02-12 09:24:51 +0000
committernextdaydelivery <12willettsh@gmail.com>2022-02-12 09:24:51 +0000
commit88df999a8ff35ea30b8fa9cf94c46dd748215581 (patch)
tree8cf665d5460fc07e15f62f9d01d9889eca76ef2b /src/main/java/io/polyfrost/oneconfig/utils/TickDelay.java
downloadOneConfig-88df999a8ff35ea30b8fa9cf94c46dd748215581.tar.gz
OneConfig-88df999a8ff35ea30b8fa9cf94c46dd748215581.tar.bz2
OneConfig-88df999a8ff35ea30b8fa9cf94c46dd748215581.zip
swoosh
Diffstat (limited to 'src/main/java/io/polyfrost/oneconfig/utils/TickDelay.java')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/utils/TickDelay.java43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/utils/TickDelay.java b/src/main/java/io/polyfrost/oneconfig/utils/TickDelay.java
new file mode 100644
index 0000000..33b02fe
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/utils/TickDelay.java
@@ -0,0 +1,43 @@
+package io.polyfrost.oneconfig.utils;
+
+import net.minecraftforge.common.MinecraftForge;
+import net.minecraftforge.fml.common.Mod.EventHandler;
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+import net.minecraftforge.fml.common.gameevent.TickEvent;
+
+public class TickDelay {
+ Integer delay;
+ Runnable function;
+
+ public TickDelay(Runnable functionName, int ticks) {
+ register();
+ delay = ticks;
+ function = functionName;
+ }
+
+ @SubscribeEvent
+ public void onTick(TickEvent.ClientTickEvent event) {
+ if (event.phase == TickEvent.Phase.START) {
+ // Delay expired
+ if (delay < 1) {
+ run();
+ destroy();
+ }
+ delay--;
+ }
+ }
+
+ @EventHandler()
+ private void destroy() {
+ MinecraftForge.EVENT_BUS.unregister(this);
+ }
+
+ @EventHandler()
+ private void register() {
+ MinecraftForge.EVENT_BUS.register(this);
+ }
+
+ private void run() {
+ function.run();
+ }
+}