aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/thatgravyboat/skyblockhud/overlay/MiningHud.java
blob: a3aab50b12b43a317cbab4a4b7eafa2093a56ec2 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.thatgravyboat.skyblockhud.overlay;

import com.thatgravyboat.skyblockhud.SkyblockHud;
import com.thatgravyboat.skyblockhud.core.config.Position;
import com.thatgravyboat.skyblockhud.textures.Textures;
import com.thatgravyboat.skyblockhud.utils.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class MiningHud extends Gui {

    private static int fuel, maxFuel;
    private static int heat;

    public static void setFuel(int fuel, int maxFuel) {
        MiningHud.fuel = fuel;
        MiningHud.maxFuel = maxFuel;
    }

    public static void setHeat(int heat) {
        MiningHud.heat = heat;
    }

    public static int getHeat() {
        return heat;
    }

    @SubscribeEvent
    public void renderOverlay(RenderGameOverlayEvent.Post event) {
        if (Utils.overlayShouldRender(event.type, SkyblockHud.hasSkyblockScoreboard(), SkyblockHud.config.mining.showDrillBar || SkyblockHud.config.mining.showHeatBar)) {
            Minecraft mc = Minecraft.getMinecraft();

            if (SkyblockHud.config.mining.barMode == 1) {
                if (heat > 0 && Utils.isDrill(mc.thePlayer.getHeldItem()) && SkyblockHud.config.mining.showDrillBar && SkyblockHud.config.mining.showHeatBar) {
                    renderFuelBar(mc, (event.resolution.getScaledWidth() / 2) - 91, event.resolution.getScaledHeight() - 31);
                    renderHeatBar(mc, (event.resolution.getScaledWidth() / 2) + 46, event.resolution.getScaledHeight() - 31);
                } else if (Utils.isDrill(mc.thePlayer.getHeldItem()) && SkyblockHud.config.mining.showDrillBar) {
                    renderFuelBar(mc, (event.resolution.getScaledWidth() / 2) - 68, event.resolution.getScaledHeight() - 31);
                } else if (heat > 0 && SkyblockHud.config.mining.showHeatBar) {
                    renderHeatBar(mc, (event.resolution.getScaledWidth() / 2) - 22, event.resolution.getScaledHeight() - 31);
                }
            } else if (SkyblockHud.config.mining.barMode == 0) {
                if (heat > 0 && SkyblockHud.config.mining.showHeatBar) {
                    Position position = SkyblockHud.config.mining.heatBar;
                    renderHeatBar(mc, position.getAbsX(event.resolution, 45), position.getAbsY(event.resolution, 7));
                }
                if (Utils.isDrill(mc.thePlayer.getHeldItem()) && SkyblockHud.config.mining.showDrillBar) {
                    Position position = SkyblockHud.config.mining.drillBar;
                    renderFuelBar(mc, position.getAbsX(event.resolution, 136), position.getAbsY(event.resolution, 7));
                }
            }
        }
    }

    private void renderFuelBar(Minecraft mc, int x, int y) {
        if (maxFuel == 0) return;
        GlStateManager.enableBlend();
        GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
        mc.renderEngine.bindTexture(Textures.texture.mines);
        drawTexturedModalRect(x, y, 0, 0, 136, 7);
        drawTexturedModalRect(x, y, 0, 7, Utils.lerp((float) fuel / (float) maxFuel, 0, 136), 7);
        String percentageText = Math.round(((float) fuel / (float) maxFuel) * 100) + "%";
        this.drawCenteredString(mc.fontRendererObj, percentageText, x + 68, y - 2, 0xffffff);
    }

    private void renderHeatBar(Minecraft mc, int x, int y) {
        GlStateManager.enableBlend();
        GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
        mc.renderEngine.bindTexture(Textures.texture.mines);
        drawTexturedModalRect(x, y, 137, 0, 45, 7);
        drawTexturedModalRect(x, y, 137, 7, Utils.lerp(heat / 100f, 0, 45), 7);
    }
}