From c3e8a211ade8a8c4471ff8098f3be45fa9e53cea Mon Sep 17 00:00:00 2001 From: xtex Date: Sun, 2 Jul 2023 17:49:14 +0800 Subject: [PATCH] fix --- .../quaedam/projection/ProjectionEffect.kt | 5 ++++- .../projection/swarm/ProjectedPersonAI.kt | 17 +++++++++++------ .../projection/swarm/ProjectedPersonEntity.kt | 1 + .../projection/swarm/SwarmProjectionEffect.kt | 8 -------- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/common/src/main/kotlin/quaedam/projection/ProjectionEffect.kt b/common/src/main/kotlin/quaedam/projection/ProjectionEffect.kt index f7e4e3f..0be05b7 100644 --- a/common/src/main/kotlin/quaedam/projection/ProjectionEffect.kt +++ b/common/src/main/kotlin/quaedam/projection/ProjectionEffect.kt @@ -9,6 +9,7 @@ import net.minecraft.resources.ResourceLocation import net.minecraft.server.level.ServerLevel import net.minecraft.world.level.Level import net.minecraft.world.level.block.state.BlockState +import quaedam.projection.swarm.SwarmProjection abstract class ProjectionEffect { @@ -38,7 +39,9 @@ data class ProjectionEffectType(val constructor: () -> T) val registryKey: ResourceKey>> = ResourceKey.createRegistryKey(ResourceLocation("quaedam", "projection_effect")) - val registry: Registry> = BuiltInRegistries.registerSimple(registryKey) { null } + val registry: Registry> = BuiltInRegistries.registerSimple(registryKey) { + SwarmProjection.effect.get() + } } diff --git a/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonAI.kt b/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonAI.kt index 05fc7fd..ee03cd2 100644 --- a/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonAI.kt +++ b/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonAI.kt @@ -57,12 +57,6 @@ object ProjectedPersonAI { fun provider(): Brain.Provider = Brain.provider(memoryTypes, sensorTypes) fun initBrain(entity: ProjectedPersonEntity, brain: Brain) { - if (entity.shape.baby) { - brain.schedule = babySchedule.get() - } else { - brain.schedule = defaultSchedule.get() - } - initCoreActivity(brain) initIdleActivity(brain) initPlayActivity(brain) @@ -70,9 +64,20 @@ object ProjectedPersonAI { initRestActivity(brain) brain.setCoreActivities(setOf(Activity.CORE)) brain.setDefaultActivity(Activity.IDLE) + updateSchedule(entity, brain, baby = false) + } + + fun updateSchedule(entity: ProjectedPersonEntity, brain: Brain, baby: Boolean) { + if (baby) { + brain.schedule = babySchedule.get() + } else { + brain.schedule = defaultSchedule.get() + } brain.updateActivityFromSchedule(entity.level().dayTime, entity.level().gameTime) } + fun updateSchedule(entity: ProjectedPersonEntity) = updateSchedule(entity, entity.brain, entity.shape.baby) + private fun initCoreActivity(brain: Brain) { brain.addActivity( Activity.CORE, 0, ImmutableList.of( diff --git a/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonEntity.kt b/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonEntity.kt index f2f6811..5a905ff 100644 --- a/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonEntity.kt +++ b/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonEntity.kt @@ -80,6 +80,7 @@ class ProjectedPersonEntity(entityType: EntityType, level: Le set(value) { field = value shapeTag = shape.toTag() + ProjectedPersonAI.updateSchedule(this) } override fun onSyncedDataUpdated(data: EntityDataAccessor<*>) { diff --git a/common/src/main/kotlin/quaedam/projection/swarm/SwarmProjectionEffect.kt b/common/src/main/kotlin/quaedam/projection/swarm/SwarmProjectionEffect.kt index f449c61..05120ff 100644 --- a/common/src/main/kotlin/quaedam/projection/swarm/SwarmProjectionEffect.kt +++ b/common/src/main/kotlin/quaedam/projection/swarm/SwarmProjectionEffect.kt @@ -7,14 +7,10 @@ import quaedam.projection.ProjectionEffect data class SwarmProjectionEffect( var maxCount: Int = 10, - var withPlayer: Boolean = true, - var withVillager: Boolean = true ) : ProjectionEffect() { companion object { const val TAG_MAX_COUNT = "MaxCount" - const val TAG_WITH_PLAYER = "WithPlayer" - const val TAG_WITH_VILLAGER = "WithVillager" } override val type @@ -22,14 +18,10 @@ data class SwarmProjectionEffect( override fun toNbt(tag: CompoundTag) { tag.putInt(TAG_MAX_COUNT, maxCount) - tag.putBoolean(TAG_WITH_PLAYER, withPlayer) - tag.putBoolean(TAG_WITH_VILLAGER, withVillager) } override fun fromNbt(tag: CompoundTag) { maxCount = tag.getInt(TAG_MAX_COUNT) - withPlayer = tag.getBoolean(TAG_WITH_PLAYER) - withVillager = tag.getBoolean(TAG_WITH_VILLAGER) } override fun randomTick(level: ServerLevel, pos: BlockPos) {