-
Notifications
You must be signed in to change notification settings - Fork 0
26.2 State Persistence and Config
| Parameter | Specification |
|---|---|
| Config Manager Class | net.instantgratification.collapsiblegamerules.GameRuleStateConfig |
| File Location | .minecraft/config/collapsible-game-rules-state.json |
| Storage Structure | Set<String> expandedCategories = new HashSet<>() |
| Serialization Engine |
com.google.gson.Gson (Pretty-Printing Enabled) |
| I/O Throttling Flag | private static boolean isDirty = false |
| Flush Hook |
ScreenMixin targeting Screen.removed() (@At("HEAD")) |
| Persistence Key Strategy | Localization Key (TranslatableContents.getKey()) or Literal String |
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.
The state is stored in a clean, human-readable JSON array inside .minecraft/config/collapsible-game-rules-state.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).
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 โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
| Method Signature | Return Type | Description |
|---|---|---|
load() |
void |
Reads collapsible-game-rules-state.json on client startup (CollapsibleGameRulesFabricClient). |
save() |
void |
Flushes the current expandedCategories set to disk via Files.newBufferedWriter. |
saveIfDirty() |
void |
Saves to disk only if isDirty == true, then resets isDirty = false. |
isExpanded(String categoryKey) |
boolean |
Checks if the given translation key is present in expandedCategories. |
setExpanded(String categoryKey, boolean expanded) |
void |
Adds or removes the key from the set and sets isDirty = true if modified. |
expandAll(Iterable<String> allKeys) |
void |
Adds all provided keys to the set in bulk and marks isDirty = true. |
collapseAll() |
void |
Clears all entries from expandedCategories and marks isDirty = true. |
State saving is hooked directly into Minecraft's base Screen.removed() method via ScreenMixin.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.
Collapsible Game Rules โข Built & Maintained by Dasik (Rifaditya)
Released under the GNU General Public License v3.0 (GPL-3.0-or-later)
GitHub Repository โข Modrinth โข CurseForge โข Issue Tracker
๐ Repository Source Disclaimer: The documentation in this Wiki reflects the current source code state in the repository, which may include recent unreleased commits or developmental features ahead of public release builds on CurseForge and Modrinth.
- ๐๏ธ Collapsible Categories
- ๐ Global Actions & Bulk Toggles
- ๐ Smart Search Integration
- โจ๏ธ Keyboard Navigation & Accessibility
- ๐ง State Persistence & JSON Config
- โจ Category Prettification & Naming
- ๐๏ธ Game Rule Presets & Widgets
- ๐ GameRules Reference Table
- ๐ฌ Brigadier Commands & Absence Scope
- ๐ Advancements & Absence Scope
- ๐ฅ๏ธ HUD, Diagnostics & Rendering
- ๐ ๏ธ Developer Setup & Gradle Builds
- ๐งฉ Architecture & Mixin Subsystem
- ๐ DasikLibrary API Integration