mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-18 11:54:59 -04:00
sound groups, reduce memory usage
This commit is contained in:
parent
a6057ffff8
commit
a1692b2d3d
@ -16,7 +16,6 @@ import de.bixilon.kutil.cast.CastUtil.unsafeCast
|
|||||||
import de.bixilon.kutil.json.JsonUtil.toJsonObject
|
import de.bixilon.kutil.json.JsonUtil.toJsonObject
|
||||||
import de.bixilon.kutil.primitive.BooleanUtil.toBoolean
|
import de.bixilon.kutil.primitive.BooleanUtil.toBoolean
|
||||||
import de.bixilon.kutil.primitive.FloatUtil.toFloat
|
import de.bixilon.kutil.primitive.FloatUtil.toFloat
|
||||||
import de.bixilon.kutil.primitive.IntUtil.toInt
|
|
||||||
import de.bixilon.minosoft.data.registries.ResourceLocation
|
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||||
import de.bixilon.minosoft.data.registries.VoxelShape
|
import de.bixilon.minosoft.data.registries.VoxelShape
|
||||||
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
|
import de.bixilon.minosoft.data.registries.blocks.properties.BlockProperties
|
||||||
@ -35,13 +34,6 @@ data class BlockState(
|
|||||||
val outlineShape: VoxelShape,
|
val outlineShape: VoxelShape,
|
||||||
val hardness: Float,
|
val hardness: Float,
|
||||||
val requiresTool: Boolean,
|
val requiresTool: Boolean,
|
||||||
val breakSoundEvent: ResourceLocation?,
|
|
||||||
val stepSoundEvent: ResourceLocation?,
|
|
||||||
val placeSoundEvent: ResourceLocation?,
|
|
||||||
val hitSoundEvent: ResourceLocation?,
|
|
||||||
val fallSoundEvent: ResourceLocation?,
|
|
||||||
val soundEventVolume: Float = 1.0f,
|
|
||||||
val soundEventPitch: Float = 1.0f,
|
|
||||||
val isSolid: Boolean,
|
val isSolid: Boolean,
|
||||||
) {
|
) {
|
||||||
var blockModel: BakedBlockModel? = null
|
var blockModel: BakedBlockModel? = null
|
||||||
@ -140,13 +132,6 @@ data class BlockState(
|
|||||||
outlineShape = outlineShape,
|
outlineShape = outlineShape,
|
||||||
hardness = data["hardness"]?.toFloat() ?: 1.0f,
|
hardness = data["hardness"]?.toFloat() ?: 1.0f,
|
||||||
requiresTool = data["requires_tool"]?.toBoolean() ?: material.soft,
|
requiresTool = data["requires_tool"]?.toBoolean() ?: material.soft,
|
||||||
breakSoundEvent = data["break_sound_type"]?.toInt()?.let { registries.soundEventRegistry[it] },
|
|
||||||
stepSoundEvent = data["step_sound_type"]?.toInt()?.let { registries.soundEventRegistry[it] },
|
|
||||||
placeSoundEvent = data["place_sound_type"]?.toInt()?.let { registries.soundEventRegistry[it] },
|
|
||||||
hitSoundEvent = data["hit_sound_type"]?.toInt()?.let { registries.soundEventRegistry[it] },
|
|
||||||
fallSoundEvent = data["fall_sound_type"]?.toInt()?.let { registries.soundEventRegistry[it] },
|
|
||||||
soundEventVolume = data["sound_type_volume"]?.toFloat() ?: 1.0f,
|
|
||||||
soundEventPitch = data["sound_type_pitch"]?.toFloat() ?: 1.0f,
|
|
||||||
isSolid = data["solid_render"]?.toBoolean() ?: false,
|
isSolid = data["solid_render"]?.toBoolean() ?: false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,8 @@ open class Block(
|
|||||||
open val jumpVelocityMultiplier = data["jump_velocity_multiplier"]?.toDouble() ?: 1.0
|
open val jumpVelocityMultiplier = data["jump_velocity_multiplier"]?.toDouble() ?: 1.0
|
||||||
var tintProvider: TintProvider? = null
|
var tintProvider: TintProvider? = null
|
||||||
|
|
||||||
|
var soundGroup = data["sound_group"]?.toInt()?.let { registries.soundGroupRegistry[it] }
|
||||||
|
|
||||||
init {
|
init {
|
||||||
this::item.inject(data["item"])
|
this::item.inject(data["item"])
|
||||||
}
|
}
|
||||||
|
@ -80,8 +80,8 @@ open class BlockItem(
|
|||||||
stack.item.decreaseCount()
|
stack.item.decreaseCount()
|
||||||
}
|
}
|
||||||
|
|
||||||
placeBlockState.placeSoundEvent?.let {
|
placeBlockState.block.soundGroup?.let { group ->
|
||||||
connection.world.playSoundEvent(it, placePosition, placeBlockState.soundEventVolume, placeBlockState.soundEventPitch)
|
group.place?.let { connection.world.playSoundEvent(it, placePosition, group.volume, group.pitch) }
|
||||||
}
|
}
|
||||||
return InteractionResults.SUCCESS
|
return InteractionResults.SUCCESS
|
||||||
}
|
}
|
||||||
|
@ -30,13 +30,13 @@ object BlockDestroyedHandler : WorldEventHandler {
|
|||||||
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:block_destroyed".toResourceLocation()
|
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:block_destroyed".toResourceLocation()
|
||||||
|
|
||||||
override fun handle(connection: PlayConnection, position: Vec3i, data: Int, isGlobal: Boolean) {
|
override fun handle(connection: PlayConnection, position: Vec3i, data: Int, isGlobal: Boolean) {
|
||||||
val state = connection.registries.blockStateRegistry[data] ?: return
|
val state = connection.registries.blockStateRegistry.getOrNull(data) ?: return
|
||||||
handleDestroy(connection, position, state)
|
handleDestroy(connection, position, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleDestroy(connection: PlayConnection, position: Vec3i, state: BlockState) {
|
fun handleDestroy(connection: PlayConnection, position: Vec3i, state: BlockState) {
|
||||||
state.breakSoundEvent?.let {
|
state.block.soundGroup?.let { group ->
|
||||||
connection.world.playSoundEvent(it, position, volume = state.soundEventVolume, pitch = state.soundEventPitch)
|
group.destroy?.let { connection.world.playSoundEvent(it, position, group.volume, group.pitch) }
|
||||||
}
|
}
|
||||||
|
|
||||||
addBlockBreakParticles(connection, position, state)
|
addBlockBreakParticles(connection, position, state)
|
||||||
|
@ -41,6 +41,7 @@ import de.bixilon.minosoft.data.registries.materials.Material
|
|||||||
import de.bixilon.minosoft.data.registries.other.containers.ContainerType
|
import de.bixilon.minosoft.data.registries.other.containers.ContainerType
|
||||||
import de.bixilon.minosoft.data.registries.particle.ParticleType
|
import de.bixilon.minosoft.data.registries.particle.ParticleType
|
||||||
import de.bixilon.minosoft.data.registries.registries.registry.*
|
import de.bixilon.minosoft.data.registries.registries.registry.*
|
||||||
|
import de.bixilon.minosoft.data.registries.sound.SoundGroup
|
||||||
import de.bixilon.minosoft.data.registries.statistics.Statistic
|
import de.bixilon.minosoft.data.registries.statistics.Statistic
|
||||||
import de.bixilon.minosoft.data.registries.versions.Version
|
import de.bixilon.minosoft.data.registries.versions.Version
|
||||||
import de.bixilon.minosoft.datafixer.RegistryFixer.fix
|
import de.bixilon.minosoft.datafixer.RegistryFixer.fix
|
||||||
@ -94,6 +95,7 @@ class Registries {
|
|||||||
|
|
||||||
val biomePrecipitationRegistry: FakeEnumRegistry<BiomePrecipitation> = FakeEnumRegistry(codec = BiomePrecipitation)
|
val biomePrecipitationRegistry: FakeEnumRegistry<BiomePrecipitation> = FakeEnumRegistry(codec = BiomePrecipitation)
|
||||||
val biomeCategoryRegistry: FakeEnumRegistry<BiomeCategory> = FakeEnumRegistry(codec = BiomeCategory)
|
val biomeCategoryRegistry: FakeEnumRegistry<BiomeCategory> = FakeEnumRegistry(codec = BiomeCategory)
|
||||||
|
val soundGroupRegistry: FakeEnumRegistry<SoundGroup> = FakeEnumRegistry(codec = SoundGroup)
|
||||||
|
|
||||||
val blockStateRegistry = BlockStateRegistry(false)
|
val blockStateRegistry = BlockStateRegistry(false)
|
||||||
|
|
||||||
@ -160,6 +162,7 @@ class Registries {
|
|||||||
|
|
||||||
motiveRegistry.rawUpdate(pixlyzerData["motives"]?.toJsonObject(), this)
|
motiveRegistry.rawUpdate(pixlyzerData["motives"]?.toJsonObject(), this)
|
||||||
soundEventRegistry.rawUpdate(pixlyzerData["sound_events"]?.toJsonObject(), null)
|
soundEventRegistry.rawUpdate(pixlyzerData["sound_events"]?.toJsonObject(), null)
|
||||||
|
soundGroupRegistry.update(pixlyzerData["sound_groups"]?.unsafeCast(), this)
|
||||||
particleTypeRegistry.rawUpdate(pixlyzerData["particles"]?.toJsonObject(), this)
|
particleTypeRegistry.rawUpdate(pixlyzerData["particles"]?.toJsonObject(), this)
|
||||||
materialRegistry.rawUpdate(pixlyzerData["materials"]?.toJsonObject(), this)
|
materialRegistry.rawUpdate(pixlyzerData["materials"]?.toJsonObject(), this)
|
||||||
enchantmentRegistry.rawUpdate(pixlyzerData["enchantments"]?.toJsonObject(), this)
|
enchantmentRegistry.rawUpdate(pixlyzerData["enchantments"]?.toJsonObject(), this)
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020-2022 Moritz Zwerger
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.bixilon.minosoft.data.registries.sound
|
||||||
|
|
||||||
|
import de.bixilon.kutil.primitive.FloatUtil.toFloat
|
||||||
|
import de.bixilon.kutil.primitive.IntUtil.toInt
|
||||||
|
import de.bixilon.minosoft.data.registries.ResourceLocation
|
||||||
|
import de.bixilon.minosoft.data.registries.registries.Registries
|
||||||
|
import de.bixilon.minosoft.data.registries.registries.registry.RegistryFakeEnumerable
|
||||||
|
import de.bixilon.minosoft.data.registries.registries.registry.codec.IdCodec
|
||||||
|
|
||||||
|
class SoundGroup(
|
||||||
|
override val name: String,
|
||||||
|
val destroy: ResourceLocation?,
|
||||||
|
val step: ResourceLocation?,
|
||||||
|
val place: ResourceLocation?,
|
||||||
|
val hit: ResourceLocation?,
|
||||||
|
val fall: ResourceLocation?,
|
||||||
|
val volume: Float = 1.0f,
|
||||||
|
val pitch: Float = 1.0f,
|
||||||
|
) : RegistryFakeEnumerable {
|
||||||
|
|
||||||
|
companion object : IdCodec<SoundGroup> {
|
||||||
|
|
||||||
|
override fun deserialize(registries: Registries, data: Map<String, Any>): SoundGroup {
|
||||||
|
return SoundGroup(
|
||||||
|
name = data["name"]?.toString()!!,
|
||||||
|
destroy = data["break_sound_type"]?.toInt()?.let { registries.soundEventRegistry[it] },
|
||||||
|
step = data["step_sound_type"]?.toInt()?.let { registries.soundEventRegistry[it] },
|
||||||
|
place = data["place_sound_type"]?.toInt()?.let { registries.soundEventRegistry[it] },
|
||||||
|
hit = data["hit_sound_type"]?.toInt()?.let { registries.soundEventRegistry[it] },
|
||||||
|
fall = data["fall_sound_type"]?.toInt()?.let { registries.soundEventRegistry[it] },
|
||||||
|
volume = data["sound_type_volume"]?.toFloat() ?: 1.0f,
|
||||||
|
pitch = data["sound_type_pitch"]?.toFloat() ?: 1.0f,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user