-
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.
- Loading branch information
Showing
7 changed files
with
127 additions
and
17 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
23 changes: 23 additions & 0 deletions
23
src/main/java/github/io/lucunji/explayerenderer/mixin/yacl/AbstractWidgetMixin.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,23 @@ | ||
package github.io.lucunji.explayerenderer.mixin.yacl; | ||
|
||
import dev.isxander.yacl3.gui.AbstractWidget; | ||
import dev.isxander.yacl3.gui.controllers.ControllerWidget; | ||
import github.io.lucunji.explayerenderer.config.Configs; | ||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.client.gui.Element; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(AbstractWidget.class) | ||
public class AbstractWidgetMixin { | ||
@Inject(method = "drawButtonRect", at = @At(value = "HEAD"), cancellable = true) | ||
public void skipDrawingButtonBackground(DrawContext graphics, int x1, int y1, int x2, int y2, boolean hovered, boolean enabled, CallbackInfo ci) { | ||
//noinspection ConstantValue | ||
if (((Element) this) instanceof ControllerWidget<?> controllerWidget | ||
&& Configs.isConfigScreen(((ControllerWidgetAccessor) controllerWidget).getScreen())) { | ||
ci.cancel(); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/github/io/lucunji/explayerenderer/mixin/yacl/ControllerWidgetAccessor.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,12 @@ | ||
package github.io.lucunji.explayerenderer.mixin.yacl; | ||
|
||
import dev.isxander.yacl3.gui.YACLScreen; | ||
import dev.isxander.yacl3.gui.controllers.ControllerWidget; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Mixin(ControllerWidget.class) | ||
public interface ControllerWidgetAccessor { | ||
@Accessor | ||
YACLScreen getScreen(); | ||
} |
79 changes: 79 additions & 0 deletions
79
src/main/java/github/io/lucunji/explayerenderer/mixin/yacl/YACLScreenMixin.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,79 @@ | ||
package github.io.lucunji.explayerenderer.mixin.yacl; | ||
|
||
import dev.isxander.yacl3.api.Option; | ||
import dev.isxander.yacl3.api.YetAnotherConfigLib; | ||
import dev.isxander.yacl3.api.utils.OptionUtils; | ||
import dev.isxander.yacl3.gui.YACLScreen; | ||
import dev.isxander.yacl3.impl.utils.YACLConstants; | ||
import github.io.lucunji.explayerenderer.config.Configs; | ||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.client.gui.screen.Screen; | ||
import net.minecraft.client.gui.tab.TabManager; | ||
import net.minecraft.text.Text; | ||
import org.spongepowered.asm.mixin.Final; | ||
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; | ||
|
||
@Mixin(YACLScreen.class) | ||
public abstract class YACLScreenMixin extends Screen { | ||
@Shadow | ||
public abstract boolean pendingChanges(); | ||
|
||
@Shadow | ||
@Final | ||
public YetAnotherConfigLib config; | ||
|
||
@Shadow | ||
@Final | ||
public TabManager tabManager; | ||
|
||
@Shadow private boolean pendingChanges; | ||
|
||
protected YACLScreenMixin(Text title) { | ||
super(title); | ||
} | ||
|
||
@Inject(method = "renderBackground", at = @At("HEAD"), cancellable = true) | ||
public void renderBackground(DrawContext guiGraphics, int mouseX, int mouseY, float partialTick, CallbackInfo ci) { | ||
if (!Configs.isConfigScreen(this)) return; | ||
|
||
renderDarkening(guiGraphics); | ||
ci.cancel(); | ||
} | ||
|
||
/** | ||
* Instantly apply changes, without saving to file or triggering any flag. | ||
* Force {@link #pendingChanges} to {@code true} | ||
*/ | ||
@Inject(method = "onOptionChanged", at = @At("RETURN"), remap = false) | ||
public void applyOnOptionChanged(Option<?> opt, CallbackInfo ci) { | ||
if (!Configs.isConfigScreen(this)) return; | ||
|
||
pendingChanges = true; | ||
|
||
OptionUtils.forEachOptions(config, Option::applyValue); | ||
OptionUtils.forEachOptions(config, option -> { | ||
if (option.changed()) { | ||
option.forgetPendingValue(); | ||
YACLConstants.LOGGER.error("Option '{}' value mismatch after applying! Reset to binding's getter.", option.name().getString()); | ||
} | ||
}); | ||
|
||
if (tabManager.getCurrentTab() instanceof YACLScreen.CategoryTab categoryTab) { | ||
categoryTab.updateButtons(); | ||
categoryTab.undoButton.active = false; | ||
} | ||
} | ||
|
||
@Inject(method = "cancelOrReset", at = @At("HEAD"), remap = false) | ||
public void reloadOnCancelled(CallbackInfo ci) { | ||
if (Configs.isConfigScreen(this)) return; | ||
|
||
if (pendingChanges()) { | ||
Configs.HANDLER.load(); | ||
} | ||
} | ||
} |
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