-
Notifications
You must be signed in to change notification settings - Fork 0
Getting started
First, you will need to add JitPack as a repository:
repositories {
maven {
name = "JitPack"
url = "https://jitpack.io"
}
}Then, add malilib and malilib-api as dependencies:
dependencies {
modImplementation "com.github.sakura-ryoko:malilib:${project.malilib_version}"
modImplementation "com.github.kr1viah.malilib-api:${project.malilib_api_version}"
annotationProcessor "com.github.kr1viah.malilib-api:${project.malilib_api_version}"
}Find the latest malilib and malilib api release matching your version to put in your gradle.properties:
version range : version name
1.21 (inclusive) - 1.21.1 (inclusive): 1.21
1.21.1 (exclusive) - 1.21.5 (inclusive): 1.21.5
1.21.6 (inclusive) - 1.21.8 (inclusive): 1.21.8
1.21.9 (inclusive) - 1.21.10 (inclusive): 1.21.10
1.21.11 : 1.21.11
So, for 1.21.5, you'd put something like this in your gradle.properties:
malilib_version=1.21.5-3a531
malilib_api_version=malilib-api-1.21.5:0.1.1
Generally, for malilib api follow malilib-api-(minecaft version):(malilib api version)
Lastly, add malilib and malilib-api to your fabric.mod.json under depends:
"malilib": "*",
"malilib-api": "*"Note: the first time you reload gradle, it might take a while and even time out a few times. This is because JitPack might have to build MaLiLib/MaLiLib API which takes some time
Malilib provides a fantastic keybind/hotkey system. The user can bind up to 5 keys to the same config. The user has the ability to:
- Activate on press/release/both
- Use in-game/gui/any
- Allow empty keybind (if the keybind is empty, malilib will always consider it to be pressed)
- Allow extra keys
- For example, if you have a keybind that is CTRL + Z, and this is disabled, pressing A, CTRL and Z in that order will not activate the keybind.
- Order sensitive
- Exclusive
- Cancel further processing
I found that Malilib was quite difficult to get into, and a lot of code in between mods like tweakeroo, minihud and litematica that is related to the config system was the same. With this, there is absolutely no boilerplate.
Malilib is in the middle of a rewrite. Also, this mod is not able to be used on itself.
Note: if something doesn't have a description and it is not clear what it is, I also have no idea what it's for, and chances are you won't ever use it.
Malilib provides several config options:
- Booleans (
ConfigBoolean) - Booleans with hotkey (
ConfigBooleanHotkeyedorConfigBooleanPlus)- Note: if you use
ConfigBooleanPlus, triggering the hotkey will automatically toggle the boolean value.
- Note: if you use
- Colors (
ConfigColor) - Doubles (
ConfigDoubleorConfigDoublePlus) - Floats (
ConfigFloat) - Hotkeys (
ConfigHotkeyorConfigHotkeyPlus) - Integers (
ConfigIntegerorConfigIntegerPlus) - Strings (
ConfigStringorConfigStringPlus) - Color lists (
ConfigColorList)- A list of colors.
- Locked lists (
ConfigLockedList) - Option lists (
ConfigOptionList) - String lists (
ConfigStringListorConfigStringListPlus)- A list of strings.
Additionally, Malilib api provides some extras:
- Button (
ConfigButton)- Button. Is not really a config type, but allows for things like batch resetting configs, or reloading something, or anything really.
- Label (
ConfigLabelor@Label)- Inserts a label.
Instead of doing new ConfigBooleanHotkeyed("Name", true, "") you can do new ConfigBooleanPlus("Name") to achieve the same thing.
I haven't used them, so you probably don't either. That or they're too complex to have a Plus for (For example, where any preset default value doesn't make sense)
By doing BOOLEAN.getBooleanValue(), or INTEGER.getIntegerValue(). Basically what makes sense. Will always be get ... Value()
To get started, all you need is a single @Config class:
@Config("Malilib api test")
public class ConfigClass) {
}That's it! Now you can insert for example a ConfigBooleanPlus:
public static final ConfigBooleanPlus BOOLEAN = new ConfigBooleanPlus("Test boolean");And it will show up in game:
You could do something like:
static final ConfigHotkeyPlus HOTKEY = new ConfigHotkeyPlus("Open gui", "B, C", (keyAction, iKeybind) -> {
MalilibApi.openScreenFor("Malilib api test"); // opens the screen
return true; // return true if pressing the hotkey did something, otherwise false.
});Then, pressing B and then C in game will open the config menu.
If you want more control, you can do the following at mod init:
String modId = "mod-id"; // note: you should use the same string as in your @Config anotations
MalilibApi.registerMod(modId, "Mod name", new ConfigHandler(modId), new InputHandler(modId));Then, override any method in ConfigHandler (preferrably or saveAdditionalData or loadAdditionalData) or InputHandler.
For examples, see kr1v-utils.