From 5b9fffe14ab5350a6774aa3043f63a87ce841fef Mon Sep 17 00:00:00 2001 From: Auxilor Date: Mon, 2 Sep 2024 11:52:48 +0100 Subject: [PATCH] Fixed nearest_attackable target goal --- .../target/TargetGoalNearestAttackable.java | 21 ++++++++++++------- .../com/willfp/eco/core/entities/Entities.kt | 3 +++ .../proxy/common/ai/EcoEntityController.kt | 2 -- .../ai/target/NearestAttackableGoalFactory.kt | 5 ++++- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/eco-api/src/main/java/com/willfp/eco/core/entities/ai/target/TargetGoalNearestAttackable.java b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/target/TargetGoalNearestAttackable.java index 16bea3bba..01dc407d3 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/entities/ai/target/TargetGoalNearestAttackable.java +++ b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/target/TargetGoalNearestAttackable.java @@ -11,19 +11,22 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.List; +import java.util.Set; import java.util.function.Predicate; +import java.util.stream.Collectors; /** * Allows an entity to attack the closest target within a given subset of specific target types. * - * @param target The type of entities to attack. + * @param targets The type of entities to attack. * @param checkVisibility If visibility should be checked. * @param checkCanNavigate If navigation should be checked. * @param reciprocalChance 1 in reciprocalChance chance of not activating on any tick. * @param targetFilter The filter for targets to match. */ public record TargetGoalNearestAttackable( - @NotNull TestableEntity target, + @NotNull Set targets, boolean checkVisibility, boolean checkCanNavigate, int reciprocalChance, @@ -32,16 +35,16 @@ public record TargetGoalNearestAttackable( /** * Create a new target goal. * - * @param target The type of entities to attack. + * @param targets The type of entities to attack. * @param checkVisibility If visibility should be checked. * @param checkCanNavigate If navigation should be checked. * @param reciprocalChance 1 in reciprocalChance chance of not activating on any tick. */ - public TargetGoalNearestAttackable(@NotNull final TestableEntity target, + public TargetGoalNearestAttackable(@NotNull final Set targets, final boolean checkVisibility, final boolean checkCanNavigate, final int reciprocalChance) { - this(target, checkVisibility, checkCanNavigate, reciprocalChance, it -> true); + this(targets, checkVisibility, checkCanNavigate, reciprocalChance, it -> true); } /** @@ -65,11 +68,15 @@ public TargetGoalNearestAttackable deserialize(@NotNull final Config config) { return null; } + Set targets = config.getStrings("target").stream() + .map(Entities::lookup) + .collect(Collectors.toSet()); + if (config.has("targetFilter")) { TestableEntity filter = Entities.lookup(config.getString("targetFilter")); return new TargetGoalNearestAttackable( - Entities.lookup(config.getString("target")), + targets, config.getBool("checkVisibility"), config.getBool("checkCanNavigate"), config.getInt("reciprocalChance"), @@ -77,7 +84,7 @@ public TargetGoalNearestAttackable deserialize(@NotNull final Config config) { ); } else { return new TargetGoalNearestAttackable( - Entities.lookup(config.getString("target")), + targets, config.getBool("checkVisibility"), config.getBool("checkCanNavigate"), config.getInt("reciprocalChance") diff --git a/eco-api/src/main/kotlin/com/willfp/eco/core/entities/Entities.kt b/eco-api/src/main/kotlin/com/willfp/eco/core/entities/Entities.kt index 7bb9d8b98..409f70c7d 100644 --- a/eco-api/src/main/kotlin/com/willfp/eco/core/entities/Entities.kt +++ b/eco-api/src/main/kotlin/com/willfp/eco/core/entities/Entities.kt @@ -3,7 +3,10 @@ package com.willfp.eco.core.entities import com.willfp.eco.core.entities.ai.EntityController +import com.willfp.eco.core.items.Items +import com.willfp.eco.core.items.TestableItem import org.bukkit.entity.Mob +import org.bukkit.inventory.ItemStack /** @see EntityController.getFor */ val T.controller: EntityController diff --git a/eco-core/core-nms/common/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/ai/EcoEntityController.kt b/eco-core/core-nms/common/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/ai/EcoEntityController.kt index 2f770d6e8..077807348 100644 --- a/eco-core/core-nms/common/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/ai/EcoEntityController.kt +++ b/eco-core/core-nms/common/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/ai/EcoEntityController.kt @@ -54,8 +54,6 @@ class EcoEntityController( priority, goal.getGoalFactory()?.create(goal, nms) ?: return this ) - nms.targetSelector - return this } diff --git a/eco-core/core-nms/common/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/ai/target/NearestAttackableGoalFactory.kt b/eco-core/core-nms/common/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/ai/target/NearestAttackableGoalFactory.kt index b1fcdbbf1..bc607d5eb 100644 --- a/eco-core/core-nms/common/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/ai/target/NearestAttackableGoalFactory.kt +++ b/eco-core/core-nms/common/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/ai/target/NearestAttackableGoalFactory.kt @@ -1,6 +1,7 @@ package com.willfp.eco.internal.spigot.proxy.common.ai.target import com.willfp.eco.core.entities.ai.target.TargetGoalNearestAttackable +import com.willfp.eco.core.lookup.matches import com.willfp.eco.internal.spigot.proxy.common.ai.TargetGoalFactory import com.willfp.eco.internal.spigot.proxy.common.toBukkitEntity import net.minecraft.world.entity.LivingEntity @@ -17,7 +18,9 @@ object NearestAttackableGoalFactory : TargetGoalFactory t.matches(bukkit) } } }