Skip to content

Move health plugin logic into a sans-io core - #4168

Open
u9g wants to merge 2 commits into
PrismarineJS:masterfrom
u9g:health-sans-io-core
Open

u9g wants to merge 2 commits into
PrismarineJS:masterfrom
u9g:health-sans-io-core

Conversation

@u9g

@u9g u9g commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

Moves the health plugin's logic into a sans-io core, in two layers:

  • lib/core/health.js: step(config, state, event) -> outputs, with no IO and no packet or version knowledge.
  • lib/core/healthCodec.js: per version, decodes update_health and respawn into core events and encodes the core's outputs into player_loaded / client_command.

lib/plugins/health.js becomes a thin adapter (via lib/core/driver.js) and keeps bot.health, bot.food, bot.foodSaturation, bot.isAlive, bot.respawn() and the spawn/health/death/respawn events as before.

test/healthCoreTest.js needs no server: the core's tests run once, and the codec's tests run per tested version, writing each packet with that version's real schema (minecraft-protocol's serializer) and parsing it back, so a wrong field name fails against the protocol.

lib/core/README.md describes the pattern for converting more plugins.

lib/core/health.js holds health and respawn handling as a plain
step(state, event) -> outputs state machine with no IO. lib/plugins/health.js
becomes a thin adapter that feeds it packets and API calls and keeps
bot.health, bot.food, bot.foodSaturation, bot.isAlive, bot.respawn() and the
spawn/health/death/respawn events as before.

Adds test/healthCoreTest.js (server-free, per tested version) and
lib/core/README.md describing the pattern for converting more plugins.
@u9g
u9g force-pushed the health-sans-io-core branch from dadd1d1 to 8980372 Compare October 5, 2026 17:37
lib/core/healthCodec.js now holds every version difference in packet names
and fields: it decodes update_health and respawn into core events and
encodes the core's clientLoaded and requestRespawn outputs into packets.
The core becomes step(config, state, event) with no version data, and
config (auto-respawn) is kept apart from the changing state.

Core tests run once instead of per version. Codec tests write each packet
with the version's real schema via minecraft-protocol and parse it back,
so a wrong field name fails against the protocol rather than against a
value derived from the same feature flag.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant