Added more entity goals
This commit is contained in:
@@ -13,7 +13,10 @@ class EcoControlledEntity(
|
||||
val craft = handle as? CraftEntity ?: return this
|
||||
val nms = craft.handle as? net.minecraft.world.entity.PathfinderMob ?: return this
|
||||
|
||||
nms.goalSelector.addGoal(priority, goal.getImplementation().generateNMSGoal(goal, nms))
|
||||
nms.goalSelector.addGoal(
|
||||
priority,
|
||||
goal.getImplementation().generateNMSGoal(goal, nms) ?: return this
|
||||
)
|
||||
|
||||
return this
|
||||
}
|
||||
@@ -22,7 +25,9 @@ class EcoControlledEntity(
|
||||
val craft = handle as? CraftEntity ?: return this
|
||||
val nms = craft.handle as? net.minecraft.world.entity.PathfinderMob ?: return this
|
||||
|
||||
nms.targetSelector.addGoal(priority, goal.getImplementation().generateNMSGoal(goal, nms))
|
||||
nms.targetSelector.addGoal(
|
||||
priority, goal.getImplementation().generateNMSGoal(goal, nms) ?: return this
|
||||
)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -21,6 +21,11 @@ import com.willfp.eco.core.entities.ai.goals.entity.EntityGoalOcelotAttack
|
||||
import com.willfp.eco.core.entities.ai.goals.entity.EntityGoalOpenDoors
|
||||
import com.willfp.eco.core.entities.ai.goals.entity.EntityGoalPanic
|
||||
import com.willfp.eco.core.entities.ai.goals.entity.EntityGoalRandomLookAround
|
||||
import com.willfp.eco.core.entities.ai.goals.entity.EntityGoalRandomStroll
|
||||
import com.willfp.eco.core.entities.ai.goals.entity.EntityGoalRandomSwimming
|
||||
import com.willfp.eco.core.entities.ai.goals.entity.EntityGoalRangedAttack
|
||||
import com.willfp.eco.core.entities.ai.goals.entity.EntityGoalRangedBowAttack
|
||||
import com.willfp.eco.core.entities.ai.goals.entity.EntityGoalRangedCrossbowAttack
|
||||
import net.minecraft.world.entity.PathfinderMob
|
||||
import net.minecraft.world.entity.ai.goal.AvoidEntityGoal
|
||||
import net.minecraft.world.entity.ai.goal.BreakDoorGoal
|
||||
@@ -43,6 +48,12 @@ import net.minecraft.world.entity.ai.goal.OcelotAttackGoal
|
||||
import net.minecraft.world.entity.ai.goal.OpenDoorGoal
|
||||
import net.minecraft.world.entity.ai.goal.PanicGoal
|
||||
import net.minecraft.world.entity.ai.goal.RandomLookAroundGoal
|
||||
import net.minecraft.world.entity.ai.goal.RandomStrollGoal
|
||||
import net.minecraft.world.entity.ai.goal.RandomSwimmingGoal
|
||||
import net.minecraft.world.entity.ai.goal.RangedAttackGoal
|
||||
import net.minecraft.world.entity.ai.goal.RangedBowAttackGoal
|
||||
import net.minecraft.world.entity.ai.goal.RangedCrossbowAttackGoal
|
||||
import net.minecraft.world.entity.monster.RangedAttackMob
|
||||
import net.minecraft.world.entity.player.Player
|
||||
|
||||
fun <T : EntityGoal> T.getImplementation(): EcoEntityGoal<T> {
|
||||
@@ -68,12 +79,17 @@ fun <T : EntityGoal> T.getImplementation(): EcoEntityGoal<T> {
|
||||
is EntityGoalOpenDoors -> OpenDoorsImpl
|
||||
is EntityGoalPanic -> PanicImpl
|
||||
is EntityGoalRandomLookAround -> RandomLookAroundImpl
|
||||
is EntityGoalRandomStroll -> RandomStrollImpl
|
||||
is EntityGoalRandomSwimming -> RandomSwimmingImpl
|
||||
is EntityGoalRangedAttack -> RangedAttackImpl
|
||||
is EntityGoalRangedBowAttack -> RangedBowAttackImpl
|
||||
is EntityGoalRangedCrossbowAttack -> RangedCrossbowAttackImpl
|
||||
else -> throw IllegalArgumentException("Unknown API goal!")
|
||||
} as EcoEntityGoal<T>
|
||||
}
|
||||
|
||||
interface EcoEntityGoal<T : EntityGoal> {
|
||||
fun generateNMSGoal(apiGoal: T, entity: PathfinderMob): Goal
|
||||
fun generateNMSGoal(apiGoal: T, entity: PathfinderMob): Goal?
|
||||
}
|
||||
|
||||
object AvoidEntityImpl : EcoEntityGoal<EntityGoalAvoidEntity> {
|
||||
@@ -264,3 +280,58 @@ object RandomLookAroundImpl : EcoEntityGoal<EntityGoalRandomLookAround> {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
object RandomStrollImpl : EcoEntityGoal<EntityGoalRandomStroll> {
|
||||
override fun generateNMSGoal(apiGoal: EntityGoalRandomStroll, entity: PathfinderMob): Goal {
|
||||
return RandomStrollGoal(
|
||||
entity,
|
||||
apiGoal.speed,
|
||||
apiGoal.interval,
|
||||
apiGoal.canDespawn
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
object RandomSwimmingImpl : EcoEntityGoal<EntityGoalRandomSwimming> {
|
||||
override fun generateNMSGoal(apiGoal: EntityGoalRandomSwimming, entity: PathfinderMob): Goal {
|
||||
return RandomSwimmingGoal(
|
||||
entity,
|
||||
apiGoal.speed,
|
||||
apiGoal.interval
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
object RangedAttackImpl : EcoEntityGoal<EntityGoalRangedAttack> {
|
||||
override fun generateNMSGoal(apiGoal: EntityGoalRangedAttack, entity: PathfinderMob): Goal? {
|
||||
return RangedAttackGoal(
|
||||
entity as? RangedAttackMob ?: return null,
|
||||
apiGoal.mobSpeed,
|
||||
apiGoal.minInterval,
|
||||
apiGoal.maxInterval,
|
||||
apiGoal.maxRange.toFloat()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
object RangedBowAttackImpl : EcoEntityGoal<EntityGoalRangedBowAttack> {
|
||||
override fun generateNMSGoal(apiGoal: EntityGoalRangedBowAttack, entity: PathfinderMob): Goal? {
|
||||
return RangedBowAttackGoal(
|
||||
entity.tryCast() ?: return null,
|
||||
apiGoal.speed,
|
||||
apiGoal.attackInterval,
|
||||
apiGoal.range.toFloat()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
object RangedCrossbowAttackImpl : EcoEntityGoal<EntityGoalRangedCrossbowAttack> {
|
||||
override fun generateNMSGoal(apiGoal: EntityGoalRangedCrossbowAttack, entity: PathfinderMob): Goal? {
|
||||
return RangedCrossbowAttackGoal(
|
||||
entity.tryCast() ?: return null,
|
||||
apiGoal.speed,
|
||||
apiGoal.range.toFloat()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.github.benmanes.caffeine.cache.Caffeine
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache
|
||||
import net.minecraft.world.entity.AgeableMob
|
||||
import net.minecraft.world.entity.LivingEntity
|
||||
import net.minecraft.world.entity.PathfinderMob
|
||||
import net.minecraft.world.entity.TamableAnimal
|
||||
import net.minecraft.world.entity.ambient.AmbientCreature
|
||||
import net.minecraft.world.entity.animal.Animal
|
||||
@@ -74,3 +75,8 @@ fun <T : org.bukkit.entity.LivingEntity> Class<T>.toNMSClass(): Class<out Living
|
||||
|
||||
fun LivingEntity.toBukkitEntity(): org.bukkit.entity.LivingEntity? =
|
||||
CraftEntity.getEntity(Bukkit.getServer() as CraftServer, this) as? org.bukkit.entity.LivingEntity
|
||||
|
||||
fun <T> PathfinderMob.tryCast(): T? {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return this as? T
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ fun <T : TargetGoal> T.getImplementation(): EcoTargetGoal<T> {
|
||||
}
|
||||
|
||||
interface EcoTargetGoal<T : TargetGoal> {
|
||||
fun generateNMSGoal(apiGoal: T, entity: PathfinderMob): Goal
|
||||
fun generateNMSGoal(apiGoal: T, entity: PathfinderMob): Goal?
|
||||
}
|
||||
|
||||
object HurtByImpl : EcoTargetGoal<TargetGoalHurtBy> {
|
||||
|
||||
Reference in New Issue
Block a user