aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/Danker/features/puzzlesolvers/SuperpairsSolver.java
blob: 6f532bdbb47c274e4f4aff67808a204ad95899d0 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package me.Danker.features.puzzlesolvers;

import me.Danker.commands.ToggleCommand;
import me.Danker.events.GuiChestBackgroundDrawnEvent;
import me.Danker.utils.RenderUtils;
import me.Danker.utils.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.inventory.GuiChest;
import net.minecraft.inventory.ContainerChest;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StringUtils;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;

import java.awt.*;
import java.util.List;
import java.util.*;

public class SuperpairsSolver {

    static ItemStack[] experimentTableSlots = new ItemStack[54];

    @SubscribeEvent(priority = EventPriority.HIGHEST)
    public void onTooltip(ItemTooltipEvent event) {
        if (!Utils.inSkyblock) return;
        if (event.toolTip == null) return;

        ItemStack item = event.itemStack;
        Minecraft mc = Minecraft.getMinecraft();
        EntityPlayerSP player = mc.thePlayer;

        if (mc.currentScreen instanceof GuiChest) {
            ContainerChest chest = (ContainerChest) player.openContainer;
            IInventory inv = chest.getLowerChestInventory();
            String chestName = inv.getDisplayName().getUnformattedText();

            if (ToggleCommand.superpairsToggled && chestName.contains("Superpairs (")) {
                if (Item.getIdFromItem(item.getItem()) != 95) return;
                if (item.getDisplayName().contains("Click any button") || item.getDisplayName().contains("Click a second button") || item.getDisplayName().contains("Next button is instantly rewarded") || item.getDisplayName().contains("Stained Glass")) {
                    Slot slot = ((GuiChest) mc.currentScreen).getSlotUnderMouse();
                    ItemStack itemStack = experimentTableSlots[slot.getSlotIndex()];
                    if (itemStack == null) return;
                    String itemName = itemStack.getDisplayName();

                    if (event.toolTip.stream().anyMatch(x -> StringUtils.stripControlCodes(x).equals(StringUtils.stripControlCodes(itemName))))
                        return;
                    event.toolTip.removeIf(x -> {
                        x = StringUtils.stripControlCodes(x);
                        if (x.equals("minecraft:stained_glass")) return true;
                        return x.startsWith("NBT: ");
                    });
                    event.toolTip.add(itemName);
                    event.toolTip.add(itemStack.getItem().getRegistryName());
                }

            }
        }
    }

    @SubscribeEvent
    public void onTick(TickEvent.ClientTickEvent event) {
        if (event.phase != TickEvent.Phase.START) return;

        Minecraft mc = Minecraft.getMinecraft();
        EntityPlayerSP player = mc.thePlayer;
        if (mc.currentScreen instanceof GuiChest) {
            if (player == null) return;
            ContainerChest chest = (ContainerChest) player.openContainer;
            List<Slot> invSlots = ((GuiChest) mc.currentScreen).inventorySlots.inventorySlots;
            String chestName = chest.getLowerChestInventory().getDisplayName().getUnformattedText().trim();

            if (ToggleCommand.superpairsToggled && chestName.startsWith("Superpairs (")) {
                for (int i = 0; i < 53; i++) {
                    ItemStack itemStack = invSlots.get(i).getStack();
                    if (itemStack == null) continue;
                    String itemName = itemStack.getDisplayName();
                    if (Item.getIdFromItem(itemStack.getItem()) == 95 || Item.getIdFromItem(itemStack.getItem()) == 160) continue;
                    if (itemName.contains("Instant Find") || itemName.contains("Gained +")) continue;
                    if (itemName.contains("Enchanted Book")) {
                        itemName = itemStack.getTooltip(mc.thePlayer, false).get(3);
                    }
                    if (itemStack.stackSize > 1) {
                        itemName = itemStack.stackSize + " " + itemName;
                    }
                    if (experimentTableSlots[i] != null) continue;
                    experimentTableSlots[i] = itemStack.copy().setStackDisplayName(itemName);
                }
            }
        }
    }

    @SubscribeEvent
    public void onGuiRender(GuiChestBackgroundDrawnEvent event) {
        if (ToggleCommand.superpairsToggled && event.displayName.contains("Superpairs (")) {
            HashMap<String, HashSet<Integer>> matches = new HashMap<>();
            for (int i = 0; i < 53; i++) {
                ItemStack itemStack = experimentTableSlots[i];
                if (itemStack == null) continue;

                //Utils.renderItem(itemStack, x, y, -100);

                String itemName = itemStack.getDisplayName();
                String keyName = itemName + itemStack.getUnlocalizedName();
                matches.computeIfAbsent(keyName, k -> new HashSet<>());
                matches.get(keyName).add(i);
            }

            Color[] colors = {
                    new Color(255, 0, 0, 100),
                    new Color(0, 0, 255, 100),
                    new Color(100, 179, 113, 100),
                    new Color(255, 114, 255, 100),
                    new Color(255, 199, 87, 100),
                    new Color(119, 105, 198, 100),
                    new Color(135, 199, 112, 100),
                    new Color(240, 37, 240, 100),
                    new Color(178, 132, 190, 100),
                    new Color(63, 135, 163, 100),
                    new Color(146, 74, 10, 100),
                    new Color(255, 255, 255, 100),
                    new Color(217, 252, 140, 100),
                    new Color(255, 82, 82, 100)
            };

            Iterator<Color> colorIterator = Arrays.stream(colors).iterator();

            matches.forEach((itemName, slotSet) -> {
                if (slotSet.size() < 2) return;
                ArrayList<Slot> slots = new ArrayList<>();
                slotSet.forEach(slotNum -> slots.add(event.slots.get(slotNum)));
                Color color = colorIterator.next();
                slots.forEach(slot -> RenderUtils.drawOnSlot(event.chestSize, slot.xDisplayPosition, slot.yDisplayPosition, color.getRGB()));
            });
        }
    }

    @SubscribeEvent
    public void onGuiOpen(GuiOpenEvent event) {
        experimentTableSlots = new ItemStack[54];
    }

}