-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ archives_base_name=mehrad-config | |
|
||
# Dependencies | ||
fabric_version=0.83.0+1.19.4 | ||
modmenu_version=6.2.2 |
44 changes: 44 additions & 0 deletions
44
src/client/java/ir/mehradn/mehradconfig/entrypoint/ModMenuEntrypoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters