Interface Skill
- All Known Subinterfaces:
Armor,Backpack,Beacon,Behavior,Bleed,Camouflage,Climb,Control,Damage,Fire,Fishing,Heal,Knockback,Life,Lightning,Lumberjack,Mining,Pickup,Poison,Potion,Ranged,Ride,Scale,Shield,Slow,Sniff,Sprint,Stomp,Taunt,Thorns,Toolbox,Wither
Each skill has a name (derived from the SkillName annotation on its implementation
class), belongs to a specific pet, and can be activated/deactivated as the pet gains levels
and receives upgrades from its Skilltree.
Skills report their current status through toPrettyComponent(String) (for
display to the player) and may optionally expose internal state via getState().
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidapplyState(SkillState state) Absorbs a previously persistedSkillStateback into the live skill's mutable fields.default StringgetName()Returns the internal name of this skill, as declared in itsSkillNameannotation.default ComponentReturns the localized display name of this skill for the given locale.getPet()Returns the pet that owns this skill instance.default Optional<? extends SkillState> getState()Returns this skill's current runtime state as a typedSkillStaterecord, orOptional.empty()if the skill has no persisted state worth exposing (the default — most skills' behavior is fully driven by skilltree upgrade levels).Returns the message components to display to the player when this skill receives an upgrade.booleanisActive()Returnstrueif this skill has been activated (i.e., at least one upgrade has been applied).voidreset()Resets this skill to its initial inactive state, undoing all upgrades.toPrettyComponent(String locale) Builds a human-readable component summarizing this skill's current state for display in the pet's skill info panel.
-
Method Details
-
getName
Returns the internal name of this skill, as declared in itsSkillNameannotation.- Returns:
- the skill name, or
nullif the annotation is missing
-
getName
Returns the localized display name of this skill for the given locale.If the skill's
SkillNameannotation specifies atranslationNode, the localized component for that node is returned. Falls back to the annotation'svalue()if no node is defined.- Parameters:
locale- the locale code to translate into- Returns:
- the display name component, or
nullif the annotation is missing
-
getPet
Pet getPet()Returns the pet that owns this skill instance.- Returns:
- the pet this skill instance belongs to
-
isActive
boolean isActive()Returnstrueif this skill has been activated (i.e., at least one upgrade has been applied).- Returns:
trueif the skilltree has granted this skill at the pet's level
-
reset
void reset()Resets this skill to its initial inactive state, undoing all upgrades. -
toPrettyComponent
Builds a human-readable component summarizing this skill's current state for display in the pet's skill info panel.- Parameters:
locale- the player's locale code for translation- Returns:
- a formatted text component
-
getUpgradeMessage
Component[] getUpgradeMessage()Returns the message components to display to the player when this skill receives an upgrade.- Returns:
- an array of text components (one per line), or an empty array if silent
-
getState
Returns this skill's current runtime state as a typedSkillStaterecord, orOptional.empty()if the skill has no persisted state worth exposing (the default — most skills' behavior is fully driven by skilltree upgrade levels).Implementations should construct a fresh, immutable record each call from their current fields. Used by
StoredPet#skillStateon the live-pet branch (the persisted-pet branch consults the registeredSkillStateCodecinstead). A skill that registers a codec must also implement this method — MyPet callsgetState()to obtain the state the codec serializes to NBT.- Returns:
- the state to persist, or empty when this skill stores nothing
-
applyState
Absorbs a previously persistedSkillStateback into the live skill's mutable fields. Called by MyPet on activation (and on pet-type change) when aSkillStateCodecis registered for this skill — the codec produces the state from NBT, this method writes it onto the skill instance.Codec-using skills should narrow
stateto their registered state type and apply it. The default is a no-op so skills that don't persist mutable runtime state can ignore it entirely.- Parameters:
state- the previously persisted state to restore
-