aboutsummaryrefslogtreecommitdiff
path: root/features/events/index.js
blob: cc2c3e5556df63be15ba508d08c15c5b000cfccf (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
/// <reference types="../../../CTAutocomplete" />
/// <reference lib="es2015" />
import Feature from "../../featureClass/class";
import { f } from "../../../mappings/mappings";
import { drawBoxAtBlock, drawBoxAtBlockNotVisThruWalls, drawCoolWaypoint, drawLine } from "../../utils/renderUtils";
import { calculateDistance, calculateDistanceQuick, fastestPathThrough } from "../../utils/utils";
import HudTextElement from "../hud/HudTextElement";
import LocationSetting from "../settings/settingThings/location";
import ToggleSetting from "../settings/settingThings/toggle";

class Events extends Feature {
    constructor() {
        super()
    }

    onEnable(){
        this.initVariables()

        this.burrialData = {
            points: [],
            locations: [],
            historicalLocations: []
        }
        this.lastRequestTime = 0
        this.nextUpdateApprox = -1
        this.lastWorldChange = 0
        this.lastRequest = 0
        this.potentialParticleLocs = {}
        this.showingWaypoints = false
        this.lastPath = []
        this.updatingPath = false
        this.hudElements = []
        this.lastPathCords = undefined


        this.burrialWaypointsEnabled = new ToggleSetting("Burrial waypoints", "Show waypoints for burrials during the diana event", true, "burrial_waypoints", this)
        this.burrialWaypointsPath = new ToggleSetting("Pathfind waypoints", "Calculate a path thru all the waypoints", true, "burrial_waypoints_path", this).requires(this.burrialWaypointsEnabled)
        this.onlyShowPath = new ToggleSetting("Only show waypoint path", "For if u want to use other mod waypoints + soopy path", false, "burrial_waypoints_only_path", this).requires(this.burrialWaypointsPath)
        this.burrialWaypointsNearest = new ToggleSetting("Show nearest using pathfinding", "Use pathfinding to highlight the next burrial instead of disance", true, "burrial_nearest_path", this).requires(this.burrialWaypointsEnabled)
        this.loadFromParticles = new ToggleSetting("Load burrials from particles", "Will load particles from burrows in the world", true, "burrial_from_partles", this).requires(this.burrialWaypointsEnabled)

        this.updateTimerEnabled = new ToggleSetting("Show API update timer", "Shows a countdown till the burrial waypoints will be next updated", true, "burrial_timer", this).requires(this.burrialWaypointsEnabled)
        this.updateTimer = new HudTextElement()
            .setToggleSetting(this.updateTimerEnabled)
            .setLocationSetting(new LocationSetting("Timer Location", "Allows you to edit the location of the timer", "burrial_timer_location", this, [10, 50, 1, 1])
                .requires(this.burrialWaypointsEnabled)
                .editTempText("&6Update&7> &f100s"))
        this.hudElements.push(this.updateTimer)

        this.shinyBlocks = []
    
        this.shinyBlockOverlayEnabled = new ToggleSetting("Shiny blocks highlight", "Will highlight shiny blocks in the end", false, "shiny_blocks_overlay", this)
        
        this.registerEvent("worldLoad", this.worldLoad)
        this.registerEvent("spawnParticle", this.spawnParticle)
        this.registerEvent("renderWorld", this.renderWorld)
        this.registerEvent("renderOverlay", this.renderOverlay)
        this.registerStep(true, 2, this.step)
        this.registerStep(false, 5, this.step_5s)
        this.registerSoopy("apiLoad", this.apiLoad)

        this.registerChat("&r&eYou dug out a Griffin Burrow! &r&7(${*}/4)&r", this.burrialClicked)
        this.registerChat("&r&eYou finished the Griffin burrow chain! &r&7(4/4)&r", this.burrialClicked)
    }

    renderOverlay(){
        for(let element of this.hudElements){
            element.render()
        }
    }

    renderWorld(ticks){
        this.shinyBlocks.forEach(([loc])=>{
            drawBoxAtBlockNotVisThruWalls(loc[0], loc[1], loc[2], 0,255,0,0.1,0.1)
        })
        if(this.showingWaypoints && this.lastPathCords && this.burrialWaypointsPath.getValue()){
            let startPoint = [Player.getPlayer()[f.lastTickPosX]+Player.getPlayer()[f.motionX.Entity]*ticks,
                Player.getPlayer()[f.lastTickPosY]+Player.getPlayer()[f.motionY.Entity]*ticks,
                Player.getPlayer()[f.lastTickPosZ]+Player.getPlayer()[f.motionZ.Entity]*ticks]
    
            let lastPoint = startPoint || [0,0,0]
    
            this.lastPathCords.forEach((point)=>{
                drawLine(...lastPoint,...point,255,255,0)
    
                lastPoint = point
            })
        }	
        if(this.showingWaypoints && !this.onlyShowPath.getValue()){
            this.burrialData.locations.forEach((loc,i)=>{

                let typeReplace = [
                    "Start",
                    "Mob",
                    "Treasure",
                    "Finish",
                    "Unknown"
                ]
                if(!loc.clicked){
                    blue = false
                    if(loc.lastPing && Date.now()-loc.lastPing < 500){
                        blue = true
                    }

                    let name = ""

                    if(loc.fromApi){
                        name = (loc.nearest?"§c":"§a")+"(" + (loc.chain+1) + "/4) " + typeReplace[loc.type] + " burrial"
                    }else{
                        name = (loc.nearest?"§c":"§a")+typeReplace[loc.type] + " burrial"
                    }

                    drawCoolWaypoint(loc.x, loc.y,loc.z,0,blue?100:255,blue?255:0, {name: name})
                }
            })
        }
    }

    sortBurrialLocations(){
        let sorted = [...this.burrialData.locations]
        sorted.sort((a,b)=>{
            let aDist = calculateDistanceQuick([Player.getX(),Player.getY(),Player.getZ()],[a.x+0.5,a.y+2.5,a.z+0.5])
            let bDist = calculateDistanceQuick([Player.getX(),Player.getY(),Player.getZ()],[b.x+0.5,b.y+2.5,b.z+0.5])

            return bDist-aDist
        })
        this.burrialData.locations = sorted
    }

    step(){
        if(!Player.getInventory()) return
        
        hasDianaShovle = false
        let slots = [0, 1, 2, 3, 4, 5, 6, 7, 8]
        slots.forEach(a=>{
            item = Player.getInventory().getStackInSlot(a)
            if(!item) return
            if(ChatLib.removeFormatting(item.getName()) === "Ancestral Spade"){
                hasDianaShovle = true
            }
        })

        let showingWaypointsNew = (this.lastWorldChange+5000<Date.now()?hasDianaShovle && this.FeatureManager.features["dataLoader"].class.area === "Hub" && this.burrialWaypointsEnabled.getValue():this.showingWaypoints || (hasDianaShovle && this.FeatureManager.features["dataLoader"].class.area === "Hub" && this.burrialWaypointsEnabled.getValue()))

        if(!this.showingWaypoints && showingWaypointsNew){
            this.loadApi()
        }else if(showingWaypointsNew){
            if(Date.now()-this.nextUpdateApprox > 0 && this.nextUpdateApprox > 0 && Date.now()-this.lastRequest>5000){
                this.nextUpdateApprox = -2
                this.loadApi()
            }
        }

        this.showingWaypoints = showingWaypointsNew

        if(this.showingWaypoints){

            this.updateTimer.setText("&6Update&7> &f" + (this.nextUpdateApprox===-1?"Updating...":(this.nextUpdateApprox===-2?"Loading...":Math.ceil((this.nextUpdateApprox-Date.now())/1000) + "s")))
        }else{
            this.updateTimer.setText("")
        }

        this.shinyBlocks = this.shinyBlocks.filter(([loc, time])=>{
            return time > Date.now()-5000
        })

    }

    step_5s(){
        if(this.showingWaypoints){
            if(this.burrialWaypointsPath.getValue() || this.burrialWaypointsNearest.getValue()){
                new Thread(()=>{
                    this.updateBurrialPath()
                }).start()
            }
        }
        this.sortBurrialLocations()

        if(this.nextUpdateApprox === -2){
            this.loadApi()
        }
    }

    worldLoad(){
        this.burrialData.points = []
        this.burrialData.locations = []
        this.burrialData.historicalLocations = []
        this.lastRequestTime = 0
        
        this.lastPath = undefined
        this.lastPathCords = undefined

        this.nextUpdateApprox = Date.now()

        this.lastWorldChange = Date.now()
    }

    loadApi(){
        this.FeatureManager.features["dataLoader"].class.loadApiData("skyblock", false)
    }

    apiLoad(data, dataType, isSoopyServer, isLatest){ 
        if(isSoopyServer || dataType !== "skyblock" || !isLatest) return
		this.lastRequest = Date.now()

        let profileData = data.profiles[0].members[Player.getUUID().toString().replace(/-/g,"")]

        data.profiles.forEach((prof)=>{
            if((prof.members[Player.getUUID().toString().replace(/-/g,"")].last_save || 0) > (profileData.last_save || 0)){
                profileData = prof.members[Player.getUUID().toString().replace(/-/g,"")]
            }
        })
        this.nextUpdateApprox = profileData.last_save+173000
        this.nextUpdateApprox += 2000 //incase ur pc time is behind
        if(profileData.last_save === this.lastRequestTime){
            return
        }
        this.lastRequestTime = profileData.last_save
        
        let locsAccessed = []
        let newLocs = []
        if(!profileData.griffin) return
        
        profileData.griffin.burrows.forEach((burrow)=>{
            let pushed = false
            this.burrialData.locations.forEach((loc, i)=>{
                if((loc.fromApi || loc.clicked) && loc.x + "," + loc.y + "," + loc.z === burrow.x + "," + burrow.y + "," + burrow.z){
                    newLocs.push(loc)
                    pushed = true
                    locsAccessed.push(i)
                }
            })
            this.burrialData.historicalLocations.forEach((loc)=>{
                if(loc.x + "," + loc.y + "," + loc.z === burrow.x + "," + burrow.y + "," + burrow.z){
                    pushed = true
                }
            })
            if(!pushed){
                burrow.clicked = false
                burrow.fromApi = true
                newLocs.push(burrow)
            }
        })
        
        this.burrialData.locations.forEach((loc)=>{
            if(!loc.fromApi){
                let found = false
                newLocs.forEach((burrow)=>{
                    if(loc.x + "," + loc.y + "," + loc.z === burrow.x + "," + burrow.y + "," + burrow.z){
                        found = true
                    }
                })

                if(!found){
                    newLocs.push(loc)
                }
            }
        })

        this.burrialData.locations = newLocs
        if(this.showingWaypoints){
            this.sortBurrialLocations()
            this.updateBurrialPath()
        }
    }

    
    spawnParticle(particle, type, event){
        if(this.shinyBlockOverlayEnabled.getValue()){
            if(particle.toString().startsWith("EntitySpellParticleFX,")){
                if(particle.getUnderlyingEntity().func_70534_d()===particle.getUnderlyingEntity().func_70535_g()){
                    let arr = [particle.getX(), particle.getY(), particle.getZ()]
                    if(arr.map(a=>Math.abs(a%1)).includes(0.25) || arr.map(a=>Math.abs(a%1)).includes(0.75)){
                        this.shinyBlocks.push([[particle.getX(), particle.getY(), particle.getZ()], Date.now()])
                    }
                }
            }
        }
        if(this.showingWaypoints && this.loadFromParticles.getValue()){
            let foundEnchant = false
            let foundCrit = false
            let foundStep = false
            let isMob = undefined

            if(particle.toString().startsWith('EntityEnchantmentTableParticleFX, ')){
                foundEnchant = true
            }
            else if(particle.toString().startsWith('EntityCrit2FX, ')){
                foundCrit = true
                
                isMob = particle.getUnderlyingEntity().func_70534_d() > 0.5 //mob)
            }
            else if(particle.toString().startsWith('EntityFootStepFX, ')){
                foundStep = true
            }
            else if(particle.toString().startsWith('EntityCritFX, ')){
                
                let locstr = Math.floor(particle.getX()) + "," + Math.floor(particle.getY()-1) + "," + Math.floor(particle.getZ())

                let removed = false
                this.burrialData.locations.filter((loc, i)=>{
                    if(!loc.clicked && loc.x + "," + loc.y + "," + loc.z === locstr){
                        loc.clicked = true
                        removed = true
                        
                        this.lastPathCords.shift()
                    }
                })
                if(!removed) return;
                this.burrialData.locations = this.burrialData.locations.filter(a=>{
                    if(!a.clicked) return true
                    if(calculateDistanceQuick([a.x,a.y,a.z],[Player.getX(),Player.getY(),Player.getZ()]) < 15*15) return true;
            
                    this.burrialData.historicalLocations.unshift(a)
            
                    return false
                })
                if(this.burrialData.historicalLocations.length > 10) this.burrialData.historicalLocations.pop()

                return;
            }

            if(!foundEnchant && !foundCrit && !foundStep) return;

            let locstr = Math.floor(particle.getX()) + "," + Math.floor(particle.getY()-1) + "," + Math.floor(particle.getZ())
            let locarr = [Math.floor(particle.getX()), Math.floor(particle.getY()-1), Math.floor(particle.getZ())]

            let found = false

            this.burrialData.locations.forEach((loc)=>{
                if(loc.x + "," + loc.y + "," + loc.z === locstr){
                    found = true
                    loc.lastPing = Date.now()
                }
                if((loc.x+1) + "," + loc.y + "," + loc.z === locstr){
                    found = true
                    loc.lastPing = Date.now()
                }
                if((loc.x-1) + "," + loc.y + "," + loc.z === locstr){
                    found = true
                    loc.lastPing = Date.now()
                }
                if(loc.x + "," + loc.y + "," + (loc.z+1) === locstr){
                    found = true
                    loc.lastPing = Date.now()
                }
                if(loc.x + "," + loc.y + "," + (loc.z-1) === locstr){
                    found = true
                    loc.lastPing = Date.now()
                }
            })
            if(this.burrialData.historicalLocations){
                this.burrialData.historicalLocations.forEach((loc)=>{
                    if(loc.x + "," + loc.y + "," + loc.z === locstr){
                        found = true
                    }
                })
            }

            if(found) return;


            if (!this.potentialParticleLocs[locstr])this.potentialParticleLocs[locstr] = {enchant: 0, crit: 0, step: 0, isMob: 0, timestamp: Date.now()}

            if(foundEnchant) this.potentialParticleLocs[locstr].enchant++
            if(foundCrit) this.potentialParticleLocs[locstr].crit++
            if(foundStep) this.potentialParticleLocs[locstr].step++
            if(foundCrit && isMob) this.potentialParticleLocs[locstr].isMob++
            if(foundCrit && !isMob) this.potentialParticleLocs[locstr].isMob--

            this.potentialParticleLocs[locstr].timestamp = Date.now()

            if(this.potentialParticleLocs[locstr].enchant > 4 && this.potentialParticleLocs[locstr].step > 10){
                this.burrialData.locations.push({
                    "x": locarr[0],
                    "y": locarr[1],
                    "z": locarr[2],
                    "type": this.potentialParticleLocs[locstr].isMob > 1? 1:(this.potentialParticleLocs[locstr].crit > this.potentialParticleLocs[locstr].enchant/20?0:2),
                    "tier": -1,
                    "chain": -1,
                    "fromApi": false
                })
                new Thread(()=>{
                    this.updateBurrialPath()
                }).start()
            }
        }
    }
    
    burrialClicked(){
        if(!this.showingWaypoints) return

        let nearestBurriali = undefined
        let nearestBurrialDist = Infinity

        this.burrialData.locations.forEach((loc, i)=>{
            let dist = calculateDistanceQuick([loc.x, loc.y, loc.z], [Player.getX(), Player.getY(), Player.getZ()])
            if(dist < nearestBurrialDist){
                nearestBurrialDist = dist
                nearestBurriali = i
            }
        })

        if(nearestBurriali === undefined) return;
        this.burrialData.locations[nearestBurriali].clicked = true

        this.burrialData.locations = this.burrialData.locations.filter(a=>{
            if(!a.clicked) return true
            if(calculateDistanceQuick([a.x,a.y,a.z],[Player.getX(),Player.getY(),Player.getZ()]) < 15*15) return true;
    
            this.burrialData.historicalLocations.unshift(a)
    
            return false
        })
        if(this.burrialData.historicalLocations.length > 10) this.burrialData.historicalLocations.pop()
        if(this.lastPathCords) this.lastPathCords.shift()
        new Thread(()=>{
            this.updateBurrialPath()
        }).start()
    }
    updateBurrialPath(){
        if(this.burrialWaypointsPath.getValue() || this.burrialWaypointsNearest.getValue()){
            let startPoint = [Player.getX(),Player.getY(),Player.getZ()]
    
            let points = this.burrialData.locations.filter((a)=>{return !a.clicked}).map((a)=>{return [a.x+0.5,a.y+1.3,a.z+0.5]})
    
            if(points.length !== 0){
    
                if(points.length >= 10){
                    this.lastPath = undefined
                    this.lastPathCords = undefined
                }else{
                    this.lastPath = fastestPathThrough(startPoint,points)

                    this.lastPathCords = []
                    this.lastPath.forEach(a=>{
                        this.lastPathCords.push(points[a])
                    })
                }
                
                if(this.lastPath.length === 0){
                    this.lastPath = undefined
                    this.lastPathCords = undefined
                }
    
            }else{
                this.lastPath = undefined
                this.lastPathCords = undefined
            }
        }

    
        if(this.showingWaypoints){
            if(this.burrialWaypointsNearest.getValue()){
                let trueI = 0
                this.burrialData.locations.forEach((loc,i)=>{
                    if(!loc.clicked && trueI === this.lastPath[0]){
                        this.burrialData.locations[i].nearest = true
                    }else{
                        this.burrialData.locations[i].nearest = false
                    }
        
                    if(!loc.clicked) trueI++
                })
            }else{
                let closestBurrialI = 0
                let closestBurrialDist = Infinity
        
                this.burrialData.locations.forEach((loc,i)=>{
                    let dist = calculateDistanceQuick([loc.x,loc.y,loc.z],[Player.getX(),Player.getY(),Player.getZ()])
                    if(dist < closestBurrialDist){
                        closestBurrialDist = dist
                        closestBurrialI = i
                    }
                    this.burrialData.locations[i].nearest = false
                })
        
                this.burrialData.locations[closestBurrialI].nearest = true
            }
        }
    }

    initVariables(){
        this.burrialData = undefined
        this.lastRequestTime = undefined
        this.nextUpdateApprox = undefined
        this.lastRequest = undefined
        this.potentialParticleLocs = undefined
        this.showingWaypoints = undefined
        this.lastPath = undefined
        this.updatingPath = undefined
        this.hudElements = undefined
        this.lastPathCords = undefined
    }

    onDisable(){
        this.initVariables()
    }
}

module.exports = {
    class: new Events()
}