Skip to content

🧠 Zustandsspeicherung & JSON-Konfiguration

ParameterSpezifikation
Konfigurationsklassenet.instantgratification.collapsiblegamerules.GameRuleStateConfig
Speicherort.minecraft/config/collapsible-game-rules-state.json
Speicherstruktur im RAMSet<String> expandedCategories = new HashSet<>()
Serialisierungs-Enginecom.google.gson.Gson (Pretty-Printing aktiviert)
I/O-Drosselungs-Flagprivate static boolean isDirty = false
SpeicherpunktScreenMixin fängt Screen.removed() ab (@At("HEAD"))
SchlüsselstrategieÜbersetzungsschlüssel (TranslatableContents.getKey()) oder Literal

📖 Übersicht

Collapsible Game Rules verfügt über eine asynchrone, gedrosselte Zustandsspeicherung. Kategorien bleiben beim Schließen und erneuten Öffnen in dem Zustand, in dem der Spieler sie hinterlassen hat.


📄 JSON-Konfigurationsformat

Die Datei .minecraft/config/collapsible-game-rules-state.json speichert ein klares JSON-Array:

json
[
  "gamerule.category.spawning",
  "gamerule.category.mobs",
  "gamerule.category.updates"
]
  • Im Array vorhanden: Die Kategorie ist aktuell AUSGEKLAPPT.
  • Im Array nicht vorhanden: Die Kategorie ist aktuell EINGEKLAPPT (Standard).

⚡ Leistungsstarke I/O-Drosselung

Festplattenzugriffe bei jedem Klick würden Mikroruckler verursachen. Um stotterfreie 60+ FPS zu garantieren, nutzt GameRuleStateConfig das isDirty-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) Ellipsis                                      │
│        ├─ Writes JSON to disk in background buffer                          │
│        └─ Resets: isDirty = false                                           │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘

💻 API-Methodenreferenz

Öffentliche Methoden von GameRuleStateConfig

MethodensignaturRückgabetypBeschreibung
load()voidLädt collapsible-game-rules-state.json beim Clientstart.
save()voidSchreibt expandedCategories über Files.newBufferedWriter auf Festplatte.
saveIfDirty()voidSchreibt nur bei isDirty == true und setzt das Flag zurück.
isExpanded(String categoryKey)booleanPrüft, ob ein Schlüssel in expandedCategories liegt.
setExpanded(String categoryKey, boolean expanded)voidÄndert den Eintrag im Set und setzt isDirty = true.
expandAll(Iterable<String> allKeys)voidFügt alle Schlüssel dem Set hinzu und markiert isDirty = true.
collapseAll()voidLeert das Set und markiert isDirty = true.

🔒 Bildschirm-Schließung über 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();
        }
    }
}

Dies gewährleistet sicheres Speichern beim Verlassen über Fertig, Abbrechen oder die Escape-Taste.


🔗 Weiterführende Dokumentation

Official documentation & web portal for Dasik Igaijinn mods.