Added more goals, added shorthand goal syntax, added kotlin extension for entity controllers
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.willfp.eco.core.entities.ai;
|
||||
|
||||
import org.bukkit.entity.Mob;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A goal for entity AI.
|
||||
@@ -8,5 +9,16 @@ import org.bukkit.entity.Mob;
|
||||
* @param <T> The type of mob that the goal can be applied to.
|
||||
*/
|
||||
public interface EntityGoal<T extends Mob> {
|
||||
|
||||
/**
|
||||
* Add the entity goal to an entity.
|
||||
*
|
||||
* @param entity The entity.
|
||||
* @param priority The priority.
|
||||
* @return The entity, modified.
|
||||
*/
|
||||
default T addToEntity(@NotNull T entity, int priority) {
|
||||
return EntityController.of(entity)
|
||||
.addEntityGoal(priority, this)
|
||||
.getEntity();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.willfp.eco.core.entities.ai;
|
||||
|
||||
import org.bukkit.entity.Mob;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A goal for entity target AI.
|
||||
@@ -8,5 +9,16 @@ import org.bukkit.entity.Mob;
|
||||
* @param <T> The type of mob that the goal can be applied to.
|
||||
*/
|
||||
public interface TargetGoal<T extends Mob> {
|
||||
|
||||
/**
|
||||
* Add the target goal to an entity.
|
||||
*
|
||||
* @param entity The entity.
|
||||
* @param priority The priority.
|
||||
* @return The entity, modified.
|
||||
*/
|
||||
default T addToEntity(@NotNull T entity, int priority) {
|
||||
return EntityController.of(entity)
|
||||
.addTargetGoal(priority, this)
|
||||
.getEntity();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.willfp.eco.core.entities.ai.target;
|
||||
|
||||
import com.willfp.eco.core.entities.ai.TargetGoal;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* Target random non-tame entity.
|
||||
*
|
||||
* @param targetClass The types of entities to heal.
|
||||
* @param checkVisibility If visibility should be checked.
|
||||
* @param targetFilter The filter for targets to match.
|
||||
*/
|
||||
public record TargetGoalNonTameRandom(
|
||||
@NotNull Class<? extends LivingEntity> targetClass,
|
||||
boolean checkVisibility,
|
||||
@NotNull Predicate<LivingEntity> targetFilter
|
||||
) implements TargetGoal<Tameable> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.willfp.eco.core.entities.ai.target;
|
||||
|
||||
import com.willfp.eco.core.entities.ai.TargetGoal;
|
||||
import org.bukkit.entity.Tameable;
|
||||
|
||||
/**
|
||||
* Target last entity that hurt the owner.
|
||||
*/
|
||||
public record TargetGoalOwnerHurt(
|
||||
) implements TargetGoal<Tameable> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.willfp.eco.core.entities.ai.target;
|
||||
|
||||
import com.willfp.eco.core.entities.ai.TargetGoal;
|
||||
import org.bukkit.entity.Tameable;
|
||||
|
||||
/**
|
||||
* Target entity that hurt the owner.
|
||||
*/
|
||||
public record TargetGoalOwnerHurtBy(
|
||||
) implements TargetGoal<Tameable> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.willfp.eco.core.entities.ai.target;
|
||||
|
||||
import com.willfp.eco.core.entities.ai.TargetGoal;
|
||||
import org.bukkit.entity.Mob;
|
||||
|
||||
/**
|
||||
* Reset universal anger.
|
||||
* <p>
|
||||
* Can only be applied to neutral mobs.
|
||||
*
|
||||
* @param triggerOthers If this should cause other nearby entities to trigger.
|
||||
*/
|
||||
public record TargetGoalResetUniversalAnger(
|
||||
boolean triggerOthers
|
||||
) implements TargetGoal<Mob> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
@file:JvmName("EntityExtensions")
|
||||
|
||||
package com.willfp.eco.core.entities
|
||||
|
||||
import com.willfp.eco.core.entities.ai.EntityController
|
||||
import org.bukkit.entity.Mob
|
||||
|
||||
/**
|
||||
* @see EntityController.of
|
||||
*/
|
||||
val <T : Mob> T.controller: EntityController<T>
|
||||
get() = EntityController.of(this)
|
||||
@@ -6,10 +6,16 @@ import com.willfp.eco.core.entities.ai.target.TargetGoalHurtBy
|
||||
import com.willfp.eco.core.entities.ai.target.TargetGoalNearestAttackable
|
||||
import com.willfp.eco.core.entities.ai.target.TargetGoalNearestAttackableWitch
|
||||
import com.willfp.eco.core.entities.ai.target.TargetGoalNearestHealableRaider
|
||||
import com.willfp.eco.core.entities.ai.target.TargetGoalNonTameRandom
|
||||
import com.willfp.eco.core.entities.ai.target.TargetGoalOwnerHurt
|
||||
import com.willfp.eco.core.entities.ai.target.TargetGoalOwnerHurtBy
|
||||
import com.willfp.eco.internal.spigot.proxy.common.ai.target.HurtByGoalFactory
|
||||
import com.willfp.eco.internal.spigot.proxy.common.ai.target.NearestAttackableGoalFactory
|
||||
import com.willfp.eco.internal.spigot.proxy.common.ai.target.NearestAttackableWitchGoalFactory
|
||||
import com.willfp.eco.internal.spigot.proxy.common.ai.target.NearestHealableRaiderGoalFactory
|
||||
import com.willfp.eco.internal.spigot.proxy.common.ai.target.NonTameRandomGoalFactory
|
||||
import com.willfp.eco.internal.spigot.proxy.common.ai.target.OwnerHurtByGoalFactory
|
||||
import com.willfp.eco.internal.spigot.proxy.common.ai.target.OwnerHurtGoalFactory
|
||||
import com.willfp.eco.internal.spigot.proxy.common.commonsProvider
|
||||
import net.minecraft.world.entity.PathfinderMob
|
||||
import net.minecraft.world.entity.ai.goal.Goal
|
||||
@@ -26,6 +32,9 @@ fun <T : TargetGoal<*>> T.getGoalFactory(): TargetGoalFactory<T>? {
|
||||
is TargetGoalNearestAttackable -> NearestAttackableGoalFactory
|
||||
is TargetGoalNearestAttackableWitch -> NearestAttackableWitchGoalFactory
|
||||
is TargetGoalNearestHealableRaider -> NearestHealableRaiderGoalFactory
|
||||
is TargetGoalNonTameRandom -> NonTameRandomGoalFactory
|
||||
is TargetGoalOwnerHurtBy -> OwnerHurtByGoalFactory
|
||||
is TargetGoalOwnerHurt -> OwnerHurtGoalFactory
|
||||
is CustomGoal<*> -> CustomGoalFactory
|
||||
else -> null
|
||||
} as TargetGoalFactory<T>?
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.common.ai.target
|
||||
|
||||
import com.willfp.eco.core.entities.ai.target.TargetGoalNonTameRandom
|
||||
import com.willfp.eco.internal.spigot.proxy.common.ai.TargetGoalFactory
|
||||
import com.willfp.eco.internal.spigot.proxy.common.ai.toBukkitEntity
|
||||
import com.willfp.eco.internal.spigot.proxy.common.ai.toNMSClass
|
||||
import net.minecraft.world.entity.PathfinderMob
|
||||
import net.minecraft.world.entity.TamableAnimal
|
||||
import net.minecraft.world.entity.ai.goal.Goal
|
||||
import net.minecraft.world.entity.ai.goal.target.NonTameRandomTargetGoal
|
||||
|
||||
object NonTameRandomGoalFactory : TargetGoalFactory<TargetGoalNonTameRandom> {
|
||||
override fun create(apiGoal: TargetGoalNonTameRandom, entity: PathfinderMob): Goal? {
|
||||
return NonTameRandomTargetGoal(
|
||||
entity as? TamableAnimal ?: return null,
|
||||
apiGoal.targetClass.toNMSClass(),
|
||||
apiGoal.checkVisibility,
|
||||
) {
|
||||
apiGoal.targetFilter.test(it.toBukkitEntity())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.common.ai.target
|
||||
|
||||
import com.willfp.eco.core.entities.ai.target.TargetGoalOwnerHurtBy
|
||||
import com.willfp.eco.internal.spigot.proxy.common.ai.TargetGoalFactory
|
||||
import net.minecraft.world.entity.PathfinderMob
|
||||
import net.minecraft.world.entity.TamableAnimal
|
||||
import net.minecraft.world.entity.ai.goal.Goal
|
||||
import net.minecraft.world.entity.ai.goal.target.OwnerHurtByTargetGoal
|
||||
|
||||
object OwnerHurtByGoalFactory : TargetGoalFactory<TargetGoalOwnerHurtBy> {
|
||||
override fun create(apiGoal: TargetGoalOwnerHurtBy, entity: PathfinderMob): Goal? {
|
||||
return OwnerHurtByTargetGoal(
|
||||
entity as? TamableAnimal ?: return null
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.common.ai.target
|
||||
|
||||
import com.willfp.eco.core.entities.ai.target.TargetGoalOwnerHurt
|
||||
import com.willfp.eco.internal.spigot.proxy.common.ai.TargetGoalFactory
|
||||
import net.minecraft.world.entity.PathfinderMob
|
||||
import net.minecraft.world.entity.TamableAnimal
|
||||
import net.minecraft.world.entity.ai.goal.Goal
|
||||
import net.minecraft.world.entity.ai.goal.target.OwnerHurtTargetGoal
|
||||
|
||||
object OwnerHurtGoalFactory : TargetGoalFactory<TargetGoalOwnerHurt> {
|
||||
override fun create(apiGoal: TargetGoalOwnerHurt, entity: PathfinderMob): Goal? {
|
||||
return OwnerHurtTargetGoal(
|
||||
entity as? TamableAnimal ?: return null
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.common.ai.target
|
||||
|
||||
import com.willfp.eco.core.entities.ai.target.TargetGoalResetUniversalAnger
|
||||
import com.willfp.eco.internal.spigot.proxy.common.ai.TargetGoalFactory
|
||||
import net.minecraft.world.entity.NeutralMob
|
||||
import net.minecraft.world.entity.PathfinderMob
|
||||
import net.minecraft.world.entity.ai.goal.Goal
|
||||
import net.minecraft.world.entity.ai.goal.target.ResetUniversalAngerTargetGoal
|
||||
|
||||
object ResetUniversalAngerGoalFactory : TargetGoalFactory<TargetGoalResetUniversalAnger> {
|
||||
override fun create(apiGoal: TargetGoalResetUniversalAnger, entity: PathfinderMob): Goal? {
|
||||
if (entity !is NeutralMob) return null
|
||||
|
||||
return ResetUniversalAngerTargetGoal(
|
||||
entity,
|
||||
apiGoal.triggerOthers
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user