Skip to content

Conversation

danth
Copy link
Contributor

@danth danth commented May 25, 2025

There seems to be an area of chunks where Level.isLoaded returns false, but PostboxBlockEntity.onChunkUnloaded has not yet been called. Any trains delivering to that area will use the offline buffer, but when the block entity is eventually unloaded, it will overwrite the delivered packages with an older version of the inventory, causing them to be lost.

I made the following changes to fix this:

  • Sync the offline buffer whenever the inventory changes, rather than in onChunkUnloaded.
  • Fix StationBlockEntity.attachPackagePort incorrectly replacing GlobalPackagePort instances with new ones, resetting their data.
  • During mail transfer, get the Level from ServerLifecycleHooks rather than CarriageContraptionEntity: this ensures a loaded postbox will always be discovered, regardless of whether the train itself is loaded.

Fixes #7491 (see my comment there for how to reproduce the bug)

Verified

This commit was signed with the committer’s verified signature.
danth Daniel Thwaites
There seems to be an area of chunks where `Level.isLoaded` returns
`false`, but `PostboxBlockEntity.onChunkUnloaded` has not yet been
called. Any trains delivering to that area will use the offline buffer,
but when the block entity is eventually unloaded, it will overwrite the
delivered packages with an older version of the inventory, causing them
to be lost.

I made the following changes to fix this:

- Sync the offline buffer whenever the inventory changes, rather than
  in `onChunkUnloaded`.
- Fix `StationBlockEntity.attachPackagePort` incorrectly replacing
  `GlobalPackagePort` instances with new ones, resetting their data.
- During mail transfer, get the `Level` from `ServerLifecycleHooks`
  rather than `CarriageContraptionEntity`: this ensures a loaded
  postbox will always be discovered, regardless of whether the train
  itself is loaded.

Fixes Creators-of-Create#7491
@IThundxr IThundxr added the pr type: fix PR fixes a bug label May 25, 2025
@aleck099
Copy link

Does your pr fix #8260 ?

@mudkip989
Copy link

Will this pull request be merged? The issue makes the mod too unstable for using packages in survival mode.

@danth
Copy link
Contributor Author

danth commented Aug 27, 2025

Does your pr fix #8260 ?

It sounds like in your case, the train is not loaded while the postbox is. If that was cause of the duplication then it should hopefully be fixed by the 3rd change in this PR. I've not tested this.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@IThundxr
Copy link
Member

Thanks!

@IThundxr IThundxr added this pull request to the merge queue Sep 16, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 16, 2025
@IThundxr IThundxr added this pull request to the merge queue Sep 16, 2025
Merged via the queue into Creators-of-Create:mc1.20.1/dev with commit 07a4fee Sep 16, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr type: fix PR fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Packages are voided instead of being placed in unloaded postboxes
4 participants