diff options
author | IlmarsXd <ilmars500@gmail.com> | 2023-03-21 17:36:46 +0200 |
---|---|---|
committer | IlmarsXd <ilmars500@gmail.com> | 2023-03-21 17:36:46 +0200 |
commit | e7723d5ff52da94eb65992b5bdd9c5bb316d5959 (patch) | |
tree | e4c1be6667f0ca5d19d499dd68e8b3bae19853eb /src/main/kotlin/dulkirmod/features | |
parent | bde95578badaa80161cd60c473f0f1ab7fadbfb3 (diff) | |
download | DulkirMod-e7723d5ff52da94eb65992b5bdd9c5bb316d5959.tar.gz DulkirMod-e7723d5ff52da94eb65992b5bdd9c5bb316d5959.tar.bz2 DulkirMod-e7723d5ff52da94eb65992b5bdd9c5bb316d5959.zip |
add memory leak fix, refactor modules
Diffstat (limited to 'src/main/kotlin/dulkirmod/features')
-rw-r--r-- | src/main/kotlin/dulkirmod/features/ListClear.kt | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/main/kotlin/dulkirmod/features/ListClear.kt b/src/main/kotlin/dulkirmod/features/ListClear.kt new file mode 100644 index 0000000..2a574d2 --- /dev/null +++ b/src/main/kotlin/dulkirmod/features/ListClear.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 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 |