Repository navigation
Creating A Module
github-actions[bot] edited this page Mar 1, 2026
·
1 revision
Step-by-step guide to creating a custom behavior module for SPP.
Create a new class that extends AbstractModule:
package org.scentient.spp.persona.module;
import org.scentient.spp.persona.ActionDecision;
import java.util.Optional;
public class NightShelterModule extends AbstractModule {
@Override
public String id() {
return "night-shelter";
}
@Override
public ActionPriority priority() {
return ActionPriority.OBSERVED;
}
@Override
public Optional<ActionDecision> evaluate(ModuleContext ctx) {
// Only act at night when outdoors
if (!ctx.environment().isNight() || ctx.environment().isInCave()) {
return Optional.empty();
}
// Seek shelter (go home)
if (ctx.position().squaredDistanceTo(ctx.homePosition()) > 100) {
return Optional.of(ActionDecision.moveTo(ctx.homePosition(), "night-go-home"));
}
return Optional.of(ActionDecision.idle("night-at-home"));
}
@Override
public String description() {
return "Returns home at night for safety";
}
}Create config/spp/behavior/night-shelter.json:
{
"enabled": true,
"shelterRadius": 64,
"nightStartTick": 13000
}Override loadConfig() to read custom settings:
@Override
public void loadConfig(JsonObject config) {
if (config != null && config.has("shelterRadius")) {
this.shelterRadius = config.get("shelterRadius").getAsInt();
}
}In PersonaManager.onServerStart(), add:
moduleRegistry.register(new NightShelterModule());- Build:
./gradle-local.sh --no-daemon build -x test - Start server:
./scripts/dev-start.sh - Check registration:
/spp module list - Check details:
/spp module info night-shelter - Toggle:
/spp module disable night-shelter//spp module enable night-shelter
- evaluate() must be fast — under 1ms, never block the server thread
- No state mutation in evaluate() — the ModuleContext is read-only
-
Use factory methods —
ActionDecision.moveTo(),.flee(),.idle(), etc. -
One decision per cycle — return
Optional.empty()if nothing to do -
Multi-tick via tick() — override
tick()and returnTickResult.CONTINUEfor ongoing actions
SPP-AI Wiki
API Reference
- PersonaModule
- AbstractModule
- ActionPriority
- TickResult
- ModuleContext
- WorldSnapshot
- PersonaInventory
- ActionDecision
- BattleCapabilityProvider
Guides
Addon System