sound groups

This commit is contained in:
Bixilon 2022-05-24 21:49:25 +02:00
parent 823191c3c0
commit 196ae226b3
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 49 additions and 8 deletions

View File

@ -11,6 +11,7 @@ import de.bixilon.pixlyzer.generator.generators.variants.FrogVariantGenerator
object Generators {
val GENERATORS: List<Generator> = mutableListOf(
ArgumentTypeGenerator,
SoundGroupGenerator,
CatVariantGenerator,
FrogVariantGenerator,

View File

@ -71,6 +71,7 @@ object BlockGenerator : Generator(
}
blockData["class"] = block::class.java.realName
blockData["sound_group"] = SoundGroupGenerator.getId(block.soundGroup)
if (block is FluidBlock) {
(FLUID_BLOCK_FLUID_FIELD.get(block) as Fluid).let {
@ -144,14 +145,6 @@ object BlockGenerator : Generator(
if (state.hasSidedTransparency()) {
stateData["has_side_transparency"] = state.hasSidedTransparency()
}
stateData["sound_type_volume"] = state.soundGroup.volume
stateData["sound_type_pitch"] = state.soundGroup.pitch
stateData["break_sound_type"] = Registry.SOUND_EVENT.getRawId(state.soundGroup.breakSound)
stateData["step_sound_type"] = Registry.SOUND_EVENT.getRawId(state.soundGroup.stepSound)
stateData["place_sound_type"] = Registry.SOUND_EVENT.getRawId(state.soundGroup.placeSound)
stateData["hit_sound_type"] = Registry.SOUND_EVENT.getRawId(state.soundGroup.hitSound)
stateData["fall_sound_type"] = Registry.SOUND_EVENT.getRawId(state.soundGroup.fallSound)
REQUIRES_CORRECT_TOOL_FOR_DROP_FIELDS?.let {
stateData["requires_tool"] = it.getBoolean(state)

View File

@ -0,0 +1,47 @@
package de.bixilon.pixlyzer.generator.generators
import de.bixilon.pixlyzer.generator.Generator
import de.bixilon.pixlyzer.util.ReflectionUtil.getClass
import de.bixilon.pixlyzer.util.Util.compound
import net.minecraft.sound.BlockSoundGroup
import net.minecraft.util.registry.Registry
import java.lang.reflect.Modifier
object SoundGroupGenerator : Generator(
"sound_groups",
) {
private val SOUND_GROUP_CLASS = getClass("net.minecraft.sound.BlockSoundGroup")
private var ids: MutableMap<BlockSoundGroup, Int> = mutableMapOf()
override fun generate() {
val fields = SOUND_GROUP_CLASS?.fields ?: return
for (field in fields) {
if (!Modifier.isStatic(field.modifiers)) {
continue
}
val data = compound()
val group = field.get(null) as BlockSoundGroup
val id = ids.size
ids[group] = id
if (group.volume != 1.0f) {
data["sound_type_volume"] = group.volume
}
if (group.volume != 1.0f) {
data["sound_type_pitch"] = group.pitch
}
data["break_sound_type"] = Registry.SOUND_EVENT.getRawId(group.breakSound)
data["step_sound_type"] = Registry.SOUND_EVENT.getRawId(group.stepSound)
data["place_sound_type"] = Registry.SOUND_EVENT.getRawId(group.placeSound)
data["hit_sound_type"] = Registry.SOUND_EVENT.getRawId(group.hitSound)
data["fall_sound_type"] = Registry.SOUND_EVENT.getRawId(group.fallSound)
this.data[id] = data
}
}
fun getId(sound: BlockSoundGroup): Int {
return ids[sound]!!
}
}