aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/Danker/features/puzzlesolvers/SelectAllColourSolver.java
blob: cce89d24db2cb64630f59cc54bd22d9bc196f40c (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
package me.Danker.features.puzzlesolvers;

import me.Danker.commands.ToggleCommand;
import me.Danker.events.GuiChestBackgroundDrawnEvent;
import me.Danker.utils.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StringUtils;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class SelectAllColourSolver {

    static Pattern selectAllTerminalPattern = Pattern.compile("[A-Z]{2,}");
    static String terminalColorNeeded;

    @SubscribeEvent
    public void onGuiRender(GuiChestBackgroundDrawnEvent event) {
        String displayName = event.displayName;
        if (ToggleCommand.selectAllToggled && Utils.inDungeons && displayName.startsWith("Select all the")) {
            String colour;
            List<String> colourParts = new ArrayList<>();
            Matcher colourMatcher = selectAllTerminalPattern.matcher(displayName);
            while (colourMatcher.find()) {
                colourParts.add(colourMatcher.group());
            }
            colour = String.join(" ", colourParts);
            terminalColorNeeded = colour;

            for (Slot slot : event.slots) {
                if (slot.inventory == Minecraft.getMinecraft().thePlayer.inventory) continue;
                ItemStack item = slot.getStack();
                if (item == null) continue;
                if (item.isItemEnchanted()) continue;
                String itemName = StringUtils.stripControlCodes(item.getDisplayName()).toUpperCase();
                if (itemName.contains(terminalColorNeeded) ||
                        (terminalColorNeeded.equals("SILVER") && itemName.contains("LIGHT GRAY")) ||
                        (terminalColorNeeded.equals("WHITE") && (itemName.equals("WOOL") || itemName.equals("BONE MEAL"))) ||
                        (terminalColorNeeded.equals("BLACK") && itemName.equals("INK SACK")) ||
                        (terminalColorNeeded.equals("BLUE") && itemName.equals("LAPIS LAZULI")) ||
                        (terminalColorNeeded.equals("BROWN") && itemName.equals("COCOA BEANS"))) {
                    Utils.drawOnSlot(event.chestSize, slot.xDisplayPosition, slot.yDisplayPosition, 0xBF40FF40);
                }
            }
        }
    }

    @SubscribeEvent
    public void onGuiOpen(GuiOpenEvent event) {
        terminalColorNeeded = null;
    }

}