|
| 1 | +package me.voidxwalker.anchiale.mixin; |
| 2 | + |
| 3 | +import me.voidxwalker.anchiale.Anchiale; |
| 4 | +import net.minecraft.client.gui.screen.*; |
| 5 | +import net.minecraft.client.gui.widget.ButtonWidget; |
| 6 | +import org.spongepowered.asm.mixin.*; |
| 7 | +import org.spongepowered.asm.mixin.injection.*; |
| 8 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 9 | + |
| 10 | +@Mixin(SettingsScreen.class) |
| 11 | +public abstract class SettingsScreenMixin extends Screen { |
| 12 | + @Unique |
| 13 | + private ButtonWidget locationButton; |
| 14 | + |
| 15 | + @ModifyArg(method = "init", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/ButtonWidget;<init>(IIIIILjava/lang/String;)V", ordinal = 0), slice = @Slice(from = @At(value = "CONSTANT", args = "stringValue=options.stream"))) |
| 16 | + private String renameBroadcastButton(String string) { |
| 17 | + return Anchiale.buttonLocation.toString(); |
| 18 | + } |
| 19 | + |
| 20 | + // modifyexpressionvalue on invoke <init> doesn't work and on new is before the string ldc for some reason |
| 21 | + @ModifyArg(method = "init", at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z", ordinal = 0), slice = @Slice(from = @At(value = "CONSTANT", args = "stringValue=options.stream"))) |
| 22 | + private Object captureLocationButton(Object button) { |
| 23 | + locationButton = (ButtonWidget) button; |
| 24 | + return button; |
| 25 | + } |
| 26 | + |
| 27 | + @Inject(method = "buttonClicked", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;getTwitchStreamProvider()Lnet/minecraft/client/util/TwitchStreamProvider;"), cancellable = true) |
| 28 | + private void locationButtonClicked(ButtonWidget button, CallbackInfo ci) { |
| 29 | + Anchiale.ButtonLocation[] locations = Anchiale.ButtonLocation.values(); |
| 30 | + Anchiale.buttonLocation = locations[(Anchiale.buttonLocation.ordinal() + 1) % locations.length]; |
| 31 | + locationButton.message = Anchiale.buttonLocation.toString(); |
| 32 | + Anchiale.saveConfig(); |
| 33 | + ci.cancel(); |
| 34 | + } |
| 35 | +} |
0 commit comments