How to Make a Game Rule

Section

What are Game Rules

Game rules are world settings that allow the player to control features of the save game they are playing on. As of 1.16, you can now set game rules before the world is created. Prior to 1.16, you had to use the command "/gamerule" to change the game rules of the world.

Creating the Element

Mod Element Name

When creating the name for your element follow these steps to ensure your element has a proper name.

  • Do not use existing vanilla names (dirt, coal, diamond, ...) for better compatibility.
  • Use upper-camel-case names if possible (eg. MoonGem)
  • Avoid using type names in element (eg. MoonGemItem, CustomTab, ...)

Game Rule Settings

Image of the game rule element settings

This following section will cover the game rule settings.

  • Machine name: 
    This is the GameRule name which is displayed in-game in commands to modify/enable the GameRules.
  • Game rule description: 
    This is the GameRule description. It is used for the GameRules setting screen.
    NOTE: This is mainly for versions 1.16, and higher, but is still required in previous versions.
  • Category:
    This is the GameRule's category. It's used for the classification of the GameRules depending on what they do.

    NOTE: Only available in Minecraft 1.16.x and higher.
    OPTIONS (Player, Updates, Chat, Drops, Misc, Mobs, and Spawning)

  • Game rule type: 
    This is the GameRule's type. You must select the best type depending on your plan(s)
    • Number means the GameRule can only be modified to be a number (integer - 0, 1,...)
    • Logic means the GameRule can only be a boolean (true or false)
  • Default value: 
    This is the GameRule's default value. The GameRule will have this value until something in the game (player or command) changes it.

Game Rule Procedures

Procedure Blocks

Image of game rule procedure blocks.

This section covers the four procedure blocks added in 2021.1 for getting and setting game rule values.

Logic: The two top procedure blocks are for logic game rule types (true or false). The first light blue block allows you to change the game rule value. The second light blue block allows you to get the value of the game rule.

Number: The two bottom procedure blocks are for number game rule types (integers). The first dark blue block allows you to set the value of the game rule. The second dark blue procedure block allows you to get the value of the game rule.

You can find these blocks under the procedure tab called "World Data". After you have made your game rule element you will see the game rule appear in the drop-down list of the corresponding game rule type blocks (logic, or number). If they do not appear you may need to replace the block, and after you have replaced the block it should show.

Procedure Example

The following examples are just to show some ways it can be used, you can use them in many ways not limited to these examples.

Example of how to make a procedure with the game rule blocks.

Video tutorial

If you prefer to watch the video, you can find the wiki page above summarized in a video:



Donate to MCreator

By donating to developers you can speed up development, as with more resources, we can dedicate more time to MCreator. It is a free project made by developers working on it in their free time.