aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/Danker/features/puzzlesolvers/ClickInOrderSolver.java
blob: e503b37bb83f17c29a442800110f2a98d52b7e3c (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
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.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.inventory.GuiChest;
import net.minecraft.init.Blocks;
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.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.util.List;

public class ClickInOrderSolver {

    static Slot[] clickInOrderSlots = new Slot[36];
    static int[] terminalNumberNeeded = new int[4];
    public static int CLICK_IN_ORDER_NEXT;
    public static int CLICK_IN_ORDER_NEXT_TO_NEXT;

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

        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.clickInOrderToggled && chestName.equals("Click in order!")) {
                event.toolTip.clear();
            }
        }
    }

    @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.clickInOrderToggled && chestName.equals("Click in order!")) {
                if (terminalNumberNeeded[0] == 0) terminalNumberNeeded[0] = 15;
                if (terminalNumberNeeded[2] == 0) terminalNumberNeeded[2] = 15;
                for (int i = 10; i <= 25; i++) {
                    if (i == 17 || i == 18) continue;
                    ItemStack prevStack = invSlots.get(terminalNumberNeeded[1]).getStack();
                    if (prevStack == null) terminalNumberNeeded[0] = 15;
                    else if (prevStack.getItem() != Item.getItemFromBlock(Blocks.stained_glass_pane))
                        terminalNumberNeeded[0] = 15;
                    else if (prevStack.getItemDamage() == 5) terminalNumberNeeded[0] = 15;

                    ItemStack itemStack = invSlots.get(i).getStack();
                    if (itemStack == null) continue;
                    if (itemStack.getItem() != Item.getItemFromBlock(Blocks.stained_glass_pane)) continue;
                    if (itemStack.getItemDamage() != 14) continue;
                    if (itemStack.stackSize < terminalNumberNeeded[0]) {
                        terminalNumberNeeded[0] = itemStack.stackSize;
                        terminalNumberNeeded[1] = i;
                    } else if (itemStack.stackSize == terminalNumberNeeded[0] + 1) {
                        terminalNumberNeeded[2] = itemStack.stackSize;
                        terminalNumberNeeded[3] = i;
                    }
                }
            }
        }
    }

    @SubscribeEvent
    public void onGuiRender(GuiChestBackgroundDrawnEvent event) {
        if (ToggleCommand.clickInOrderToggled && event.displayName.equals("Click in order!")) {
            int chestSize = event.chestSize;
            List<Slot> invSlots = event.slots;
            Slot slot = invSlots.get(terminalNumberNeeded[1]);
            Utils.drawOnSlot(chestSize, slot.xDisplayPosition, slot.yDisplayPosition, CLICK_IN_ORDER_NEXT + 0xFF000000);
            Slot nextSlot = invSlots.get(terminalNumberNeeded[3]);
            if (nextSlot != slot && nextSlot.getSlotIndex() != 0) {
                Utils.drawOnSlot(chestSize, nextSlot.xDisplayPosition, nextSlot.yDisplayPosition, CLICK_IN_ORDER_NEXT_TO_NEXT + 0xFF000000);
            }
        }
    }

    @SubscribeEvent
    public void onGuiOpen(GuiOpenEvent event) {
        terminalNumberNeeded = new int[4];
    }

}