Package de.Keyle.MyPet.api.skill
Interface SkillStateCodec<T extends SkillState>
- Type Parameters:
T- the state record this codec reads and writes
public interface SkillStateCodec<T extends SkillState>
Bundles the write and read halves of a skill's persisted state into one
object. Both directions share one set of NBT key/type literals — a typo
in one cannot drift from the other.
With a codec, both directions share one set of key/type literals. The
codec is registered once per skill via
SkillManager.registerCodec(Class, Class, SkillStateCodec); MyPet
then drives all NBT round-trips through it:
- Persist — MyPet calls
Skill.getState(), narrows the result to the codec's state type, and callswrite(SkillState)to produce the per-skill compound stored underskillInfo. - Activate — MyPet calls
read(CompoundBinaryTag)and hands the resulting state toSkill.applyState(SkillState)so the live skill can rebuild its mutable fields. - Query a stored pet —
StoredPet#skillStateconsults the codec to materialize the typed state from the persisted compound.
read(CompoundBinaryTag) should return Optional.empty()
when the compound is empty or missing required fields rather than throwing
— callers treat both as "no persisted state for this skill".
-
Method Summary
Modifier and TypeMethodDescriptionread(CompoundBinaryTag compound) Reads a skill's state back.Writes a skill's state out for persistence.
-
Method Details
-
write
Writes a skill's state out for persistence.- Parameters:
state- the state to write- Returns:
- the state as NBT
-
read
Reads a skill's state back.- Parameters:
compound- the persisted NBT- Returns:
- the state, or empty when the compound holds nothing for this skill
-