-
Notifications
You must be signed in to change notification settings - Fork 512
feat!: Use ServiceLoader for Renderer registry, RendererReadyEntrypoint
#5185
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
base: 26.1
Are you sure you want to change the base?
Changes from all commits
03e63f3
1260f4b
06bca83
ee27791
a236245
b53602f
80ac9d2
6da3e44
e15d217
1f7eb43
ce336b0
c11e491
1b3b8fa
a9417e2
9c32272
67e8380
adf1e2c
5869245
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * Copyright (c) 2016, 2017, 2018, 2019 FabricMC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package net.fabricmc.fabric.api.client.renderer.v1; | ||
|
|
||
| import org.jetbrains.annotations.ApiStatus; | ||
|
|
||
| import net.fabricmc.fabric.impl.client.renderer.RendererManager; | ||
| import net.fabricmc.loader.api.FabricLoader; | ||
|
|
||
| /** | ||
| * An abstraction for registering {@link Renderer} implementations. | ||
| * | ||
| * <p>Before Minecraft is initialized, implementations of {@link RendererProvider} are | ||
| * loaded via {@link FabricLoader#getEntrypointContainers(String, Class)}, after which | ||
| * {@link #getRenderer()} is called. | ||
| * | ||
| * @implSpec Renderers are expected to add a {@code fabric-renderer-api-v1:renderer_provider} entrypoint | ||
| * referencing their implementations of {@link RendererProvider}. | ||
| */ | ||
| public interface RendererProvider { | ||
| /** | ||
| * Gets the mod ID of the current, chosen {@link RendererProvider} or finds one if it has not | ||
| * yet been chosen. | ||
| * | ||
| * @return the mod ID of the current {@link RendererProvider}. | ||
| */ | ||
| static String getId() { | ||
| return RendererManager.getOrLoadRendererProvider().getProvider().getMetadata().getId(); | ||
| } | ||
|
|
||
| /** | ||
| * Get or instantiate an implementation of {@link Renderer}. | ||
| * | ||
| * @return an instance of the {@link Renderer} to be registered. | ||
| * @implSpec This method should instantiate an implementation of {@link Renderer} the first time | ||
| * it is invoked and return that instance for any subsequent calls. | ||
sylv256 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| */ | ||
| @ApiStatus.OverrideOnly | ||
| Renderer getRenderer(); | ||
|
|
||
| /** | ||
| * The higher a renderer's priority is, the more likely it is to be loaded. So, the | ||
| * {@link RendererProvider} with the highest priority is loaded. | ||
| * | ||
| * @return this renderer's priority. | ||
| * @implSpec Implementations of {@link Renderer} should use priority {@code 1000} in most cases. | ||
| * However, they may choose any priority or even change priorities based on some conditions. | ||
| * Implementors should avoid priorities of {@code 0} or below as that is Indigo's priority. | ||
| */ | ||
| @ApiStatus.OverrideOnly | ||
| default int priority() { | ||
| return 1000; | ||
| } | ||
|
Comment on lines
+56
to
+67
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an anti pattern, and something we dont do else where. It always ends up in a mess and people will put max int to force them selves to be first. Im really no keen on this at all. Use the toposort with a before/after mod id.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this in CONTRIBUTING.md? If not I'll probably add it
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may be a good idea, we have used the toposorting logic in quite a few places now. Let me know if you need help to wire it up.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there an example in fapi where it's used?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ParticleGroupRegistryImpl.registerOrdering net.fabricmc.fabric.impl.base.toposort.NodeSorting is what everything uses. Don't spend ages on this if you cannot figure it out, do let me know if you arent making any progress. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* | ||
| * Copyright (c) 2016, 2017, 2018, 2019 FabricMC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package net.fabricmc.fabric.impl.client.indigo.renderer; | ||
|
|
||
| import net.fabricmc.fabric.api.client.renderer.v1.Renderer; | ||
| import net.fabricmc.fabric.api.client.renderer.v1.RendererProvider; | ||
|
|
||
| public class IndigoRendererProvider implements RendererProvider { | ||
| @Override | ||
| public Renderer getRenderer() { | ||
| return IndigoRenderer.getOrCreateInstance(); | ||
| } | ||
|
|
||
| @Override | ||
| public int priority() { | ||
| return 0; // This ensures other renderers override Indigo | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This javadoc should clarify that this method is called only if
thisprovider is selected and that this method is guaranteed to run at the same time asClientModInitializer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is relevant anymore.