aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerHandler.java
blob: d89ea1817392c95398b8ac2db757c0233b48a4b3 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package com.thatgravyboat.skyblockhud.tracker;

import com.thatgravyboat.skyblockhud.LorenzMod;
import com.thatgravyboat.skyblockhud.api.events.SkyBlockEntityKilled;
import com.thatgravyboat.skyblockhud.location.LocationHandler;
import com.thatgravyboat.skyblockhud.location.Locations;
import java.util.*;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class TrackerHandler extends Gui {

    public static Set<TrackerObject> trackerObjects = new HashSet<>();
    public static LinkedHashMap<Locations, Map<String, TrackerObject>> trackers = new LinkedHashMap<>();

    public static <K, V> Map<K, V> sortTrackers(Map<K, V> map, Comparator<? super Map.Entry<K, V>> comparator) {
        List<Map.Entry<K, V>> list = new ArrayList<>(map.entrySet());
        list.sort(comparator);

        Map<K, V> result = new LinkedHashMap<>();
        for (Map.Entry<K, V> entry : list) {
            result.put(entry.getKey(), entry.getValue());
        }

        return result;
    }

    public static void onItemAdded(String id, int amount, String specialId, int number) {
        if (LorenzMod.hasSkyblockScoreboard() && trackers.containsKey(LocationHandler.getCurrentLocation())) {
            Map<String, TrackerObject> trackerMap = trackers.get(LocationHandler.getCurrentLocation());
            String dropId = id;
            if (specialId != null) {
                dropId = specialId.toUpperCase() + ";" + number;
            }

            if (trackerMap != null && trackerMap.containsKey(dropId)) {
                TrackerObject object = trackerMap.get(dropId);
                object.increaseCount(amount);
                trackers.put(LocationHandler.getCurrentLocation(), sortTrackers(trackerMap, (entry1, entry2) -> Integer.compare(entry2.getValue().getCount(), entry1.getValue().getCount())));
            }
        }
    }

    public static void drawItemStack(ItemStack stack, int x, int y) {
        if (stack == null) return;
        RenderItem itemRender = Minecraft.getMinecraft().getRenderItem();
        RenderHelper.enableGUIStandardItemLighting();
        itemRender.zLevel = -145;
        itemRender.renderItemAndEffectIntoGUI(stack, x, y);
        itemRender.zLevel = 0;
        RenderHelper.disableStandardItemLighting();
    }

    @SubscribeEvent
    public void onSbEntityDeath(SkyBlockEntityKilled event) {
        if (LorenzMod.hasSkyblockScoreboard() && trackers.containsKey(LocationHandler.getCurrentLocation())) {
            Map<String, TrackerObject> trackerMap = trackers.get(LocationHandler.getCurrentLocation());
            if (trackerMap.containsKey("ENTITY:" + event.id)) {
                TrackerObject object = trackerMap.get("ENTITY:" + event.id);
                object.increaseCount();
                trackers.put(LocationHandler.getCurrentLocation(), sortTrackers(trackerMap, (entry1, entry2) -> Integer.compare(entry2.getValue().getCount(), entry1.getValue().getCount())));
            }
        }
    }

    @SubscribeEvent
    public void renderOverlay(RenderGameOverlayEvent.Post event) {
        //        if (Utils.overlayShouldRender(event.type, SkyblockHud.hasSkyblockScoreboard(), trackers.containsKey(LocationHandler.getCurrentLocation()), !SkyblockHud.config.trackers.hideTracker)) {
        //            Map<String, TrackerObject> tracker = trackers.get(LocationHandler.getCurrentLocation());
        //            Minecraft mc = Minecraft.getMinecraft();
        //
        //            if (tracker != null) {
        //                Position pos = SkyblockHud.config.trackers.trackerPosition;
        //                int startPos = pos.getAbsX(event.resolution, (tracker.size() >= 6 ? 130 : tracker.size() * 20));
        //                int y = pos.getAbsY(event.resolution, (int) (10 + Math.ceil(tracker.size() / 5d) * 20));
        //
        //                Gui.drawRect(startPos, y, startPos + 130, y + 10, -1072689136);
        //                mc.fontRendererObj.drawString("Tracker", startPos + 4, y + 1, 0xffffff, false);
        //                y += 10;
        //                Gui.drawRect(startPos, y, startPos + (tracker.size() >= 6 ? 130 : (tracker.size() * 20) + 10), (int) (y + (Math.ceil(tracker.size() / 5d) * 20)), 1610612736);
        //                int x = startPos + 5;
        //                for (TrackerObject object : tracker.values()) {
        //                    String s = Utils.formattedNumber(object.getCount(), 1000);
        //                    GlStateManager.disableLighting();
        //                    GlStateManager.enableDepth();
        //                    drawItemStack(object.getDisplayStack(), x, y);
        //                    GlStateManager.disableDepth();
        //                    GlStateManager.disableBlend();
        //                    mc.fontRendererObj.drawStringWithShadow(s, (float) (x + 19 - 2 - mc.fontRendererObj.getStringWidth(s)), (float) (y + 9), object.getCount() < 1 ? 16733525 : 16777215);
        //                    GlStateManager.enableBlend();
        //                    GlStateManager.enableDepth();
        //
        //                    if ((x - startPos + 5) / 20 == 5) {
        //                        x = startPos + 5;
        //                        y += 20;
        //                    } else {
        //                        x += 20;
        //                    }
        //                }
        //            }
        //        }
    }
}