1818
1919package io .github .axolotlclient .oldanimations .mixin ;
2020
21+ import com .llamalad7 .mixinextras .expression .Expression ;
2122import com .llamalad7 .mixinextras .injector .ModifyExpressionValue ;
2223import com .llamalad7 .mixinextras .injector .v2 .WrapWithCondition ;
24+ import com .llamalad7 .mixinextras .injector .wrapoperation .Operation ;
25+ import com .llamalad7 .mixinextras .injector .wrapoperation .WrapOperation ;
2326import io .github .axolotlclient .oldanimations .config .OldAnimationsConfig ;
27+ import net .minecraft .client .gui .screen .Screen ;
2428import net .minecraft .client .gui .screen .options .OptionsScreen ;
29+ import net .minecraft .client .gui .widget .ButtonWidget ;
30+ import net .minecraft .client .options .GameOptions ;
31+ import net .minecraft .client .resource .language .I18n ;
32+ import net .minecraft .client .world .ClientWorld ;
33+ import net .minecraft .world .Difficulty ;
2534import org .objectweb .asm .Opcodes ;
35+ import org .spongepowered .asm .mixin .Final ;
2636import org .spongepowered .asm .mixin .Mixin ;
37+ import org .spongepowered .asm .mixin .Shadow ;
2738import org .spongepowered .asm .mixin .injection .At ;
39+ import org .spongepowered .asm .mixin .injection .Inject ;
40+ import org .spongepowered .asm .mixin .injection .ModifyArg ;
41+ import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
2842
2943import java .util .List ;
3044
3145@ Mixin (OptionsScreen .class )
32- public class OptionsScreenMixin {
46+ public abstract class OptionsScreenMixin extends Screen {
47+
48+ @ Shadow
49+ @ Final
50+ private GameOptions options ;
51+
52+ @ Shadow
53+ private ButtonWidget difficultyButton ;
54+
55+ @ Shadow
56+ public abstract String getButtonLabel (Difficulty difficulty );
3357
3458 @ WrapWithCondition (method = "init" , at = @ At (value = "INVOKE" , target = "Ljava/util/List;add(Ljava/lang/Object;)Z" , ordinal = 5 ))
3559 private <E > boolean axolotlclient$disableSkinCustomizationButton (List <?> instance , E e ) {
@@ -43,9 +67,81 @@ public class OptionsScreenMixin {
4367 return OldAnimationsConfig .isEnabled () && OldAnimationsConfig .instance .oldMultiplayerSettingsPage .get () ? "options.multiplayer.title" : original ;
4468 }
4569
46- @ ModifyExpressionValue (method = "buttonClicked" , at = @ At (value = "FIELD" , opcode = Opcodes .GETFIELD , target = "Lnet/minecraft/client/gui/widget/ButtonWidget;id:I" , ordinal = 4 ))
47- private int axolotlclient$disableSkinCustomizationButton2 (int original ) {
48- /* disables the functionality of the skin customization button */
49- return OldAnimationsConfig .isEnabled () && OldAnimationsConfig .instance .disableSkinCustomizationButton .get () ? -1 : original ;
70+ @ Inject (method = "buttonClicked" , at = @ At (value = "FIELD" , opcode = Opcodes .GETFIELD , target = "Lnet/minecraft/client/gui/widget/ButtonWidget;id:I" , ordinal = 2 ))
71+ private void axolotlclient$onlySetIfInWorld (ButtonWidget buttonWidget , CallbackInfo ci ) {
72+ if (OldAnimationsConfig .isEnabled () && OldAnimationsConfig .instance .disableSkinCustomizationButton .get () && minecraft .world == null && buttonWidget .id == 108 ) {
73+ /* this is so silly... but the alternatives are not fun :p */
74+ options .difficulty = Difficulty .byId (options .difficulty .getId () + 1 & 3 );
75+ difficultyButton .message = getButtonLabel (options .difficulty );
76+ }
77+ }
78+
79+ @ ModifyExpressionValue (method = "buttonClicked" , at = @ At (value = "FIELD" , opcode = Opcodes .GETFIELD , target = "Lnet/minecraft/client/gui/widget/ButtonWidget;id:I" , ordinal = 2 ))
80+ private int axolotlclient$onlySetIfInWorld (int original ) {
81+ /* because we're going to be able to toggle this button while not in a world, we can avoid the game crashing by */
82+ /* checking if the world is valid before we set the difficulty */
83+ return OldAnimationsConfig .isEnabled () && OldAnimationsConfig .instance .disableSkinCustomizationButton .get () && minecraft .world == null ? -1 : original ;
84+ }
85+
86+ @ ModifyArg (method = "buttonClicked" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/world/Difficulty;byId(I)Lnet/minecraft/world/Difficulty;" ), index = 0 )
87+ private int axolotlclient$useOptionsDifficulty (int i ) {
88+ /* use the options difficulty */
89+ if (OldAnimationsConfig .isEnabled () && OldAnimationsConfig .instance .oldDifficultyButtonLogic .get ()) {
90+ return options .difficulty .getId () + 1 & 3 ;
91+ }
92+ return i ;
93+ }
94+
95+ @ Inject (method = "buttonClicked" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/gui/screen/options/OptionsScreen;getButtonLabel(Lnet/minecraft/world/Difficulty;)Ljava/lang/String;" ))
96+ private void axolotlclient$updateOptionsDifficulty (ButtonWidget buttonWidget , CallbackInfo ci ) {
97+ /* update the options difficulty */
98+ if (OldAnimationsConfig .isEnabled () && OldAnimationsConfig .instance .oldDifficultyButtonLogic .get ()) {
99+ options .difficulty = Difficulty .byId (options .difficulty .getId () + 1 & 3 );
100+ }
101+ }
102+
103+ @ WrapOperation (method = "init" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/world/ClientWorld;getDifficulty()Lnet/minecraft/world/Difficulty;" ))
104+ private Difficulty axolotlclient$tryNotToCrashGame (ClientWorld instance , Operation <Difficulty > original ) {
105+ /* if we don't do this, our game will crash as no valid world is loaded */
106+ if (OldAnimationsConfig .isEnabled () && OldAnimationsConfig .instance .oldDifficultyButtonLogic .get ()) {
107+ return options .difficulty ;
108+ }
109+ return original .call (instance );
110+ }
111+
112+ @ Expression ("? != null" )
113+ @ ModifyExpressionValue (method = "init" , at = @ At (value = "MIXINEXTRAS:EXPRESSION" , ordinal = 0 ))
114+ private boolean axolotlclient$skipRealmsNotificationButton (boolean original ) {
115+ if (OldAnimationsConfig .isEnabled () && OldAnimationsConfig .instance .oldDifficultyButtonLogic .get ()) {
116+ /* now, the realms notification button will never be rendered. */
117+ /* unfortunately, this was the only injection i could think of to get this feature out in a compatible manner */
118+ return true ;
119+ }
120+ return original ;
121+ }
122+
123+ @ ModifyExpressionValue (method = "init" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/Minecraft;isInSingleplayer()Z" ))
124+ private boolean axolotlclient$skipLockedDifficultyRendering (boolean original ) {
125+ if (OldAnimationsConfig .isEnabled () && OldAnimationsConfig .instance .oldDifficultyButtonLogic .get ()) {
126+ /* we might as well skip over this to reduce the amount of work needed to replicate the old difficulty button */
127+ return false ;
128+ }
129+ return original ;
130+ }
131+
132+ @ WrapWithCondition (method = "init" , at = @ At (value = "FIELD" , target = "Lnet/minecraft/client/gui/widget/ButtonWidget;active:Z" , ordinal = 1 ))
133+ private boolean axolotlclient$disableActiveState (ButtonWidget instance , boolean value ) {
134+ /* you were a pawn */
135+ return !OldAnimationsConfig .isEnabled () || !OldAnimationsConfig .instance .oldDifficultyButtonLogic .get ();
136+ }
137+
138+ @ Inject (method = "init" , at = @ At (value = "FIELD" , target = "Lnet/minecraft/client/gui/widget/ButtonWidget;active:Z" , ordinal = 1 ))
139+ private void axolotlclient$addHardcoreState (CallbackInfo ci ) {
140+ if (OldAnimationsConfig .isEnabled () && OldAnimationsConfig .instance .oldDifficultyButtonLogic .get () &&
141+ minecraft .world != null && minecraft .world .getData ().isHardcore ()) {
142+ /* because we basically overwrote the original hardcore button code, we should add this :p */
143+ difficultyButton .active = false ;
144+ difficultyButton .message = I18n .translate ("options.difficulty" ) + ": " + I18n .translate ("options.difficulty.hardcore" );
145+ }
50146 }
51147}
0 commit comments