11package se .icus .mag .statuseffecttimer .mixin ;
22
3- import com .google . common . collect . Ordering ;
3+ import com .llamalad7 . mixinextras . sugar . Local ;
44import net .fabricmc .api .EnvType ;
55import net .fabricmc .api .Environment ;
66import net .minecraft .client .MinecraftClient ;
77import net .minecraft .client .gui .DrawableHelper ;
88import net .minecraft .client .gui .hud .InGameHud ;
99import net .minecraft .client .resource .language .I18n ;
1010import net .minecraft .client .util .math .MatrixStack ;
11- import net .minecraft .entity .effect .StatusEffect ;
1211import net .minecraft .entity .effect .StatusEffectInstance ;
1312import net .minecraft .util .math .MathHelper ;
1413import org .jetbrains .annotations .NotNull ;
1918import org .spongepowered .asm .mixin .injection .Inject ;
2019import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
2120
22- import java .util .Collection ;
21+ import java .util .List ;
2322
2423// Set priority to 500, to load before default at 1000. This is to better cooperate with HUDTweaks.
2524@ Environment (EnvType .CLIENT )
@@ -28,38 +27,14 @@ public abstract class StatusEffectTimerMixin extends DrawableHelper {
2827 @ Shadow @ Final
2928 private MinecraftClient client ;
3029
31- @ Inject (method = "renderStatusEffectOverlay" , at = @ At ("TAIL" ))
32- private void renderDurationOverlay (MatrixStack matrices , CallbackInfo c ) {
33- Collection <StatusEffectInstance > collection = this .client .player .getStatusEffects ();
34- if (!collection .isEmpty ()) {
35- // Replicate vanilla placement algorithm to get the duration
36- // labels to line up exactly right.
37-
38- int beneficialCount = 0 ;
39- int nonBeneficialCount = 0 ;
40- for (StatusEffectInstance statusEffectInstance : Ordering .natural ().reverse ().sortedCopy (collection )) {
41- StatusEffect statusEffect = statusEffectInstance .getEffectType ();
42- if (statusEffectInstance .shouldShowIcon ()) {
43- int x = this .client .getWindow ().getScaledWidth ();
44- int y = 1 ;
45-
46- if (this .client .isDemo ()) {
47- y += 15 ;
48- }
49-
50- if (statusEffect .isBeneficial ()) {
51- beneficialCount ++;
52- x -= 25 * beneficialCount ;
53- } else {
54- nonBeneficialCount ++;
55- x -= 25 * nonBeneficialCount ;
56- y += 26 ;
57- }
58-
59- drawStatusEffectOverlay (matrices , statusEffectInstance , x , y );
60- }
61- }
62- }
30+ @ Inject (method = "renderStatusEffectOverlay" ,
31+ at = @ At (value = "INVOKE" , target = "Ljava/util/List;add(Ljava/lang/Object;)Z" , shift = At .Shift .AFTER ))
32+ private void appendOverlayDrawing (MatrixStack matrices , CallbackInfo c ,
33+ @ Local List <Runnable > list , @ Local StatusEffectInstance statusEffectInstance ,
34+ @ Local (ordinal = 4 ) int x , @ Local (ordinal = 3 ) int y ) {
35+ list .add (() -> {
36+ drawStatusEffectOverlay (matrices , statusEffectInstance , x , y );
37+ });
6338 }
6439
6540 private void drawStatusEffectOverlay (MatrixStack matrices , StatusEffectInstance statusEffectInstance , int x , int y ) {
0 commit comments