Skip to content

feat: add NeoForge storage adapters#369

Open
AdolfoCarneiro wants to merge 3 commits into
Indemnity83:mc/26.1from
AdolfoCarneiro:pr/neoforge-storage-adapters
Open

feat: add NeoForge storage adapters#369
AdolfoCarneiro wants to merge 3 commits into
Indemnity83:mc/26.1from
AdolfoCarneiro:pr/neoforge-storage-adapters

Conversation

@AdolfoCarneiro
Copy link
Copy Markdown
Contributor

Summary

Part 1 of the NeoForge runtime wiring stack.

Adds NeoForge equivalents for the Fabric storage adapters so common code can interact with NeoForge item, fluid, and energy APIs through the existing loader-agnostic abstractions.

Changes

  • Add NeoForgeItemStorage and NeoForgeItemKey.
  • Add NeoForgeFluidStorage and NeoForgeFluidKey.
  • Add NeoForgeEnergyStorage.
  • Wire NeoForgeEnergyCapabilityLookup to NeoForge energy capabilities.
  • Ignore generated local run/build artifacts so test output is not accidentally tracked.

Notes

This PR intentionally does not register capabilities yet. It only adds the adapter layer needed by the next PR in the stack.

Validation

Validated on the final stack:

  • ./gradlew :neoforge:build
  • ./gradlew :fabric:build
  • ./gradlew spotlessCheck
  • ./gradlew :neoforge:runServer reached Done without recipe parse errors

@AdolfoCarneiro AdolfoCarneiro marked this pull request as ready for review May 16, 2026 19:58
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 16, 2026

Review Change Stack

Warning

Rate limit exceeded

@AdolfoCarneiro has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 44 minutes and 12 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 96118972-ac0a-46eb-a77c-12d1a37a9385

📥 Commits

Reviewing files that changed from the base of the PR and between 9703b9f and aa84efd.

📒 Files selected for processing (1)
  • neoforge/src/main/java/com/logistics/neoforge/energy/NeoForgeEnergyStorage.java
📝 Walkthrough

Walkthrough

This PR introduces complete NeoForge adapter implementations for three resource types: energy, fluids, and items. Each resource type receives a key wrapper class (e.g., NeoForgeEnergyStorage, NeoForgeFluidKey, NeoForgeItemKey) that bridges the common interfaces to NeoForge's resource abstractions. The storage adapters wrap NeoForge handlers using snapshot-journal transaction semantics to stage changes via pending deltas and commit only on non-simulated operations. The energy capability lookup is updated to perform actual queries and wrap results. Build configuration is updated to ignore generated mod development directories.

Possibly related PRs

  • Indemnity83/logistics#349: Introduces the common IItemKey/IItemStorage contract that is directly implemented by NeoForgeItemKey and NeoForgeItemStorage in this PR.
  • Indemnity83/logistics#351: Introduces the common IFluidKey/IFluidStorage contract that is directly implemented by NeoForgeFluidKey and NeoForgeFluidStorage in this PR.
  • Indemnity83/logistics#360: Introduces the stubbed energy wiring that this PR replaces with functional NeoForgeEnergyStorage and updates to NeoForgeEnergyCapabilityLookup.find.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add NeoForge storage adapters' accurately captures the main change, which is adding NeoForge storage adapter implementations.
Description check ✅ Passed The description clearly explains the PR's purpose as Part 1 of the NeoForge runtime wiring stack, detailing all major additions and validation performed.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
neoforge/src/main/java/com/logistics/neoforge/storage/NeoForgeItemStorage.java (1)

34-62: 💤 Low value

Consider reusing the transaction-checking pattern from NeoForgeEnergyStorage.

NeoForgeEnergyStorage uses an openTransaction() helper that checks for an existing transaction and opens a nested transaction if one is already open. Here, Transaction.openRoot() is always called, which could break atomicity if these methods are ever invoked within an existing NeoForge transaction context (the new root would commit independently).

For consistency and future-proofing, consider extracting the same helper pattern:

private static Transaction openTransaction() {
    TransactionContext current = Transaction.getCurrentOpenedTransaction();
    return current == null ? Transaction.openRoot() : Transaction.open(current);
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@neoforge/src/main/java/com/logistics/neoforge/storage/NeoForgeItemStorage.java`
around lines 34 - 62, The insert/extract methods call Transaction.openRoot()
directly which can break atomicity when invoked inside an existing transaction;
add a private static Transaction openTransaction() helper (as used in
NeoForgeEnergyStorage) that checks Transaction.getCurrentOpenedTransaction() and
returns Transaction.openRoot() or Transaction.open(current) accordingly, then
replace all Transaction.openRoot() calls in insert(IItemKey...),
extract(IItemKey...) with openTransaction() so these methods join existing
transactions instead of always starting a new root.
neoforge/src/main/java/com/logistics/neoforge/energy/NeoForgeEnergyStorage.java (1)

144-153: 💤 Low value

Consider validating commit result to detect unexpected shortfalls.

If the capacity calculation bug above is fixed, this should be safe. However, if for any reason the actual storage.insert or storage.extract returns less than delta, the discrepancy is silently ignored. Consider logging or asserting that the returned value matches expectations for debugging purposes in development builds.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@neoforge/src/main/java/com/logistics/neoforge/energy/NeoForgeEnergyStorage.java`
around lines 144 - 153, The onRootCommit method applies pendingDelta to storage
but ignores the returned amount from storage.insert and storage.extract, so
shortfalls are silently dropped; update onRootCommit to capture the returned
long from storage.insert(delta, false) and storage.extract(-delta, false) and
then compare it to the expected delta (pendingDelta/original calculation) and in
development builds either assert equality or log an error showing expected vs
actual (use a descriptive message including pendingDelta, delta, and the
returned amount) so unexpected shortfalls are detected for debugging; keep the
existing behavior in production but ensure the debug/assert path triggers when
values differ.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@neoforge/src/main/java/com/logistics/neoforge/energy/NeoForgeEnergyStorage.java`:
- Around line 114-122: The insert method is not accounting for already-staged
inserts (pendingDelta) and can over-stage; fix NeoForgeEnergyStorage.insert by
computing the actual insertable amount as the simulated storage.insert(amount,
true) minus the current pendingDelta (use getAmountAsLong() or pendingDelta to
reference staged amount), clamp that to >=0, then add that computed inserted
long to pendingDelta and return clampToInt(inserted); keep calling
updateSnapshots(transaction) first and preserve types and clampToInt usage so
commit sees the correct staged total.

---

Nitpick comments:
In
`@neoforge/src/main/java/com/logistics/neoforge/energy/NeoForgeEnergyStorage.java`:
- Around line 144-153: The onRootCommit method applies pendingDelta to storage
but ignores the returned amount from storage.insert and storage.extract, so
shortfalls are silently dropped; update onRootCommit to capture the returned
long from storage.insert(delta, false) and storage.extract(-delta, false) and
then compare it to the expected delta (pendingDelta/original calculation) and in
development builds either assert equality or log an error showing expected vs
actual (use a descriptive message including pendingDelta, delta, and the
returned amount) so unexpected shortfalls are detected for debugging; keep the
existing behavior in production but ensure the debug/assert path triggers when
values differ.

In
`@neoforge/src/main/java/com/logistics/neoforge/storage/NeoForgeItemStorage.java`:
- Around line 34-62: The insert/extract methods call Transaction.openRoot()
directly which can break atomicity when invoked inside an existing transaction;
add a private static Transaction openTransaction() helper (as used in
NeoForgeEnergyStorage) that checks Transaction.getCurrentOpenedTransaction() and
returns Transaction.openRoot() or Transaction.open(current) accordingly, then
replace all Transaction.openRoot() calls in insert(IItemKey...),
extract(IItemKey...) with openTransaction() so these methods join existing
transactions instead of always starting a new root.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0f08bf6d-9775-4332-af38-f37a81019a05

📥 Commits

Reviewing files that changed from the base of the PR and between 9941b54 and 9703b9f.

📒 Files selected for processing (7)
  • .gitignore
  • neoforge/src/main/java/com/logistics/neoforge/energy/NeoForgeEnergyCapabilityLookup.java
  • neoforge/src/main/java/com/logistics/neoforge/energy/NeoForgeEnergyStorage.java
  • neoforge/src/main/java/com/logistics/neoforge/fluids/NeoForgeFluidKey.java
  • neoforge/src/main/java/com/logistics/neoforge/fluids/NeoForgeFluidStorage.java
  • neoforge/src/main/java/com/logistics/neoforge/storage/NeoForgeItemKey.java
  • neoforge/src/main/java/com/logistics/neoforge/storage/NeoForgeItemStorage.java

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