diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/GlobalEventHandler.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/GlobalEventHandler.kt index 1d5d80e8f..4803fafc4 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/GlobalEventHandler.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/GlobalEventHandler.kt @@ -5,7 +5,6 @@ package ru.dbotthepony.mc.otm import net.minecraft.client.server.IntegratedServer import net.minecraft.server.MinecraftServer -import net.minecraft.server.level.ServerLevel import net.minecraft.world.level.Level import net.minecraftforge.api.distmarker.Dist import net.minecraftforge.event.TickEvent @@ -164,11 +163,11 @@ fun onWorldTick(event: LevelTickEvent) { } fun onceServerPre(ticker: ITickable) { - preServerTick.add(ticker, SERVER_IS_LIVE, "Server is stopping") + preServerTick.once(ticker, SERVER_IS_LIVE, "Server is stopping") } fun onceServer(ticker: ITickable) { - postServerTick.add(ticker, SERVER_IS_LIVE, "Server is stopping") + postServerTick.once(ticker, SERVER_IS_LIVE, "Server is stopping") } fun tickServerPre(ticker: IConditionalTickable) { @@ -203,7 +202,7 @@ fun Level.once(ticker: ITickable) { return } - postWorldTick.computeIfAbsent(this) { TickList() }.add(ticker) + postWorldTick.computeIfAbsent(this) { TickList() }.once(ticker) } fun Level.oncePre(ticker: ITickable) { @@ -214,7 +213,7 @@ fun Level.oncePre(ticker: ITickable) { return } - preWorldTick.computeIfAbsent(this) { TickList() }.add(ticker) + preWorldTick.computeIfAbsent(this) { TickList() }.once(ticker) } fun Level.addTicker(ticker: IConditionalTickable) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/ClientTickHandler.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/ClientTickHandler.kt index 7b04b4ebc..4f5473b31 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/ClientTickHandler.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/ClientTickHandler.kt @@ -17,12 +17,12 @@ var LOGGED_IN = false fun onceClient(ticker: ITickable) { check(isClient) { "Illegal side" } - postTickList.add(ticker, LOGGED_IN, "Not logged in") + postTickList.once(ticker, LOGGED_IN, "Not logged in") } fun onceClientPre(ticker: ITickable) { check(isClient) { "Illegal side" } - preTickList.add(ticker, LOGGED_IN, "Not logged in") + preTickList.once(ticker, LOGGED_IN, "Not logged in") } fun onceClient(inTicks: Int, ticker: Runnable) { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/TickList.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/TickList.kt index f244f5381..23060d6d0 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/TickList.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/util/TickList.kt @@ -21,7 +21,7 @@ class TickList { } } - fun add(ticker: ITickable) { + fun once(ticker: ITickable) { if (inTicker) { onceValveTime.add(ticker) } else { @@ -46,13 +46,13 @@ class TickList { return add(ticker) } - fun add(ticker: ITickable, condition: Boolean, reason: String) { + fun once(ticker: ITickable, condition: Boolean, reason: String) { if (!condition) { LOGGER.error("Refusing to add tickable $ticker because we $reason", IllegalStateException(reason)) return } - return add(ticker) + return once(ticker) } fun until(ticker: () -> Boolean) = add(IConditionalTickable.wrap(ticker))