Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.18.x] Allow safely registering RenderType predicates at any time #8671

Merged
merged 2 commits into from Jun 30, 2022
Merged

[1.18.x] Allow safely registering RenderType predicates at any time #8671

merged 2 commits into from Jun 30, 2022

Conversation

XFactHD
Copy link
Contributor

@XFactHD XFactHD commented Jun 7, 2022

This PR effectively supersedes #8664 by providing a solution that keeps the performance benefit of the initial change in #8476 while avoiding breaking mods that need access to the predicate map, such as CTM.
This is done by using a lazy "copy-on-write" implementation where the map is only actually copied on the first read access after modification.
The PR also adds getters to allow mods like CTM to access an unmodifiable view of the maps instead of accessing internals via reflection.

Quote of the description of #8664 for completeness:

This PR reverts to an earlier approach from #8476 which is less likely to cause any breakage for mods. Instead of erroring on registration from outside of client setup, a copy-on-write map is used. This maintains the intent of the previous PR by not requiring synchronisation, but also resolves a crash in the case where a mod registers render type checks outside of client setup. For example, some mods such as CTM are registering render type checks from resource reload.

@AterAnimAvis AterAnimAvis added Performance This request deals with performance, whether reporting issues or claiming to improve it. Rendering This request deals with rendering. These must be treated with care, and tend to progress slowly. Triage This request requires the active attention of the Triage Team. Requires labelling or reviews. 1.18 labels Jun 7, 2022
@sciwhiz12 sciwhiz12 added Assigned This request has been assigned to a core developer. Will not go stale. and removed Triage This request requires the active attention of the Triage Team. Requires labelling or reviews. labels Jun 16, 2022
+ }
+
+
+ public static Map<net.minecraftforge.registries.IRegistryDelegate<Fluid>, java.util.function.Predicate<RenderType>> getFluidLayerPredicatesView() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these view methods necessary? The map being wrapped is already a copy, creating an unmodifiable instance seems like unnecessary overhead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These methods only provide a view to prevent callers from modifying the map that may be concurrently accessed by the rendering process.

@tterrag1098
Copy link
Contributor

This looks completely fine to me, but I will leave it to another team member to merge, as I am too close to the issue and a bit out of the loop in general.

@covers1624 covers1624 merged commit dbf1c8f into MinecraftForge:1.18.x Jun 30, 2022
@XFactHD XFactHD deleted the rendertype_reg_in_reload branch June 30, 2022 12:51
tmvkrpxl0 pushed a commit to tmvkrpxl0/MinecraftForge that referenced this pull request Jul 24, 2022
…inecraftForge#8671)

* Allow safely registering RenderType predicates at any time

* Requested changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.18 Assigned This request has been assigned to a core developer. Will not go stale. LTS This issue/PR is related to the current LTS version. Performance This request deals with performance, whether reporting issues or claiming to improve it. Rendering This request deals with rendering. These must be treated with care, and tend to progress slowly.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants