From 718bcd1c4fafc709e4354d3381d35a41077d9417 Mon Sep 17 00:00:00 2001 From: xtex Date: Mon, 10 Jul 2023 15:46:48 +0800 Subject: [PATCH] feat: sound projection --- common/src/main/kotlin/quaedam/Quaedam.kt | 2 + .../quaedam/projection/SoundProjection.kt | 52 +++++++++++++++++++ .../projection/swarm/ProjectedPersonEntity.kt | 5 ++ 3 files changed, 59 insertions(+) create mode 100644 common/src/main/kotlin/quaedam/projection/SoundProjection.kt diff --git a/common/src/main/kotlin/quaedam/Quaedam.kt b/common/src/main/kotlin/quaedam/Quaedam.kt index 20c08e3..1c87334 100644 --- a/common/src/main/kotlin/quaedam/Quaedam.kt +++ b/common/src/main/kotlin/quaedam/Quaedam.kt @@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory import quaedam.projection.ProjectionCommand import quaedam.projection.ProjectionEffectType import quaedam.projection.SkylightProjection +import quaedam.projection.SoundProjection import quaedam.projection.swarm.SwarmProjection import quaedam.projector.Projector @@ -42,6 +43,7 @@ object Quaedam { ProjectionEffectType SkylightProjection SwarmProjection + SoundProjection ProjectionCommand creativeModeTabs.register() diff --git a/common/src/main/kotlin/quaedam/projection/SoundProjection.kt b/common/src/main/kotlin/quaedam/projection/SoundProjection.kt new file mode 100644 index 0000000..c506a87 --- /dev/null +++ b/common/src/main/kotlin/quaedam/projection/SoundProjection.kt @@ -0,0 +1,52 @@ +package quaedam.projection + +import net.minecraft.core.BlockPos +import net.minecraft.nbt.CompoundTag +import net.minecraft.server.level.ServerLevel +import net.minecraft.world.item.BlockItem +import net.minecraft.world.item.Item +import net.minecraft.world.level.block.state.BlockState +import quaedam.Quaedam + +object SoundProjection { + + const val ID = "sound_projection" + const val SHORT_ID = "sound" + + val block = Quaedam.blocks.register(ID) { SoundProjectionBlock }!! + + val item = Quaedam.items.register(ID) { + BlockItem( + SoundProjectionBlock, Item.Properties() + .`arch$tab`(Quaedam.creativeModeTab) + ) + }!! + + val effect = Quaedam.projectionEffects.register(SHORT_ID) { + ProjectionEffectType { SoundProjectionEffect } + }!! + +} + +object SoundProjectionBlock : ProjectionBlock(createProperties().lightLevel { 3 }) { + + override fun createProjectionEffect( + level: ServerLevel, + state: BlockState, + pos: BlockPos + ) = SoundProjectionEffect + +} + +object SoundProjectionEffect : ProjectionEffect() { + + override val type + get() = SoundProjection.effect.get()!! + + override fun toNbt(tag: CompoundTag) { + } + + override fun fromNbt(tag: CompoundTag) { + } + +} diff --git a/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonEntity.kt b/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonEntity.kt index 1a14781..6cb6832 100644 --- a/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonEntity.kt +++ b/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonEntity.kt @@ -25,6 +25,7 @@ import net.minecraft.world.entity.npc.InventoryCarrier import net.minecraft.world.level.Level import net.minecraft.world.level.ServerLevelAccessor import quaedam.Quaedam +import quaedam.projection.SoundProjection import quaedam.projection.swarm.ai.ProjectedPersonAI import quaedam.projection.swarm.ai.ProjectedPersonNavigation import quaedam.projector.Projector @@ -228,4 +229,8 @@ class ProjectedPersonEntity(entityType: EntityType, level: Le inventory.removeAllItems().forEach(::spawnAtLocation) } + override fun isSilent() = + super.isSilent() + && Projector.findNearbyProjections(level(), blockPosition(), SoundProjection.effect.get()).isNotEmpty() + } \ No newline at end of file