mirror of
https://hub.spigotmc.org/stash/scm/spigot/bukkit.git
synced 2025-09-18 13:22:51 +00:00
SPIGOT-3531: Add goal ids and custom move towards location goal
This commit is contained in:
parent
9e2701a58b
commit
6e82ba38c8
3 changed files with 320 additions and 8 deletions
|
@ -86,12 +86,10 @@ public interface Mob extends LivingEntity, Lootable {
|
|||
* {@link GoalFactory} Javadoc explains which goals are available for which
|
||||
* entities.
|
||||
*
|
||||
* @param goalName custom goal name, to be used instead of the default one,
|
||||
* can be used to differentiate goals
|
||||
* @return created goal instance
|
||||
*/
|
||||
@NotNull
|
||||
public GoalFactory addGoal(@Nullable String goalName);
|
||||
public GoalFactory addGoal();
|
||||
|
||||
/**
|
||||
* Remove a goal from this entity.
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package org.bukkit.entity.ai;
|
||||
|
||||
import static org.bukkit.NamespacedKey.BUKKIT;
|
||||
import static org.bukkit.NamespacedKey.minecraft;
|
||||
import java.util.Set;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
|
@ -10,12 +13,289 @@ import org.jetbrains.annotations.NotNull;
|
|||
public interface Goal {
|
||||
|
||||
/**
|
||||
* Get goal name.
|
||||
* Attack target entity with arrows.
|
||||
*/
|
||||
NamespacedKey ARROW_ATTACK = minecraft("arrow_attack");
|
||||
/**
|
||||
* Avoid target entity.
|
||||
*/
|
||||
NamespacedKey AVOID_TARGET = minecraft("avoid_target");
|
||||
/**
|
||||
* Beg.
|
||||
*/
|
||||
NamespacedKey BEG = minecraft("beg");
|
||||
/**
|
||||
* Shoot a bow.
|
||||
*/
|
||||
NamespacedKey BOW_SHOOT = minecraft("bow_shoot");
|
||||
/**
|
||||
* Break doors.
|
||||
*/
|
||||
NamespacedKey BREAK_DOOR = minecraft("break_door");
|
||||
/**
|
||||
* Take a breath.
|
||||
*/
|
||||
NamespacedKey BREATH = minecraft("breath");
|
||||
/**
|
||||
* Breed.
|
||||
*/
|
||||
NamespacedKey BREED = minecraft("breed");
|
||||
/**
|
||||
* Climb on top of powdered snow.
|
||||
*/
|
||||
NamespacedKey CLIMB_ON_TOP_OF_POWDER_SNOW = minecraft("climb_on_top_of_powder_snow");
|
||||
/**
|
||||
* Attack target entity with a crossbow.
|
||||
*/
|
||||
NamespacedKey CROSSBOW_ATTACK = minecraft("crossbow_attack");
|
||||
/**
|
||||
* Defend a village.
|
||||
*/
|
||||
NamespacedKey DEFEND_VILLAGE = minecraft("defend_village");
|
||||
/**
|
||||
* Eat a tile.
|
||||
*/
|
||||
NamespacedKey EAT_TILE = minecraft("eat_tile");
|
||||
/**
|
||||
* Follow fish school.
|
||||
*/
|
||||
NamespacedKey FISH_SCHOOL = minecraft("fish_school");
|
||||
/**
|
||||
* Flee sunlight.
|
||||
*/
|
||||
NamespacedKey FLEE_SUN = minecraft("flee_sun");
|
||||
/**
|
||||
* Float in water.
|
||||
*/
|
||||
NamespacedKey FLOAT = minecraft("float");
|
||||
/**
|
||||
* Follow boats.
|
||||
*/
|
||||
NamespacedKey FOLLOW_BOAT = minecraft("follow_boat");
|
||||
/**
|
||||
* Follow entities.
|
||||
*/
|
||||
NamespacedKey FOLLOW_ENTITY = minecraft("follow_entity");
|
||||
/**
|
||||
* Follow owner.
|
||||
*/
|
||||
NamespacedKey FOLLOW_OWNER = minecraft("follow_owner");
|
||||
/**
|
||||
* Follow parent.
|
||||
*/
|
||||
NamespacedKey FOLLOW_PARENT = minecraft("follow_parent");
|
||||
/**
|
||||
* Target the attacking entity.
|
||||
*/
|
||||
NamespacedKey HURT_BY_TARGET = minecraft("hurt_by_target");
|
||||
/**
|
||||
* Stroll towards a villager who needs a golem.
|
||||
*/
|
||||
NamespacedKey STROLL_VILLAGE_GOLEM = minecraft("stroll_village_golem");
|
||||
/**
|
||||
* Jump on block.
|
||||
*/
|
||||
NamespacedKey JUMP_ON_BLOCK = minecraft("jump_on_block");
|
||||
/**
|
||||
* Leap at target.
|
||||
*/
|
||||
NamespacedKey LEAP_AT_TARGET = minecraft("leap_at_target");
|
||||
/**
|
||||
* Follow a llama caravan.
|
||||
*/
|
||||
NamespacedKey LLAMA_FOLLOW = minecraft("llama_follow");
|
||||
/**
|
||||
* Look at an entity.
|
||||
*/
|
||||
NamespacedKey LOOK_AT_PLAYER = minecraft("look_at_player");
|
||||
/**
|
||||
* Look at a trading player.
|
||||
*/
|
||||
NamespacedKey LOOK_AT_TRADING_PLAYER = minecraft("look_at_trading_player");
|
||||
/**
|
||||
* Melee attack.
|
||||
*/
|
||||
NamespacedKey MELEE_ATTACK = minecraft("melee_attack");
|
||||
/**
|
||||
* Move through village.
|
||||
*/
|
||||
NamespacedKey MOVE_THROUGH_VILLAGE = minecraft("move_through_village");
|
||||
/**
|
||||
* Move within a restriction radius.
|
||||
*/
|
||||
NamespacedKey MOVE_TOWARDS_RESTRICTION = minecraft("move_towards_restriction");
|
||||
/**
|
||||
* Move towards target.
|
||||
*/
|
||||
NamespacedKey MOVE_TOWARDS_TARGET = minecraft("move_towards_target");
|
||||
/**
|
||||
* Move towards the nearest village.
|
||||
*/
|
||||
NamespacedKey NEAREST_VILLAGE = minecraft("nearest_village");
|
||||
/**
|
||||
* Target the nearest attackable entity.
|
||||
*/
|
||||
NamespacedKey NEAREST_ATTACKABLE_TARGET = minecraft("nearest_attackable_target");
|
||||
/**
|
||||
* Target the nearest healable raider.
|
||||
*/
|
||||
NamespacedKey NEAREST_HEALABLE_RAIDER = minecraft("nearest_healable_raider");
|
||||
/**
|
||||
* Ocelot specific attack.
|
||||
*/
|
||||
NamespacedKey OCELOT_ATTACK = minecraft("ocelot_attack");
|
||||
/**
|
||||
* Offer flower.
|
||||
*/
|
||||
NamespacedKey OFFER_FLOWER = minecraft("offer_flower");
|
||||
/**
|
||||
* Open doors.
|
||||
*/
|
||||
NamespacedKey DOOR_OPEN = minecraft("door_open");
|
||||
/**
|
||||
* Target entities who hurt the owner.
|
||||
*/
|
||||
NamespacedKey OWNER_HURT_BY_TARGET = minecraft("owner_hurt_by_target");
|
||||
/**
|
||||
* Target entities attacked by the owner.
|
||||
*/
|
||||
NamespacedKey OWNER_HURT_TARGET = minecraft("owner_hurt_target");
|
||||
/**
|
||||
* Panic.
|
||||
*/
|
||||
NamespacedKey PANIC = minecraft("panic");
|
||||
/**
|
||||
* Perch.
|
||||
*/
|
||||
NamespacedKey PERCH = minecraft("perch");
|
||||
/**
|
||||
* Join a raid.
|
||||
*/
|
||||
NamespacedKey RAID = minecraft("raid");
|
||||
/**
|
||||
* Fly randomly.
|
||||
*/
|
||||
NamespacedKey RANDOM_FLY = minecraft("random_fly");
|
||||
/**
|
||||
* Look around randomly.
|
||||
*/
|
||||
NamespacedKey RANDOM_LOOKAROUND = minecraft("random_lookaround");
|
||||
/**
|
||||
* Stand on hind legs.
|
||||
*/
|
||||
NamespacedKey RANDOM_STAND = minecraft("random_stand");
|
||||
/**
|
||||
* Stroll in random directions.
|
||||
*/
|
||||
NamespacedKey RANDOM_STROLL = minecraft("random_stroll");
|
||||
/**
|
||||
* Stroll in random directions on land.
|
||||
*/
|
||||
NamespacedKey RANDOM_STROLL_LAND = minecraft("random_stroll_land");
|
||||
/**
|
||||
* Swim in random directions.
|
||||
*/
|
||||
NamespacedKey RANDOM_SWIM = minecraft("random_swim");
|
||||
/**
|
||||
* Target random entity if not tamed.
|
||||
*/
|
||||
NamespacedKey RANDOM_TARGET_NON_TAMED = minecraft("random_target_non_tamed");
|
||||
/**
|
||||
* Remove block.
|
||||
*/
|
||||
NamespacedKey REMOVE_BLOCK = minecraft("remove_block");
|
||||
/**
|
||||
* Avoid sunlight.
|
||||
*/
|
||||
NamespacedKey RESTRICT_SUN = minecraft("restrict_sun");
|
||||
/**
|
||||
* Sit.
|
||||
*/
|
||||
NamespacedKey SIT = minecraft("sit");
|
||||
/**
|
||||
* Sit on bed.
|
||||
*/
|
||||
NamespacedKey CAT_SIT_ON_BED = minecraft("cat_sit_on_bed");
|
||||
/**
|
||||
* Stroll towards a village.
|
||||
*/
|
||||
NamespacedKey STROLL_VILLAGE = minecraft("stroll_village");
|
||||
/**
|
||||
* Swell.
|
||||
*/
|
||||
NamespacedKey SWELL = minecraft("swell");
|
||||
/**
|
||||
* Tame.
|
||||
*/
|
||||
NamespacedKey TAME = minecraft("tame");
|
||||
/**
|
||||
* Tempt.
|
||||
*/
|
||||
NamespacedKey TEMPT = minecraft("tempt");
|
||||
/**
|
||||
* Trade with a player.
|
||||
*/
|
||||
NamespacedKey TRADE_WITH_PLAYER = minecraft("trade_with_player");
|
||||
/**
|
||||
* Reset universal anger.
|
||||
*/
|
||||
NamespacedKey UNIVERSAL_ANGER_RESET = minecraft("universal_anger_reset");
|
||||
/**
|
||||
* Use an item.
|
||||
*/
|
||||
NamespacedKey USE_ITEM = minecraft("use_item");
|
||||
/**
|
||||
* Move towards water.
|
||||
*/
|
||||
NamespacedKey WATER = minecraft("water");
|
||||
/**
|
||||
* Jump from water.
|
||||
*/
|
||||
NamespacedKey WATER_JUMP = minecraft("water_jump");
|
||||
/**
|
||||
* Zombie attack.
|
||||
*/
|
||||
NamespacedKey ZOMBIE_ATTACK = minecraft("zombie_attack");
|
||||
/**
|
||||
* Move towards a location.
|
||||
*/
|
||||
NamespacedKey MOVE_TOWARDS_LOCATION = new NamespacedKey(BUKKIT, "move_towards_location");
|
||||
/**
|
||||
* Other.
|
||||
*/
|
||||
NamespacedKey OTHER = new NamespacedKey(BUKKIT, "other");
|
||||
|
||||
/**
|
||||
* Get goal key.
|
||||
*
|
||||
* @return goal name
|
||||
* <p>Note: some vanilla goals are not supported in the API.
|
||||
* {@link Goal#OTHER} will be returned in such cases.
|
||||
*
|
||||
* @return goal key
|
||||
*/
|
||||
@NotNull
|
||||
String getName();
|
||||
NamespacedKey getId();
|
||||
|
||||
/**
|
||||
* Set goal id.
|
||||
*
|
||||
* @param id new goal id
|
||||
*/
|
||||
void setId(@NotNull NamespacedKey id);
|
||||
|
||||
/**
|
||||
* Check whether this goal is currently enabled.
|
||||
*
|
||||
* @return whether this goal is enabled
|
||||
*/
|
||||
boolean isEnabled();
|
||||
|
||||
/**
|
||||
* Enable or disable this goal.
|
||||
*
|
||||
* @param enabled whether this goal should be enabled
|
||||
*/
|
||||
void setEnabled(boolean enabled);
|
||||
|
||||
/**
|
||||
* Get goal priority. The lower the value, the higher the priority. Goals
|
||||
|
|
|
@ -3,9 +3,12 @@ package org.bukkit.entity.ai;
|
|||
import java.util.Set;
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import org.bukkit.Difficulty;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.Tag;
|
||||
|
@ -70,7 +73,7 @@ public interface GoalFactory {
|
|||
Goal beg(int priority, float lookDistance);
|
||||
|
||||
/**
|
||||
* Shoow a bow.
|
||||
* Shoot a bow.
|
||||
*
|
||||
* <p>Note: this goal is only applicable to monsters capable of shooting
|
||||
* a bow.
|
||||
|
@ -867,15 +870,46 @@ public interface GoalFactory {
|
|||
@NotNull
|
||||
Goal zombieAttack(int priority, double speed, boolean followWithoutLineOfSight);
|
||||
|
||||
/**
|
||||
* Move towards a given location.
|
||||
*
|
||||
* @param priority goal priority
|
||||
* @param speed speed modifier
|
||||
* @param maxDistance maximum distance from the target location
|
||||
* @param interval average interval between attempts to follow this goal
|
||||
* @param location target location
|
||||
* @return created goal
|
||||
*/
|
||||
@NotNull
|
||||
Goal moveTowardsLocation(int priority, double speed, float maxDistance, int interval, @NotNull Location location);
|
||||
|
||||
/**
|
||||
* Move towards a given location.
|
||||
*
|
||||
* <p>Note: this goal will not be used if {@code locationFunction} returns
|
||||
* {@code null}. You can use this to conditionally enable this goal, e.g.
|
||||
* in a specific dimension.
|
||||
*
|
||||
* @param priority goal priority
|
||||
* @param speed speed modifier
|
||||
* @param maxDistance maximum distance from the target location
|
||||
* @param interval average interval between attempts to follow this goal
|
||||
* @param locationFunction location function
|
||||
* @return created goal
|
||||
*/
|
||||
@NotNull
|
||||
Goal moveTowardsLocation(int priority, double speed, float maxDistance, int interval, @NotNull Function<Mob, Location> locationFunction);
|
||||
|
||||
/**
|
||||
* Create a custom goal.
|
||||
*
|
||||
* @param goalId goal id
|
||||
* @param priority goal priority
|
||||
* @param customGoalRegistration goal definition
|
||||
* @return created goal
|
||||
*/
|
||||
@NotNull
|
||||
Goal custom(int priority, @NotNull CustomGoalRegistration customGoalRegistration);
|
||||
Goal custom(@NotNull NamespacedKey goalId, int priority, @NotNull CustomGoalRegistration customGoalRegistration);
|
||||
|
||||
/**
|
||||
* Custom goal definition.
|
||||
|
|
Loading…
Add table
Reference in a new issue