Skip to content

Fix NPE in EnergyStorageItemBlockEnergyContainer when itemAccess is null#1665

Merged
rubensworks merged 1 commit intomaster-26from
copilot/fix-crash-issue
Apr 19, 2026
Merged

Fix NPE in EnergyStorageItemBlockEnergyContainer when itemAccess is null#1665
rubensworks merged 1 commit intomaster-26from
copilot/fix-crash-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 19, 2026

inventoryTick was obtaining the energy capability with null as the ItemAccess context, which propagated into EnergyStorageItemBlockEnergyContainer.itemAccess = null. When the auto-supply tick triggered extract() with a live TransactionContext, setItemStackEnergy would crash calling itemAccess.exchange().

Change

  • Pass ItemAccess.forStack(itemStack) instead of null in inventoryTick, consistent with every other capability lookup in the codebase.
// Before
EnergyHandler energyStorage = itemStack.getCapability(Capabilities.Energy.ITEM, null);

// After
EnergyHandler energyStorage = itemStack.getCapability(Capabilities.Energy.ITEM, ItemAccess.forStack(itemStack));

@rubensworks rubensworks marked this pull request as ready for review April 19, 2026 11:59
@rubensworks rubensworks merged commit 602a030 into master-26 Apr 19, 2026
5 of 6 checks passed
@rubensworks rubensworks deleted the copilot/fix-crash-issue branch April 19, 2026 12:02
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.

2 participants