This commit is contained in:
xtex 2023-07-02 17:49:14 +08:00
parent 89473d2dcc
commit c3e8a211ad
Signed by: xtex
GPG Key ID: B918086ED8045B91
4 changed files with 16 additions and 15 deletions

View File

@ -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<T : ProjectionEffect>(val constructor: () -> T)
val registryKey: ResourceKey<Registry<ProjectionEffectType<*>>> =
ResourceKey.createRegistryKey(ResourceLocation("quaedam", "projection_effect"))
val registry: Registry<ProjectionEffectType<*>> = BuiltInRegistries.registerSimple(registryKey) { null }
val registry: Registry<ProjectionEffectType<*>> = BuiltInRegistries.registerSimple(registryKey) {
SwarmProjection.effect.get()
}
}

View File

@ -57,12 +57,6 @@ object ProjectedPersonAI {
fun provider(): Brain.Provider<out ProjectedPersonEntity> = Brain.provider(memoryTypes, sensorTypes)
fun initBrain(entity: ProjectedPersonEntity, brain: Brain<ProjectedPersonEntity>) {
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<ProjectedPersonEntity>, 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<ProjectedPersonEntity>) {
brain.addActivity(
Activity.CORE, 0, ImmutableList.of(

View File

@ -80,6 +80,7 @@ class ProjectedPersonEntity(entityType: EntityType<out PathfinderMob>, level: Le
set(value) {
field = value
shapeTag = shape.toTag()
ProjectedPersonAI.updateSchedule(this)
}
override fun onSyncedDataUpdated(data: EntityDataAccessor<*>) {

View File

@ -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) {