From 82de489963ea25dadbe7e4067d3c3243a95fed2f Mon Sep 17 00:00:00 2001 From: xtex Date: Wed, 19 Jul 2023 19:49:08 +0800 Subject: [PATCH] refactor: move misc projections to misc package --- .../java/quaedam/mixin/MixinClientLevel.java | 4 +- common/src/main/kotlin/quaedam/Quaedam.kt | 4 +- .../projection/EntityProjectionBlock.kt | 59 +++++++++++++++++++ .../projection/{ => misc}/NoiseProjection.kt | 5 +- .../{ => misc}/SkylightProjection.kt | 5 +- .../projection/{ => misc}/SoundProjection.kt | 5 +- .../projection/swarm/ProjectedPersonEntity.kt | 2 +- 7 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 common/src/main/kotlin/quaedam/projection/EntityProjectionBlock.kt rename common/src/main/kotlin/quaedam/projection/{ => misc}/NoiseProjection.kt (89%) rename common/src/main/kotlin/quaedam/projection/{ => misc}/SkylightProjection.kt (90%) rename common/src/main/kotlin/quaedam/projection/{ => misc}/SoundProjection.kt (88%) diff --git a/common/src/main/java/quaedam/mixin/MixinClientLevel.java b/common/src/main/java/quaedam/mixin/MixinClientLevel.java index d7ff37a..ce4a133 100644 --- a/common/src/main/java/quaedam/mixin/MixinClientLevel.java +++ b/common/src/main/java/quaedam/mixin/MixinClientLevel.java @@ -8,8 +8,8 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import quaedam.projection.SkylightProjection; -import quaedam.projection.SkylightProjectionEffect; +import quaedam.projection.misc.SkylightProjection; +import quaedam.projection.misc.SkylightProjectionEffect; import quaedam.projector.Projector; import java.util.List; diff --git a/common/src/main/kotlin/quaedam/Quaedam.kt b/common/src/main/kotlin/quaedam/Quaedam.kt index 14b6355..0dcd5f6 100644 --- a/common/src/main/kotlin/quaedam/Quaedam.kt +++ b/common/src/main/kotlin/quaedam/Quaedam.kt @@ -8,9 +8,11 @@ import net.minecraft.network.chat.Component import net.minecraft.resources.ResourceLocation import net.minecraft.world.item.CreativeModeTab import net.minecraft.world.item.ItemStack -import net.minecraft.world.item.Items import org.slf4j.LoggerFactory import quaedam.projection.* +import quaedam.projection.misc.NoiseProjection +import quaedam.projection.misc.SkylightProjection +import quaedam.projection.misc.SoundProjection import quaedam.projection.swarm.SwarmProjection import quaedam.projector.Projector diff --git a/common/src/main/kotlin/quaedam/projection/EntityProjectionBlock.kt b/common/src/main/kotlin/quaedam/projection/EntityProjectionBlock.kt new file mode 100644 index 0000000..6a0dbe2 --- /dev/null +++ b/common/src/main/kotlin/quaedam/projection/EntityProjectionBlock.kt @@ -0,0 +1,59 @@ +package quaedam.projection + +import net.minecraft.core.BlockPos +import net.minecraft.world.entity.LivingEntity +import net.minecraft.world.item.ItemStack +import net.minecraft.world.level.Level +import net.minecraft.world.level.LevelAccessor +import net.minecraft.world.level.block.Block +import net.minecraft.world.level.block.state.BlockState +import net.minecraft.world.level.material.MapColor +import net.minecraft.world.level.storage.loot.LootParams +import quaedam.projector.ProjectorBlockEntity +import quaedam.utils.getChunksNearby + +abstract class EntityProjectionBlock

(properties: Properties = createProperties()) : Block(properties), + ProjectionProvider

{ + + companion object { + fun createProperties(): Properties = Properties.of() + .strength(3.5f) + .requiresCorrectToolForDrops() + .mapColor(MapColor.COLOR_GRAY) + + fun findNearbyProjectors(level: Level, pos: BlockPos) = level.getChunksNearby(pos, 1) + .flatMap { + it.blockEntities.filter { (_, v) -> v is ProjectorBlockEntity } + .keys + .filterNotNull() + } + .toSet() + + } + + @Suppress("OVERRIDE_DEPRECATION") + override fun getDrops(blockState: BlockState, builder: LootParams.Builder) = listOf(ItemStack(asItem())) + + override fun setPlacedBy( + level: Level, + pos: BlockPos, + state: BlockState, + placer: LivingEntity?, + itemStack: ItemStack + ) { + super.setPlacedBy(level, pos, state, placer, itemStack) + if (!level.isClientSide) { + findNearbyProjectors(level, pos) + .forEach { (level.getBlockEntity(it) as ProjectorBlockEntity).checkUpdate() } + } + } + + override fun destroy(level: LevelAccessor, pos: BlockPos, state: BlockState) { + super.destroy(level, pos, state) + if (level is Level && !level.isClientSide) { + findNearbyProjectors(level, pos) + .forEach { (level.getBlockEntity(it) as ProjectorBlockEntity).checkUpdate() } + } + } + +} diff --git a/common/src/main/kotlin/quaedam/projection/NoiseProjection.kt b/common/src/main/kotlin/quaedam/projection/misc/NoiseProjection.kt similarity index 89% rename from common/src/main/kotlin/quaedam/projection/NoiseProjection.kt rename to common/src/main/kotlin/quaedam/projection/misc/NoiseProjection.kt index a70ab76..de01ff1 100644 --- a/common/src/main/kotlin/quaedam/projection/NoiseProjection.kt +++ b/common/src/main/kotlin/quaedam/projection/misc/NoiseProjection.kt @@ -1,4 +1,4 @@ -package quaedam.projection +package quaedam.projection.misc import net.minecraft.core.BlockPos import net.minecraft.nbt.CompoundTag @@ -7,6 +7,9 @@ import net.minecraft.world.item.BlockItem import net.minecraft.world.item.Item import net.minecraft.world.level.block.state.BlockState import quaedam.Quaedam +import quaedam.projection.ProjectionBlock +import quaedam.projection.ProjectionEffect +import quaedam.projection.ProjectionEffectType object NoiseProjection { diff --git a/common/src/main/kotlin/quaedam/projection/SkylightProjection.kt b/common/src/main/kotlin/quaedam/projection/misc/SkylightProjection.kt similarity index 90% rename from common/src/main/kotlin/quaedam/projection/SkylightProjection.kt rename to common/src/main/kotlin/quaedam/projection/misc/SkylightProjection.kt index 7b3274f..3cdb562 100644 --- a/common/src/main/kotlin/quaedam/projection/SkylightProjection.kt +++ b/common/src/main/kotlin/quaedam/projection/misc/SkylightProjection.kt @@ -1,4 +1,4 @@ -package quaedam.projection +package quaedam.projection.misc import net.minecraft.core.BlockPos import net.minecraft.nbt.CompoundTag @@ -7,6 +7,9 @@ import net.minecraft.world.item.BlockItem import net.minecraft.world.item.Item import net.minecraft.world.level.block.state.BlockState import quaedam.Quaedam +import quaedam.projection.ProjectionBlock +import quaedam.projection.ProjectionEffect +import quaedam.projection.ProjectionEffectType object SkylightProjection { diff --git a/common/src/main/kotlin/quaedam/projection/SoundProjection.kt b/common/src/main/kotlin/quaedam/projection/misc/SoundProjection.kt similarity index 88% rename from common/src/main/kotlin/quaedam/projection/SoundProjection.kt rename to common/src/main/kotlin/quaedam/projection/misc/SoundProjection.kt index c506a87..b0f7de7 100644 --- a/common/src/main/kotlin/quaedam/projection/SoundProjection.kt +++ b/common/src/main/kotlin/quaedam/projection/misc/SoundProjection.kt @@ -1,4 +1,4 @@ -package quaedam.projection +package quaedam.projection.misc import net.minecraft.core.BlockPos import net.minecraft.nbt.CompoundTag @@ -7,6 +7,9 @@ import net.minecraft.world.item.BlockItem import net.minecraft.world.item.Item import net.minecraft.world.level.block.state.BlockState import quaedam.Quaedam +import quaedam.projection.ProjectionBlock +import quaedam.projection.ProjectionEffect +import quaedam.projection.ProjectionEffectType object SoundProjection { diff --git a/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonEntity.kt b/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonEntity.kt index 8fe767b..0bc7f0b 100644 --- a/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonEntity.kt +++ b/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonEntity.kt @@ -26,7 +26,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.misc.SoundProjection import quaedam.projection.swarm.ai.ProjectedPersonAI import quaedam.projection.swarm.ai.ProjectedPersonNavigation import quaedam.projector.Projector