feat: rate parameter for sound projection
This commit is contained in:
@@ -6,7 +6,10 @@ import net.minecraft.world.item.context.BlockPlaceContext
|
|||||||
import net.minecraft.world.level.BlockGetter
|
import net.minecraft.world.level.BlockGetter
|
||||||
import net.minecraft.world.level.Level
|
import net.minecraft.world.level.Level
|
||||||
import net.minecraft.world.level.LevelAccessor
|
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.BlockState
|
||||||
import net.minecraft.world.level.block.state.StateDefinition
|
import net.minecraft.world.level.block.state.StateDefinition
|
||||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties
|
||||||
|
@@ -6,7 +6,10 @@ import net.minecraft.world.item.context.BlockPlaceContext
|
|||||||
import net.minecraft.world.level.BlockGetter
|
import net.minecraft.world.level.BlockGetter
|
||||||
import net.minecraft.world.level.Level
|
import net.minecraft.world.level.Level
|
||||||
import net.minecraft.world.level.LevelAccessor
|
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.BlockState
|
||||||
import net.minecraft.world.level.block.state.StateDefinition
|
import net.minecraft.world.level.block.state.StateDefinition
|
||||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties
|
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.level.material.MapColor
|
||||||
import net.minecraft.world.phys.shapes.CollisionContext
|
import net.minecraft.world.phys.shapes.CollisionContext
|
||||||
import net.minecraft.world.phys.shapes.Shapes
|
import net.minecraft.world.phys.shapes.Shapes
|
||||||
import net.minecraft.world.phys.shapes.VoxelShape
|
|
||||||
|
|
||||||
object RSBlock : HorizontalDirectionalBlock(
|
object RSBlock : HorizontalDirectionalBlock(
|
||||||
Properties.of()
|
Properties.of()
|
||||||
|
@@ -10,6 +10,7 @@ import quaedam.projection.ProjectionEffectType
|
|||||||
import quaedam.projection.SimpleProjectionEntity
|
import quaedam.projection.SimpleProjectionEntity
|
||||||
import quaedam.shell.ProjectionEffectShell
|
import quaedam.shell.ProjectionEffectShell
|
||||||
import quaedam.shell.buildProjectionEffectShell
|
import quaedam.shell.buildProjectionEffectShell
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
object SoundProjection {
|
object SoundProjection {
|
||||||
|
|
||||||
@@ -26,11 +27,11 @@ object SoundProjection {
|
|||||||
}!!
|
}!!
|
||||||
|
|
||||||
val effect = Quaedam.projectionEffects.register(SHORT_ID) {
|
val effect = Quaedam.projectionEffects.register(SHORT_ID) {
|
||||||
ProjectionEffectType { SoundProjectionEffect }
|
ProjectionEffectType { SoundProjectionEffect() }
|
||||||
}!!
|
}!!
|
||||||
|
|
||||||
val blockEntity = Quaedam.blockEntities.register(ID) {
|
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
|
override val type
|
||||||
get() = SoundProjection.effect.get()!!
|
get() = SoundProjection.effect.get()!!
|
||||||
|
|
||||||
override fun toNbt(tag: CompoundTag) {
|
override fun toNbt(tag: CompoundTag) {
|
||||||
|
tag.putInt(TAG_RATE, rate)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fromNbt(tag: CompoundTag, trusted: Boolean) {
|
override fun fromNbt(tag: CompoundTag, trusted: Boolean) {
|
||||||
|
rate = tag.getInt(TAG_RATE)
|
||||||
|
if (!trusted) {
|
||||||
|
rate = min(rate, 210)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createShell() = buildProjectionEffectShell(this) {
|
override fun createShell() = buildProjectionEffectShell(this) {
|
||||||
|
intSlider("quaedam.shell.sound.rate", ::rate, 0..210)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -236,12 +236,14 @@ class ProjectedPersonEntity(entityType: EntityType<out PathfinderMob>, level: Le
|
|||||||
inventory.removeAllItems().forEach(::spawnAtLocation)
|
inventory.removeAllItems().forEach(::spawnAtLocation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun findNearbySoundProjection() =
|
||||||
|
Projector.findNearbyProjections(level(), blockPosition(), SoundProjection.effect.get()).firstOrNull()
|
||||||
|
|
||||||
override fun isSilent() =
|
override fun isSilent() =
|
||||||
super.isSilent()
|
super.isSilent() && findNearbySoundProjection() != null
|
||||||
&& Projector.findNearbyProjections(level(), blockPosition(), SoundProjection.effect.get()).isNotEmpty()
|
|
||||||
|
|
||||||
override fun getAmbientSound(): SoundEvent? {
|
override fun getAmbientSound(): SoundEvent? {
|
||||||
if (Projector.findNearbyProjections(level(), blockPosition(), SoundProjection.effect.get()).isNotEmpty()) {
|
if (findNearbySoundProjection() != null) {
|
||||||
// sound projection available
|
// sound projection available
|
||||||
return soundNoise.get()
|
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 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()
|
override fun isEffectiveAi() = super.isEffectiveAi() && checkProjectionEffect()
|
||||||
|
|
||||||
|
@@ -18,5 +18,6 @@
|
|||||||
"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.swarm.max_count": "Max Count"
|
"quaedam.shell.swarm.max_count": "Max Count",
|
||||||
|
"quaedam.shell.sound.rate": "Rate"
|
||||||
}
|
}
|
@@ -18,5 +18,6 @@
|
|||||||
"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.swarm.max_count": "最大数量"
|
"quaedam.shell.swarm.max_count": "最大数量",
|
||||||
|
"quaedam.shell.sound.rate": "速率"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user