diff options
Diffstat (limited to 'features/cosmetics')
-rw-r--r-- | features/cosmetics/cosmetic.js | 6 | ||||
-rw-r--r-- | features/cosmetics/cosmetic/dragon/dragonWings.js | 11 | ||||
-rw-r--r-- | features/cosmetics/index.js | 76 |
3 files changed, 39 insertions, 54 deletions
diff --git a/features/cosmetics/cosmetic.js b/features/cosmetics/cosmetic.js index 4b52fa8..1627f2f 100644 --- a/features/cosmetics/cosmetic.js +++ b/features/cosmetics/cosmetic.js @@ -1,11 +1,15 @@ class Cosmetic{ - constructor(player, parent){ + constructor(player, parent, id){ /** * @type {PlayerMP | Player} */ this.player = player this.parent = parent + + this.id = id + + this.settings = this.parent.getPlayerCosmeticSettings(this.player, id) } onRender(){ diff --git a/features/cosmetics/cosmetic/dragon/dragonWings.js b/features/cosmetics/cosmetic/dragon/dragonWings.js index a5b76d8..28d51bb 100644 --- a/features/cosmetics/cosmetic/dragon/dragonWings.js +++ b/features/cosmetics/cosmetic/dragon/dragonWings.js @@ -8,7 +8,7 @@ const EssentialCosmeticSlot = Java.type("gg.essential.cosmetics.CosmeticSlot") const FACING = Java.type("net.minecraft.block.BlockDirectional").field_176387_N let dragon = new ModelDragon(0) //too lazy to make my own model so i just yoink it from modelDragon lmfao -let textures = { +let textures = {//TODO: dynamicly load textures from server classic: new Image(javax.imageio.ImageIO.read(new java.io.File("./config/ChatTriggers/modules/SoopyV2/features/cosmetics/textures/dragon/classic.png"))), purple: new Image(javax.imageio.ImageIO.read(new java.io.File("./config/ChatTriggers/modules/SoopyV2/features/cosmetics/textures/dragon/purple.png"))) } @@ -18,15 +18,14 @@ const GL11 = Java.type("org.lwjgl.opengl.GL11"); class DragonWings extends Cosmetic { constructor(player, parent) { - super(player, parent); - - this.settings = this.parent.getPlayerCosmeticSettings(this.player, "dragon_wings") + super(player, parent, "dragon_wings"); this.animOffset = Math.random()*20*Math.PI this.lastRender = Date.now() this.lastFlapSound = this.animOffset } + onRender(ticks){ if(this.player.getPlayer().func_98034_c(Player.getPlayer())){ @@ -291,7 +290,7 @@ class DragonWings extends Cosmetic { if(wingCosmetic !== null){ this.player.getPlayer().getEssentialCosmeticModels().get(Essential.instance.getConnectionManager().getCosmeticsManager().getCosmetic(wingCosmetic)).getModel().getModel().boneList.forEach(b=>{ b.isHidden = true - this.parent.hiddenCosmetics.push(b) + this.parent.hiddenEssentialCosmetics.push(b) }) }else{ let fullBodyCosmetic = this.player.getPlayer().getEssentialCosmetics().get(EssentialCosmeticSlot.FULL_BODY) @@ -300,7 +299,7 @@ class DragonWings extends Cosmetic { if(b.boxName === "wing_left_1" || b.boxName === "wing_right_1"){ b.isHidden = true - this.parent.hiddenCosmetics.push(b) + this.parent.hiddenEssentialCosmetics.push(b) } }) } diff --git a/features/cosmetics/index.js b/features/cosmetics/index.js index 4fb1242..11f3abd 100644 --- a/features/cosmetics/index.js +++ b/features/cosmetics/index.js @@ -3,8 +3,6 @@ import Feature from "../../featureClass/class"; import DragonWings from "./cosmetic/dragon/dragonWings" import Toggle from "../settings/settingThings/toggle" -const Essential = Java.type("gg.essential.Essential") -const EssentialCosmeticSlot = Java.type("gg.essential.cosmetics.CosmeticSlot") class Cosmetics extends Feature { constructor() { @@ -18,7 +16,11 @@ class Cosmetics extends Feature { this.cosmeticsData = {} - this.hiddenCosmetics = [] + this.hiddenEssentialCosmetics = [] + + this.cosmeticsList = { + "dragon_wings": DragonWings + } this.playerHasACosmeticA = false @@ -52,13 +54,7 @@ class Cosmetics extends Feature { setUserCosmeticsInformation(uuid, cosmetics){ if(!this.enabled) return - this.loadedCosmetics = this.loadedCosmetics.filter(cosmetic=>{ - if(cosmetic.player.getUUID().toString().replace(/-/g,"") === uuid){ - this.uuidToCosmetic[cosmetic.player.getUUID().toString().replace(/-/g,"")] = undefined - return false - } - return true - }) + this.filterUnloadedCosmetics() if(!cosmetics){ delete this.cosmeticsData[uuid] @@ -72,19 +68,21 @@ class Cosmetics extends Feature { this.scanForNewCosmetics() } scanForNewCosmetics(){ - - if(!this.uuidToCosmetic[Player.getUUID().toString().replace(/-/g,"")] && this.shouldPlayerHaveCosmetic(Player, "dragon_wings")){ - let cosmetic = new DragonWings(Player, this) - this.loadedCosmetics.push(cosmetic) - this.uuidToCosmetic[Player.getUUID().toString().replace(/-/g,"")] = cosmetic - } - World.getAllPlayers().forEach(p=>{ - if(p.getUUID().toString().replace(/-/g,"") === Player.getUUID().toString().replace(/-/g,"") || this.uuidToCosmetic[p.getUUID().toString().replace(/-/g,"")]) return - if(this.shouldPlayerHaveCosmetic(p, "dragon_wings")){ - let cosmetic = new DragonWings(p, this) + this.loadCosmeticsForPlayer(p) + }) + } + + loadCosmeticsForPlayer(player){ + Object.keys(this.cosmeticsList).forEach(cosmeticName=>{ + if(!this.uuidToCosmetic[cosmeticName]) this.uuidToCosmetic[cosmeticName] = {} + + if(this.uuidToCosmetic[cosmeticName][player.getUUID().toString().replace(/-/g,"")]) return + + if(this.shouldPlayerHaveCosmetic(player, cosmeticName)){ + let cosmetic = new (this.cosmeticsList[cosmeticName])(player, this) this.loadedCosmetics.push(cosmetic) - this.uuidToCosmetic[p.getUUID().toString().replace(/-/g,"")] = cosmetic + this.uuidToCosmetic[cosmeticName][player.getUUID().toString().replace(/-/g,"")] = cosmetic } }) } @@ -93,37 +91,19 @@ class Cosmetics extends Feature { this.loadedCosmetics = [] this.uuidToCosmetic = {} - if(this.shouldPlayerHaveCosmetic(Player, "dragon_wings") && !this.uuidToCosmetic[Player.getUUID().toString().replace(/-/g,"")]){ - let cosmetic = new DragonWings(Player, this) - this.loadedCosmetics.push(cosmetic) - this.uuidToCosmetic[Player.getUUID().toString().replace(/-/g,"")] = cosmetic - } - - World.getAllPlayers().forEach(p=>{ - if(p.getUUID().toString().replace(/-/g,"") === Player.getUUID().toString().replace(/-/g,"")) return - if(this.shouldPlayerHaveCosmetic(p, "dragon_wings") && !this.uuidToCosmetic[p.getUUID().toString().replace(/-/g,"")]){ - let cosmetic = new DragonWings(p, this) - this.loadedCosmetics.push(cosmetic) - this.uuidToCosmetic[p.getUUID().toString().replace(/-/g,"")] = cosmetic - } - }) + this.scanForNewCosmetics() } playerJoined(player){ if(player.getUUID().toString().replace(/-/g,"") === Player.getUUID().toString().replace(/-/g,"")) return - if(this.shouldPlayerHaveCosmetic(player, "dragon_wings") && !this.uuidToCosmetic[player.getUUID().toString().replace(/-/g,"")]){ - let cosmetic = new DragonWings(player, this) - this.playerHasACosmeticA = true - this.loadedCosmetics.push(cosmetic) - this.uuidToCosmetic[player.getUUID().toString().replace(/-/g,"")] = cosmetic - } + this.loadCosmeticsForPlayer(player) } playerLeft(playerName){ this.loadedCosmetics.filter(cosmetic=>{ if(cosmetic.player.getName() === playerName){ - this.uuidToCosmetic[cosmetic.player.getUUID().toString().replace(/-/g,"")] = undefined + this.uuidToCosmetic[cosmetic.id][cosmetic.player.getUUID().toString().replace(/-/g,"")] = undefined return false } return true @@ -141,11 +121,11 @@ class Cosmetics extends Feature { return this.cosmeticsData[player.getUUID().toString().replace(/-/g,"")]?.[cosmetic] } - filterUnloadedCosmetics(tick){ + filterUnloadedCosmetics(tick=false){ this.loadedCosmetics = this.loadedCosmetics.filter(cosmetic => { if(tick) cosmetic.onTick() if(cosmetic.player.getPlayer().field_70128_L){ //filter out players that are no longer loaded - this.uuidToCosmetic[cosmetic.player.getUUID().toString().replace(/-/g,"")] = undefined + this.uuidToCosmetic[cosmetic.id][cosmetic.player.getUUID().toString().replace(/-/g,"")] = undefined return false } return true @@ -159,10 +139,10 @@ class Cosmetics extends Feature { } restoreEssentialCosmetics(){ - this.hiddenCosmetics.forEach(cosmetic=>{ + this.hiddenEssentialCosmetics.forEach(cosmetic=>{ cosmetic.isHidden = false }) - this.hiddenCosmetics = [] + this.hiddenEssentialCosmetics = [] } renderWorld(ticks){ @@ -176,7 +156,9 @@ class Cosmetics extends Feature { this.uuidToCosmetic = undefined this.playerHasACosmeticA = undefined this.cosmeticsData = undefined - this.hiddenCosmetics = undefined + this.hiddenEssentialCosmetics = undefined + this.hiddenEssentialCosmetics = undefined + this.cosmeticsList = undefined } onDisable(){ |