Optimization!

This commit is contained in:
kirillsaint 2023-07-04 19:31:46 +06:00
parent 133c46c01c
commit 94d0798a41
3 changed files with 34 additions and 34 deletions

View File

@ -81,7 +81,6 @@ public class Client {
public static BackgroundPanorama backgroundPanorama;
private KeyBindManager keyBindManager;
private IMetadataSerializer iMetadataSerializer;
private CustomSkin customSkin = new CustomSkin();
public static void memoryDebug(String paramString) {
LogManager.getLogger().info("-- Start Memory Debug -- " + paramString);
@ -559,8 +558,4 @@ public class Client {
public void setiMetadataSerializer(IMetadataSerializer iMetadataSerializer) {
this.iMetadataSerializer = iMetadataSerializer;
}
public CustomSkin getCustomSkin() {
return customSkin;
}
}

View File

@ -3,9 +3,7 @@ package net.silentclient.client.mixin.mixins;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.network.NetworkPlayerInfo;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.client.resources.DefaultPlayerSkin;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StringUtils;
import net.minecraft.world.World;
@ -14,10 +12,7 @@ import net.silentclient.client.admin.AdminRender;
import net.silentclient.client.cosmetics.*;
import net.silentclient.client.cosmetics.dynamiccurved.DynamicCape;
import net.silentclient.client.event.impl.EventFovUpdate;
import net.silentclient.client.mixin.accessors.AbstractClientPlayerAccessor;
import net.silentclient.client.mixin.accessors.NetworkPlayerInfoAccessor;
import net.silentclient.client.mixin.ducks.AbstractClientPlayerExt;
import net.silentclient.client.mods.player.NickHiderMod;
import net.silentclient.client.mods.render.AnimationsMod;
import net.silentclient.client.mods.settings.CosmeticsMod;
import net.silentclient.client.utils.CustomSkin;
@ -25,7 +20,6 @@ import net.silentclient.client.utils.Players;
import net.silentclient.client.utils.SCTextureManager;
import net.silentclient.client.utils.types.PlayerResponse;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@ -36,10 +30,6 @@ import java.util.Random;
@Mixin(AbstractClientPlayer.class)
public abstract class AbstractClientPlayerMixin implements AbstractClientPlayerExt {
@Shadow protected abstract NetworkPlayerInfo getPlayerInfo();
@Shadow public abstract String getSkinType();
@Unique private AnimatedResourceLocation silent$cape;
@Unique private AnimatedResourceLocation silent$bandana;
@Unique private HatData silent$hat;
@ -56,7 +46,6 @@ public abstract class AbstractClientPlayerMixin implements AbstractClientPlayerE
@Unique private PlayerResponse.Account silent$account;
@Unique private String silent$capeType = "dynamic_curved";
@Unique private boolean silent$shouldersBool = true;
@Unique private CustomSkin silent$customSkin = new CustomSkin();
@Inject(method = "<init>", at = @At("RETURN"))
public void initCustom(World worldIn, GameProfile playerProfile, CallbackInfo ci) {
@ -109,21 +98,32 @@ public abstract class AbstractClientPlayerMixin implements AbstractClientPlayerE
}
if(Client.getInstance().getSettingsManager().getSettingByClass(CosmeticsMod.class, "Custom Skins").getValBoolean() && this.silent$getAccount() != null && this.silent$getAccount().getCustomSkin()) {
if(silent$customSkin.getLocation() == null && !silent$customSkin.isLoading()) {
silent$customSkin.setLoading(true);
if(!CustomSkin.skins.containsKey(silent$nameClear.toLowerCase())) {
Client.logger.info(String.format("Custom Skin not found in cache! Putting Custom Skin to cache. (%s)", silent$nameClear));
CustomSkin.skins.put(silent$nameClear.toLowerCase(), new CustomSkin());
}
CustomSkin customSkin = CustomSkin.skins.get(silent$nameClear.toLowerCase());
if(!customSkin.isLoaded() && !CustomSkin.loading) {
Client.logger.info(String.format("Starting Download Skin (%s)", silent$nameClear));
CustomSkin.loading = true;
(new Thread("CustomSkinThread") {
public void run() {
Client.logger.info("Downloading Custom Skin");
silent$customSkin.setImage(SCTextureManager.getImage("https://cdn.silentclient.net/skins/" + silent$nameClear.toLowerCase() + ".png"));
Client.logger.info(String.format("Downloading Custom Skin (%s)", silent$nameClear));
customSkin.setImage(SCTextureManager.getImage("https://cdn.silentclient.net/skins/" + silent$nameClear.toLowerCase() + ".png"));
CustomSkin.loading = false;
customSkin.setLoaded(true);
Client.logger.info(String.format("Custom Skin downloaded! (%s)", silent$nameClear));
}
}).start();
}
if(silent$customSkin.getImage() != null && !silent$customSkin.isInitialized()) {
silent$customSkin.setLocation(Minecraft.getMinecraft().getTextureManager().getDynamicTextureLocation("custom_skin_" + new Random().nextLong(), new DynamicTexture(silent$customSkin.getImage())));
silent$customSkin.setInitialized(true);
if(customSkin.getImage() != null && !customSkin.isInitialized()) {
Client.logger.info(String.format("Initializing Custom Skin (%s)", silent$nameClear));
customSkin.setLocation(Minecraft.getMinecraft().getTextureManager().getDynamicTextureLocation("custom_skin_" + new Random().nextLong(), new DynamicTexture(customSkin.getImage())));
customSkin.setInitialized(true);
Client.logger.info(String.format("Custom Skin Initialized (%s)", silent$nameClear));
}
if(silent$customSkin.getLocation() != null) {
cir.setReturnValue(silent$customSkin.getLocation());
if(customSkin.getLocation() != null) {
cir.setReturnValue(customSkin.getLocation());
cir.cancel();
}
}

View File

@ -3,9 +3,14 @@ package net.silentclient.client.utils;
import net.minecraft.util.ResourceLocation;
import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.Map;
public class CustomSkin {
private boolean loading = false;
public static Map<String, CustomSkin> skins = new HashMap();
public static boolean loading = false;
private boolean loaded = false;
private BufferedImage image;
private ResourceLocation location;
private boolean initialized = false;
@ -22,10 +27,6 @@ public class CustomSkin {
return initialized;
}
public boolean isLoading() {
return loading;
}
public void setImage(BufferedImage image) {
this.image = image;
}
@ -34,11 +35,15 @@ public class CustomSkin {
this.initialized = initialized;
}
public void setLoading(boolean loading) {
this.loading = loading;
}
public void setLocation(ResourceLocation location) {
this.location = location;
}
public boolean isLoaded() {
return loaded;
}
public void setLoaded(boolean loaded) {
this.loaded = loaded;
}
}