Skip to content

🧩 Arquitetura & Subsistema Mixin

ParâmetroEspecificação
Arquivo de Mixinsrc/main/resources/collapsible-game-rules.mixins.json
Identificador Refmapcollapsible-game-rules-refmap.json
Nível de CompatibilidadeJAVA_25
Default Require1
Pacote Raiznet.instantgratification.collapsiblegamerules
Pacote Mixinnet.instantgratification.collapsiblegamerules.mixin
Total de Mixins4 Mixins de Cliente (3 Injetores + 1 Acessor de Interface)

📖 Arquitetura de Pacotes

net.instantgratification.collapsiblegamerules
├── CollapsibleGameRulesFabric.java           ──> Main ModInitializer (Guard & Hard Dependency check)
├── CollapsibleGameRulesFabricClient.java     ──> ClientModInitializer (Loads GameRuleStateConfig)
├── GameRuleStateConfig.java                  ──> Config & JSON state persistence (Set<String>)
├── mixin
│   ├── AbstractGameRulesScreenRuleListMixin.java ──> Core engine (List interception, CollapsibleCategoryRuleEntry)
│   ├── CategoryRuleEntryAccessor.java        ──> Interface Accessor for category Component label
│   ├── IntegerRuleEntryMixin.java            ──> Abstract wrapper for integer rule entries
│   └── ScreenMixin.java                      ──> Intercepts Screen.removed() to flush pending state
├── preset
│   └── GameRulePresetEngine.java             ──> Built-in preset definitions (Builder, Fast Play, Hardcore)
├── ui
│   ├── BooleanToggleWidget.java              ──> Interactive emerald green / ruby red toggle switch
│   ├── GlobalActionsRuleEntry.java           ──> Pinned index 0 bulk toggle header ([ Expand ] / [ Collapse ])
│   └── IntegerSliderWidget.java              ──> Draggable numeric slider with math normalization
└── util
    ├── CategoryPrettifier.java               ──> Regex & string parser for unlocalized category keys
    ├── DasikMetadataHelper.java              ──> Lazy-loaded isolation layer querying DasikLibrary
    ├── GameRuleSliderHelper.java             ──> Vanilla integer rule bounds and default values
    └── ModVersionGuard.java                  ──> Zero-dependency runtime Knot ClassLoader integrity check

🔍 Detalhamento dos Mixins

1. AbstractGameRulesScreenRuleListMixin

  • Classe Alvo: net.minecraft.client.gui.screens.worldselection.AbstractGameRulesScreen.RuleList.class
  • Hierarquia: Estende ContainerObjectSelectionList<AbstractGameRulesScreen.RuleEntry>
  • Papel: Controlador principal da interface. Intercepta a montagem da lista, calcula regras por categoria, filtra visibilidade e desenha os cabeçalhos dinâmicos.
java
@Mixin(AbstractGameRulesScreen.RuleList.class)
public abstract class AbstractGameRulesScreenRuleListMixin
        extends ContainerObjectSelectionList<AbstractGameRulesScreen.RuleEntry> {

    @Unique
    private List<AbstractGameRulesScreen.RuleEntry> collapsible_game_rules$allEntries = new ArrayList<>();

    @Unique
    private String collapsible_game_rules$currentFilter = "";

    @Inject(method = "populateChildren(Ljava/lang/String;)V", at = @At("TAIL"))
    private void collapsible_game_rules$onPopulateChildren(String filter, CallbackInfo ci) {
        this.collapsible_game_rules$currentFilter = (filter != null) ? filter.toLowerCase(java.util.Locale.ROOT) : "";
        this.collapsible_game_rules$allEntries = new ArrayList<>(this.children());
        this.collapsible_game_rules$updateVisibleEntries();
    }
}

2. CategoryRuleEntryAccessor

  • Classe Alvo: net.minecraft.client.gui.screens.worldselection.AbstractGameRulesScreen.CategoryRuleEntry.class
  • Papel: Oferece acesso via bytecode ao campo privado Component label dos cabeçalhos Vanilla.
java
@Mixin(AbstractGameRulesScreen.CategoryRuleEntry.class)
public interface CategoryRuleEntryAccessor {
    @Accessor("label")
    Component collapsible_game_rules$getLabel();
}

3. ScreenMixin

  • Classe Alvo: net.minecraft.client.gui.screens.Screen.class
  • Papel: Escuta o fechamento de telas. Ao sair do AbstractGameRulesScreen, descarrega alterações para o disco através de GameRuleStateConfig.saveIfDirty().
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();
        }
    }
}

4. IntegerRuleEntryMixin

  • Classe Alvo: net.minecraft.client.gui.screens.worldselection.AbstractGameRulesScreen.IntegerRuleEntry.class
  • Papel: Ponte abstrata para integrar widgets nos campos de inteiros do Vanilla.
java
@Mixin(AbstractGameRulesScreen.IntegerRuleEntry.class)
public abstract class IntegerRuleEntryMixin extends AbstractGameRulesScreen.RuleEntry {
    public IntegerRuleEntryMixin() {
        super(null);
    }
}

📜 Arquivo de Configuração Mixin (collapsible-game-rules.mixins.json)

json
{
    "required": true,
    "package": "net.instantgratification.collapsiblegamerules.mixin",
    "refmap": "collapsible-game-rules-refmap.json",
    "compatibilityLevel": "JAVA_25",
    "client": [
        "ScreenMixin",
        "AbstractGameRulesScreenRuleListMixin",
        "CategoryRuleEntryAccessor",
        "IntegerRuleEntryMixin"
    ],
    "injectors": {
        "defaultRequire": 1
    }
}

🔗 Documentação Relacionada

Official documentation & web portal for Dasik Igaijinn mods.