aboutsummaryrefslogtreecommitdiff
path: root/features/cosmetics
diff options
context:
space:
mode:
authorSoopyboo32 <49228220+Soopyboo32@users.noreply.github.com>2022-03-05 21:17:08 +0800
committerSoopyboo32 <49228220+Soopyboo32@users.noreply.github.com>2022-03-05 21:17:08 +0800
commit7ba09eb9ee619197849f3ed8de971e6bfab7d721 (patch)
treeaacc1e22caf9d36ed593e2b6aeef7bc19e652d2b /features/cosmetics
parent4a1947673debcd858247698b2670d0c7a24f04ee (diff)
downloadSoopyV2-7ba09eb9ee619197849f3ed8de971e6bfab7d721.tar.gz
SoopyV2-7ba09eb9ee619197849f3ed8de971e6bfab7d721.tar.bz2
SoopyV2-7ba09eb9ee619197849f3ed8de971e6bfab7d721.zip
performance improvements + fix rare dungeon map breaking issue
Diffstat (limited to 'features/cosmetics')
-rw-r--r--features/cosmetics/cosmetic/dragon/dragonWings.js5
-rw-r--r--features/cosmetics/index.js50
2 files changed, 40 insertions, 15 deletions
diff --git a/features/cosmetics/cosmetic/dragon/dragonWings.js b/features/cosmetics/cosmetic/dragon/dragonWings.js
index bad1fc2..add23d1 100644
--- a/features/cosmetics/cosmetic/dragon/dragonWings.js
+++ b/features/cosmetics/cosmetic/dragon/dragonWings.js
@@ -347,7 +347,10 @@ class DragonWings extends Cosmetic {
this.testPlaySound()
- if(!this.player.getPlayer().getEssentialCosmetics || !this.player.getPlayer().getEssentialCosmetics()) return
+ }
+
+ removeEssentialCosmetics(){
+ if(!this.player.getPlayer() || !this.player.getPlayer().getEssentialCosmetics || !this.player.getPlayer().getEssentialCosmetics()) return
let wingCosmetic = this.player.getPlayer().getEssentialCosmetics().get(EssentialCosmeticSlot.WINGS)
if(wingCosmetic !== null){
diff --git a/features/cosmetics/index.js b/features/cosmetics/index.js
index c5ff21e..d4b9fcb 100644
--- a/features/cosmetics/index.js
+++ b/features/cosmetics/index.js
@@ -38,6 +38,8 @@ class Cosmetics extends Feature {
})
})
+ this.postRenderEntityTrigger = undefined
+
this.loadCosmeticsData()
this.worldLoad()
@@ -48,6 +50,12 @@ class Cosmetics extends Feature {
this.registerEvent("playerLeft", this.playerLeft)
this.registerEvent("worldLoad", this.worldLoad)
this.registerStep(false, 2, this.step)
+ this.registerEvent('worldUnload', ()=>{
+ if(this.postRenderEntityTrigger){
+ this.postRenderEntityTrigger.unregister()
+ this.postRenderEntityTrigger = undefined
+ }
+ })
// this.registerStep(false, 60*10, ()=>{
// new Thread(()=>{this.loadCosmeticsData.call(this)}).start()
// })
@@ -75,22 +83,22 @@ class Cosmetics extends Feature {
}
}
- renderEntity(entity, pos, ticks, event){
- if(ticks !== 1) return
- if(this.uuidToCosmeticDirect[entity.getUUID().toString().replace(/-/g,"")]){
- Object.values(this.uuidToCosmeticDirect[entity.getUUID().toString().replace(/-/g,"")]).forEach(cosmetic => {
- cosmetic.onRenderEntity(ticks, true)
- })
- }
- }
-
loadCosmeticsData(){
let data = JSON.parse(FileLib.getUrlContent("http://soopymc.my.to/api/soopyv2/cosmetics.json"))
this.cosmeticsData = data
this.playerHasACosmeticA = !!data[Player.getUUID().toString().replace(/-/g,"")]
if(this.playerHasACosmeticA && !this.loadedRenderEntity){
- this.registerEvent("postRenderEntity", this.renderEntity)
+ // this.registerEvent("postRenderEntity", this.renderEntity)
+ this.postRenderEntityTrigger = register("postRenderEntity", (entity, pos, ticks, event)=>{
+ if(ticks !== 1) return
+ if(this.uuidToCosmeticDirect[entity.getUUID().toString().replace(/-/g,"")]){
+ let cosmetics = Object.values(this.uuidToCosmeticDirect[entity.getUUID().toString().replace(/-/g,"")])
+ for(let cosmetic of cosmetics){
+ cosmetic.onRenderEntity(ticks, true)
+ }
+ }
+ })
this.loadedRenderEntity = true
}
@@ -124,6 +132,14 @@ class Cosmetics extends Feature {
step(){
this.scanForNewCosmetics()
+
+ this.filterUnloadedCosmetics(false)
+
+ this.restoreEssentialCosmetics()
+
+ this.loadedCosmetics.forEach(c=>{
+ c.removeEssentialCosmetics()
+ })
}
scanForNewCosmetics(){
this.loadCosmeticsForPlayer(Player)
@@ -204,9 +220,9 @@ class Cosmetics extends Feature {
}
tick(){
- this.restoreEssentialCosmetics()
-
- this.filterUnloadedCosmetics(true)
+ for(let cosmetic of this.loadedCosmetics){
+ cosmetic.onTick()
+ }
}
restoreEssentialCosmetics(){
@@ -219,7 +235,7 @@ class Cosmetics extends Feature {
initVariables(){
this.loadedCosmetics = undefined
this.uuidToCosmetic = undefined
- this.uuidToCosmeticDirect = undefined
+ this.uuidToCosmeticDirect = {}
this.playerHasACosmeticA = undefined
this.cosmeticsData = undefined
this.hiddenEssentialCosmetics = undefined
@@ -228,6 +244,12 @@ class Cosmetics extends Feature {
}
onDisable(){
+
+ if(this.postRenderEntityTrigger){
+ this.postRenderEntityTrigger.unregister()
+ this.postRenderEntityTrigger = undefined
+ }
+
this.restoreEssentialCosmetics()
this.initVariables()