Lua Функции для получения конфигов материалов и жидкостей
This commit is contained in:
parent
11d73a6fd5
commit
faa2e57724
@ -89,6 +89,7 @@ import java.util.function.BinaryOperator
|
|||||||
import java.util.function.Function
|
import java.util.function.Function
|
||||||
import java.util.function.Supplier
|
import java.util.function.Supplier
|
||||||
import java.util.stream.Collector
|
import java.util.stream.Collector
|
||||||
|
import kotlin.NoSuchElementException
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
@ -687,6 +688,42 @@ class Starbound : ISBFileLocator {
|
|||||||
1
|
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.pop()
|
||||||
|
|
||||||
state.load(polyfill, "@starbound.jar!/scripts/polyfill.lua")
|
state.load(polyfill, "@starbound.jar!/scripts/polyfill.lua")
|
||||||
@ -759,7 +796,6 @@ class Starbound : ISBFileLocator {
|
|||||||
archivePaths.add(pak)
|
archivePaths.add(pak)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getTileDefinition(name: String) = tiles[name]
|
|
||||||
private val initCallbacks = ArrayList<() -> Unit>()
|
private val initCallbacks = ArrayList<() -> Unit>()
|
||||||
|
|
||||||
var playerDefinition: PlayerDefinition by WriteOnce()
|
var playerDefinition: PlayerDefinition by WriteOnce()
|
||||||
|
@ -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: String?) = this@LuaState.push(value)
|
||||||
fun push(value: JsonElement?) = this@LuaState.push(value)
|
fun push(value: JsonElement?) = this@LuaState.push(value)
|
||||||
fun push(value: RegistryObject<*>?) = 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())
|
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 {
|
companion object {
|
||||||
private val LOGGER = LogManager.getLogger()
|
private val LOGGER = LogManager.getLogger()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user