nms custom villager and restructuring for teams

This commit is contained in:
ruby
2025-01-05 01:27:42 +13:00
parent 35c7124451
commit f8825d535f
17 changed files with 347 additions and 162 deletions

View File

@ -0,0 +1,21 @@
package com.pobnellion.aoe.entity
import com.pobnellion.aoe.building.Building
import com.pobnellion.aoe.entity.goals.GoToBuildingGoal
import net.minecraft.world.entity.EntityType
import net.minecraft.world.entity.npc.Villager
import org.bukkit.Location
import org.bukkit.craftbukkit.CraftWorld
class AoeVillager(location: Location) : Villager(EntityType.VILLAGER, (location.world as CraftWorld).handle) {
init {
setPos(location.x, location.y, location.z)
level().addFreshEntity(this)
targetSelector.removeAllGoals { true }
}
fun goToBuilding(building: Building) {
targetSelector.addGoal(0, GoToBuildingGoal(this, building, 1.0))
}
}

View File

@ -0,0 +1,35 @@
package com.pobnellion.aoe.entity.goals
import com.pobnellion.aoe.building.Building
import net.minecraft.world.entity.PathfinderMob
import net.minecraft.world.entity.ai.goal.Goal
import java.util.*
class GoToBuildingGoal(
private val mob: PathfinderMob,
private val building: Building,
private var speedModifier: Double
): Goal() {
private var recalculateTicks = 0
init {
this.setFlags(EnumSet.of(Flag.MOVE, Flag.JUMP))
}
override fun canUse(): Boolean {
return true
}
override fun start() {
mob.navigation.moveTo(building.location.x, building.location.y, building.location.z, speedModifier)
}
override fun tick() {
recalculateTicks++
if (recalculateTicks % 40 == 0)
mob.navigation.moveTo(building.location.x, building.location.y, building.location.z, speedModifier)
}
override fun requiresUpdateEveryTick(): Boolean = true
}