Skip to content

Registry for custom behaviour with external storage for specific blocks#979

Open
lucasser wants to merge 2 commits intorefinedmods:developfrom
lucasser:feat/customizable-external-storage
Open

Registry for custom behaviour with external storage for specific blocks#979
lucasser wants to merge 2 commits intorefinedmods:developfrom
lucasser:feat/customizable-external-storage

Conversation

@lucasser
Copy link
Contributor

Implements #976

@Nodrance
Copy link
Collaborator

based

@lucasser
Copy link
Contributor Author

Will let us integrate with QIO and AE2 very easily.

@Nodrance
Copy link
Collaborator

"is rs2 or ae2 better" we're doing both now keep up

@raoulvdberge
Copy link
Contributor

raoulvdberge commented Apr 30, 2025

I'm not sure that this will work properly. The external storage API is designed to just be active for all providers all the time, regardless of block type. We can't be block type dependant. The reason for this is: if we are block type dependant, that means you need to reload the storage if the connected block changes (this currently doesn't happen, by design). If you reload when the connected block changes, this causes 2 problems:

  • Items are flickering in the Grid
  • Server strain

Listening to connected block changes isn't bad per se, but some blocks constantly send block updates. See #886
And yes, indeed, interfaces get an exception for the neighbor changed event and do cause a reload.

Regarding possible AE integration:

Refined Storage shouldn't have integration with Applied Energistics, there is no use case for it and encourages people to create weird setups for no reason that create problems.

@raoulvdberge
Copy link
Contributor

If we were to merge this, only for QIO integration, ExternalStorageBlock#neighborChanged needs to be updated as well for block change detection.

@lucasser
Copy link
Contributor Author

I have two solutions. I changed the neighbourChanged method to re initialize if the changed block is in the registry. This might cause problems if the special block always sends updates. The other option is we store the block the storage is currently sitting on, and if it changes:

if (savedBlock.getLootTable().registry() != newBlock.getLootTable().registry()) {
    blockEntity.loadStorage(serverLevel);
} else...

then we change the provider.

@lucasser
Copy link
Contributor Author

I am trying to prevent hardcoded blocks/values so that if there is something else that need a custom provider, it'll be easy to integrate (for example create storage system)

@raoulvdberge
Copy link
Contributor

I have two solutions. I changed the neighbourChanged method to re initialize if the changed block is in the registry. This might cause problems if the special block always sends updates.

Yes, but that is less of a problem since we explicitly whitelist these blocks and can check them.

The other option is we store the block the storage is currently sitting on, and if it changes:

That is bound to cause issues: you have to deal with syncing world state & cache invalidation.

@raoulvdberge
Copy link
Contributor

brokeSpecialBlock should probably check isPresent instead? Please thoroughly test these changes!

I do not want to create more instability in a phase of development where we already have so many bugs.

@lucasser lucasser force-pushed the feat/customizable-external-storage branch from 9fbc450 to 1834b02 Compare April 30, 2025 16:43
@lucasser
Copy link
Contributor Author

Also, this doesn't have to be an urgent thing, I'm just submitting PRs as I finish working on them for you to review whenever you can.

@lucasser lucasser force-pushed the feat/customizable-external-storage branch 2 times, most recently from c8b592a to 1da3a0e Compare August 12, 2025 20:18
@lucasser
Copy link
Contributor Author

Is there a reason for updating external storage provider when an interface/special block is broken as opposed to just update when something is placed

@lucasser lucasser force-pushed the feat/customizable-external-storage branch from 1da3a0e to 6cab5f0 Compare October 21, 2025 15:58
@lucasser
Copy link
Contributor Author

lucasser commented Oct 21, 2025

I updated this PR to 2.0.0, and stress tested. It correctly updates the provider on world load, when a block gets placed, and when a block gets instant replaced in creative mode. The one thing that doesn't work is entangled blocks, since they will load the composite provider when you place it and not update the provider depending on what's inside (but they won't work with an interface either). To fix it there would have to be an EntangledBlockExternalStorageProvider which would correctly update it. Everything else works fine.

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

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants

Comments