Class PetGoalRetention

java.lang.Object
de.Keyle.MyPet.api.goal.PetGoalRetention

public final class PetGoalRetention extends Object
Per-pet-type declaration of vanilla Bukkit goals that PetGoalInstaller should keep on the live mob at spawn time, instead of stripping every goal via Bukkit.getMobGoals().removeAllGoals(mob).

The default behavior — when no PetGoalRetention is declared for a pet type — is to strip every vanilla goal. This works for pets whose vanilla AI MyPet replaces entirely with its own goals (Wolf, Pig, Camel, etc.). But some pet types have vanilla goals that are uniquely valuable (e.g., Phantom's PhantomCircleAroundAnchorGoal translates the per-tick setAnchorLocation into orbit motion via moveTargetPoint; stripping it leaves the phantom flying toward Vec3.ZERO). Declaring a retention list keeps those goals intact.

Declared as a static field on the matching PetXxx class:


 public static final PetGoalRetention GOAL_RETENTION = new PetGoalRetention(
         "Phantom",
         "phantom_circle_around_anchor");
 

Construction self-registers with PetGoalRetentionRegistry. PetGoalInstaller consults the registry per spawned pet and removes only the goals whose key isn't in the retention set.

Goal names are the path part of the vanilla GoalKey's NamespacedKey (i.e., the snake_case identifier without the minecraft: namespace). Match by name avoids per-mob Goal subclass typing concerns and is stable across Mojang's occasional reorganization of vanilla goal classes.

The set of names is stored in declaration order (a LinkedHashSet) for stable log output if the installer ever logs retained goals.

  • Constructor Details

    • PetGoalRetention

      public PetGoalRetention(String petType, String... goalKeyNames)
      Declares the goals to keep for one pet type, registering itself as it is built.
      Parameters:
      petType - the pet type these goals belong to
      goalKeyNames - namespaced vanilla goal keys to keep on the live mob
  • Method Details

    • petType

      public String petType()
      Returns the pet type this declaration applies to.
      Returns:
      the pet type name
    • goalKeyNames

      public Set<String> goalKeyNames()
      Returns the goals to keep, in declaration order.
      Returns:
      an immutable set of vanilla goal-key names