Skip to content

Commit

Permalink
重新实现maxHealth问题
Browse files Browse the repository at this point in the history
  • Loading branch information
way-zer committed Sep 23, 2023
1 parent eec5481 commit 4681e23
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Content, CTNode>()
override fun collectChild(node: CTNode) {
Expand Down Expand Up @@ -50,6 +62,7 @@ object MindustryContentsResolver : ContentsTweaker.NodeCollector {
it.setBars()
}
}
+healthReload
}
}
node += object : CTNode.Indexable {
Expand All @@ -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<Content>.extend() {
Expand Down

0 comments on commit 4681e23

Please sign in to comment.