diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt index 4cae7643..d6c8b86d 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt @@ -71,6 +71,7 @@ import ru.dbotthepony.kstarbound.util.ItemStack import ru.dbotthepony.kstarbound.util.PathStack import ru.dbotthepony.kstarbound.util.SBPattern import ru.dbotthepony.kstarbound.util.WriteOnce +import ru.dbotthepony.kstarbound.util.filterNotNull import ru.dbotthepony.kstarbound.util.set import ru.dbotthepony.kstarbound.util.traverseJsonPath import ru.dbotthepony.kvector.vector.nint.Vector2i @@ -224,6 +225,13 @@ class Starbound : ISBFileLocator { add(species::get) add(statusEffects::get) add(particles::get) + add(questTemplates::get) + add(techs::get) + add(jsonFunctions::get) + add(json2Functions::get) + add(npcTypes::get) + add(projectiles::get) + add(tenants::get) }) registerTypeAdapter(LongRangeAdapter) @@ -539,6 +547,22 @@ class Starbound : ISBFileLocator { 1 } + state.setTableFunction("liquidStatusEffects", this) { args -> + val liquid: LiquidDefinition + + if (args.isStringAt()) { + val name = args.getString() + liquid = this.liquid[name]?.value ?: throw NoSuchElementException("No such liquid with name $name") + } else { + val id = args.getInt() + liquid = this.liquidByID[id]?.value ?: throw NoSuchElementException("No such liquid with ID $id") + } + + args.lua.pushStrings(liquid.statusEffects.stream().map { it.value?.value?.name }.filterNotNull().toList()) + + 1 + } + state.pop() state.load(polyfill, "@starbound.jar!/scripts/polyfill.lua") diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/tile/LiquidDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/tile/LiquidDefinition.kt index bdf9ad27..ae36260d 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/tile/LiquidDefinition.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/tile/LiquidDefinition.kt @@ -1,6 +1,8 @@ package ru.dbotthepony.kstarbound.defs.tile import com.google.common.collect.ImmutableList +import ru.dbotthepony.kstarbound.defs.RegistryReference +import ru.dbotthepony.kstarbound.defs.StatusEffectDefinition import ru.dbotthepony.kstarbound.io.json.builder.JsonFactory import ru.dbotthepony.kvector.vector.Color @@ -12,7 +14,7 @@ data class LiquidDefinition( val tickDelta: Int = 1, val color: Color, val itemDrop: String? = null, - val statusEffects: ImmutableList = ImmutableList.of(), + val statusEffects: ImmutableList> = ImmutableList.of(), val interactions: ImmutableList = ImmutableList.of(), val texture: String, val bottomLightMix: Color, diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/lua/LuaState.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/lua/LuaState.kt index 026859a1..67c5eec4 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/lua/LuaState.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/lua/LuaState.kt @@ -463,7 +463,7 @@ class LuaState private constructor(private val pointer: Pointer, val stringInter fun hasSomethingAt(position: Int): Boolean { check(position in 1 ..this.top) { "JVM code error: Invalid argument position: $position" } - return this@LuaState.typeAt() != LuaType.NONE + return this@LuaState.typeAt(position) != LuaType.NONE } fun hasSomethingAt(): Boolean { @@ -475,6 +475,14 @@ class LuaState private constructor(private val pointer: Pointer, val stringInter return false } + fun isStringAt(position: Int = this.position): Boolean { + return this@LuaState.typeAt(position) == LuaType.STRING + } + + fun isNumberAt(position: Int = this.position): Boolean { + return this@LuaState.typeAt(position) == LuaType.NUMBER + } + fun getString(position: Int = this.position++, limit: Long = DEFAULT_STRING_LIMIT): String { check(position in 1 ..this.top) { "JVM code error: Invalid argument position: $position" } return this@LuaState.getString(position, limit = limit) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/util/Utils.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/util/Utils.kt index 49807ef7..90bef9f2 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/util/Utils.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/util/Utils.kt @@ -9,6 +9,7 @@ import com.google.gson.JsonObject import ru.dbotthepony.kstarbound.Starbound import java.util.* import java.util.function.Consumer +import java.util.stream.Stream import kotlin.collections.ArrayList fun String.sbIntern(): String { @@ -87,3 +88,8 @@ fun UUID.toStarboundString(): String { return builder.toString() } + +@Suppress("unchecked_cast") +fun Stream.filterNotNull(): Stream { + return filter { it != null } as Stream +}