From b311c8516b5f3fe1541d43b9fdcb6998e0f8d178 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Mon, 10 Apr 2023 19:01:53 +0700 Subject: [PATCH] root.materialMiningSound root.materialFootstepSound --- .../ru/dbotthepony/kstarbound/Starbound.kt | 33 +++++++++++++++++-- .../kstarbound/defs/tile/MaterialModifier.kt | 4 ++- .../kstarbound/defs/tile/TileDefinition.kt | 2 ++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt index a9309d5d..13d1c140 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/Starbound.kt @@ -72,7 +72,6 @@ import ru.dbotthepony.kstarbound.util.ITimeSource import ru.dbotthepony.kstarbound.util.ItemStack import ru.dbotthepony.kstarbound.util.JVMTimeSource import ru.dbotthepony.kstarbound.util.PathStack -import ru.dbotthepony.kstarbound.util.PausableTimeSource import ru.dbotthepony.kstarbound.util.SBPattern import ru.dbotthepony.kstarbound.util.WriteOnce import ru.dbotthepony.kstarbound.util.filterNotNull @@ -90,10 +89,8 @@ 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 -import kotlin.random.nextInt class Starbound : ISBFileLocator { private val logger = LogManager.getLogger() @@ -645,6 +642,36 @@ class Starbound : ISBFileLocator { 1 } + state.setTableFunction("materialMiningSound", 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.miningSounds.firstOrNull()) + } else { + val getMod = tileModifiers[mod] ?: throw NoSuchElementException("No such material modifier $mod") + args.push(getMod.value.miningSounds.firstOrNull() ?: mat.value.miningSounds.firstOrNull()) + } + + 1 + } + + state.setTableFunction("materialFootstepSound", 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.footstepSound) + } else { + val getMod = tileModifiers[mod] ?: throw NoSuchElementException("No such material modifier $mod") + args.push(getMod.value.footstepSound ?: mat.value.footstepSound) + } + + 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 d484321d..af8a030d 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/tile/MaterialModifier.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/tile/MaterialModifier.kt @@ -18,9 +18,11 @@ data class MaterialModifier( val harvestLevel: Int = 0, val breaksWithTile: Boolean = true, val grass: Boolean = false, - val miningSounds: ImmutableList = ImmutableList.of(), val miningParticle: String? = null, + val footstepSound: String? = null, + val miningSounds: ImmutableList = ImmutableList.of(), + @JsonPropertyConfig(isFlat = true) val descriptionData: ThingDescription, diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/tile/TileDefinition.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/tile/TileDefinition.kt index 5d278533..7b50472e 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/tile/TileDefinition.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/tile/TileDefinition.kt @@ -1,5 +1,6 @@ package ru.dbotthepony.kstarbound.defs.tile +import com.google.common.collect.ImmutableList import com.google.gson.GsonBuilder import ru.dbotthepony.kstarbound.defs.AssetReference import ru.dbotthepony.kstarbound.defs.IThingWithDescription @@ -17,6 +18,7 @@ data class TileDefinition( val particleColor: Color? = null, val itemDrop: String? = null, val footstepSound: String? = null, + val miningSounds: ImmutableList = ImmutableList.of(), val blocksLiquidFlow: Boolean = true, val soil: Boolean = false,