Skip to content

Conversation

@Atopona
Copy link

@Atopona Atopona commented Dec 27, 2025

Pull Request Checklist

Please review and complete all items before submitting your pull request:

  • I have thoroughly tested the changes and verified they work as expected.
  • The code follows the coding standards and best practices of the project.
  • I have reviewed the changes for potential security or performance issues.

MIT License Confirmation

  • I confirm that all code included in this PR is compatible with the MIT License.
  • I understand and accept that, by submitting this pull request, all contributions are permanently licensed under the MIT License, and I waive any rights to revoke or change the license in the future.

Description

Crash Cause

ModularAccumulatorBlockEntity.handlerForCapability() has a recursive call defect.

When getControllerBE() returns this under certain conditions (e.g., level == null or chunk not loaded) while isController() returns false, it causes handlerForCapability() to infinitely recurse, resulting in a StackOverflowError.

Fix Summary

Added controllerBE != this check in handlerForCapability() to prevent the method from recursively calling itself.

// Before
private InternalEnergyStorage handlerForCapability() {
    return isController() ? energyCapability
        : (getControllerBE() != null
            ? getControllerBE().handlerForCapability()
            : new InternalEnergyStorage(0, ...));
}

// After
private InternalEnergyStorage handlerForCapability() {
    if (isController()) return energyCapability;

    ModularAccumulatorBlockEntity controllerBE = getControllerBE();
    if (controllerBE != null && controllerBE != this) {
        return controllerBE.handlerForCapability();
    }

    return new InternalEnergyStorage(0, ...);
}

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