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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
package com.thatgravyboat.skyblockhud.handlers;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.thatgravyboat.skyblockhud.SkyblockHud;
import com.thatgravyboat.skyblockhud.Utils;
import com.thatgravyboat.skyblockhud.api.events.LocationChangeEvent;
import com.thatgravyboat.skyblockhud.commands.SimpleCommand;
import com.thatgravyboat.skyblockhud.location.LocationCategory;
import com.thatgravyboat.skyblockhud.location.LocationHandler;
import com.thatgravyboat.skyblockhud.location.Locations;
import java.awt.*;
import java.awt.datatransfer.StringSelection;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.command.ICommandSender;
import net.minecraft.event.ClickEvent;
import net.minecraft.event.HoverEvent;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatStyle;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class CrystalWaypoints {
public static final Pattern LOCATION_MESSAGE_REGEX = Pattern.compile("\\{(.*) : \\((-?\\d+)/(-?\\d+)/(-?\\d+)\\)}");
public static final HashMap<String, BlockPos> waypoints = new HashMap<>();
private static final Set<Locations> IMPORTANT_WAYPOINTS = Sets.newHashSet(Locations.GOBLINQUEENSDEN, Locations.LOSTPRECURSORCITY, Locations.JUNGLETEMPLE, Locations.MINESOFDIVAN, Locations.KHAZADDM, Locations.FAIRYGROTTO);
@SubscribeEvent
public void onRenderLast(RenderWorldLastEvent event) {
GlStateManager.disableCull();
GlStateManager.disableDepth();
waypoints.forEach((text, pos) -> Utils.renderWaypointText(text, pos, event.partialTicks));
GlStateManager.enableCull();
GlStateManager.enableDepth();
}
@SubscribeEvent
public void onWorldChange(EntityJoinWorldEvent event) {
if (event.entity == Minecraft.getMinecraft().thePlayer) {
waypoints.clear();
}
}
@SubscribeEvent
public void onLocationChange(LocationChangeEvent event) {
if (!event.newLocation.getCategory().equals(LocationCategory.CRYSTALHOLLOWS)) {
waypoints.clear();
} else if (!waypoints.containsKey("Crystal Nucleus") && SkyblockHud.config.mining.autoWaypoint) {
waypoints.put("Crystal Nucleus", new BlockPos(512.5, 106.5, 512.5));
}
if (IMPORTANT_WAYPOINTS.contains(event.newLocation) && SkyblockHud.config.mining.autoWaypoint) {
if (!waypoints.containsKey(event.newLocation.getDisplayName())) {
waypoints.put(event.newLocation.getDisplayName(), Minecraft.getMinecraft().thePlayer.getPosition());
}
}
}
@SubscribeEvent
public void onChatMessage(ClientChatReceivedEvent event){
if (event.type != 2 && LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.CRYSTALHOLLOWS)) {
Matcher matcher = LOCATION_MESSAGE_REGEX.matcher(event.message.getUnformattedText());
if (!matcher.find()) return;
ChatStyle style = new ChatStyle();
style.setParentStyle(event.message.getChatStyle());
ClickEvent.Action action = SkyblockHud.config.mining.chatWaypointMode == 0 ? ClickEvent.Action.RUN_COMMAND : ClickEvent.Action.SUGGEST_COMMAND;
style.setChatClickEvent(new ClickEvent(
action,
"/sbhpoints addat " + matcher.group(2) + " " + matcher.group(3) + " " + matcher.group(4) + " " + matcher.group(1)
));
style.setChatHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
new ChatComponentText("Click to add waypoint!").setChatStyle(new ChatStyle().setBold(true))
));
event.message.setChatStyle(style);
}
}
private static String copyWayPoint(String name){
BlockPos pos = waypoints.get(name);
if (pos == null) {
return null;
}
return "{" + name + " : (" + pos.getX() + "/" + pos.getY() + "/" + pos.getZ() + ")}";
}
public static class WaypointCommand extends SimpleCommand {
public WaypointCommand() {
super(
"sbhpoints",
new ProcessCommandRunnable() {
@Override
public void processCommand(ICommandSender sender, String[] args) {
if (args.length == 0) return;
String subCommand = args[0].toLowerCase();
String name = String.join(" ", Arrays.copyOfRange(args, 1, args.length));
switch (subCommand) {
case "add":
if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.CRYSTALHOLLOWS)) {
if (!CrystalWaypoints.waypoints.containsKey(name) && name.length() > 1) {
CrystalWaypoints.waypoints.put(name, sender.getPosition().add(0.5, 0.5, 0.5));
} else if (name.length() < 2) {
sbhMessage(sender, "Waypoint name needs to be longer than 1");
} else {
sbhMessage(sender, "Waypoint already exists!");
}
}
break;
case "remove":
if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.CRYSTALHOLLOWS)) {
if (CrystalWaypoints.waypoints.containsKey(name)) {
CrystalWaypoints.waypoints.remove(name);
} else {
sbhMessage(sender, "Waypoint doesnt exist!");
}
}
break;
case "move":
if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.CRYSTALHOLLOWS)) {
if (CrystalWaypoints.waypoints.containsKey(name)) {
CrystalWaypoints.waypoints.put(name, sender.getPosition().add(0.5, 0.5, 0.5));
} else {
sbhMessage(sender, "Waypoint doesnt exist!");
}
}
break;
case "clear":
CrystalWaypoints.waypoints.clear();
break;
case "addat":
if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.CRYSTALHOLLOWS)) {
name = String.join(" ", Arrays.copyOfRange(args, 4, args.length));
try {
if (!CrystalWaypoints.waypoints.containsKey(name)) {
CrystalWaypoints.waypoints.put(name, parseBlockPos(sender, args, 1, true));
} else if (name.length() < 2) {
sbhMessage(sender, "Waypoint name needs to be longer than 1");
} else {
sbhMessage(sender, "Waypoint already exists!");
}
} catch (Exception e) {
sbhMessage(sender, "Error!");
}
}
break;
case "copy":
String copyText = copyWayPoint(name);
if (copyText == null) {
sbhMessage(sender, "No waypoint with that name!");
break;
}
StringSelection clipboard = new StringSelection(copyText);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(clipboard, clipboard);
break;
case "send":
String sendText = copyWayPoint(name);
if (sendText == null) {
sbhMessage(sender, "No waypoint with that name!");
break;
}
Minecraft.getMinecraft().thePlayer.sendChatMessage(sendText);
break;
}
}
},
new TabCompleteRunnable() {
@Override
public List<String> tabComplete(ICommandSender sender, String[] args, BlockPos pos) {
if (args.length == 2 && Utils.equalsIgnoreCaseAnyOf(args[0], "remove", "copy", "move", "send")) {
return getListOfStringsMatchingLastWord(args, waypoints.keySet());
}
if (args.length == 1) {
return getListOfStringsMatchingLastWord(args, Lists.newArrayList("add", "clear", "remove", "copy", "addat", "move", "send"));
}
if (args.length > 1 && args[0].equalsIgnoreCase("addat")) {
return func_175771_a(args, 1, pos);
}
return null;
}
}
);
}
private static void sbhMessage(ICommandSender sender, String message) {
sender.addChatMessage(new ChatComponentText("[" + EnumChatFormatting.RED + EnumChatFormatting.BOLD + "SkyBlockHud" + EnumChatFormatting.RESET + "] : " + EnumChatFormatting.GRAY + message));
}
}
}
|