From 11d73a6fd573b8a4cedce451531ec96391db79b1 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Mon, 10 Apr 2023 19:10:05 +0700 Subject: [PATCH] root.materialHealth --- .../kotlin/ru/dbotthepony/kstarbound/Starbound.kt | 15 +++++++++++++++ .../kstarbound/defs/tile/MaterialModifier.kt | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt index 13d1c140..ac5e6569 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt @@ -672,6 +672,21 @@ class Starbound : ISBFileLocator { 1 } + state.setTableFunction("materialHealth", this) { args -> + val name = args.getString() + val mod = if (args.hasSomethingAt()) args.getString() else null + val mat = tiles[name] ?: throw NoSuchElementException("No such material $name") + + if (mod == null) { + args.push(mat.value.health) + } else { + val getMod = tileModifiers[mod] ?: throw NoSuchElementException("No such material modifier $mod") + args.push(getMod.value.health + mat.value.health) + } + + 1 + } + state.pop() state.load(polyfill, "@starbound.jar!/scripts/polyfill.lua") diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/tile/MaterialModifier.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/tile/MaterialModifier.kt index af8a030d..2746e84a 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/tile/MaterialModifier.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/tile/MaterialModifier.kt @@ -14,8 +14,8 @@ data class MaterialModifier( val modId: Int, val modName: String, val itemDrop: String? = null, - val health: Int = 0, - val harvestLevel: Int = 0, + val health: Double = 0.0, + val harvestLevel: Double = 0.0, val breaksWithTile: Boolean = true, val grass: Boolean = false, val miningParticle: String? = null,