Skip to content

Fix battery capacity reverting to default on world reload#1667

Merged
rubensworks merged 1 commit intomaster-26from
copilot/fix-battery-revert-bug
Apr 20, 2026
Merged

Fix battery capacity reverting to default on world reload#1667
rubensworks merged 1 commit intomaster-26from
copilot/fix-battery-revert-bug

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 20, 2026

Battery capacity (set via crafting multiple batteries together) was silently discarded on save/load — SimpleEnergyHandler.serialize() only persists energy, not capacity. On reload, the block entity's energy handler was re-constructed with the default 1M capacity, capping stored energy even when the actual capacity was higher.

Changes

  • SimpleEnergyHandlerCapacity: Override serialize/deserialize to also persist the capacity field. Deserialize falls back to the current (constructor-provided) value when the field is absent, preserving backward compatibility with existing saves.
@Override
public void serialize(ValueOutput output) {
    super.serialize(output);
    output.putInt("capacity", capacity);
}

@Override
public void deserialize(ValueInput input) {
    super.deserialize(input);
    capacity = Math.max(0, input.getIntOr("capacity", capacity));
}
  • GameTestsBattery: Add testBatteryCapacityPersistence — sets a 2× capacity handler with energy above the default cap, round-trips through serialize/deserialize, asserts both capacity and energy are preserved.

@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 53.974% (+0.03%) from 53.947% — copilot/fix-battery-revert-bug into master-26

@rubensworks rubensworks marked this pull request as ready for review April 20, 2026 16:38
@rubensworks rubensworks merged commit e563929 into master-26 Apr 20, 2026
7 checks passed
@rubensworks rubensworks deleted the copilot/fix-battery-revert-bug branch April 20, 2026 16:51
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.

3 participants