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

Remove static ModLoadingContext access #39

Open
Shadows-of-Fire opened this issue Nov 14, 2023 · 0 comments
Open

Remove static ModLoadingContext access #39

Shadows-of-Fire opened this issue Nov 14, 2023 · 0 comments
Labels
breaking-change enhancement New feature or request

Comments

@Shadows-of-Fire
Copy link

The ModLoadingContext introduces a fair amount of global state through the field private static final ThreadLocal<ModLoadingContext> context, which is primarily used to resolve modids automatically in registration code. This usage should be removed, as global variables promote poor design and reduce readability of all code that reaches them.

There are two uses of this global state:

  1. Automatic modid deduction (for registration of registry entries, configs, and client objects, and for IMC).
  2. Provision of the language-specific loading context (i.e., FMLJavaModLoadingContext).

Case 1 is trivially resolvable. Modders should (and are very capable) of providing a modid to registration code at the time of registration. At most it adds one method argument, and produces a much higher degree of readability and transparency, and the registered object's modid is not at the whim of a global state object.

Case 2 is resolvable by passing the language-specific loading context as a constructor argument to the target mod.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant