-
Notifications
You must be signed in to change notification settings - Fork 270
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
Fake mod containers #192
base: master
Are you sure you want to change the base?
Fake mod containers #192
Changes from all commits
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,13 @@ | ||
package net.fabricmc.api; | ||
|
||
import net.fabricmc.loader.api.ModContainer; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Hook for adding "fake" mod containers to Loader's list. | ||
* Should run <i>after</i> {@link ModInitializer#onInitialize()} | ||
*/ | ||
public interface FakeModProvider { | ||
Collection<ModContainer> getFakeMods(); | ||
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. Should this be like below instead? void registerFakeMods(Consumer<ProvidedModContainer> acceptor); That would allow for a few things: public void registerFakeMods(Consumer<ProvidedModContainer> acceptor) {
ProvidedModContainer container1 = ...
ProvidedModContainer container2 = ...
acceptor.accept(container1);
acceptor.accept(container2);
} 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. that might be a good idea. I'll think about it. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,8 @@ public class FabricLoader implements net.fabricmc.loader.api.FabricLoader { | |
|
||
protected final Map<String, ModContainer> modMap = new HashMap<>(); | ||
protected List<ModContainer> mods = new ArrayList<>(); | ||
protected final Map<String, net.fabricmc.loader.api.ModContainer> fakeModMap = new HashMap<>(); | ||
protected List<net.fabricmc.loader.api.ModContainer> fakeMods = new ArrayList<>(); | ||
|
||
private final Map<String, LanguageAdapter> adapterMap = new HashMap<>(); | ||
private final EntrypointStorage entrypointStorage = new EntrypointStorage(); | ||
|
@@ -242,9 +244,14 @@ public Collection<net.fabricmc.loader.api.ModContainer> getAllMods() { | |
return Collections.unmodifiableList(mods); | ||
} | ||
|
||
@Override | ||
public Collection<net.fabricmc.loader.api.ModContainer> getFakeMods() { | ||
return Collections.unmodifiableList(mods); | ||
} | ||
|
||
@Override | ||
public boolean isModLoaded(String id) { | ||
return modMap.containsKey(id); | ||
return modMap.containsKey(id) || fakeModMap.containsKey(id); | ||
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. My request for this would require a contract to be established that a 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. oh that's a good point. |
||
} | ||
|
||
@Override | ||
|
@@ -416,6 +423,13 @@ public void prepareModInit(File newRunDir, Object gameInstance) { | |
} | ||
} | ||
|
||
public void appendFakeMods(Collection<net.fabricmc.loader.api.ModContainer> mods) { | ||
for (net.fabricmc.loader.api.ModContainer mod : mods) { | ||
fakeModMap.put(mod.getMetadata().getId(), mod); | ||
fakeMods.add(mod); | ||
} | ||
} | ||
|
||
public Logger getLogger() { | ||
return LOGGER; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,12 @@ static FabricLoader getInstance() { | |
*/ | ||
Collection<ModContainer> getAllMods(); | ||
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. Should Or should we make this exclusively real mods. 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. I feel like it'd be better to have near-total separation between fake and real mods. I might even want to have 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. I disagree with boundary here, I think mods should be all equal by default. If someone provides a "fake" mod with the same id as a real mod, there should be a good reason, and they should be treated the same. |
||
|
||
/** | ||
* Gets all mod containers added through {@link net.fabricmc.api.FakeModProvider}s. | ||
* @return A collection of all added fake mod containers. | ||
*/ | ||
Collection<ModContainer> getFakeMods(); | ||
|
||
/** | ||
* Checks if a mod with a given ID is loaded. | ||
* @param id The ID of the mod, as defined in fabric.mod.json. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
package net.fabricmc.loader.entrypoint.minecraft.hooks; | ||
|
||
import net.fabricmc.api.ClientModInitializer; | ||
import net.fabricmc.api.FakeModProvider; | ||
import net.fabricmc.api.ModInitializer; | ||
import net.fabricmc.loader.FabricLoader; | ||
|
||
|
@@ -30,6 +31,7 @@ public static void start(File runDir, Object gameInstance) { | |
|
||
FabricLoader.INSTANCE.prepareModInit(runDir, gameInstance); | ||
EntrypointUtils.invoke("main", ModInitializer.class, ModInitializer::onInitialize); | ||
FabricLoader.INSTANCE.getEntrypoints("fake_mods", FakeModProvider.class).forEach(provider -> FabricLoader.INSTANCE.appendFakeMods(provider.getFakeMods())); | ||
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. The question I have is, is this the right spot for the FakeModProviders to run? I personally think that we should load fake mods after the GameProvider is set but before onInitialize after each of the ModInitializers fires their constructors. 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. The main worry there is that then the fake mods likely haven't been loaded. You'd almost definitely want to do that in 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. What is your reason for loading fake mods after the mod initializer (thereby the client/server would be loaded). Sponge's events cover some states near what on Initialize would cover. |
||
EntrypointUtils.invoke("client", ClientModInitializer.class, ClientModInitializer::onInitializeClient); | ||
} | ||
} |
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.
There is currently not way to distinguish between a normal and fake mod container.
First I think we should add a isFake/isProvided method.
I think we should have return a
ProvidedModContainer
which extendsModContainer
and aModContainer getProvider();
so we could track which mod made the fake mod. Of course this would require a way to get what ModContainer provides an entrypoint (so we have a source of the FakeModProvider).