nms custom villager and restructuring for teams
This commit is contained in:
21
src/main/kotlin/com/pobnellion/aoe/entity/Villager.kt
Normal file
21
src/main/kotlin/com/pobnellion/aoe/entity/Villager.kt
Normal 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))
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user