diff --git a/loaderMod/src/main/kotlin/cf/wayzer/contentsMod/ContentsLoader.kt b/loaderMod/src/main/kotlin/cf/wayzer/contentsMod/ContentsLoader.kt index f8897a7..2df3b91 100644 --- a/loaderMod/src/main/kotlin/cf/wayzer/contentsMod/ContentsLoader.kt +++ b/loaderMod/src/main/kotlin/cf/wayzer/contentsMod/ContentsLoader.kt @@ -2,6 +2,7 @@ package cf.wayzer.contentsMod import arc.func.Cons import arc.func.Prov +import arc.struct.ObjectIntMap import arc.struct.ObjectMap import arc.struct.Seq import arc.util.Log @@ -11,6 +12,7 @@ import mindustry.ctype.ContentList import mindustry.ctype.ContentType import mindustry.gen.Call import mindustry.gen.ClientPacketReliableCallPacket +import mindustry.logic.LExecutor import mindustry.mod.Mod import mindustry.net.Net import mindustry.net.Packet @@ -69,6 +71,18 @@ class ContentsLoader : Mod() { val time = measureTimeMillis { it.load() } Log.infoTag("ContentsLoader", "Loaded ${it.lastContent!!::class.qualifiedName} costs ${time}ms") } + val timeReloadConstants = measureTimeMillis { + Vars.constants.apply { + javaClass.getDeclaredField("namesToIds") + .apply { isAccessible = true } + .set(this, ObjectIntMap()) + javaClass.getDeclaredField("vars") + .apply { isAccessible = true } + .set(this, Seq(LExecutor.Var::class.java)) + init() + } + } + Log.infoTag("ContentsLoader", "Reload Vars.constants costs ${timeReloadConstants}ms") if (!Vars.headless) { val timeLoadColors = measureTimeMillis { MyContentLoader.loadColors() diff --git a/loaderMod/src/main/kotlin/cf/wayzer/contentsMod/MyContentLoader.kt b/loaderMod/src/main/kotlin/cf/wayzer/contentsMod/MyContentLoader.kt index 16e2fe8..8ce2a8b 100644 --- a/loaderMod/src/main/kotlin/cf/wayzer/contentsMod/MyContentLoader.kt +++ b/loaderMod/src/main/kotlin/cf/wayzer/contentsMod/MyContentLoader.kt @@ -14,11 +14,11 @@ import mindustry.io.SaveVersion import mindustry.mod.Mods object MyContentLoader : ContentLoader() { - class ContentContainer(val type: ContentType, val default: ContentList) { + class ContentContainer(val type: ContentType?, val default: ContentList) { var content: ContentList = default var lastContent: ContentList? = null private set - val contentMap: Seq = Vars.content.getBy(type).copy() + val contentMap: Seq = if (type == null) Seq() else Vars.content.getBy(type).copy() val nameMap = contentMap.filterIsInstance().associateByTo(mutableMapOf()) { it.name } fun maskChanged() { @@ -54,8 +54,10 @@ object MyContentLoader : ContentLoader() { ContentContainer(ContentType.bullet, Bullets()), ContentContainer(ContentType.unit, UnitTypes()), ContentContainer(ContentType.block, Blocks()), + ContentContainer(null, Loadouts()), + ContentContainer(null, TechTree()), ) - val contentMap = contents.associateBy { it.type } + val contentMap = contents.filter { it.type != null }.associateBy { it.type } override fun clear() = Unit/*throw NotImplementedError()*/ override fun createBaseContent() = throw NotImplementedError()