From 4681e2384921d073b8d015199e1e6d777bef2d0f Mon Sep 17 00:00:00 2001 From: way-zer Date: Sun, 24 Sep 2023 00:13:18 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=96=B0=E5=AE=9E=E7=8E=B0maxHealth?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resolvers/MindustryContentsResolver.kt | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/cf/wayzer/contentsTweaker/resolvers/MindustryContentsResolver.kt b/src/main/kotlin/cf/wayzer/contentsTweaker/resolvers/MindustryContentsResolver.kt index de3d34d..f8b774a 100644 --- a/src/main/kotlin/cf/wayzer/contentsTweaker/resolvers/MindustryContentsResolver.kt +++ b/src/main/kotlin/cf/wayzer/contentsTweaker/resolvers/MindustryContentsResolver.kt @@ -17,6 +17,18 @@ import mindustry.world.meta.Stats object MindustryContentsResolver : ContentsTweaker.NodeCollector { private val Block.barMap: OrderedMap<*, *> by reflectDelegate() + private val healthReload = CTNode.AfterHandler { + if (Vars.world.isGenerating) return@AfterHandler + Vars.world.tiles.forEach { + val build = it.build ?: return@forEach + val oldMax = build.maxHealth + val max = build.block.health.toFloat() + if (oldMax == max) return@forEach + build.maxHealth = max + if (build.health == oldMax) + build.health = max + } + } private val contentNodes = mutableMapOf() override fun collectChild(node: CTNode) { @@ -50,6 +62,7 @@ object MindustryContentsResolver : ContentsTweaker.NodeCollector { it.setBars() } } + +healthReload } } node += object : CTNode.Indexable { @@ -59,10 +72,10 @@ object MindustryContentsResolver : ContentsTweaker.NodeCollector { return node.children[normalize] } } - if (type == ContentType.block) - node += CTNode.AfterHandler { - ContentsTweaker.reloadWorld() - } +// if (type == ContentType.block) +// node += CTNode.AfterHandler { +// ContentsTweaker.reloadWorld() +// } } private fun CTNodeTypeChecked.extend() {