aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/mixins/PlayerListHudMixin.java
blob: a96a7727408396c9a841b1cffe169da047ab0a9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package de.hysky.skyblocker.mixins;

import de.hysky.skyblocker.skyblock.tabhud.screenbuilder.ScreenMaster;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.tabhud.TabHud;
import de.hysky.skyblocker.skyblock.tabhud.util.PlayerListMgr;
import de.hysky.skyblocker.utils.Utils;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.hud.PlayerListHud;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import com.llamalad7.mixinextras.sugar.Local;

@Environment(EnvType.CLIENT)
@Mixin(PlayerListHud.class)
public class PlayerListHudMixin {
    @Shadow
    private Text footer;

    @Inject(at = @At("HEAD"), method = "render", cancellable = true)
    public void skyblocker$renderTabHud(CallbackInfo info, @Local(argsOnly = true) DrawContext context, @Local(argsOnly = true) int w) {
        if (!Utils.isInDungeons() || !SkyblockerConfigManager.get().uiAndVisuals.tabHud.tabHudEnabled || TabHud.defaultTgl.isPressed()) {
            return;
        }

        ClientPlayNetworkHandler nwH = MinecraftClient.getInstance().getNetworkHandler();
        if (nwH == null) {
            return;
        }

        int h = MinecraftClient.getInstance().getWindow().getScaledHeight();
        float scale = SkyblockerConfigManager.get().uiAndVisuals.tabHud.tabHudScale / 100f;
        w = (int) (w / scale);
        h = (int) (h / scale);

        PlayerListMgr.updateFooter(footer);

        try {
            ScreenMaster.render(context, w,h);
            // Screen screen = Screen.getCorrect(w, h, footer);
            // screen.render(context);
            info.cancel();
        } catch (Exception e) {
            TabHud.LOGGER.error("[Skyblocker] Encountered unknown exception while drawing default hud", e);
        }
    }

}