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

import com.google.gson.JsonArray;
import me.Danker.DankersSkyblockMod;
import me.Danker.commands.ToggleCommand;
import me.Danker.utils.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.util.*;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import java.util.List;

public class ThreeManSolver {

    // Hard coded solutions if api call fails
    static String[] riddleSolutions = {"The reward is not in my chest!", "At least one of them is lying, and the reward is not in",
            "My chest doesn't have the reward. We are all telling the truth", "My chest has the reward and I'm telling the truth",
            "The reward isn't in any of our chests", "Both of them are telling the truth."};
    static BlockPos riddleChest = null;

    @SubscribeEvent
    public void onWorldChange(WorldEvent.Load event) {
        riddleChest = null;
    }

    @SubscribeEvent
    public void onChat(ClientChatReceivedEvent event) {
        String message = StringUtils.stripControlCodes(event.message.getUnformattedText());

        if (!Utils.inDungeons) return;

        if (ToggleCommand.threeManToggled && message.contains("[NPC]")) {
            if (DankersSkyblockMod.data != null && DankersSkyblockMod.data.has("threeman")) {
                JsonArray riddleSolutions = DankersSkyblockMod.data.get("threeman").getAsJsonArray();

                for (int i = 0; i < riddleSolutions.size(); i++) {
                    String solution = riddleSolutions.get(i).getAsString();
                    if (message.contains(solution)) {
                        answer(message);
                        break;
                    }
                }
            } else {
                for (String solution : riddleSolutions) {
                    if (message.contains(solution)) {
                        answer(message);
                        break;
                    }
                }
            }
        }
    }

    @SubscribeEvent
    public void onWorldRender(RenderWorldLastEvent event) {
        if (ToggleCommand.threeManToggled && riddleChest != null) {
            Utils.drawFilled3DBox(new AxisAlignedBB(riddleChest.getX() - 0.05, riddleChest.getY(), riddleChest.getZ() - 0.05, riddleChest.getX() + 1.05, riddleChest.getY() + 1, riddleChest.getZ() + 1.05), 0x197F19, true, true, event.partialTicks);
        }
    }

    public static void answer(String message) {
        Minecraft mc = Minecraft.getMinecraft();
        String npcName = message.substring(message.indexOf("]") + 2, message.indexOf(":"));
        mc.thePlayer.addChatMessage(new ChatComponentText(DankersSkyblockMod.ANSWER_COLOUR + EnumChatFormatting.BOLD + StringUtils.stripControlCodes(npcName) + DankersSkyblockMod.MAIN_COLOUR + " has the blessing."));

        if (riddleChest == null) {
            List<Entity> entities = mc.theWorld.getLoadedEntityList();
            for (Entity entity : entities) {
                if (entity == null || !entity.hasCustomName()) continue;
                if (entity.getCustomNameTag().contains(npcName)) {
                    BlockPos npcLocation = new BlockPos(entity.posX, 69, entity.posZ);
                    if (mc.theWorld.getBlockState(npcLocation.north()).getBlock() == Blocks.chest) {
                        riddleChest = npcLocation.north();
                    } else if (mc.theWorld.getBlockState(npcLocation.east()).getBlock() == Blocks.chest) {
                        riddleChest = npcLocation.east();
                    } else if (mc.theWorld.getBlockState(npcLocation.south()).getBlock() == Blocks.chest) {
                        riddleChest = npcLocation.south();
                    } else if (mc.theWorld.getBlockState(npcLocation.west()).getBlock() == Blocks.chest) {
                        riddleChest = npcLocation.west();
                    } else {
                        System.out.print("Could not find correct riddle chest.");
                    }
                    break;
                }
            }
        }
    }

}