2323import com .llamalad7 .mixinextras .sugar .Local ;
2424import com .mojang .blaze3d .pipeline .RenderPipeline ;
2525import dev .terminalmc .effecttimerplus .config .Config ;
26- import net .minecraft .client .DeltaTracker ;
2726import net .minecraft .client .Minecraft ;
28- import net .minecraft .client .gui .Gui ;
2927import net .minecraft .client .gui .GuiGraphicsExtractor ;
28+ import net .minecraft .client .gui .screens .inventory .EffectsInInventory ;
3029import net .minecraft .resources .Identifier ;
3130import net .minecraft .world .effect .MobEffectInstance ;
3231import org .jetbrains .annotations .Nullable ;
3837import org .spongepowered .asm .mixin .injection .Inject ;
3938import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
4039
40+ import java .util .Collection ;
41+
4142import static dev .terminalmc .effecttimerplus .util .IndicatorUtil .*;
4243
4344/**
4445 * This file includes derivative work of code from
4546 * <a href="https://github.com/magicus/statuseffecttimer">Status Effect Timer</a>
4647 */
4748@ Mixin (
48- value = Gui .class ,
49+ value = EffectsInInventory .class ,
4950 priority = 2000
5051)
51- public abstract class MixinGui {
52+ public abstract class EffectsInInventoryMixin {
5253
5354 @ Final
5455 @ Shadow
@@ -62,7 +63,16 @@ public abstract class MixinGui {
6263 method = "extractEffects" ,
6364 at = @ At ("HEAD" )
6465 )
65- private void scale (GuiGraphicsExtractor graphics , DeltaTracker delta , CallbackInfo ci ) {
66+ private void scale (
67+ GuiGraphicsExtractor graphics ,
68+ Collection <MobEffectInstance > activeEffects ,
69+ int x0 ,
70+ int yStep ,
71+ int mouseX ,
72+ int mouseY ,
73+ int maxWidth ,
74+ CallbackInfo ci
75+ ) {
6676 float scale = (float ) Config .get ().scale ;
6777 graphics .pose ().pushMatrix ();
6878 graphics .pose ().translate (graphics .guiWidth () * (1 - scale ), 0.0F );
@@ -73,7 +83,16 @@ private void scale(GuiGraphicsExtractor graphics, DeltaTracker delta, CallbackIn
7383 method = "extractEffects" ,
7484 at = @ At ("RETURN" )
7585 )
76- private void descale (GuiGraphicsExtractor graphics , DeltaTracker delta , CallbackInfo ci ) {
86+ private void descale (
87+ GuiGraphicsExtractor graphics ,
88+ Collection <MobEffectInstance > activeEffects ,
89+ int x0 ,
90+ int yStep ,
91+ int mouseX ,
92+ int mouseY ,
93+ int maxWidth ,
94+ CallbackInfo ci
95+ ) {
7796 graphics .pose ().popMatrix ();
7897 }
7998
@@ -85,17 +104,24 @@ private void descale(GuiGraphicsExtractor graphics, DeltaTracker delta, Callback
85104 )
86105 )
87106 private void CreateOverlayRunnable (
88- GuiGraphicsExtractor graphics , RenderPipeline pipeline ,
89- Identifier sprite , int x , int y , int width , int height ,
90- Operation <Void > original , @ Local MobEffectInstance effectInstance
107+ GuiGraphicsExtractor instance ,
108+ RenderPipeline renderPipeline ,
109+ Identifier location ,
110+ int x ,
111+ int y ,
112+ int width ,
113+ int height ,
114+ Operation <Void > original ,
115+ @ Local (name = "effect" ) MobEffectInstance effect
116+
91117 ) {
92- original .call (graphics , pipeline , sprite , x , y , width , height );
118+ original .call (instance , renderPipeline , location , x , y , width , height );
93119
94120 Config options = Config .get ();
95121 effectTimerPlus$runnable = () -> {
96122 // Render potency overlay
97- if (options .potencyEnabled && effectInstance .getAmplifier () > 0 ) {
98- String label = getAmplifierAsString (effectInstance .getAmplifier ());
123+ if (options .potencyEnabled && effect .getAmplifier () > 0 ) {
124+ String label = getAmplifierAsString (effect .getAmplifier ());
99125 int labelWidth = minecraft .font .width (label );
100126 int posX = x + getTextOffsetX (options .potencyLocation , labelWidth , width );
101127 int posY = y + getTextOffsetY (
@@ -105,37 +131,37 @@ private void CreateOverlayRunnable(
105131 );
106132
107133 float scale = (float ) Config .get ().potencyScale ;
108- graphics .pose ().pushMatrix ();
109- graphics .pose ().translate (posX * (1 - scale ), posY * (1 - scale ));
110- graphics .pose ().translate (
134+ instance .pose ().pushMatrix ();
135+ instance .pose ().translate (posX * (1 - scale ), posY * (1 - scale ));
136+ instance .pose ().translate (
111137 getScaleTranslateX (options .potencyLocation , labelWidth , scale ),
112138 getScaleTranslateY (
113139 options .potencyLocation ,
114140 minecraft .font .lineHeight ,
115141 scale
116142 )
117143 );
118- graphics .pose ().scale (scale , scale );
144+ instance .pose ().scale (scale , scale );
119145 if (options .potencyBack ) {
120- graphics .fill (
146+ instance .fill (
121147 posX - 1 , posY - 1 , posX + labelWidth ,
122148 posY + minecraft .font .lineHeight - 1 , options .potencyBackColor
123149 );
124150 }
125- graphics .text (
151+ instance .text (
126152 minecraft .font ,
127153 label ,
128154 posX ,
129155 posY ,
130156 options .potencyColor ,
131157 options .potencyShadow
132158 );
133- graphics .pose ().popMatrix ();
159+ instance .pose ().popMatrix ();
134160 }
135161 // Render timer overlay
136162 if (options .timerEnabled && (options .timerEnabledAmbient
137- || !effectInstance .isAmbient ())) {
138- String label = getDurationAsString (effectInstance .getDuration ());
163+ || !effect .isAmbient ())) {
164+ String label = getDurationAsString (effect .getDuration ());
139165 int labelWidth = minecraft .font .width (label );
140166 int posX = x + getTextOffsetX (options .timerLocation , labelWidth , width );
141167 int posY = y + getTextOffsetY (
@@ -145,26 +171,26 @@ private void CreateOverlayRunnable(
145171 );
146172
147173 int color = getTimerColor (
148- effectInstance , options .timerColor ,
174+ effect , options .timerColor ,
149175 options .timerWarnEnabled , options .timerWarnTime ,
150176 options .timerWarnColor , options .timerFlashEnabled
151177 );
152178 float scale = (float ) Config .get ().timerScale ;
153- graphics .pose ().pushMatrix ();
154- graphics .pose ().translate (posX * (1 - scale ), posY * (1 - scale ));
155- graphics .pose ().translate (
179+ instance .pose ().pushMatrix ();
180+ instance .pose ().translate (posX * (1 - scale ), posY * (1 - scale ));
181+ instance .pose ().translate (
156182 getScaleTranslateX (options .timerLocation , labelWidth , scale ),
157183 getScaleTranslateY (options .timerLocation , minecraft .font .lineHeight , scale )
158184 );
159- graphics .pose ().scale (scale , scale );
185+ instance .pose ().scale (scale , scale );
160186 if (options .timerBack ) {
161- graphics .fill (
187+ instance .fill (
162188 posX - 1 , posY - 1 , posX + labelWidth ,
163189 posY + minecraft .font .lineHeight - 1 , options .timerBackColor
164190 );
165191 }
166- graphics .text (minecraft .font , label , posX , posY , color , options .timerShadow );
167- graphics .pose ().popMatrix ();
192+ instance .text (minecraft .font , label , posX , posY , color , options .timerShadow );
193+ instance .pose ().popMatrix ();
168194 }
169195 };
170196 }
@@ -173,13 +199,18 @@ private void CreateOverlayRunnable(
173199 method = "extractEffects" ,
174200 at = @ At (
175201 value = "INVOKE" ,
176- target = "Lnet/minecraft/client/gui/GuiGraphicsExtractor;blitSprite(Lcom/mojang/blaze3d/pipeline/RenderPipeline;Lnet/minecraft/resources/Identifier;IIIII )V" ,
202+ target = "Lnet/minecraft/client/gui/GuiGraphicsExtractor;blitSprite(Lcom/mojang/blaze3d/pipeline/RenderPipeline;Lnet/minecraft/resources/Identifier;IIII )V" ,
177203 shift = At .Shift .AFTER
178204 )
179205 )
180206 private void AddOverlayRunnable (
181207 GuiGraphicsExtractor graphics ,
182- DeltaTracker deltaTracker ,
208+ Collection <MobEffectInstance > activeEffects ,
209+ int x0 ,
210+ int yStep ,
211+ int mouseX ,
212+ int mouseY ,
213+ int maxWidth ,
183214 CallbackInfo ci
184215 ) {
185216 if (effectTimerPlus$runnable != null ) {
0 commit comments