diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt index ac5e6569..533fd9c1 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt @@ -89,6 +89,7 @@ import java.util.function.BinaryOperator import java.util.function.Function import java.util.function.Supplier import java.util.stream.Collector +import kotlin.NoSuchElementException import kotlin.collections.ArrayList import kotlin.random.Random @@ -687,6 +688,42 @@ class Starbound : ISBFileLocator { 1 } + state.setTableFunction("materialConfig", this) { args -> + val name = args.getString() + args.pushFull(tiles[name]) + 1 + } + + state.setTableFunction("modConfig", this) { args -> + val name = args.getString() + args.pushFull(tileModifiers[name]) + 1 + } + + state.setTableFunction("liquidConfig", this) { args -> + if (args.isNumberAt()) { + val id = args.getLong().toInt() + args.pushFull(liquidByID[id]) + } else { + val name = args.getString() + args.pushFull(liquid[name]) + } + + 1 + } + + state.setTableFunction("liquidName", this) { args -> + val id = args.getLong().toInt() + args.push(liquidByID[id]?.value?.name ?: throw NoSuchElementException("No such liquid with ID $id")) + 1 + } + + state.setTableFunction("liquidId", this) { args -> + val name = args.getString() + args.push(liquid[name]?.value?.name ?: throw NoSuchElementException("No such liquid $name")) + 1 + } + state.pop() state.load(polyfill, "@starbound.jar!/scripts/polyfill.lua") @@ -759,7 +796,6 @@ class Starbound : ISBFileLocator { archivePaths.add(pak) } - fun getTileDefinition(name: String) = tiles[name] private val initCallbacks = ArrayList<() -> Unit>() var playerDefinition: PlayerDefinition by WriteOnce() diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/lua/LuaState.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/lua/LuaState.kt index 619384f2..d25aaf91 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/lua/LuaState.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/lua/LuaState.kt @@ -597,6 +597,7 @@ class LuaState private constructor(private val pointer: Pointer, val stringInter fun push(value: String?) = this@LuaState.push(value) fun push(value: JsonElement?) = this@LuaState.push(value) fun push(value: RegistryObject<*>?) = this@LuaState.push(value) + fun pushFull(value: RegistryObject<*>?) = this@LuaState.pushFull(value) } /** @@ -1065,6 +1066,16 @@ class LuaState private constructor(private val pointer: Pointer, val stringInter push(value.toJson()) } + fun pushFull(value: RegistryObject<*>?) { + if (value == null) + push() + else { + pushTable(hashSize = 2) + setTableValue("path", value.file.computeFullPath()) + setTableValue("config", value.toJson()) + } + } + companion object { private val LOGGER = LogManager.getLogger()