aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/xmrvizzy/skyblocker/skyblock/experiment/ChronomatronSolver.java
blob: d62383be3a6a9e1c99109c0360687bf792bd27e1 (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
package me.xmrvizzy.skyblocker.skyblock.experiment;

import com.google.common.collect.ImmutableMap;
import me.xmrvizzy.skyblocker.config.SkyblockerConfig;
import me.xmrvizzy.skyblocker.utils.render.gui.ColorHighlight;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.GenericContainerScreen;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;

import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ChronomatronSolver extends ExperimentSolver {
    public static final ImmutableMap<Item, Item> TERRACOTTA_TO_GLASS = ImmutableMap.ofEntries(
            new AbstractMap.SimpleImmutableEntry<>(Items.RED_TERRACOTTA, Items.RED_STAINED_GLASS),
            new AbstractMap.SimpleImmutableEntry<>(Items.ORANGE_TERRACOTTA, Items.ORANGE_STAINED_GLASS),
            new AbstractMap.SimpleImmutableEntry<>(Items.YELLOW_TERRACOTTA, Items.YELLOW_STAINED_GLASS),
            new AbstractMap.SimpleImmutableEntry<>(Items.LIME_TERRACOTTA, Items.LIME_STAINED_GLASS),
            new AbstractMap.SimpleImmutableEntry<>(Items.GREEN_TERRACOTTA, Items.GREEN_STAINED_GLASS),
            new AbstractMap.SimpleImmutableEntry<>(Items.CYAN_TERRACOTTA, Items.CYAN_STAINED_GLASS),
            new AbstractMap.SimpleImmutableEntry<>(Items.LIGHT_BLUE_TERRACOTTA, Items.LIGHT_BLUE_STAINED_GLASS),
            new AbstractMap.SimpleImmutableEntry<>(Items.BLUE_TERRACOTTA, Items.BLUE_STAINED_GLASS),
            new AbstractMap.SimpleImmutableEntry<>(Items.PURPLE_TERRACOTTA, Items.PURPLE_STAINED_GLASS),
            new AbstractMap.SimpleImmutableEntry<>(Items.PINK_TERRACOTTA, Items.PINK_STAINED_GLASS)
    );

    private final List<Item> chronomatronSlots = new ArrayList<>();
    private int chronomatronChainLengthCount;
    private int chronomatronCurrentSlot;
    private int chronomatronCurrentOrdinal;

    public ChronomatronSolver() {
        super("^Chronomatron \\(\\w+\\)$");
    }

    public List<Item> getChronomatronSlots() {
        return chronomatronSlots;
    }

    public int getChronomatronCurrentOrdinal() {
        return chronomatronCurrentOrdinal;
    }

    public int incrementChronomatronCurrentOrdinal() {
        return ++chronomatronCurrentOrdinal;
    }

    @Override
    protected boolean isEnabled(SkyblockerConfig.Experiments experimentsConfig) {
        return experimentsConfig.enableChronomatronSolver;
    }

    @Override
    protected void tick(Screen screen) {
        if (isEnabled() && screen instanceof GenericContainerScreen genericContainerScreen && genericContainerScreen.getTitle().getString().startsWith("Chronomatron (")) {
            switch (getState()) {
                case REMEMBER -> {
                    Inventory inventory = genericContainerScreen.getScreenHandler().getInventory();
                    if (chronomatronCurrentSlot == 0) {
                        for (int index = 10; index < 43; index++) {
                            if (inventory.getStack(index).hasEnchantments()) {
                                if (chronomatronSlots.size() <= chronomatronChainLengthCount) {
                                    chronomatronSlots.add(TERRACOTTA_TO_GLASS.get(inventory.getStack(index).getItem()));
                                    setState(State.WAIT);
                                } else {
                                    chronomatronChainLengthCount++;
                                }
                                chronomatronCurrentSlot = index;
                                return;
                            }
                        }
                    } else if (!inventory.getStack(chronomatronCurrentSlot).hasEnchantments()) {
                        chronomatronCurrentSlot = 0;
                    }
                }
                case WAIT -> {
                    if (genericContainerScreen.getScreenHandler().getInventory().getStack(49).getName().getString().startsWith("Timer: ")) {
                        setState(State.SHOW);
                    }
                }
                case END -> {
                    String name = genericContainerScreen.getScreenHandler().getInventory().getStack(49).getName().getString();
                    if (!name.startsWith("Timer: ")) {
                        if (name.equals("Remember the pattern!")) {
                            chronomatronChainLengthCount = 0;
                            chronomatronCurrentOrdinal = 0;
                            setState(State.REMEMBER);
                        } else {
                            reset();
                        }
                    }
                }
            }
        } else {
            reset();
        }
    }

    @Override
    protected List<ColorHighlight> getColors(String[] groups, Map<Integer, ItemStack> slots) {
        List<ColorHighlight> highlights = new ArrayList<>();
        if (getState() == State.SHOW && chronomatronSlots.size() > chronomatronCurrentOrdinal) {
            for (Map.Entry<Integer, ItemStack> indexStack : slots.entrySet()) {
                int index = indexStack.getKey();
                ItemStack stack = indexStack.getValue();
                Item item = chronomatronSlots.get(chronomatronCurrentOrdinal);
                if (stack.isOf(item) || TERRACOTTA_TO_GLASS.get(stack.getItem()) == item) {
                    highlights.add(ColorHighlight.green(index));
                }
            }
        }
        return highlights;
    }

    @Override
    protected void reset() {
        super.reset();
        chronomatronSlots.clear();
        chronomatronChainLengthCount = 0;
        chronomatronCurrentSlot = 0;
        chronomatronCurrentOrdinal = 0;
    }
}