ModManagerMC / ModManager

A ModManager extension for ModMenu
Apache License 2.0
79 stars 11 forks source link

[FEAUTURE REQUEST] Custom Categories API #74

Closed CamperSamu closed 2 years ago

CamperSamu commented 2 years ago

I'm working on a Client Mod for my Minecraft Server and it integrates with various mods too if they are installed. One of those mods was Mod Manager, I had a mixin that added a custom category for the (optional) mods the client and the server support for Mod Manager 1.0.1 to help the playerbase discover and install new mods from other developers since the philosophy of the client is not to replace other mods but to integrate them in order to give credit to the original mod creator and idea and allow for modularity.

Now in ModManager 1.1 this is not possible anymore because Mixins are not supported in Kotlin and I haven't found a good way to add custom origins or categories from another mod in the code.

Thanks in advance!

DeathsGun commented 2 years ago

Hi ModManager has an API for custom providers since 1.0.0 it allows you to register a custom provider.

A basic provider would look like this: ```java package xyz.deathsgun.modmanager; import net.minecraft.text.TranslatableText; import org.jetbrains.annotations.NotNull; import xyz.deathsgun.modmanager.api.http.CategoriesResult; import xyz.deathsgun.modmanager.api.http.ModResult; import xyz.deathsgun.modmanager.api.http.ModsResult; import xyz.deathsgun.modmanager.api.http.VersionResult; import xyz.deathsgun.modmanager.api.mod.Category; import xyz.deathsgun.modmanager.api.provider.IModProvider; import xyz.deathsgun.modmanager.api.provider.Sorting; import java.util.ArrayList; public class TestProvider implements IModProvider { @NotNull @Override public CategoriesResult getCategories() { ArrayList categories = new ArrayList<>(); // Add your categories here return new CategoriesResult.Success(categories); } @NotNull @Override public ModsResult getMods(@NotNull Sorting sorting, int page, int limit) { return new ModsResult.Success(new ArrayList<>()); } @NotNull @Override public ModsResult getMods(@NotNull Category category, @NotNull Sorting sorting, int page, int limit) { return new ModsResult.Success(new ArrayList<>()); } @NotNull @Override public ModsResult search(@NotNull String query, @NotNull Sorting sorting, int page, int limit) { return new ModsResult.Success(new ArrayList<>()); } @NotNull @Override public ModResult getMod(@NotNull String id) { return new ModResult.Error(new TranslatableText(""), null); } @NotNull @Override public String getName() { return "My custom mods"; } @NotNull @Override public VersionResult getVersionsForMod(@NotNull String id) { return new VersionResult.Success(new ArrayList<>()); } } ```
And you register it like this: ```java package xyz.deathsgun.modmanager; import net.fabricmc.api.ClientModInitializer; public class TestMod implements ClientModInitializer { @Override public void onInitializeClient() { ModManager.modManager.getProvider().put("myProvider", new TestProvider()); } } ```

If need something else let me know.

CamperSamu commented 2 years ago

Hi and thanks for replying to me so quickly!

The integration is working, I had to work around some jank because I don't want to make the mod a required dependency, but it works!

I wanted to just include my category inside the Modrinth provider, but this works too, I'll work on categorizing the various mods now.

Thanks for the support!


(ignore the placeholder background lol)

image