Skip to main content

API & Events

The Pet System fires Hytale events that other mods can listen to for integration. These events use Hytale's native IEvent system.


Events

All events are in the com.kyuubisoft.pets.event package.

PetSpawnedEvent

Fired when a pet NPC is successfully spawned in the world.

public class PetSpawnedEvent implements IEvent<Void> {
public PlayerRef getPlayerRef(); // Owner
public String getPetTypeId(); // Pet type ID (e.g., "wolf")
public String getPetInstanceId(); // Unique instance UUID
}

PetDespawnedEvent

Fired when a pet NPC is despawned (dismissed, owner disconnect, egg dropped, etc.).

public class PetDespawnedEvent implements IEvent<Void> {
public PlayerRef getPlayerRef(); // Owner
public String getPetTypeId(); // Pet type ID
public String getPetInstanceId(); // Unique instance UUID
}

PetLevelUpEvent

Fired when a pet levels up. Includes both the old and new level.

public class PetLevelUpEvent implements IEvent<Void> {
public PlayerRef getPlayerRef(); // Owner
public String getPetTypeId(); // Pet type ID
public String getPetInstanceId(); // Unique instance UUID
public int getOldLevel(); // Level before
public int getNewLevel(); // Level after
}

PetXpGainedEvent

Fired when a pet gains XP from any source.

public class PetXpGainedEvent implements IEvent<Void> {
public PlayerRef getPlayerRef(); // Owner
public String getPetTypeId(); // Pet type ID
public double getAmount(); // XP gained this tick
public double getTotalXp(); // Cumulative total XP earned
}

Listening to Events

To listen to pet events from another mod, use Hytale's event system:

EventBus.get().register(PetLevelUpEvent.class, event -> {
PlayerRef owner = event.getPlayerRef();
int newLevel = event.getNewLevel();
// Your integration logic here
});

Key Data Structures

PetInstance

Represents a single pet owned by a player. Key fields:

FieldTypeDescription
instanceIdStringUnique UUID for this pet instance
petTypeIdStringID of the pet type definition
nicknameStringCustom display name
levelintCurrent level (1-based)
currentXpdoubleXP toward next level
totalXpEarnedlongLifetime XP earned
itemsPickedUplongTotal items collected (collector pets)
mobsKilledlongTotal mobs killed (combat pets)
combatModeString"defensive", "aggressive", or "passive"
statsList<PetStat>Rolled random stats
filterPickupFilterConfigPickup filter rules (collector pets)
createdAtlongTimestamp of creation
lastSummonedlongTimestamp of last summon

PetStat

A single random stat on a pet:

FieldTypeDescription
typeStringStat type ID (e.g., "damage_bonus")
baseValuedoubleValue at level 1
perLeveldoubleGrowth per level
unlockLevelintLevel at which this stat becomes active

Effective value formula:

value = baseValue + (perLevel * (currentLevel - 1))

A stat returns 0 if the pet's level is below the stat's unlockLevel.

PetTypeDefinition

Defines a pet type loaded from JSON. Key fields:

FieldTypeDescription
idStringUnique type identifier
displayNameStringDisplay name
entityTypeIdStringHytale NPC entity type
moduleString"collector", "combat", or "mount"
rarityString"common", "uncommon", "rare", "epic", or "legendary"
maxLevelintMaximum pet level
combatStatsCombatStatsCombat-specific stats (combat module only)
mountConfigMountConfigMount-specific config (mount module only)

Optional Dependencies

The Pet System has no required dependencies but supports optional integration:

DependencyPurpose
KyuubiSoft CoreSmartConfigManager for merge-based config loading
DynamicTooltipsLibEnhanced item tooltips showing pet stats, level, and rarity
hytale:mountsNative mount system integration (declared as optional in manifest)

Database

Pet data is stored in SQLite via the PetDatabase class. Each pet instance is stored with its full state (stats, level, XP, filter config). Player runtime data is cached in-memory with dirty-flag tracking and periodic auto-save (configurable via autoSaveIntervalSeconds).

The database file is located at plugins/Pets/data/pets.db.