-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auto create config gui if no gui factory is registered (#79)
Co-authored-by: Martin Robertz <[email protected]>
- Loading branch information
1 parent
4ddb3e8
commit 3d6099b
Showing
5 changed files
with
94 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/main/java/com/gtnewhorizon/gtnhlib/mixins/early/fml/MixinGuiModList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.gtnewhorizon.gtnhlib.mixins.early.fml; | ||
|
||
import net.minecraft.client.gui.GuiButton; | ||
import net.minecraft.client.gui.GuiScreen; | ||
|
||
import org.spongepowered.asm.lib.Opcodes; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import com.gtnewhorizon.gtnhlib.config.ConfigException; | ||
import com.gtnewhorizon.gtnhlib.config.ConfigurationManager; | ||
import com.gtnewhorizon.gtnhlib.config.SimpleGuiConfig; | ||
import com.llamalad7.mixinextras.sugar.Local; | ||
|
||
import cpw.mods.fml.client.GuiModList; | ||
import cpw.mods.fml.client.IModGuiFactory; | ||
import cpw.mods.fml.common.ModContainer; | ||
|
||
@Mixin(GuiModList.class) | ||
public abstract class MixinGuiModList extends GuiScreen { | ||
|
||
@Shadow(remap = false) | ||
private ModContainer selectedMod; | ||
|
||
@Shadow(remap = false) | ||
private GuiButton configModButton; | ||
|
||
@Inject( | ||
method = "actionPerformed", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lcpw/mods/fml/client/IModGuiFactory;mainConfigGuiClass()Ljava/lang/Class;", | ||
remap = false), | ||
cancellable = true) | ||
private void gtnhlib$autoCreateGuiConfig(GuiButton button, CallbackInfo ci, @Local IModGuiFactory guiFactory) { | ||
if (guiFactory == null && ConfigurationManager.isModRegistered(selectedMod.getModId())) { | ||
ci.cancel(); | ||
try { | ||
GuiScreen config = new SimpleGuiConfig(this, selectedMod.getModId(), selectedMod.getName()); | ||
mc.displayGuiScreen(config); | ||
} catch (ConfigException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
|
||
@Inject( | ||
method = "drawScreen", | ||
at = @At( | ||
value = "FIELD", | ||
opcode = Opcodes.PUTFIELD, | ||
target = "Lnet/minecraft/client/gui/GuiButton;enabled:Z", | ||
shift = At.Shift.AFTER, | ||
ordinal = 4)) | ||
private void gtnhlib$checkForRegisteredConfig(int p_571_1_, int p_571_2_, float p_571_3_, CallbackInfo ci) { | ||
if (ConfigurationManager.isModRegistered(selectedMod.getModId())) { | ||
configModButton.enabled = true; | ||
} | ||
} | ||
} |