From 519060ca23e507172b867e792823863513a04f2a Mon Sep 17 00:00:00 2001 From: xtex Date: Sat, 29 Jul 2023 16:35:36 +0800 Subject: [PATCH] feat: rate parameter for sound projection --- .../kotlin/quaedam/misc/causality/CABlock.kt | 5 ++++- .../main/kotlin/quaedam/misc/reality/RSBlock.kt | 6 ++++-- .../quaedam/projection/misc/SoundProjection.kt | 17 ++++++++++++++--- .../projection/swarm/ProjectedPersonEntity.kt | 10 ++++++---- .../resources/assets/quaedam/lang/en_us.json | 3 ++- .../resources/assets/quaedam/lang/zh_cn.json | 3 ++- 6 files changed, 32 insertions(+), 12 deletions(-) diff --git a/common/src/main/kotlin/quaedam/misc/causality/CABlock.kt b/common/src/main/kotlin/quaedam/misc/causality/CABlock.kt index 9f9ee5a..78c0442 100644 --- a/common/src/main/kotlin/quaedam/misc/causality/CABlock.kt +++ b/common/src/main/kotlin/quaedam/misc/causality/CABlock.kt @@ -6,7 +6,10 @@ import net.minecraft.world.item.context.BlockPlaceContext import net.minecraft.world.level.BlockGetter import net.minecraft.world.level.Level import net.minecraft.world.level.LevelAccessor -import net.minecraft.world.level.block.* +import net.minecraft.world.level.block.Block +import net.minecraft.world.level.block.EntityBlock +import net.minecraft.world.level.block.HorizontalDirectionalBlock +import net.minecraft.world.level.block.SimpleWaterloggedBlock import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.block.state.StateDefinition import net.minecraft.world.level.block.state.properties.BlockStateProperties diff --git a/common/src/main/kotlin/quaedam/misc/reality/RSBlock.kt b/common/src/main/kotlin/quaedam/misc/reality/RSBlock.kt index 949a8ea..d180547 100644 --- a/common/src/main/kotlin/quaedam/misc/reality/RSBlock.kt +++ b/common/src/main/kotlin/quaedam/misc/reality/RSBlock.kt @@ -6,7 +6,10 @@ import net.minecraft.world.item.context.BlockPlaceContext import net.minecraft.world.level.BlockGetter import net.minecraft.world.level.Level import net.minecraft.world.level.LevelAccessor -import net.minecraft.world.level.block.* +import net.minecraft.world.level.block.Block +import net.minecraft.world.level.block.EntityBlock +import net.minecraft.world.level.block.HorizontalDirectionalBlock +import net.minecraft.world.level.block.SimpleWaterloggedBlock import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.block.state.StateDefinition import net.minecraft.world.level.block.state.properties.BlockStateProperties @@ -15,7 +18,6 @@ import net.minecraft.world.level.material.Fluids import net.minecraft.world.level.material.MapColor import net.minecraft.world.phys.shapes.CollisionContext import net.minecraft.world.phys.shapes.Shapes -import net.minecraft.world.phys.shapes.VoxelShape object RSBlock : HorizontalDirectionalBlock( Properties.of() diff --git a/common/src/main/kotlin/quaedam/projection/misc/SoundProjection.kt b/common/src/main/kotlin/quaedam/projection/misc/SoundProjection.kt index c7ea648..aceb21a 100644 --- a/common/src/main/kotlin/quaedam/projection/misc/SoundProjection.kt +++ b/common/src/main/kotlin/quaedam/projection/misc/SoundProjection.kt @@ -10,6 +10,7 @@ import quaedam.projection.ProjectionEffectType import quaedam.projection.SimpleProjectionEntity import quaedam.shell.ProjectionEffectShell import quaedam.shell.buildProjectionEffectShell +import kotlin.math.min object SoundProjection { @@ -26,11 +27,11 @@ object SoundProjection { }!! val effect = Quaedam.projectionEffects.register(SHORT_ID) { - ProjectionEffectType { SoundProjectionEffect } + ProjectionEffectType { SoundProjectionEffect() } }!! val blockEntity = Quaedam.blockEntities.register(ID) { - SimpleProjectionEntity.createBlockEntityType(block) { SoundProjectionEffect } + SimpleProjectionEntity.createBlockEntityType(block) { SoundProjectionEffect() } }!! } @@ -41,18 +42,28 @@ object SoundProjectionBlock : EntityProjectionBlock(creat } -object SoundProjectionEffect : ProjectionEffect(), ProjectionEffectShell.Provider { +data class SoundProjectionEffect(var rate: Int = 60) : ProjectionEffect(), ProjectionEffectShell.Provider { + + companion object { + const val TAG_RATE = "Rate" + } override val type get() = SoundProjection.effect.get()!! override fun toNbt(tag: CompoundTag) { + tag.putInt(TAG_RATE, rate) } override fun fromNbt(tag: CompoundTag, trusted: Boolean) { + rate = tag.getInt(TAG_RATE) + if (!trusted) { + rate = min(rate, 210) + } } override fun createShell() = buildProjectionEffectShell(this) { + intSlider("quaedam.shell.sound.rate", ::rate, 0..210) } } diff --git a/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonEntity.kt b/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonEntity.kt index e405189..e25d032 100644 --- a/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonEntity.kt +++ b/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonEntity.kt @@ -236,12 +236,14 @@ class ProjectedPersonEntity(entityType: EntityType, level: Le inventory.removeAllItems().forEach(::spawnAtLocation) } + fun findNearbySoundProjection() = + Projector.findNearbyProjections(level(), blockPosition(), SoundProjection.effect.get()).firstOrNull() + override fun isSilent() = - super.isSilent() - && Projector.findNearbyProjections(level(), blockPosition(), SoundProjection.effect.get()).isNotEmpty() + super.isSilent() && findNearbySoundProjection() != null override fun getAmbientSound(): SoundEvent? { - if (Projector.findNearbyProjections(level(), blockPosition(), SoundProjection.effect.get()).isNotEmpty()) { + if (findNearbySoundProjection() != null) { // sound projection available return soundNoise.get() } @@ -252,7 +254,7 @@ class ProjectedPersonEntity(entityType: EntityType, level: Le override fun getVoicePitch() = super.getVoicePitch() * (random.nextFloat() * 0.55f + 0.7f) - override fun getAmbientSoundInterval() = 80 - random.nextInt(700) + override fun getAmbientSoundInterval() = 80 - random.nextInt((findNearbySoundProjection()?.rate ?: 0) * 5) override fun isEffectiveAi() = super.isEffectiveAi() && checkProjectionEffect() diff --git a/common/src/main/resources/assets/quaedam/lang/en_us.json b/common/src/main/resources/assets/quaedam/lang/en_us.json index 10f46b0..50dbd0b 100644 --- a/common/src/main/resources/assets/quaedam/lang/en_us.json +++ b/common/src/main/resources/assets/quaedam/lang/en_us.json @@ -18,5 +18,6 @@ "quaedam.shell.skylight.factor": "Factor", "quaedam.shell.noise.rate": "Rate", "quaedam.shell.noise.amount": "Amount", - "quaedam.shell.swarm.max_count": "Max Count" + "quaedam.shell.swarm.max_count": "Max Count", + "quaedam.shell.sound.rate": "Rate" } \ No newline at end of file diff --git a/common/src/main/resources/assets/quaedam/lang/zh_cn.json b/common/src/main/resources/assets/quaedam/lang/zh_cn.json index 920831e..595ee3d 100644 --- a/common/src/main/resources/assets/quaedam/lang/zh_cn.json +++ b/common/src/main/resources/assets/quaedam/lang/zh_cn.json @@ -18,5 +18,6 @@ "quaedam.shell.skylight.factor": "因子", "quaedam.shell.noise.rate": "速率", "quaedam.shell.noise.amount": "数量", - "quaedam.shell.swarm.max_count": "最大数量" + "quaedam.shell.swarm.max_count": "最大数量", + "quaedam.shell.sound.rate": "速率" }