Skip to content

[26.1] Fix potential desync in BrewingStandBlockEntity.doBrew - #3181

Draft
ApexModder wants to merge 1 commit into
neoforged:26.1.xfrom
ApexModder:26.1/doBrew-refresh
Draft

[26.1] Fix potential desync in BrewingStandBlockEntity.doBrew#3181
ApexModder wants to merge 1 commit into
neoforged:26.1.xfrom
ApexModder:26.1/doBrew-refresh

Conversation

@ApexModder

@ApexModder ApexModder commented May 18, 2026

Copy link
Copy Markdown
Member

This PR fixes a potential desync and oversight in BrewingStandBlockEntity.doBrew, where the PotionBrewEvent.Post event allows users to modify the ingredient slot via the setItem method.

While the event does modify the backing NonNullList the doBrew method relies on a local ingredient field which is not correctly updated after the event has fired leading to this desync.

This is fixed by simply refreshing the local fields value after the event to pull in any potential mutations that might have occurred.

Note: Initially opening as draft as this PR may need updating after #3179 has been merged to ensure the crafting remainder line is correctly below the patched in field refresher line

@ApexModder ApexModder added the 26.1 Targeted at Minecraft 26.1 label May 18, 2026
@neoforged-pr-publishing

Copy link
Copy Markdown
  • Publish PR to GitHub Packages

@ChampionAsh5357

Copy link
Copy Markdown
Contributor

For transparency, there is still the open question of whether mutation should event be allowed in the post-event. This is just one solution depending on the assumptions made.

@ApexModder ApexModder added the request for comments For gathering opinions on some topic or subject label May 18, 2026
@ApexModder

Copy link
Copy Markdown
Member Author

If we prefer not to allow mutations via the Post event the other fix I would suggest is moving the setItem method up into Pre from the base PotionBrewEvent.

While this would be a breaking change it would ensure changes via the event happen before doBrew occurs and always runs with the most up-to-date values

@neoforged-automation

Copy link
Copy Markdown
Contributor

@ApexModder, this pull request has conflicts, please resolve them for this PR to move forward.

@sciwhiz12

Copy link
Copy Markdown
Member

I think part of the problem here is that we have two pathways where Post is invoked:

  1. If Pre is not cancelled, then vanilla brewing takes place, then Post is fired.
  2. If Pre is cancelled (i.e., by a mod inserting its own logic in place of vanilla), then Post is fired.

If we go by the usual pattern that Pre is mutable and Post is immutable, then it would not be possible for a mod to react after vanilla brewing and modify the outputs, because Pre is fired before vanilla brewing is invoked.

What I'm thinking we could do here instead is to refactor PotionBrewingEvent.Pre such that it contains both input stacks and output stacks, and is fired after vanilla brewing with both inputs and outputs.

Mods can then react to vanilla brewing or fully replace it with their own. Post could be retained as a final event after a successful brew.

What is questionable in this is the role that cancellation of the Pre event plays here. Currently, cancelling it has three effects: the contents of the brewing stand are overwritten and vanilla brewing (including the associated level event) is skipped, but Post is still fired. I'm not sure how best to deal with that.

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

Labels

26.1 Targeted at Minecraft 26.1 request for comments For gathering opinions on some topic or subject

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants