LibGamerule
Libgamerule allows for easily adding custom gamerules on the Fabric modloader.
Usage (for mod devs)
// Adding a boolean gamerule
GameRules.RuleKey<BooleanRule> MY_GAMERULE = Gamerule.register(
"myGameRule", // name in /gamerule
BooleanRule.create(true) // default to true
);
// Get the gamerule data
boolean value = Gamerule.get(MY_GAMERULE);
Supported Rule types:
- BooleanRule
- DoubleRule (+min/max)
- IntRule (+min/max)
- EnumRule (Any Enum)
- StringRule (greedy strings)
Libcd support (datapack/modpack devs)
Conditions (note: does not support enums)
{
"when": [
{
"comment": "Boolean gamerule check",
"libgamerule:gamerule_has_value": "my_gamerule"
},
{
"comment": "Typed gamerule check",
"libgamerule:gamerule_has_value": {
"name": "my_gamerule_typed",
"type": "int",
"value": 10
}
}
]
}
Creating gamerules in scripts
var GameruleTweaker = libcd.require("libgamerule.GameruleTweaker");
GameruleTweaker.addGamerule("my_gamerule", "boolean", false);
GameruleTweaker.addGamerule("my_gamerule_typed", "integer", 7);
now we have another problem, libCD support's been dropped by boundary, and as far as I'm aware you need that make to use this one
sorry if I'm putting this here, but at the time of writing your issues link wasn't working. This crashes whenever you click on the singleplayer button in the main menu
https://gist.github.com/Nathan22211/40acf93cc8e471a868de54685fb57c50
Uploading a new version, should fix the issue
now that this is updated to 1.16, i noticed that you dont post a way to set category. Does this support gamerule display in the new game menu and if so what category are the rules put into?
Categories are currently unsupported and default to MISC as I just wanted to get a working version out. I'll look into adding support for the game menu you mentioned when I've got time.
In reply to Martmists:
It should be built in i think, just need the lang entries.
Like all of my mods, this will not get updated to the latest snapshots as 1.16 is introducing a lot of breaking stuff. Please have patience until 1.16-pre1 releases.
please update to 20w18a
you don't really have any showing on how to retrieve what a gamerule has been set to in libCD scripts
Can you please add some pictures to this, it's hard to understand how the script and datapack ones work.
What do you mean exactly? I added sample code for both.
In reply to Martmists:
I mean like what each argument does like "comment": "Typed gamerule check" //adds...
That's... what the comments are for...?