Config - McMellonTeam/easierworldcreator GitHub Wiki
Concept
Starting from 2.4.0, the mod provide an integrated config that you can use.
A Mod Config is composed of categories (1 - n number of categories) defined by the modder
categories example:
- server
- client
- mob1
- mob2
- mob3
- biome1
- biome2
- ...
Those are just examples and if you want to put everything under one category, you can.
Each categories are composed of:
- BooleanConfigObject
- IntegerConfigObject
- EnumsConfigObject
Representing each differents aspects of the configuration.
ConfigObject
a config object is an object used to store:
- the default value of an object (true/ false for booleans, x for ints...)
- the value set by the user(can or cannot be equal to the default value)
- the name related to the value
- an optional boolean to define the restart of the game when the value is modified. To activate it, set
requireRestart
to true.
BooleanConfigObject
used to store differents booleans variables
IntegerConfigObject
used to store differents integers values.
You can set a minimum and a maximum value accepted.
The default value has to be between between the max and min value
EnumConfigObject
used to store a set of String.
the default value has to be present in the set of string.
Create custom config:
You can see the following example
public class ExampleConfig {
//the base config
public static final ModConfig CONFIG = new ModConfig(EWCTest.MOD_ID);
//the categories belonging to the base config
public static final ConfigCategory FOO = new ConfigCategory("foo");
public static final ConfigCategory DOO = new ConfigCategory("doo");
public static void registerConfig() {
//booleans
BooleanConfigObject bool1Test = new BooleanConfigObject(true, "bool1test");
// if the boolean is modified, the game will restart when clicking on "save & exit
bool1Test.requireRestart = true;
//we add the category
FOO.addBoolean(bool1Test);
//we add other categories
FOO.addBoolean(new BooleanConfigObject(false, "here is some description that will be written in the config file", "bool2test"));
FOO.addBoolean("bool3test", "other way of registering the boolean", true);
//integers
IntegerConfigObject int1Test = new IntegerConfigObject(0, "int1test");
int1Test.requireRestart = true;
FOO.addInt(int1Test);
FOO.addInt(new IntegerConfigObject(78, "otherint"));
FOO.addInt("int2test", 12, "adding min and max values", -9, 15151);
//enums
EnumConfigObject enum1Test = new EnumConfigObject("value1", "enum1test", Set.of("value1", "value2", "value3", "value4"));
enum1Test.requireRestart = true;
FOO.addEnum(enum1Test);
FOO.addEnum(new EnumConfigObject("banana", "fruits", "list of some fruits", Set.of("banana", "apple", "orange", "tomato")));
FOO.addEnum("newenum", "hello", Set.of("hello", "world"));
CONFIG.addCategory(FOO);
// will add the empty doo category
CONFIG.addCategory(DOO);
CONFIG.init();
}
//methods to get the value of the config
public static boolean getBool1Test() {
return CONFIG.getCategory("foo").getBools().get("bool1test").getActualValue();
}
public static int getInt1Test() {
return CONFIG.getCategory("foo").getInts().get("int1test").getActualValue();
}
}
you also need to add translation:
"config.mod_id.foo" : "Foo",
"config.mod_id.bool1test" : "Hello Bool1Test",
"config.mod_id.bool1test.description" : "This is the Bool1Test description"
...
it will create a new screen like this when mod-menu is installed:
Custom Config Screen
You can also set a custom config screen see mushrooomsmod-(my-other-mod)
I add some custom buttons and a custom background
public class MushrooomsConfigScreen extends DefaultConfigScreen {
//icons
private static final Identifier DISCORD_ICON = Identifier.of(EasierWorldCreator.MOD_ID, "textures/gui/discord.png");
private static final Identifier GITHUB_ICON = Identifier.of(EasierWorldCreator.MOD_ID, "textures/gui/github.png");
private static final Identifier KOFI_ICON = Identifier.of(EasierWorldCreator.MOD_ID, "textures/gui/kofi.png");
private static final Identifier CURSEFORGE_ICON = Identifier.of(EasierWorldCreator.MOD_ID, "textures/gui/curseforge.png");
private static final Identifier MODRINTH_ICON = Identifier.of(EasierWorldCreator.MOD_ID, "textures/gui/modrinth.png");
//links
private static final String DISCORD_LINK = "https://discord.gg/bAQRUxNyFj";
private static final String GITHUB_LINK = "https://github.com/McMellonTeam/mushroooms-mod";
private static final String KOFI_LINK = "https://ko-fi.com/rodofire";
private static final String CURSEFORGE_LINK = "https://www.curseforge.com/minecraft/mc-mods/mushroooms";
private static final String MODRINTH_LINK = "https://modrinth.com/mod/mushroooms";
public MushrooomsConfigScreen(Screen parent) {
//we create a custom screen with a custom background
super(parent, MushrooomsConfig.CONFIG, MushrooomsMod.MOD_ID, Identifier.of(MushrooomsMod.MOD_ID, "textures/gui/config_background.png"), 1920, 1080, 0xAFAFAFFF, 0xC8000000);
}
@Override
protected void init(ConfigCategory category) {
super.init(category);
List<ImageButtonWidget> buttons = getButtons();
for (ImageButtonWidget button : buttons) {
this.addDrawableChild(button);
}
}
public ImageButtonWidget createButton(String link, int yOffset, Identifier icon) {
int getIconSize = getIconSize();
MinecraftClient client = MinecraftClient.getInstance();
return new ImageButtonWidget(
8, client.getWindow().getScaledHeight() / 2 + (int) (yOffset * (getIconSize == 24 ? 1 : 0.75)),
getIconSize(), getIconSize(), icon,
button -> {
MinecraftClient.getInstance().setScreen(new ConfirmLinkScreen(
open -> {
if (open) {
Util.getOperatingSystem().open(link);
}
MinecraftClient.getInstance().setScreen(this);
}, link, true)
);
}
);
}
public int getIconSize() {
int large = MinecraftClient.getInstance().getWindow().getScaledHeight();
return large < 300 ? 20 : 24;
}
@Unique
public List<ImageButtonWidget> getButtons() {
List<ImageButtonWidget> buttons = new ArrayList<>();
buttons.add(createButton(GITHUB_LINK, 28, GITHUB_ICON));
buttons.add(createButton(DISCORD_LINK, 0, DISCORD_ICON));
buttons.add(createButton(KOFI_LINK, 56, KOFI_ICON));
buttons.add(createButton(CURSEFORGE_LINK, -28, CURSEFORGE_ICON));
buttons.add(createButton(MODRINTH_LINK, -56, MODRINTH_ICON));
return buttons;
}
}
You should the add the modMenu compat:
public class ModMenuCompat implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return MushrooomsConfigScreen::new;
}
}
and set the entrypoint in your fabric.mod.json
"entrypoints": {
//other entrypoints
"modmenu": [
"net.rodofire.mushrooomsmod.compat.ModMenuCompat"
]
},