feat: rate parameter for sound projection

This commit is contained in:
xtex 2023-07-29 16:35:36 +08:00
parent 249d060075
commit 519060ca23
Signed by: xtex
GPG Key ID: B918086ED8045B91
6 changed files with 32 additions and 12 deletions

View File

@ -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

View File

@ -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()

View File

@ -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<SoundProjectionEffect>(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)
}
}

View File

@ -236,12 +236,14 @@ class ProjectedPersonEntity(entityType: EntityType<out PathfinderMob>, 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<out PathfinderMob>, 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()

View File

@ -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"
}

View File

@ -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": "速率"
}