Compare commits

...

5 Commits

Author SHA1 Message Date
f794f9848b
fix: remove debug log 2023-08-10 22:22:40 +08:00
f2b60ca6b0
fix(i18n): json syntax 2023-08-10 22:11:25 +08:00
a68b68a0e3
fix: remove duplicated key 2023-08-10 22:09:21 +08:00
33604db8a0
feat(i18n): add translations 2023-08-10 22:07:56 +08:00
a31321e662
feat: volume scaler 2023-08-10 22:03:32 +08:00
6 changed files with 30 additions and 10 deletions

View File

@ -59,10 +59,11 @@ object NoiseProjection {
if (projections.isNotEmpty()) { if (projections.isNotEmpty()) {
val rate = projections.maxOf { it.rate } val rate = projections.maxOf { it.rate }
val amount = min(projections.sumOf { it.amount }, 12) val amount = min(projections.sumOf { it.amount }, 12)
val volume = projections.fold(1.0f) { v, p -> v * p.volume }
if (amount != 0 && random.nextInt(1000 / rate) == 1) { if (amount != 0 && random.nextInt(1000 / rate) == 1) {
for (i in 0 until random.nextInt(amount)) { for (i in 0 until random.nextInt(amount)) {
// play random noise // play random noise
playRandomNoise(random, game) playRandomNoise(random, game, volume)
} }
} }
} }
@ -70,7 +71,7 @@ object NoiseProjection {
} }
} }
private fun playRandomNoise(random: RandomSource, game: Minecraft) { private fun playRandomNoise(random: RandomSource, game: Minecraft, volume: Float) {
val volumeFactor = random.nextInt(100) val volumeFactor = random.nextInt(100)
val sound = SimpleSoundInstance( val sound = SimpleSoundInstance(
soundEvent.get().location, soundEvent.get().location,
@ -80,7 +81,7 @@ object NoiseProjection {
in 10..15 -> random.nextFloat() * 0.5f + 0.5f in 10..15 -> random.nextFloat() * 0.5f + 0.5f
in 21..50 -> random.nextFloat() * 0.3f in 21..50 -> random.nextFloat() * 0.3f
else -> random.nextFloat() * 0.2f else -> random.nextFloat() * 0.2f
}, } * volume,
random.nextFloat() + 0.4f, random.nextFloat() + 0.4f,
RandomSource.create(random.nextLong()), RandomSource.create(random.nextLong()),
false, false,
@ -102,12 +103,14 @@ object NoiseProjectionBlock : EntityProjectionBlock<NoiseProjectionEffect>(creat
} }
data class NoiseProjectionEffect(var rate: Int = 250, var amount: Int = 3) : ProjectionEffect(), data class NoiseProjectionEffect(var rate: Int = 250, var amount: Int = 3, var volume: Float = 1.0f) :
ProjectionEffect(),
ProjectionEffectShell.Provider { ProjectionEffectShell.Provider {
companion object { companion object {
const val TAG_RATE = "Rate" const val TAG_RATE = "Rate"
const val TAG_AMOUNT = "Amount" const val TAG_AMOUNT = "Amount"
const val TAG_VOLUME = "Volume"
val maxAmount get() = QuaedamConfig.current.valuesInt["projection.noise.max_amount"] ?: 8 val maxAmount get() = QuaedamConfig.current.valuesInt["projection.noise.max_amount"] ?: 8
val maxRate get() = QuaedamConfig.current.valuesInt["projection.noise.max_rate"] ?: 300 val maxRate get() = QuaedamConfig.current.valuesInt["projection.noise.max_rate"] ?: 300
@ -119,11 +122,13 @@ data class NoiseProjectionEffect(var rate: Int = 250, var amount: Int = 3) : Pro
override fun toNbt(tag: CompoundTag) { override fun toNbt(tag: CompoundTag) {
tag.putInt(TAG_RATE, rate) tag.putInt(TAG_RATE, rate)
tag.putInt(TAG_AMOUNT, amount) tag.putInt(TAG_AMOUNT, amount)
tag.putFloat(TAG_VOLUME, volume)
} }
override fun fromNbt(tag: CompoundTag, trusted: Boolean) { override fun fromNbt(tag: CompoundTag, trusted: Boolean) {
rate = tag.getInt(TAG_RATE) rate = tag.getInt(TAG_RATE)
amount = tag.getInt(TAG_AMOUNT) amount = tag.getInt(TAG_AMOUNT)
volume = tag.getFloat(TAG_VOLUME)
if (!trusted) { if (!trusted) {
amount = min(amount, maxAmount) amount = min(amount, maxAmount)
rate = min(rate, maxRate) rate = min(rate, maxRate)
@ -133,6 +138,7 @@ data class NoiseProjectionEffect(var rate: Int = 250, var amount: Int = 3) : Pro
override fun createShell() = buildProjectionEffectShell(this) { override fun createShell() = buildProjectionEffectShell(this) {
intSlider("quaedam.shell.noise.rate", ::rate, 0..maxRate step 5) intSlider("quaedam.shell.noise.rate", ::rate, 0..maxRate step 5)
intSlider("quaedam.shell.noise.amount", ::amount, 0..maxAmount) intSlider("quaedam.shell.noise.amount", ::amount, 0..maxAmount)
floatSlider("quaedam.shell.noise.volume", ::volume, 0.0f..1.0f, 0.1f)
} }
} }

View File

@ -43,10 +43,12 @@ object SoundProjectionBlock : EntityProjectionBlock<SoundProjectionEffect>(creat
} }
data class SoundProjectionEffect(var rate: Int = 60) : ProjectionEffect(), ProjectionEffectShell.Provider { data class SoundProjectionEffect(var rate: Int = 60, var volume: Float = 1.0f) : ProjectionEffect(),
ProjectionEffectShell.Provider {
companion object { companion object {
const val TAG_RATE = "Rate" const val TAG_RATE = "Rate"
const val TAG_VOLUME = "Volume"
val maxRate get() = QuaedamConfig.current.valuesInt["projection.sound.max_rate"] ?: 210 val maxRate get() = QuaedamConfig.current.valuesInt["projection.sound.max_rate"] ?: 210
} }
@ -56,10 +58,12 @@ data class SoundProjectionEffect(var rate: Int = 60) : ProjectionEffect(), Proje
override fun toNbt(tag: CompoundTag) { override fun toNbt(tag: CompoundTag) {
tag.putInt(TAG_RATE, rate) tag.putInt(TAG_RATE, rate)
tag.putFloat(TAG_VOLUME, volume)
} }
override fun fromNbt(tag: CompoundTag, trusted: Boolean) { override fun fromNbt(tag: CompoundTag, trusted: Boolean) {
rate = tag.getInt(TAG_RATE) rate = tag.getInt(TAG_RATE)
volume = tag.getFloat(TAG_VOLUME)
if (!trusted) { if (!trusted) {
rate = min(rate, maxRate) rate = min(rate, maxRate)
} }
@ -67,6 +71,7 @@ data class SoundProjectionEffect(var rate: Int = 60) : ProjectionEffect(), Proje
override fun createShell() = buildProjectionEffectShell(this) { override fun createShell() = buildProjectionEffectShell(this) {
intSlider("quaedam.shell.sound.rate", ::rate, 0..maxRate) intSlider("quaedam.shell.sound.rate", ::rate, 0..maxRate)
floatSlider("quaedam.shell.sound.volume", ::volume, 0.0f..1.0f, 0.1f)
} }
} }

View File

@ -237,24 +237,27 @@ class ProjectedPersonEntity(entityType: EntityType<out PathfinderMob>, level: Le
} }
fun findNearbySoundProjection() = fun findNearbySoundProjection() =
Projector.findNearbyProjections(level(), blockPosition(), SoundProjection.effect.get()).firstOrNull() Projector.findNearbyProjections(level(), blockPosition(), SoundProjection.effect.get())
override fun isSilent() = override fun isSilent() =
super.isSilent() && findNearbySoundProjection() != null super.isSilent() && findNearbySoundProjection().isEmpty()
override fun getAmbientSound(): SoundEvent? { override fun getAmbientSound(): SoundEvent? {
if (findNearbySoundProjection() != null) { if (findNearbySoundProjection().isNotEmpty()) {
// sound projection available // sound projection available
return soundNoise.get() return soundNoise.get()
} }
return null return null
} }
override fun getSoundVolume() = super.getSoundVolume() * (random.nextFloat() * 1.1f + 0.4f) override fun getSoundVolume() =
super.getSoundVolume() * (random.nextFloat() * 1.1f + 0.4f) *
findNearbySoundProjection().fold(1.0f) { v, p -> v * p.volume }
override fun getVoicePitch() = super.getVoicePitch() * (random.nextFloat() * 0.55f + 0.7f) override fun getVoicePitch() = super.getVoicePitch() * (random.nextFloat() * 0.55f + 0.7f)
override fun getAmbientSoundInterval() = 80 - random.nextInt((findNearbySoundProjection()?.rate ?: 1) * 5) override fun getAmbientSoundInterval() =
80 - random.nextInt((findNearbySoundProjection().firstOrNull()?.rate ?: 1) * 5)
override fun isEffectiveAi() = super.isEffectiveAi() && checkProjectionEffect() override fun isEffectiveAi() = super.isEffectiveAi() && checkProjectionEffect()

View File

@ -23,8 +23,10 @@
"quaedam.shell.skylight.factor": "Factor", "quaedam.shell.skylight.factor": "Factor",
"quaedam.shell.noise.rate": "Rate", "quaedam.shell.noise.rate": "Rate",
"quaedam.shell.noise.amount": "Amount", "quaedam.shell.noise.amount": "Amount",
"quaedam.shell.noise.volume": "Volume",
"quaedam.shell.swarm.max_count": "Max Count", "quaedam.shell.swarm.max_count": "Max Count",
"quaedam.shell.sound.rate": "Rate", "quaedam.shell.sound.rate": "Rate",
"quaedam.shell.sound.volume": "Volume",
"quaedam.shell.music.volume_factor": "Volume Factor", "quaedam.shell.music.volume_factor": "Volume Factor",
"quaedam.shell.music.particle": "Particle", "quaedam.shell.music.particle": "Particle",
"quaedam.shell.music.particle.true": "Display", "quaedam.shell.music.particle.true": "Display",

View File

@ -23,8 +23,10 @@
"quaedam.shell.skylight.factor": "因子", "quaedam.shell.skylight.factor": "因子",
"quaedam.shell.noise.rate": "速率", "quaedam.shell.noise.rate": "速率",
"quaedam.shell.noise.amount": "数量", "quaedam.shell.noise.amount": "数量",
"quaedam.shell.noise.volume": "响度因子",
"quaedam.shell.swarm.max_count": "最大数量", "quaedam.shell.swarm.max_count": "最大数量",
"quaedam.shell.sound.rate": "速率", "quaedam.shell.sound.rate": "速率",
"quaedam.shell.sound.volume": "响度因子",
"quaedam.shell.music.volume_factor": "响度因子", "quaedam.shell.music.volume_factor": "响度因子",
"quaedam.shell.music.particle": "粒子效果", "quaedam.shell.music.particle": "粒子效果",
"quaedam.shell.music.particle.true": "显示", "quaedam.shell.music.particle.true": "显示",

View File

@ -23,8 +23,10 @@
"quaedam.shell.skylight.factor": "防晒系数", "quaedam.shell.skylight.factor": "防晒系数",
"quaedam.shell.noise.rate": "急急急等级", "quaedam.shell.noise.rate": "急急急等级",
"quaedam.shell.noise.amount": "声卡压榨等级", "quaedam.shell.noise.amount": "声卡压榨等级",
"quaedam.shell.noise.volume": "振幅大小",
"quaedam.shell.swarm.max_count": "显卡和处理器迫害等级", "quaedam.shell.swarm.max_count": "显卡和处理器迫害等级",
"quaedam.shell.sound.rate": "急急急等级", "quaedam.shell.sound.rate": "急急急等级",
"quaedam.shell.sound.volume": "振幅大小",
"quaedam.shell.music.volume_factor": "振幅大小", "quaedam.shell.music.volume_factor": "振幅大小",
"quaedam.shell.music.particle": "会变色的颗粒buff", "quaedam.shell.music.particle": "会变色的颗粒buff",
"quaedam.shell.music.particle.true": "打开", "quaedam.shell.music.particle.true": "打开",