-
-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathFeatureTrackerQuest.java
More file actions
322 lines (287 loc) · 14.2 KB
/
FeatureTrackerQuest.java
File metadata and controls
322 lines (287 loc) · 14.2 KB
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
package codes.biscuit.skyblockaddons.features.EntityOutlines;
import codes.biscuit.skyblockaddons.SkyblockAddons;
import codes.biscuit.skyblockaddons.core.Feature;
import codes.biscuit.skyblockaddons.core.Location;
import codes.biscuit.skyblockaddons.core.Translations;
import codes.biscuit.skyblockaddons.events.RenderEntityOutlineEvent;
import codes.biscuit.skyblockaddons.features.cooldowns.CooldownManager;
import codes.biscuit.skyblockaddons.gui.buttons.ButtonLocation;
import codes.biscuit.skyblockaddons.listeners.RenderListener;
import codes.biscuit.skyblockaddons.utils.ColorCode;
import codes.biscuit.skyblockaddons.utils.DrawUtils;
import codes.biscuit.skyblockaddons.utils.TextUtils;
import codes.biscuit.skyblockaddons.utils.Utils;
import lombok.Getter;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityArmorStand;
import net.minecraft.entity.passive.*;
import net.minecraft.potion.Potion;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.client.event.RenderLivingEvent.Specials.Pre;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
import java.util.EnumSet;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class FeatureTrackerQuest {
private static final EnumSet<Location> mushroomIslandLocations = EnumSet.of(Location.MUSHROOM_DESERT, Location.TRAPPERS_DEN,
Location.DESERT_SETTLEMENT, Location.OASIS, Location.GLOWING_MUSHROOM_CAVE, Location.MUSHROOM_GORGE,
Location.SHEPHERDS_KEEP, Location.OVERGROWN_MUSHROOM_CAVE, Location.JAKES_HOUSE, Location.TREASURE_HUNTER_CAMP);
private static final Pattern TRACKED_ANIMAL_NAME_PATTERN = Pattern.compile("\\[Lv[0-9]+] (?<rarity>[a-zA-Z]+) (?<animal>[a-zA-Z]+) .*❤");
private static final Pattern TREVOR_FIND_ANIMAL_PATTERN = Pattern.compile("\\[NPC] Trevor: You can find your [A-Z]+ animal near the [a-zA-Z ]+.");
private static final Pattern ANIMAL_DIED_PATTERN = Pattern.compile("Your mob died randomly, you are rewarded [0-9]+ pelts?.");
private static final Pattern ANIMAL_KILLED_PATTERN = Pattern.compile("Killing the animal rewarded you [0-9]+ pelts?.");
private static final ResourceLocation TICKER_SYMBOL = new ResourceLocation("skyblockaddons", "tracker.png");
private static boolean isTrackingAnimal = false;
private static TrackedEntity entityToOutline = null;
public FeatureTrackerQuest() {
}
/**
* Draws cell-service-like bars to indicate the proximity to the tracked entity
*
* @param mc the minecraft
* @param scale the button scale
* @param buttonLocation the button location in gui location menu
*/
// TODO: This should not be static after the feature refactor
public static void drawTrackerLocationIndicator(Minecraft mc, float scale, ButtonLocation buttonLocation) {
SkyblockAddons main = SkyblockAddons.getInstance();
if (buttonLocation != null || isTrackingAnimal) {
RenderListener listener = main.getRenderListener();
float x = main.getConfigValues().getActualX(Feature.TREVOR_TRACKED_ENTITY_PROXIMITY_INDICATOR);
float y = main.getConfigValues().getActualY(Feature.TREVOR_TRACKED_ENTITY_PROXIMITY_INDICATOR);
int height = 9;
int width = 3 * 11 + 9;
x = listener.transformXY(x, width, scale);
y = listener.transformXY(y, height, scale);
if (buttonLocation != null) {
buttonLocation.checkHoveredAndDrawBox(x, x + width, y, y + height, scale);
}
main.getUtils().enableStandardGLOptions();
int maxTickers = 4;
int fullTickers;
if (buttonLocation != null) {
fullTickers = 3;
}
// Flash indicator on and off when it's very far away
else if (entityToOutline == null) {
fullTickers = getFlashingTickers();
}
// Progressive distances away from player
else if (entityToOutline.getDistanceToPlayer() < 16) {
fullTickers = 4;
} else if (entityToOutline.getDistanceToPlayer() < 32) {
fullTickers = 3;
} else if (entityToOutline.getDistanceToPlayer() < 48) {
fullTickers = 2;
} else if (entityToOutline.getDistanceToPlayer() < 64) {
fullTickers = 1;
} else {
fullTickers = getFlashingTickers();
}
// Draw the indicator
for (int tickers = 0; tickers < maxTickers; tickers++) {
mc.getTextureManager().bindTexture(TICKER_SYMBOL);
GlStateManager.enableAlpha();
if (tickers < fullTickers) {
DrawUtils.drawModalRectWithCustomSizedTexture(x + tickers * 11, y, 0, 0, 9, 9, 18, 9, false);
} else {
DrawUtils.drawModalRectWithCustomSizedTexture(x + tickers * 11, y, 9, 0, 9, 9, 18, 9, false);
}
}
main.getUtils().restoreGLOptions();
}
}
private static int getFlashingTickers() {
if (CooldownManager.getRemainingCooldown("TREVOR_THE_TRAPPER_HUNT") % 2000 < 1000) {
return 0;
}
return 1;
}
@SubscribeEvent
public void onEntityOutline(RenderEntityOutlineEvent e) {
if (e.getType() == RenderEntityOutlineEvent.Type.NO_XRAY) {
if (SkyblockAddons.getInstance().getConfigValues().isEnabled(Feature.TREVOR_THE_TRAPPER_FEATURES) &&
SkyblockAddons.getInstance().getConfigValues().isEnabled(Feature.TREVOR_HIGHLIGHT_TRACKED_ENTITY) &&
isTrackingAnimal && entityToOutline != null && entityToOutline.getAnimal() != null &&
!Minecraft.getMinecraft().thePlayer.isPotionActive(Potion.blindness)) {
e.queueEntityToOutline(entityToOutline.getAnimal(), entityToOutline.getRarity().getColorInt());
}
}
}
@SubscribeEvent
public void onEntityEvent(LivingUpdateEvent e) {
SkyblockAddons main = SkyblockAddons.getInstance();
Entity entity = e.entity;
if (SkyblockAddons.getInstance().getConfigValues().isEnabled(Feature.TREVOR_THE_TRAPPER_FEATURES) &&
(main.getConfigValues().isEnabled(Feature.TREVOR_TRACKED_ENTITY_PROXIMITY_INDICATOR) || main.getConfigValues().isEnabled(Feature.TREVOR_HIGHLIGHT_TRACKED_ENTITY)) &&
mushroomIslandLocations.contains(main.getUtils().getLocation())) {
if (entity instanceof EntityArmorStand && entity.hasCustomName() && entity.ticksExisted > 30) {
Matcher m = TRACKED_ANIMAL_NAME_PATTERN.matcher(TextUtils.stripColor(entity.getCustomNameTag()));
if (m.matches()) {
TrackerRarity rarity = TrackerRarity.getFromString(m.group("rarity"));
TrackerType animal = TrackerType.getFromString(m.group("animal"));
if (rarity != null && animal != null) {
try {
TrackedEntity trackedEntity = new TrackedEntity((EntityArmorStand) entity, animal, rarity);
trackedEntity.attachAnimal(Minecraft.getMinecraft().theWorld.getEntitiesWithinAABB(animal.getClazz(),
new AxisAlignedBB(entity.posX - 2, entity.posY - 2, entity.posZ - 2, entity.posX + 2, entity.posY + 2, entity.posZ + 2)));
entityToOutline = trackedEntity;
} catch (NullPointerException ignored) {
}
}
}
}
}
}
@SubscribeEvent
public void onChatReceived(ClientChatReceivedEvent e) {
if (SkyblockAddons.getInstance().getConfigValues().isEnabled(Feature.TREVOR_THE_TRAPPER_FEATURES) &&
e.type != 2 && SkyblockAddons.getInstance().getUtils().isOnSkyblock()) {
String stripped = TextUtils.stripColor(e.message.getFormattedText());
// Once the player has started the hunt, start some timers
if (TREVOR_FIND_ANIMAL_PATTERN.matcher(stripped).matches()) {
// Start the quest
isTrackingAnimal = true;
// The player has 10 minutes to kill the animal
CooldownManager.put("TREVOR_THE_TRAPPER_HUNT", 600000);
// The player has 30 seconds before they can receive another animal after killing the current one
CooldownManager.put("TREVOR_THE_TRAPPER_RETURN", 30000);
}
// Once the player has killed the animal, remove the hunt timer
else if (ANIMAL_DIED_PATTERN.matcher(stripped).matches() || ANIMAL_KILLED_PATTERN.matcher(stripped).matches()) {
CooldownManager.remove("TREVOR_THE_TRAPPER_HUNT");
onQuestEnded();
}
}
}
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onNameTagRender(Pre<EntityLivingBase> e) {
Entity entity = e.entity;
if (SkyblockAddons.getInstance().getConfigValues().isEnabled(Feature.TREVOR_THE_TRAPPER_FEATURES) &&
!e.isCanceled() && SkyblockAddons.getInstance().getConfigValues().isEnabled(Feature.TREVOR_SHOW_QUEST_COOLDOWN) &&
CooldownManager.isOnCooldown("TREVOR_THE_TRAPPER_RETURN")) {
Pattern p = Pattern.compile("Trevor");
String s = TextUtils.stripColor(entity.getCustomNameTag());
if (p.matcher(s).matches()) {
String str = Utils.MESSAGE_PREFIX_SHORT + Translations.getMessage("messages.worldRenderedCooldownTime",
CooldownManager.getRemainingCooldown("TREVOR_THE_TRAPPER_RETURN") / 1000);
DrawUtils.drawTextInWorld(str, e.x, e.y + entity.height + .75, e.z);
}
}
}
@SubscribeEvent
public void onClientTick(ClientTickEvent e) {
if (SkyblockAddons.getInstance().getConfigValues().isEnabled(Feature.TREVOR_THE_TRAPPER_FEATURES) &&
e.phase == Phase.START && Minecraft.getMinecraft().thePlayer != null) {
if (isTrackingAnimal && CooldownManager.getRemainingCooldown("TREVOR_THE_TRAPPER_HUNT") == 0) {
onQuestEnded();
} else if (entityToOutline != null) {
entityToOutline.cacheDistanceToPlayer();
}
}
}
private void onQuestEnded() {
isTrackingAnimal = false;
entityToOutline = null;
}
private enum TrackerType {
COW("Cow", EntityCow.class),
PIG("Pig", EntityPig.class),
SHEEP("Sheep", EntitySheep.class),
RABBIT("Rabbit", EntityRabbit.class),
CHICKEN("Chicken", EntityChicken.class);
@Getter
private final String name;
@Getter
private final Class<? extends Entity> clazz;
TrackerType(String entityName, Class<? extends Entity> entityClass) {
name = entityName;
clazz = entityClass;
}
public static TrackerType getFromString(String s) {
for (TrackerType type : values()) {
if (type.name.equals(s)) {
return type;
}
}
return null;
}
}
private enum TrackerRarity {
TRACKABLE("Trackable", ColorCode.WHITE),
UNTRACKABLE("Untrackable", ColorCode.DARK_GREEN),
UNDETECTED("Undetected", ColorCode.DARK_BLUE),
ENDANGERED("Endangered", ColorCode.DARK_PURPLE),
ELUSIVE("Elusive", ColorCode.GOLD);
@Getter
private final String nameTagName;
@Getter
private final ColorCode colorCode;
@Getter
private final int colorInt;
TrackerRarity(String nameTag, ColorCode color) {
nameTagName = nameTag;
colorCode = color;
colorInt = color.getColor();
}
public static TrackerRarity getFromString(String s) {
for (TrackerRarity type : values()) {
if (type.nameTagName.equals(s)) {
return type;
}
}
return null;
}
}
private static class TrackedEntity {
@Getter
private final EntityArmorStand armorStand;
@Getter
private final TrackerType type;
@Getter
private final TrackerRarity rarity;
@Getter
private Entity animal;
@Getter
private double distanceToPlayer;
public TrackedEntity(EntityArmorStand theArmorStand, TrackerType trackerType, TrackerRarity trackerRarity) {
armorStand = theArmorStand;
type = trackerType;
rarity = trackerRarity;
cacheDistanceToPlayer();
}
public void attachAnimal(List<Entity> animalList) {
if (animalList.size() == 0) {
animal = null;
}
//System.out.println("hi");
double minDist = Double.MAX_VALUE;
for (Entity e : animalList) {
// Minimize the distance between entities on the horizontal plane
double horizDist = (e.posX - armorStand.posX) * (e.posX - armorStand.posX) + (e.posZ - armorStand.posZ) * (e.posZ - armorStand.posZ);
//System.out.println(Math.abs(e.posY - armorStand.posZ));
if (horizDist < minDist && Math.abs(e.posY - armorStand.posY) < 2) {
minDist = horizDist;
animal = e;
}
}
}
public void cacheDistanceToPlayer() {
if (animal != null) {
distanceToPlayer = Minecraft.getMinecraft().thePlayer.getDistanceToEntity(animal);
} else {
distanceToPlayer = Minecraft.getMinecraft().thePlayer.getDistanceToEntity(armorStand);
}
}
}
}