Skip to content

Commit

Permalink
Added support for ModMenu
Browse files Browse the repository at this point in the history
  • Loading branch information
MehradN committed Jun 30, 2023
1 parent 0749910 commit a9a3d3f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repositories {
url 'https://maven.parchmentmc.org'
}
maven {
url 'https://jitpack.io'
url 'https://maven.terraformersmc.com/releases'
}
}

Expand All @@ -41,6 +41,8 @@ dependencies {

modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}"
}

processResources {
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ archives_base_name=mehrad-config

# Dependencies
fabric_version=0.83.0+1.19.4
modmenu_version=6.2.2
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package ir.mehradn.mehradconfig.entrypoint;

import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import ir.mehradn.mehradconfig.MehradConfig;
import ir.mehradn.mehradconfig.gui.ConfigScreenBuilder;
import ir.mehradn.mehradconfig.gui.screen.MehradConfigScreen;
import net.minecraft.client.gui.screens.Screen;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;

/**
* This is the entrypoint used by ModMenu to create the config buttons. Use the {@link #register} to register your configs.
*/
public class ModMenuEntrypoint implements ModMenuApi {
private static final Map<String, ConfigScreenLoader> screenBuilders = new HashMap<>();

/**
* Registers a config constructor and a config screen builder to build screens for ModMenu. The screen will be created by
* {@link ConfigScreenBuilder#buildAndLoad}.
*
* @param modId the mod id of your mod
* @param configConstructor a constructor for the type of the config to load, modify and save
* @param configScreenBuilder the config screen builder to build the screen with
*/
public static void register(String modId, Supplier<MehradConfig> configConstructor, ConfigScreenBuilder configScreenBuilder) {
screenBuilders.put(modId, new ConfigScreenLoader(configConstructor, configScreenBuilder));
}

@Override
public Map<String, ConfigScreenFactory<?>> getProvidedConfigScreenFactories() {
Map<String, ConfigScreenFactory<?>> factories = new HashMap<>();
for (Map.Entry<String, ConfigScreenLoader> entry : screenBuilders.entrySet())
factories.put(entry.getKey(), (parent) -> entry.getValue().build(parent));
return factories;
}

private record ConfigScreenLoader(Supplier<MehradConfig> configConstructor, ConfigScreenBuilder configScreenBuilder) {
MehradConfigScreen build(Screen parentScreen) {
return this.configScreenBuilder.buildAndLoad(this.configConstructor, parentScreen);
}
}
}
3 changes: 3 additions & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"entrypoints": {
"main": [
"ir.mehradn.mehradconfig.entrypoint.MehradConfigEntrypoint"
],
"modmenu": [
"ir.mehradn.mehradconfig.entrypoint.ModMenuEntrypoint"
]
},
"depends": {
Expand Down

0 comments on commit a9a3d3f

Please sign in to comment.