aboutsummaryrefslogtreecommitdiff
path: root/features/specialMining/index.js
blob: faba13c586e21894922e11aa174624cbf2b43076 (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
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
import Feature from "../../featureClass/class";
import SettingBase from "../settings/settingThings/settingBase";
import { numberWithCommas, timeNumber } from "../../utils/numberUtils";
import HudTextElement from "../hud/HudTextElement";
import LocationSetting from "../settings/settingThings/location";
import ToggleSetting from "../settings/settingThings/toggle";
import { delay } from "../../utils/delayUtils";
import TextSetting from "../settings/settingThings/textSetting";
import { drawBoxAtBlock, drawFilledBox } from "../../utils/renderUtils";
import RenderLib2D from "../../utils/renderLib2d";
import { f, m } from "../../../mappings/mappings";

class PowderAndScatha extends Feature {
    constructor() {
        super();
    }

    onEnable() {
        this.initVariables();
        new SettingBase("Chest Miner", "Powder mining feature here are made mainly for powder chest grinding", undefined, "chest_mining_info", this);
        this.compactedChat = new ToggleSetting("Compact Powder Messages", "same as the one in skytils but support following setting", false, "compact_powder_chat", this)
        this.fixChatForDoublePowder = new ToggleSetting("Fix Chat Messages During Double Powder", "so it's the correct amount of powder you received during the event", false, "fix_chat_dpowder", this)
        this.fixChatForDoublePowderSuffix = new TextSetting("Suffix of previous message", "(so you can tell )change it yourself!", "&a(&b2X Powder&a)", "chat_dpowder_suffix", this, "(none)", false).requires(this.fixChatForDoublePowder);
        this.PowderElement = new ToggleSetting("Powder Mining Info Hud (MAIN TOGGLE)", "This will show your current powder mining section (only in CH)", true, "powder_mining_hud", this).contributor("EmeraldMerchant");
        this.PowderOverlayElement = new HudTextElement()
            .setText("")
            .setToggleSetting(this.PowderElement)
            .setLocationSetting(new LocationSetting("Powder Mining Info Hud Location", "Allows you to edit the location of Powder Mining Info Hud", "powder_mining_hud_location", this, [10, 50, 1, 1]).requires(this.PowderElement).editTempText(`&b2x Powder: &cINACTIVE\n&aChests: &b32\n&bMithril: &d12,768\n&bGems: &d21,325`).contributor("EmeraldMerchant"));
        this.hudElements.push(this.PowderOverlayElement);
        this.PowderOverlayElement.disableRendering()

        new SettingBase("/resetpowderdata", "to reset powder mining data", undefined, "reset_powder_data_command_info", this).requires(this.PowderElement);
        this.resetPowderWhenLeaveCH = new ToggleSetting("Reset Powder When Left CH", "Should it reset powder hud whenever you left ch", false, "reset_powder_when_left_ch", this).requires(this.PowderElement);
        this.resetPowderWhenLeaveGame = new ToggleSetting("Reset Powder When Left Game", "Should it reset powder hud whenever you left game", false, "reset_powder_when_left_game", this).requires(this.PowderElement);
        this.chestUncoverAlert = new ToggleSetting("Alert When You Dug a Chest Out", "so you don't miss it", false, "chest_uncover_alert", this).requires(this.PowderElement);
        this.chestUnlockHelper = new ToggleSetting("Chest unlock helper", "so you don't miss it", true, "chest_unlock_help", this).requires(this.PowderElement);
        this.chestUncoverAlertSound = new ToggleSetting("Alert Sound for Chest Alert", "should the alert also play a sound? (sound: levelup)", false, "chest_uncover_alert_sound", this).requires(this.chestUncoverAlert);
        this.hideGemstoneMessage = new ToggleSetting("Gemstone Messages Hider", "like: &r&aYou received &r&f16 &r&f❈ &r&fRough Amethyst Gemstone&r&a.&r", false, "gemstone_message_hider", this).requires(this.PowderElement)
        this.showFlawlessGemstone = new ToggleSetting("Gemstone Messages Hider Show Flawless", "should the hider ^ ignore flawless gemstones?", false, "gemstone_show_flawless", this).requires(this.hideGemstoneMessage)
        this.hideWishingCompassMessage = new ToggleSetting("Wishing Compass Message Hider", "like: &r&aYou received &r&f1 &r&aWishing Compass&r&a.&r", false, "compass_message_hider", this).requires(this.PowderElement)
        this.hideAscensionRope = new ToggleSetting("Ascension Rope Hider", "like: &r&aYou received &r&f1 &r&9Ascension Rope&r&a.&r", false, "ascension_rope_hider", this).requires(this.PowderElement)
        this.showAreaTreasure = new ToggleSetting("Show Area Treasure", "whether or not to show each sub zone's treasures from chests", false, "show_area_treasure", this).requires(this.PowderElement)

        this.tempLoot = { global: {}, Jungle: {}, Goblin_Holdout: {}, Lost_Precursor_City: {}, Mithril_Deposits: {} }
        this.tempLocation = undefined
        //this will add the treasure and switch display location to it (it's from the most recent location)
        this.addTreasure = (Area, treasure, amount) => {
            if (amount < 0 || !amount) return
            if (this.tempLoot[Area][treasure]) this.tempLoot[Area][treasure] += amount
            else this.tempLoot[Area][treasure] = amount
            if (Area !== "global") this.tempLocation = Area
        }

        this.treasureColored = {
            Sludge_Juice: "&aSludge Juice",
            Oil_Barrel: "&aOil Barrel",
            Jungle_Heart: "&6Jungle Heart",
            Green_Goblin_Egg: "&aGreen Goblin Egg",
            Red_Goblin_Egg: "&cRed Goblin Egg",
            Yellow_Goblin_Egg: "&eYellow Goblin Egg",
            Blue_Goblin_Egg: "&3Blue Goblin Egg",
            Goblin_Egg: "&9Goblin Egg",
            Control_Switch: "&9Control Switch",
            FTX_3070: "&9FTX 3070",
            Electron_Transmitter: "&9Electron Transmitter",
            Robotron_Reflector: "&9Robotron Reflector",
            Synthetic_Heart: "&9Synthetic Heart",
            Superlite_Motor: "&9Superlite Motor",
            Treasurite: "&5Treasurite",
            Pickonimbus_2000: "&5Pickonimbus 2000",
            Prehistoric_Egg: "&fPrehistoric Egg"
        }
        //&r&aYou received &r&f1 &r&a&r&aGreen Goblin Egg&r&a.&r
        this.registerChat("&r&aYou received ${thing}&r&a.&r", (thing, e) => {
            if (this.hideGemstoneMessage.getValue() && thing.endsWith("Gemstone") && (this.showFlawlessGemstone.getValue() ? !thing.includes("Flawless") : true)) cancel(e)
            if (this.hideWishingCompassMessage.getValue() && thing.endsWith("Wishing Compass")) cancel(e)
            if (this.hideAscensionRope.getValue() && thing.endsWith("Ascension Rope")) cancel(e)
            if (this.showAreaTreasure.getValue()) {
                let treasure = undefined
                let amount = Math.floor(Number(thing.split(" ")[0].removeFormatting()))
                //jungle
                if (thing.endsWith("Sludge Juice")) treasure = "Sludge_Juice"
                if (thing.endsWith("Oil Barrel")) treasure = "Oil_Barrel"
                if (thing.endsWith("Jungle Heart")) treasure = "Jungle_Heart"
                if (treasure) {
                    this.addTreasure("Jungle", treasure, amount)
                    return
                }
                //goblin holdout
                if (thing.endsWith("Goblin Egg")) {
                    if (thing.includes("Green")) treasure = "Green_Goblin_Egg"
                    else if (thing.includes("Red")) treasure = "Red_Goblin_Egg"
                    else if (thing.includes("Yellow")) treasure = "Yellow_Goblin_Egg"
                    else if (thing.includes("Blue")) treasure = "Blue_Goblin_Egg"
                    else treasure = "&9Goblin_Egg"
                }
                if (treasure) {
                    this.addTreasure("Goblin_Holdout", treasure, amount)
                    return
                }
                //&r&aYou received &r&f1 &r&9Superlite Motor&r&a.&r
                //precursor city
                if (thing.endsWith("Control Switch")) treasure = "Control_Switch"
                if (thing.endsWith("FTX 3070")) treasure = "FTX_3070"
                if (thing.endsWith("Electron Transmitter")) treasure = "Electron_Transmitter"
                if (thing.endsWith("Robotron Reflector")) treasure = "Robotron_Reflector"
                if (thing.endsWith("Synthetic Heart")) treasure = "Synthetic_Heart"
                if (thing.endsWith("Superlite Motor")) treasure = "Superlite_Motor"
                if (treasure) {
                    this.addTreasure("Lost_Precursor_City", treasure, amount)
                    return
                }
                //mithril deposits
                if (thing.endsWith("Treasurite")) treasure = "Treasurite"
                if (treasure) {
                    this.addTreasure("Mithril_Deposits", treasure, amount)
                    return
                }
                //global
                if (thing.endsWith("Pickonimbus 2000")) treasure = "Pickonimbus_2000"
                if (thing.endsWith("Prehistoric Egg")) treasure = "Prehistoric_Egg"
                if (treasure) {
                    this.addTreasure("global", treasure, amount)
                    return
                }
            }
        })

        this.registerStep(true, 1, () => {
            if (this.FeatureManager.features["dataLoader"].class.area === "Crystal Hollows") {
                if (!this.leftCH && !this.inCrystalHollows) {
                    this.foundWither = false
                    this.inCrystalHollows = true
                }
            } else if (this.inCHfromChest) {
                this.inCrystalHollows = true
                this.dPowder = 0
                this.inCHfromChest = false
            }
        })
        this.dPowder = 0;
        this.sL = Renderer.getStringWidth(" ")

        this.overlayLeft = []
        this.overlayRight = []

        this.leftCH = false;
        this.registerEvent("worldLoad", () => {
            if (this.inCrystalHollows) {
                this.leftCH = true;
                this.inCrystalHollows = false;
                if (this.resetPowderWhenLeaveCH.getValue()) {
                    this.resetMiningData("powder")
                }
                this.chests.clear()
            } else this.leftCH = false
        })

        this.miningData = {}
        this.saveMiningData = () => {
            new Thread(() => {
                FileLib.write("soopyAddonsData", "miningData.json", JSON.stringify(this.miningData));
            }).start();
        }
        this.miningData = JSON.parse(FileLib.read("soopyAddonsData", "miningData.json") || "{}") || {}
        if (!this.miningData.powder) this.miningData.powder = { chests: 0, mithril: 0, gemstone: 0 }
        this.expRateInfo = []
        this.mythrilRate = 0
        this.gemstoneRate = 0
        this.chestRate = 0
        this.saveMiningData();

        this.registerCommand("resetpowderdata", () => {
            this.resetMiningData("powder");
            ChatLib.chat(this.FeatureManager.messagePrefix + "Successfully reset powder data.")
        }, this)

        this.registerChat("&r&aYou uncovered a treasure chest!&r", (e) => {
            if (!this.inCrystalHollows) {
                this.inCrystalHollows = true
                this.inCHfromChest = true
            }
            if (this.chestUncoverAlert.getValue()) Client.showTitle("&aTreasure Chest!", "", 0, 60, 20);
            if (this.chestUncoverAlertSound.getValue()) World.playSound("random.levelup", 1, 1);
        })

        this.registerChat("&r&r&r${space}&r&b&l2X POWDER ${status}!&r", (space, status, e) => {
            if (status.removeFormatting() === "STARTED") {
                this.dPowder = Date.now() + 15 * 1000 * 60
            } else this.dPowder = 0
        })
        this.inCHfromChest = false;
        this.registerChat("&r&6You have successfully picked the lock on this chest!&r", (e) => {
            this.miningData.powder.chests++
            delay(100, () => {
                this.expRateInfo.push([Date.now(), this.miningData.powder.mithril, this.miningData.powder.gemstone, this.miningData.powder.chests])
                if (this.expRateInfo.length > 20) this.expRateInfo.shift()

                let [time, mythril, gemstone, chest] = this.expRateInfo[0]

                this.mythrilRate = (this.miningData.powder.mithril - mythril) / (Date.now() - time)
                this.gemstoneRate = (this.miningData.powder.gemstone - gemstone) / (Date.now() - time)
                this.chestRate = (this.miningData.powder.chests - chest) / (Date.now() - time)
            })
        })

        this.lastPowderReceived = { mithril: 0, gemstone: 0 }
        this.lastPowderReceivedExecuted = false;
        this.registerChat("&r&aYou received &r&b+${amount} &r&aMithril Powder&r", (amount, e) => {
            let p = (this.dPowder ? 2 : 1) * parseInt(amount)
            this.miningData.powder.mithril += p
            if (this.compactedChat.getValue()) {
                cancel(e)
                this.lastPowderReceived.mithril += p
                return
            }
            if (this.fixChatForDoublePowder.getValue() && this.dPowder) {
                cancel(e)
                let suffix = "";
                if (this.fixChatForDoublePowderSuffix.getValue() !== "") suffix = this.fixChatForDoublePowderSuffix.getValue()
                ChatLib.chat(`&r&aYou received &r&b+${2 * amount} &r&aMithril Powder&r ${suffix}`)
            }
        })
        this.registerChat("&r&aYou received &r&b+${amount} &r&aGemstone Powder&r", (amount, e) => {
            let p = (this.dPowder ? 2 : 1) * parseInt(amount)
            this.miningData.powder.gemstone += p
            if (this.compactedChat.getValue()) {
                cancel(e)
                this.lastPowderReceived.gemstone += p
                return
            }
            if (this.fixChatForDoublePowder.getValue() && this.dPowder) {
                cancel(e)
                let suffix = "";
                if (this.fixChatForDoublePowderSuffix.getValue() !== "") suffix = this.fixChatForDoublePowderSuffix.getValue()
                ChatLib.chat(`&r&aYou received &r&b+${2 * amount} &r&aGemstone Powder&r ${suffix}`)
            }
        })

        this.registerStep(true, 5, this.compactPowderChat)

        this.chests = new Map()


        this.registerEvent("renderOverlay", this.renderOverlay)
        this.registerEvent("renderWorld", () => {
            if (!this.inCrystalHollows || !this.chestUnlockHelper.getValue()) return

            let del = []
            for (let key of this.chests.keys()) {
                let pos = this.chests.get(key)
                let size = 0.2
                let { x1, y1, x2, y2 } = RenderLib2D.calculateBoundingBox(new net.minecraft.util.AxisAlignedBB(pos[1] - size / 2, pos[2] - size / 2, pos[3] - size / 2, pos[1] + size / 2, pos[2] + size / 2, pos[3] + size / 2))

                let hovered = (x1 < Renderer.screen.getWidth() / 2 && x2 > Renderer.screen.getWidth() / 2 && y1 < Renderer.screen.getHeight() / 2 && y2 > Renderer.screen.getHeight() / 2)

                drawFilledBox(pos[1], pos[2] - size / 2, pos[3], size, size, hovered ? 0 : 255, hovered ? 255 : 0, 0, 1, false)

                if (Date.now() - pos[0] > 5000) {
                    del.push(key)
                }
            }

            del.forEach(k => this.chests.delete(k))
        })
        this.registerEvent("spawnParticle", this.spawnParticle)

        //==============================================Scatha=Feature=Below================================================================

        if (!this.miningData.scatha) this.miningData.scatha = { total_worms: 0, worms: 0, scathas: 0, rare: 0, epic: 0, legandary: 0, since_scatha: 0, since_pet: 0 }
        this.saveMiningData();

        this.scathaMain = new ToggleSetting("SCATHA!", "This is the main toggle of Scatha Feature", false, "scatha_main", this);

        this.scathaCounter = new ToggleSetting("Scatha Counter Hud", "This will show your scatha mining progress (only in CH)", false, "scatha_mining_hud", this).requires(this.scathaMain).contributor("EmeraldMerchant");
        this.scathaCounterElement = new HudTextElement()
            .setText("")
            .setToggleSetting(this.scathaCounter)
            .setLocationSetting(new LocationSetting("Scatha Counter Hud Location", "Allows you to edit the location of Scatha Counter Hud", "scatha_mining_hud_location", this, [10, 50, 1, 1]).requires(this.scathaCounter).editTempText(`&6Scatha Counter\n&bKills: 1,000\n&bWorms: 800\n&bScathas: 200\n&bSince Scatha: 10\n&9Rare Scatha Pets: 5\n&5Epic Scatha Pets: 3\n&6Leg Scatha Pets: 1\n&bSince Pet: 20`));
        this.hudElements.push(this.scathaCounterElement);

        this.wormEntity = undefined;
        this.scathaHealth = new ToggleSetting("Scatha Health Hud", "This will show worm/scatha mob HP on screen", false, "scatha_hp_hud", this).requires(this.scathaMain).contributor("EmeraldMerchant");
        this.scathaHealthElement = new HudTextElement()
            .setText("")
            .setToggleSetting(this.scathaHealth)
            .setLocationSetting(new LocationSetting("Scatha Health Hud Location", "Allows you to edit the location of Scatha Health Hud", "scatha_hp_hud_location", this, [10, 50, 1, 1]).requires(this.scathaHealth).editTempText(`&8[&7Lv5&8] &cWorm &e5&c❤`));
        this.hudElements.push(this.scathaHealthElement);

        new SettingBase("/scathaset <thing> <value>", "This command will change values in the counter", undefined, "scatha_cmd", this).requires(this.scathaMain);
        new SettingBase("/ss <thing> <value> works too", "you can press TAB for <thing> auto-complete", undefined, "scatha_cmd2", this).requires(this.scathaMain);
        this.scathaCmdComp = ["worms", "scathas", "rare", "epic", "legandary", "since_scatha", "since_pet"]
        this.registerCommand("scathaset", (thing, value) => this.scathaCmd(thing, value), this.scathaCmdComp);
        this.registerCommand("ss", (thing, value) => this.scathaCmd(thing, value), this.scathaCmdComp);

        this.wormSpawnedWarn = new ToggleSetting("Worm/Scatha Spawned Alert", "make a title and a sound when a worm/scatha spawned", false, "worm_spawned_alert", this).requires(this.scathaMain);
        this.registerChat("&r&7&oYou hear the sound of something approaching...&r", this.wormSpawning);
        this.wormSpawnedChatMessage = new ToggleSetting("Worm/Scatha Spawned Chat Message", "if a chat info should be sent when a worm/scatha spawned", false, "worm_spawned_chat_message", this).requires(this.scathaMain);
        this.petDroppedAlert = new ToggleSetting("Pet Dropped Alert", "Big title when a scatha pet dropped", false, "scatha_pet_dropped_alert", this).requires(this.scathaMain);
        this.colorToRarity = { 9: "rare", 5: "epic", 6: "legandary" }
        //&r&6&lPET DROP! &r&9Scatha &r&b(+&r&b291% &r&b✯ Magic Find&r&b)&r
        this.registerChat("&r&6&lPET DROP! &r&${rarity}Scatha &r&b(+&r&b${mf}% &r&b✯ Magic Find${end}", (rarity, mf, end, e) => {
            let r = this.colorToRarity[rarity]
            this.miningData.scatha[r]++
            this.miningData.scatha.since_pet = 0
            this.saveMiningData()
            if (this.petDroppedAlert.getValue()) {
                World.playSound('note.pling', 1, 1);
                Client.showTitle(`${rarity}${r.toUpperCase()} SCATHA PET!`, ChatLib.getChatMessage(e), 0, 100, 10);
            }
        })

        this.registerStep(true, 2, this.step2fps);
        this.registerStep(true, 3, this.wormStep);
        this.registerStep(true, 5, this.scathaHP);
    }

    spawnParticle(particle, type, event) {
        if (this.inCrystalHollows && this.chestUnlockHelper.getValue() && particle.toString().startsWith("EntityCrit2FX,")) {
            if (World.getBlockAt(particle.getX() + 1, particle.getY(), particle.getZ()).type.getID() === 54
                || World.getBlockAt(particle.getX() - 1, particle.getY(), particle.getZ()).type.getID() === 54
                || World.getBlockAt(particle.getX(), particle.getY(), particle.getZ() + 1).type.getID() === 54
                || World.getBlockAt(particle.getX(), particle.getY(), particle.getZ() - 1).type.getID() === 54) {
                this.chests.set(Math.floor(particle.getX()) + "," + Math.floor(particle.getY()) + "," + Math.floor(particle.getZ()), [Date.now(), particle.getX(), particle.getY(), particle.getZ()])
                cancel(event)
            }
        }
    }

    resetMiningData(type) {
        if (type === "powder") {
            Object.keys(this.miningData.powder).forEach(thing => this.miningData.powder[thing] = 0)
            this.expRateInfo = []
            this.tempLocation = undefined
            this.tempLoot = { global: {}, Jungle: {}, Goblin_Holdout: {}, Lost_Precursor_City: {}, Mithril_Deposits: {} }
        } else if (type === "scatha") {
            Object.keys(this.miningData.scatha).forEach(thing => this.miningData.scatha[thing] = 0)
        }
    }

    renderOverlay() {
        if (this.PowderOverlayElement.isEnabled()) {
            let width = Renderer.getStringWidth("&b2x Powder: &cINACTIVE")

            let x = this.PowderOverlayElement.locationSetting.x
            let y = this.PowderOverlayElement.locationSetting.y
            let scale = this.PowderOverlayElement.locationSetting.scale

            Renderer.retainTransforms(true)
            Renderer.scale(scale)
            Renderer.translate(x / scale, y / scale)

            this.overlayLeft.forEach((l, i) => {
                Renderer.drawStringWithShadow(l, 0, 10 * i)
            })

            this.overlayRight.forEach((l, i) => {
                Renderer.drawStringWithShadow(l, width - Renderer.getStringWidth(l), 10 * i)
            })

            Renderer.retainTransforms(false)
        }
    }

    step2fps() {
        if (!this.foundWither) {
            World.getAllEntitiesOfType(net.minecraft.entity.boss.EntityWither)?.forEach(e => {
                if (e.getName().startsWith("§e§lPASSIVE EVENT §b§l2X POWDER §e§lRUNNING FOR §a§l")) {
                    this.dPowder = Date.now();
                    let time = ChatLib.removeFormatting(e.getName()).split("RUNNING FOR ").pop()

                    let [m, s] = time.split(":")
                    this.dPowder += 1000 * parseInt(s)
                    this.dPowder += 60 * 1000 * parseInt(m)
                };
                this.foundWither = true;
            });
        }

        this.overlayLeft = []
        this.overlayRight = []

        if (this.PowderElement.getValue() && this.inCrystalHollows) {
            this.overlayLeft.push(`&b2x Powder:`)
            this.overlayRight.push(this.dPowder ? "&a" + timeNumber(Math.max(0, this.dPowder - Date.now())) : "&cINACTIVE")

            if (this.miningData.powder.chests) {
                let c = this.miningData.powder.chests

                this.overlayLeft.push(`&aChests:`)
                this.overlayRight.push(`&b${numberWithCommas(c)}`)
            }
            if (this.miningData.powder.mithril) {
                let m = this.miningData.powder.mithril

                this.overlayLeft.push(`&bMithril:`)
                this.overlayRight.push(`&d${numberWithCommas(m)}`)
            }
            if (this.miningData.powder.gemstone) {
                let g = this.miningData.powder.gemstone

                this.overlayLeft.push(`&bGems:`)
                this.overlayRight.push(`&d${numberWithCommas(g)}`)
            }
            if (this.mythrilRate) {
                this.overlayLeft.push(`&bMithril/h:`)
                this.overlayRight.push(`&d${numberWithCommas(Math.round(this.mythrilRate * 1000 * 60 * 60))}`)
            }
            if (this.gemstoneRate) {
                this.overlayLeft.push(`&bGems/h:`)
                this.overlayRight.push(`&d${numberWithCommas(Math.round(this.gemstoneRate * 1000 * 60 * 60))}`)
            }
            if (this.chestRate) {
                this.overlayLeft.push(`&bChests/h:`)
                this.overlayRight.push(`&d${numberWithCommas(Math.round(this.chestRate * 1000 * 60 * 60))}`)
            }
            if (this.showAreaTreasure.getValue()) {
                if (Object.keys(this.tempLoot.global).length > 0) {
                    Object.keys(this.tempLoot.global).forEach(t => {
                        if (this.tempLoot.global[t] > 0) {
                            this.overlayLeft.push(`${this.treasureColored[t]}&b:`)
                            this.overlayRight.push(`&b${this.tempLoot.global[t]}`)
                        }
                    })
                }
                if (this.tempLocation && Object.keys(this.tempLoot[this.tempLocation]).length > 0) {
                    Object.keys(this.tempLoot[this.tempLocation]).forEach(t => {
                        if (this.tempLoot[this.tempLocation][t] > 0) {
                            this.overlayLeft.push(`${this.treasureColored[t]}&b:`)
                            this.overlayRight.push(`&b${this.tempLoot[this.tempLocation][t]}`)
                        }
                    })
                }
            }
        }
        if (this.scathaCounter.getValue() && this.inCrystalHollows) {
            let tempText = `&6Scatha Counter\n&bKills: ${this.miningData.scatha.total_worms}\n&bWorms: ${this.miningData.scatha.worms}\n&bScathas: ${this.miningData.scatha.scathas}\n&bSince Scatha: ${this.miningData.scatha.since_scatha}\n`
            if (this.miningData.scatha.rare > 0) tempText += `&9Rare Scatha Pets: ${this.miningData.scatha.rare}\n`
            if (this.miningData.scatha.epic > 0) tempText += `&5Epic Scatha Pets: ${this.miningData.scatha.epic}\n`
            if (this.miningData.scatha.legandary > 0) tempText += `&6Leg Scatha Pets: ${this.miningData.scatha.legandary}`
            if (this.miningData.scatha.rare + this.miningData.scatha.epic + this.miningData.scatha.legandary > 0) tempText += `&bSince Pet: ${this.miningData.scatha.since_pet}`
            this.scathaCounterElement.setText(tempText)
        }
    }

    compactPowderChat() {
        if (this.lastPowderReceived.mithril > 0 && this.lastPowderReceived.gemstone > 0 && !this.lastPowderReceivedExecuted) {
            this.lastPowderReceivedExecuted = true
            delay(300, () => {
                let m = this.lastPowderReceived.mithril
                let g = this.lastPowderReceived.gemstone
                let msg = ""
                if (g > 0) msg += `&r&aYou received &r&b+${g} &r&aGemstone `
                if (m > 0) {
                    if (!msg) msg += `&r&aYou received &r&b+${m} &r&aMithril `
                    else msg += `and &r&b+${m} &r&aMithril `
                }
                msg += `Powder&r`
                if (this.dPowder) {
                    let suffix = "";
                    if (this.fixChatForDoublePowderSuffix.getValue() !== "") suffix = this.fixChatForDoublePowderSuffix.getValue()
                    ChatLib.chat(`${msg} ${suffix}`)
                } else ChatLib.chat(msg)
                this.lastPowderReceived = { mithril: 0, gemstone: 0 }
                this.lastPowderReceivedExecuted = false
            })
        }
    }

    scathaCmd(thing, value) {
        if (!this.scathaCmdComp.includes(thing) || parseInt(value) === NaN) {
            ChatLib.chat(this.FeatureManager.messagePrefix + "Invalid inputs! Usage: /scathaset <thing> <value>")
            return
        }
        let v = parseInt(value);
        this.miningData.scatha[thing] = v;
        this.miningData.scatha.total_worms = this.miningData.scatha.worms + this.miningData.scatha.scathas
        ChatLib.chat(this.FeatureManager.messagePrefix + "Successfully set " + thing + " to " + v + "!")
        this.saveMiningData();
    }

    wormSpawning() {
        if (this.wormSpawnedWarn.getValue()) {
            World.playSound('note.pling', 1, 1);
            Client.showTitle("&cWorm Spawning", "", 0, 20, 10);
            this.wormSpawned = true
        }
    }

    wormStep() {
        if (!this.inCrystalHollows || !this.scathaMain.getValue()) {
            this.scathaCounterElement.setText("")
            return
        }
        if (!this.wormSpawned) return
        World.getAllEntitiesOfType(net.minecraft.entity.item.EntityArmorStand).forEach(entity => {
            let name = entity.getName()
            //§8[§7Lv5§8] §cWorm§r §e5§c❤
            if (name.startsWith("§8[§7Lv5§8] §cWorm")) {
                if (this.wormSpawnedChatMessage.getValue()) ChatLib.chat("&c&lWorm Spawned. (Since Scatha: " + (this.miningData.scatha.since_scatha + 1) + ")");
                if (this.wormSpawnedWarn.getValue()) Client.showTitle("&c&lWorm Spawned!", "", 0, 20, 10);
                this.miningData.scatha.total_worms++;
                this.miningData.scatha.worms++;
                this.miningData.scatha.since_scatha++;
                this.saveMiningData()
                this.wormSpawned = false;
                if (this.scathaHealth.getValue()) this.wormEntity = entity
            }
            if (name.startsWith("§8[§7Lv10§8] §cScatha")) {
                if (this.wormSpawnedChatMessage.getValue()) ChatLib.chat("&c&lScatha Spawned.");
                if (this.wormSpawnedWarn.getValue()) Client.showTitle("&c&lScatha Spawned!", "", 0, 20, 10);
                this.miningData.scatha.total_worms++;
                this.miningData.scatha.scathas++;
                this.miningData.scatha.since_pet++;
                this.miningData.scatha.since_scatha = 0
                this.saveMiningData()
                this.wormSpawned = false;
                if (this.scathaHealth.getValue()) this.wormEntity = entity
            }
        });
    }

    scathaHP() {
        let tempText = ""
        if (this.scathaHealth.getValue()) {
            if (this.wormEntity && this.wormEntity.getEntity()[f.isDead]) {
                this.wormEntity = undefined;
            }
        } else if (this.wormEntity) {
            this.wormEntity = undefined;
        }
        if (this.wormEntity) {
            tempText = this.wormEntity.getName()
            this.scathaHealthElement.setText(tempText)
        } else {
            this.scathaHealthElement.setText("")
        }
    }

    initVariables() {
        this.hudElements = [];
        this.inCrystalHollows = false;
        this.foundWither = true;
        this.dPowder = 0;
        this.wormSpawned = false;
        this.wormEntity = undefined;
    }

    onDisable() {
        this.hudElements.forEach(h => h.delete())
        this.saveMiningData();
        if (this.resetPowderWhenLeaveGame.getValue()) {
            this.resetMiningData("powder");
        }
        this.initVariables();
    }
}

module.exports = {
    class: new PowderAndScatha(),
};