Skip to content

🧠 State Persistence & JSON Configuration

ParameterSpecification
Config Manager Classnet.instantgratification.collapsiblegamerules.GameRuleStateConfig
File Location.minecraft/config/collapsible-game-rules-state.json
Storage StructureSet<String> expandedCategories = new HashSet<>()
Serialization Enginecom.google.gson.Gson (Pretty-Printing Enabled)
I/O Throttling Flagprivate static boolean isDirty = false
Flush HookScreenMixin targeting Screen.removed() (@At("HEAD"))
Persistence Key StrategyLocalization Key (TranslatableContents.getKey()) or Literal String

📖 Overview

Collapsible Game Rules features an asynchronous, throttled state persistence engine. Rather than resetting to default expansion states every time a world or menu is opened, the mod remembers the exact categories you have expanded or collapsed across restarts.


📄 JSON Configuration Format

The state is stored in a clean, human-readable JSON array inside .minecraft/config/collapsible-game-rules-state.json:

json
[
  "gamerule.category.spawning",
  "gamerule.category.mobs",
  "gamerule.category.updates"
]
  • Presence in Array: Indicates that the category is currently EXPANDED.
  • Absence from Array: Indicates that the category is currently COLLAPSED (default state).

⚡ High-Performance I/O Throttling Architecture

Writing to disk on every mouse click or keyboard toggle creates unnecessary disk I/O and micro-stutter when players rapidly expand or collapse multiple categories.

To ensure zero frame drops, GameRuleStateConfig uses an isDirty state flag:

┌─────────────────────────────────────────────────────────────────────────────┐
│                       THROTTLED PERSISTENCE WORKFLOW                        │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                             │
│   Player clicks Category Header                                             │
│        │                                                                    │
│        ▼                                                                    │
│   GameRuleStateConfig.setExpanded(key, state)                               │
│        ├─ Updates in-memory HashSet<String> in 0.0001 μs                    │
│        └─ Marks: isDirty = true (ZERO DISK I/O)                             │
│                                                                             │
│   Player closes Game Rules Screen (Esc, Done, or Cancel)                    │
│        │                                                                    │
│        ▼                                                                    │
│   ScreenMixin.collapsible_game_rules$onRemoved()                            │
│        │                                                                    │
│        ▼                                                                    │
│   GameRuleStateConfig.saveIfDirty()                                         │
│        ├─ Checks: if (isDirty) { ... }                                      │
│        ├─ Writes JSON to disk in background buffer                          │
│        └─ Resets: isDirty = false                                           │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

💻 API & Method Reference

GameRuleStateConfig Public Methods

Method SignatureReturn TypeDescription
load()voidReads collapsible-game-rules-state.json on client startup (CollapsibleGameRulesFabricClient).
save()voidFlushes the current expandedCategories set to disk via Files.newBufferedWriter.
saveIfDirty()voidSaves to disk only if isDirty == true, then resets isDirty = false.
isExpanded(String categoryKey)booleanChecks if the given translation key is present in expandedCategories.
setExpanded(String categoryKey, boolean expanded)voidAdds or removes the key from the set and sets isDirty = true if modified.
expandAll(Iterable<String> allKeys)voidAdds all provided keys to the set in bulk and marks isDirty = true.
collapseAll()voidClears all entries from expandedCategories and marks isDirty = true.

🔒 Screen Removal Mixin Integration

State saving is hooked directly into Minecraft's base Screen.removed() method via ScreenMixin.java:

java
@Mixin(Screen.class)
public abstract class ScreenMixin {

    @Inject(method = "removed", at = @At("HEAD"))
    private void collapsible_game_rules$onRemoved(CallbackInfo ci) {
        if ((Object) this instanceof AbstractGameRulesScreen) {
            GameRuleStateConfig.saveIfDirty();
        }
    }
}

This guarantees that whenever the player exits the screen—whether by clicking Done, Cancel, or pressing Escape—all modifications are safely preserved.


Official documentation & web portal for Dasik Igaijinn mods.