Compare commits

...

4 Commits

Author SHA1 Message Date
d110d688c6
fix: only stroll in near positions 2023-08-11 16:00:14 +08:00
6cc16233fa
fix: work poi missing 2023-08-11 15:55:17 +08:00
00ce17cb21
fix: disable despawn for swarm 2023-08-11 15:44:22 +08:00
3a4ad875e2
fix: missing bed memory for swarm 2023-08-11 15:33:25 +08:00
3 changed files with 62 additions and 3 deletions

View File

@ -177,7 +177,8 @@ class ProjectedPersonEntity(entityType: EntityType<out PathfinderMob>, level: Le
Projector.findNearbyProjections(level(), blockPosition(), SwarmProjection.effect.get()).isNotEmpty() Projector.findNearbyProjections(level(), blockPosition(), SwarmProjection.effect.get()).isNotEmpty()
override fun checkDespawn() { override fun checkDespawn() {
super.checkDespawn() // no despawn
// super.checkDespawn()
if (!checkProjectionEffect() && !CausalityAnchor.checkEffect(level(), blockPosition())) { if (!checkProjectionEffect() && !CausalityAnchor.checkEffect(level(), blockPosition())) {
dropEquipment() dropEquipment()
remove(RemovalReason.KILLED) remove(RemovalReason.KILLED)

View File

@ -71,6 +71,7 @@ object ProjectedPersonAI {
MemoryModuleType.CANT_REACH_WALK_TARGET_SINCE, MemoryModuleType.CANT_REACH_WALK_TARGET_SINCE,
MemoryModuleType.HOME, MemoryModuleType.HOME,
MemoryModuleType.LAST_WOKEN, MemoryModuleType.LAST_WOKEN,
MemoryModuleType.NEAREST_BED,
NearestVisibleContainer.memory.get(), NearestVisibleContainer.memory.get(),
) )
} }
@ -158,7 +159,15 @@ object ProjectedPersonAI {
brain.addActivity( brain.addActivity(
Activity.WORK, ImmutableList.of( Activity.WORK, ImmutableList.of(
5 weight ExchangeItem(), 5 weight ExchangeItem(),
10 weight createStrollBehavior(), 7 weight WorkPoiAI.createStrollAroundPoi(),
7 weight WorkPoiAI.createStrollToPoi(),
10 weight RunOne(
mapOf(),
listOf(
1 weightR createStrollBehavior(),
1 weightR WorkPoiAI.createAcquirePoi(),
)
),
) )
) )
} }
@ -182,7 +191,7 @@ object ProjectedPersonAI {
private fun createStrollBehavior() = RunOne( private fun createStrollBehavior() = RunOne(
listOf( listOf(
2 weightR RandomStroll.stroll(1.0f), 2 weightR RandomStroll.stroll(1.0f, 25, 12),
2 weightR SetWalkTargetFromLookTarget.create(1.0f, 5), 2 weightR SetWalkTargetFromLookTarget.create(1.0f, 5),
1 weightR DoNothing(30, 60) 1 weightR DoNothing(30, 60)
) )

View File

@ -0,0 +1,49 @@
package quaedam.projection.swarm.ai
import net.minecraft.core.GlobalPos
import net.minecraft.world.entity.ai.behavior.AcquirePoi
import net.minecraft.world.entity.ai.behavior.StrollAroundPoi
import net.minecraft.world.entity.ai.behavior.StrollToPoi
import net.minecraft.world.entity.ai.memory.MemoryModuleType
import net.minecraft.world.entity.ai.village.poi.PoiTypes
import quaedam.Quaedam
import java.util.*
object WorkPoiAI {
const val ID = "work"
val poiTypes by lazy {
setOf(
PoiTypes.ARMORER,
PoiTypes.BUTCHER,
PoiTypes.CARTOGRAPHER,
PoiTypes.CLERIC,
PoiTypes.FARMER,
PoiTypes.FISHERMAN,
PoiTypes.FLETCHER,
PoiTypes.LEATHERWORKER,
PoiTypes.LIBRARIAN,
PoiTypes.MASON,
PoiTypes.SHEPHERD,
PoiTypes.TOOLSMITH,
PoiTypes.WEAPONSMITH,
PoiTypes.LODESTONE,
PoiTypes.LIGHTNING_ROD,
)
}
val memory = Quaedam.memoryTypes.register(ID) {
MemoryModuleType(Optional.of(GlobalPos.CODEC))
}!!
fun createAcquirePoi() =
AcquirePoi.create({ it.`is` { key -> key in poiTypes } }, memory.get(), false, Optional.empty())
fun createStrollToPoi() =
StrollToPoi.create(memory.get(), 0.4f, 7, 4)
fun createStrollAroundPoi() =
StrollAroundPoi.create(memory.get(), 0.4f, 5)
}