77import net .minecraft .client .gui .DrawContext ;
88import net .minecraft .client .gui .hud .InGameHud ;
99import net .minecraft .client .render .RenderTickCounter ;
10- import net .minecraft .client .resource .language .I18n ;
1110import net .minecraft .entity .effect .StatusEffectInstance ;
12- import net .minecraft .util .math .MathHelper ;
1311import org .spongepowered .asm .mixin .Final ;
1412import org .spongepowered .asm .mixin .Mixin ;
1513import org .spongepowered .asm .mixin .Shadow ;
14+ import org .spongepowered .asm .mixin .Unique ;
1615import org .spongepowered .asm .mixin .injection .At ;
1716import org .spongepowered .asm .mixin .injection .Inject ;
1817import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
19-
20- import java .util .List ;
18+ import se .icus .mag .statuseffecttimer .StatusEffectTimerRenderer ;
2119
2220// Set priority to 500, to load before default at 1000. This is to better cooperate with HUDTweaks.
2321@ Environment (EnvType .CLIENT )
2422@ Mixin (value = InGameHud .class , priority = 500 )
2523public abstract class StatusEffectTimerMixin {
24+ @ Unique
25+ private StatusEffectTimerRenderer renderer = new StatusEffectTimerRenderer ();
26+
2627 @ Shadow @ Final
2728 private MinecraftClient client ;
2829
@@ -33,37 +34,6 @@ public abstract class StatusEffectTimerMixin {
3334 private void appendOverlayDrawing (DrawContext context , RenderTickCounter tickCounter , CallbackInfo c ,
3435 @ Local StatusEffectInstance statusEffectInstance ,
3536 @ Local (ordinal = 2 ) int x , @ Local (ordinal = 3 ) int y ) {
36- drawStatusEffectOverlay (context , statusEffectInstance , x , y );
37- }
38-
39- private void drawStatusEffectOverlay (DrawContext context , StatusEffectInstance statusEffectInstance , int x , int y ) {
40- String duration = getDurationAsString (statusEffectInstance );
41- int durationLength = client .textRenderer .getWidth (duration );
42- context .drawTextWithShadow (client .textRenderer , duration , x + 13 - (durationLength / 2 ), y + 14 , 0x99FFFFFF );
43-
44- int amplifier = statusEffectInstance .getAmplifier ();
45- if (amplifier > 0 ) {
46- // Convert to roman numerals if possible
47- String amplifierString = (amplifier < 10 ) ? I18n .translate ("enchantment.level." + (amplifier + 1 )) : "**" ;
48- int amplifierLength = client .textRenderer .getWidth (amplifierString );
49- context .drawTextWithShadow (client .textRenderer , amplifierString , x + 22 - amplifierLength , y + 3 , 0x99FFFFFF );
50- }
51- }
52-
53- private String getDurationAsString (StatusEffectInstance statusEffectInstance ) {
54- if (statusEffectInstance .isInfinite ()) {
55- return I18n .translate ("effect.duration.infinite" );
56- }
57-
58- int ticks = MathHelper .floor ((float ) statusEffectInstance .getDuration ());
59- int seconds = ticks / 20 ;
60-
61- if (seconds >= 3600 ) {
62- return seconds / 3600 + "h" ;
63- } else if (seconds >= 60 ) {
64- return seconds / 60 + "m" ;
65- } else {
66- return String .valueOf (seconds );
67- }
37+ renderer .drawStatusEffectOverlay (client , context , statusEffectInstance , x , y );
6838 }
6939}
0 commit comments