Skip to content

Client GameRule and GUI Helpers

Rifa edited this page Aug 9, 2026 · 1 revision

Client GameRule & GUI Helpers

Helper Class Environment Purpose
ClientGameRuleHelper Client Singleplayer / Integrated Server Queries integrated server GameRules on client thread
ConfigHelper Common (Client/Server) Atomic JSON config loading, saving, and backup swaps
GuiHelper Client Optional ModMenu / Cloth Config screen helpers

๐Ÿ–ฅ๏ธ Dedicated Server Classloading Safety

To allow 100% server-side compatibility without dedicated server crashes, client-side GUI and integrated server helpers use lazy classloading checks (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT).

                      DynamicGameRuleManager.getInt(level, ruleKey)
                                        โ”‚
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ–ผ                                       โ–ผ
          [ level instanceof ServerLevel ]       [ Client Environment ]
                    โ”‚                                       โ”‚
                    โ–ผ                                       โ–ผ
            Direct Level Lookup                   ClientGameRuleHelper
                                            (Queries Integrated Server)

๐Ÿ“„ Atomic JSON Swaps in ConfigHelper

ConfigHelper provides robust JSON file persistence with atomic swap logic:

  1. Writes new configuration data to temporary file config.json.tmp.
  2. Validates JSON structure and file size.
  3. Creates automatic backup config.json.bak.
  4. Performs atomic file swap config.json.tmp -> config.json via Files.move(..., StandardCopyOption.ATOMIC_MOVE).

๐Ÿ”— Related Pages

Clone this wiki locally