root.liquidStatusEffects

This commit is contained in:
DBotThePony 2023-03-29 19:42:44 +07:00
parent 6a39ed7f56
commit c67c2095a0
Signed by: DBot
GPG Key ID: DCC23B5715498507
4 changed files with 42 additions and 2 deletions

View File

@ -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")

View File

@ -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<String> = ImmutableList.of(),
val statusEffects: ImmutableList<RegistryReference<StatusEffectDefinition>> = ImmutableList.of(),
val interactions: ImmutableList<Interaction> = ImmutableList.of(),
val texture: String,
val bottomLightMix: Color,

View File

@ -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)

View File

@ -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 <T> Stream<T?>.filterNotNull(): Stream<T> {
return filter { it != null } as Stream<T>
}