From 5ae62c00d0326cdf22a116a31b0f1e08a2419b0b Mon Sep 17 00:00:00 2001 From: xtex Date: Sun, 2 Jul 2023 11:55:38 +0800 Subject: [PATCH] feat: navigate in projected area --- .../projection/swarm/ProjectedPersonEntity.kt | 2 ++ .../swarm/ProjectedPersonNavigation.kt | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonNavigation.kt diff --git a/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonEntity.kt b/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonEntity.kt index 0fa33e2..e5741f5 100644 --- a/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonEntity.kt +++ b/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonEntity.kt @@ -104,4 +104,6 @@ class ProjectedPersonEntity(entityType: EntityType, level: Le override fun getNameTagOffsetY() = super.getNameTagOffsetY() - (BOUNDING_HEIGHT * (1.2f - shape.scaleY)) + override fun createNavigation(level: Level) = ProjectedPersonNavigation(this, level) + } \ No newline at end of file diff --git a/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonNavigation.kt b/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonNavigation.kt new file mode 100644 index 0000000..d10779f --- /dev/null +++ b/common/src/main/kotlin/quaedam/projection/swarm/ProjectedPersonNavigation.kt @@ -0,0 +1,18 @@ +package quaedam.projection.swarm + +import net.minecraft.core.BlockPos +import net.minecraft.world.entity.ai.navigation.GroundPathNavigation +import net.minecraft.world.level.Level +import net.minecraft.world.level.pathfinder.Path +import quaedam.projector.Projector + +class ProjectedPersonNavigation(val entity: ProjectedPersonEntity, level: Level) : GroundPathNavigation(entity, level) { + + override fun createPath(set: MutableSet, i: Int, bl: Boolean, j: Int, f: Float): Path? { + if (set.any { Projector.findNearbyProjections(level, it, SwarmProjection.effect.get()).isEmpty() }) { + return null + } + return super.createPath(set, i, bl, j, f) + } + +} \ No newline at end of file