From 1c7d76cd3f6df63a71baf615369a493b65ed0409 Mon Sep 17 00:00:00 2001 From: IlmarsXd Date: Tue, 21 Mar 2023 18:18:44 +0200 Subject: rename memory leak fix, fix wrong check --- src/main/kotlin/dulkirmod/features/ListClear.kt | 34 ---------------------- .../kotlin/dulkirmod/features/MemoryLeakFix.kt | 34 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 34 deletions(-) delete mode 100644 src/main/kotlin/dulkirmod/features/ListClear.kt create mode 100644 src/main/kotlin/dulkirmod/features/MemoryLeakFix.kt (limited to 'src/main/kotlin') diff --git a/src/main/kotlin/dulkirmod/features/ListClear.kt b/src/main/kotlin/dulkirmod/features/ListClear.kt deleted file mode 100644 index 2a574d2..0000000 --- a/src/main/kotlin/dulkirmod/features/ListClear.kt +++ /dev/null @@ -1,34 +0,0 @@ -package dulkirmod.features - -import dulkirmod.DulkirMod.Companion.mc -import dulkirmod.config.Config -import net.minecraft.entity.Entity -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.common.gameevent.TickEvent - -object ListClear { - var lastClear = System.currentTimeMillis() - - @SubscribeEvent - fun onTick(event: TickEvent.ClientTickEvent) { - if (!Config.crimsonIslesMemoryLeakPatch) - - if (System.currentTimeMillis() - lastClear >= 30000L) { - val world = mc.theWorld ?: return - val currentEnts = world.playerEntities.toMutableList() - currentEnts.forEach { - if (it.isDead) { - world.playerEntities.remove(it) - } - if (isNullVec(it)) { - world.removeEntityFromWorld(it.entityId) - } - } - lastClear = System.currentTimeMillis() - } - } - - private fun isNullVec(entity: Entity): Boolean { - return entity.posX == 0.0 && entity.posY == 0.0 && entity.posZ == 0.0 - } -} \ No newline at end of file diff --git a/src/main/kotlin/dulkirmod/features/MemoryLeakFix.kt b/src/main/kotlin/dulkirmod/features/MemoryLeakFix.kt new file mode 100644 index 0000000..a4dfc9b --- /dev/null +++ b/src/main/kotlin/dulkirmod/features/MemoryLeakFix.kt @@ -0,0 +1,34 @@ +package dulkirmod.features + +import dulkirmod.DulkirMod.Companion.mc +import dulkirmod.config.Config +import net.minecraft.entity.Entity +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent + +object MemoryLeakFix { + var lastClear = System.currentTimeMillis() + + @SubscribeEvent + fun onTick(event: TickEvent.ClientTickEvent) { + if (!Config.crimsonIslesMemoryLeakPatch) return + + if (System.currentTimeMillis() - lastClear >= 30000L) { + val world = mc.theWorld ?: return + val currentEnts = world.playerEntities.toMutableList() + currentEnts.forEach { + if (it.isDead) { + world.playerEntities.remove(it) + } + if (isNullVec(it)) { + world.removeEntityFromWorld(it.entityId) + } + } + lastClear = System.currentTimeMillis() + } + } + + private fun isNullVec(entity: Entity): Boolean { + return entity.posX == 0.0 && entity.posY == 0.0 && entity.posZ == 0.0 + } +} \ No newline at end of file -- cgit