refactor: move misc projections to misc package

This commit is contained in:
xtex 2023-07-19 19:49:08 +08:00
parent 60304f5c14
commit 82de489963
Signed by: xtex
GPG Key ID: B918086ED8045B91
7 changed files with 77 additions and 7 deletions

View File

@ -8,8 +8,8 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import quaedam.projection.SkylightProjection; import quaedam.projection.misc.SkylightProjection;
import quaedam.projection.SkylightProjectionEffect; import quaedam.projection.misc.SkylightProjectionEffect;
import quaedam.projector.Projector; import quaedam.projector.Projector;
import java.util.List; import java.util.List;

View File

@ -8,9 +8,11 @@ import net.minecraft.network.chat.Component
import net.minecraft.resources.ResourceLocation import net.minecraft.resources.ResourceLocation
import net.minecraft.world.item.CreativeModeTab import net.minecraft.world.item.CreativeModeTab
import net.minecraft.world.item.ItemStack import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.Items
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import quaedam.projection.* 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.projection.swarm.SwarmProjection
import quaedam.projector.Projector import quaedam.projector.Projector

View File

@ -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<P : ProjectionEffect>(properties: Properties = createProperties()) : Block(properties),
ProjectionProvider<P> {
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() }
}
}
}

View File

@ -1,4 +1,4 @@
package quaedam.projection package quaedam.projection.misc
import net.minecraft.core.BlockPos import net.minecraft.core.BlockPos
import net.minecraft.nbt.CompoundTag 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.item.Item
import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.block.state.BlockState
import quaedam.Quaedam import quaedam.Quaedam
import quaedam.projection.ProjectionBlock
import quaedam.projection.ProjectionEffect
import quaedam.projection.ProjectionEffectType
object NoiseProjection { object NoiseProjection {

View File

@ -1,4 +1,4 @@
package quaedam.projection package quaedam.projection.misc
import net.minecraft.core.BlockPos import net.minecraft.core.BlockPos
import net.minecraft.nbt.CompoundTag 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.item.Item
import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.block.state.BlockState
import quaedam.Quaedam import quaedam.Quaedam
import quaedam.projection.ProjectionBlock
import quaedam.projection.ProjectionEffect
import quaedam.projection.ProjectionEffectType
object SkylightProjection { object SkylightProjection {

View File

@ -1,4 +1,4 @@
package quaedam.projection package quaedam.projection.misc
import net.minecraft.core.BlockPos import net.minecraft.core.BlockPos
import net.minecraft.nbt.CompoundTag 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.item.Item
import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.block.state.BlockState
import quaedam.Quaedam import quaedam.Quaedam
import quaedam.projection.ProjectionBlock
import quaedam.projection.ProjectionEffect
import quaedam.projection.ProjectionEffectType
object SoundProjection { object SoundProjection {

View File

@ -26,7 +26,7 @@ import net.minecraft.world.entity.npc.InventoryCarrier
import net.minecraft.world.level.Level import net.minecraft.world.level.Level
import net.minecraft.world.level.ServerLevelAccessor import net.minecraft.world.level.ServerLevelAccessor
import quaedam.Quaedam import quaedam.Quaedam
import quaedam.projection.SoundProjection import quaedam.projection.misc.SoundProjection
import quaedam.projection.swarm.ai.ProjectedPersonAI import quaedam.projection.swarm.ai.ProjectedPersonAI
import quaedam.projection.swarm.ai.ProjectedPersonNavigation import quaedam.projection.swarm.ai.ProjectedPersonNavigation
import quaedam.projector.Projector import quaedam.projector.Projector