aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/kr/syeyoung/dungeonsguide/roomprocessor/RoomProcessorButtonSolver.java
blob: 4faf456c9b0e8bd2676b9ce382c236785c28c5ed (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
/*
 *     Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod
 *     Copyright (C) 2021  cyoung06
 *
 *     This program is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU Affero General Public License as published
 *     by the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU Affero General Public License for more details.
 *
 *     You should have received a copy of the GNU Affero General Public License
 *     along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package kr.syeyoung.dungeonsguide.roomprocessor;

import kr.syeyoung.dungeonsguide.dungeon.data.OffsetPointSet;
import kr.syeyoung.dungeonsguide.dungeon.roomfinder.DungeonRoom;
import kr.syeyoung.dungeonsguide.utils.RenderUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.BlockPos;
import net.minecraft.util.IChatComponent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;

import java.awt.*;
import java.util.Arrays;

public class RoomProcessorButtonSolver extends GeneralRoomProcessor {
    public RoomProcessorButtonSolver(DungeonRoom dungeonRoom) {
        super(dungeonRoom);

        OffsetPointSet ops = (OffsetPointSet) dungeonRoom.getDungeonRoomInfo().getProperties().get("buttons");
        if (ops == null) {
            bugged = true;
            return;
        }

        buttons = new BlockPos[12];
        woods = new BlockPos[12];
        for (int i = 0; i < ops.getOffsetPointList().size(); i++) {
            buttons[i] = ops.getOffsetPointList().get(i).getBlockPos(dungeonRoom);
            woods[i] = buttons[i].add(0,-1,0);
        }
    }

    private boolean bugged;

    private BlockPos[] buttons;
    private BlockPos[] woods;

    private long clicked;
    private int clickedButton = -1;

    private final int[] result = new int[12];

    @Override
    public void onInteractBlock(PlayerInteractEvent event) {
        super.onInteractBlock(event);
        if (bugged) return;

        if (event.action != PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) return;
        for (int i = 0; i < buttons.length; i++) {
            if (event.pos.equals(buttons[i])) {
                clicked = System.currentTimeMillis();
                clickedButton = i;
                return;
            }
        }
    }

    @Override
    public void chatReceived(IChatComponent chat) {
        super.chatReceived(chat);
        if (bugged) return;

        if (clickedButton == -1) return;
        if (clicked + 500 < System.currentTimeMillis()) return;

        String msg = chat.getFormattedText();
        if (msg.equals("§r§cThis button doesn't seem to do anything...§r")) {
            result[clickedButton] = -1;
            clickedButton = -1;
        } else if (msg.equals("§r§aThis button seems connected to something§r")) {
            Arrays.fill(result, -1);
            if (clickedButton % 4 != 0) result[clickedButton - 1] = 1;
            if (clickedButton % 4 != 3) result[clickedButton + 1] = 1;
            clickedButton = -1;
        } else if (msg.equals("§r§aClick! you Hear the sound of a door opening§r")) {
            Arrays.fill(result, -1);
            result[clickedButton] = 2;
            clickedButton = -1;
        } else if (msg.equals("§r§aWrong button, looks like the system reset!§r")) {
            Arrays.fill(result, 0);
            clickedButton = -1;
        }
    }

    @Override
    public void drawWorld(float partialTicks) {
        super.drawWorld(partialTicks);
        if (bugged) return;
        if (Minecraft.getMinecraft().thePlayer.getPosition().distanceSq(woods[6]) > 100) return;


        for (int i = 0; i < woods.length; i++) {
            int data = result[i];
            BlockPos pos = woods[i];

            if (data == 0) {
                RenderUtils.highlightBlock(pos, new Color(0, 255, 255, 50), partialTicks, false);
            } else if (data == -1) {
                RenderUtils.highlightBlock(pos, new Color(255, 0, 0, 50), partialTicks, false);
            } else if (data == 1) {
                RenderUtils.highlightBlock(pos, new Color(0, 255, 0, 50), partialTicks, false);
            } else if (data == 2) {
                RenderUtils.highlightBlock(pos, new Color(0, 255, 0, 100), partialTicks, false);
            }
        }
    }

    public static class Generator implements RoomProcessorGenerator<RoomProcessorButtonSolver> {
        @Override
        public RoomProcessorButtonSolver createNew(DungeonRoom dungeonRoom) {
            RoomProcessorButtonSolver defaultRoomProcessor = new RoomProcessorButtonSolver(dungeonRoom);
            return defaultRoomProcessor;
        }
    }
}