Class PetDistanceMath

java.lang.Object
de.Keyle.MyPet.api.entity.PetDistanceMath

public final class PetDistanceMath extends Object
The per-pet distance formula, in one place.

A player sets two 5-step scales per pet: a minimum (personal space) and a maximum (follow distance). Every block value is width/2 + gap: half the pet's hitbox width so the threshold clears its own bounding box, plus a step-driven gap. Because every threshold carries the same width/2 offset, the ordering rules between them reduce to rules between the gaps, so a rule that holds for a Wolf holds for an Ender Dragon without per-species special cases.

Pure arithmetic, no Bukkit types: unit-tested in :plugin:test.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    One pet's resolved thresholds, in blocks from the owner.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    Blocks between min (personal space activates below it) and release (follow stops there, personal space releases there).
    static final int
    The step a new pet, and a pre-feature stored pet, starts on.
    static final int
    Largest step of either scale.
    static final double
    Smallest gap-space distance between the two scales after clamping.
    static final int
    Smallest step of either scale.
  • Method Summary

    Modifier and Type
    Method
    Description
    band(int minStep, int maxStep, double width)
    Resolves both scales for one pet.
    static int
    clampStep(int step)
    Forces a step into [MIN_STEP, MAX_STEP]; for API setters and commands.
    static double
    maxDistance(int minStep, int maxStep, double width)
    Follow-distance radius.
    static double
    minDistance(int minStep, double width)
    Personal-space radius for a pet of the given hitbox width.
    static int
    normalizeStep(int step)
    Maps anything outside [MIN_STEP, MAX_STEP] to DEFAULT_STEP; for values read from storage, where a NULL column arrives as 0 and must mean "unset".

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MIN_STEP

      public static final int MIN_STEP
      Smallest step of either scale.
      See Also:
    • MAX_STEP

      public static final int MAX_STEP
      Largest step of either scale.
      See Also:
    • DEFAULT_STEP

      public static final int DEFAULT_STEP
      The step a new pet, and a pre-feature stored pet, starts on.
      See Also:
    • DEADBAND

      public static final double DEADBAND
      Blocks between min (personal space activates below it) and release (follow stops there, personal space releases there). Without it the two goals would hand the pet back and forth every tick at exactly min.
      See Also:
    • MIN_MAX_SEPARATION

      public static final double MIN_MAX_SEPARATION
      Smallest gap-space distance between the two scales after clamping.
      See Also:
  • Method Details

    • clampStep

      public static int clampStep(int step)
      Forces a step into [MIN_STEP, MAX_STEP]; for API setters and commands.
      Parameters:
      step - the requested step
      Returns:
      the nearest valid step
    • normalizeStep

      public static int normalizeStep(int step)
      Maps anything outside [MIN_STEP, MAX_STEP] to DEFAULT_STEP; for values read from storage, where a NULL column arrives as 0 and must mean "unset".
      Parameters:
      step - the stored step
      Returns:
      step when valid, otherwise DEFAULT_STEP
    • minDistance

      public static double minDistance(int minStep, double width)
      Personal-space radius for a pet of the given hitbox width.
      Parameters:
      minStep - the minimum-scale step; clamped into range
      width - the pet's hitbox width in blocks
      Returns:
      the personal-space radius in blocks
    • maxDistance

      public static double maxDistance(int minStep, int maxStep, double width)
      Follow-distance radius. Takes the min step too, because MIN_GAP[5] equals MAX_GAP[1] and the band must never collapse: the max gap is raised to at least minGap + MIN_MAX_SEPARATION.
      Parameters:
      minStep - the minimum-scale step; clamped into range
      maxStep - the maximum-scale step; clamped into range
      width - the pet's hitbox width in blocks
      Returns:
      the follow-distance radius in blocks
    • band

      public static PetDistanceMath.Band band(int minStep, int maxStep, double width)
      Resolves both scales for one pet.
      Parameters:
      minStep - the minimum-scale step; clamped into range
      maxStep - the maximum-scale step; clamped into range
      width - the pet's hitbox width in blocks
      Returns:
      the pet's min, release and max thresholds