Download LibGamerule — Minecraft Mods — MetaMods

LibGamerule

Active

Downloads

0

Last update

5 years ago
Client
Fabric
Quilt
Forge
Neoforge
Libraries

LibGamerule

Built on Fabric, the LibGamerule library simplifies the creation of custom game rules. This tool is primarily aimed at mod developers but also offers capabilities for those working with datapacks and modpacks.

For Mod Developers

The module provides a straightforward interface for registering various rule types. Here's an example of creating a boolean rule:

// Registering a boolean rule GameRules.RuleKey<BooleanRule> MY_GAMERULE = Gamerule.register( "myGameRule", // command name in /gamerule BooleanRule.create(true) // default value: true );

// Getting the rule value boolean value = Gamerule.get(MY_GAMERULE);

Available rule types include:

  • BooleanRule — boolean values
  • DoubleRule — floating-point numbers (with optional min/max constraints)
  • IntRule — integer values (also with range setting capability)
  • EnumRule — support for any enumerations
  • StringRule — arbitrary length string values

Libcd Integration

For modpack and datapack authors, compatibility with Libcd is implemented, allowing rule configuration through scripts and conditions.

Application Conditions

Please note that this functionality is not available for enumerations.

{ "when": [ { "comment": "Boolean rule check", "libgamerule:gamerule_has_value": "my_gamerule" }, { "comment": "Typed rule check", "libgamerule:gamerule_has_value": { "name": "my_gamerule_typed", "type": "int", "value": 10 } } ] }

Dynamic Rule Creation

New rules can be added directly in scripts:

var GameruleTweaker = libcd.require("libgamerule.GameruleTweaker"); GameruleTweaker.addGamerule("my_gamerule", "boolean", false); GameruleTweaker.addGamerule("my_gamerule_typed", "integer", 7);

Project members
Martmists

Martmists

Created: 30 Jun 2020

ID: 26717