Update Cosmetics.java

This commit is contained in:
kirillsaint 2023-08-06 00:19:27 +06:00
parent 11ba2942f9
commit 06c44a74cc

View File

@ -12,10 +12,12 @@ import net.silentclient.client.mixin.ducks.AbstractClientPlayerExt;
import net.silentclient.client.mods.settings.CosmeticsMod;
import net.silentclient.client.utils.Players;
import net.silentclient.client.utils.Requests;
import net.silentclient.client.utils.types.CosmeticsResponse;
import net.silentclient.client.utils.types.PlayerResponse;
import net.silentclient.client.utils.types.PlayerResponse.Account.Cosmetics.CosmeticItem;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
@ -58,13 +60,13 @@ public class Cosmetics {
Client.logger.info("STARTING > cosmeitcs > default_icon");
defaultIcon = new StaticResourceLocation("silentclient/icons/player_icon.png");
if(!Client.getInstance().isDebug()) {
CosmeticsResponse allCosmetics = getAllCosmetics();
PlayerResponse.Account.Cosmetics allCosmetics = getAllCosmetics();
Client.logger.info("STARTING > cosmeitcs > capes");
capes.clear();
capesShoulders.clear();
if(allCosmetics != null && allCosmetics.getCosmetics() != null && allCosmetics.getCosmetics().getCapes() != null) {
allCosmetics.getCosmetics().getCapes().forEach((cape) -> {
if(allCosmetics != null && allCosmetics.getCapes() != null) {
allCosmetics.getCapes().forEach((cape) -> {
capes.put(cape.getId(), new AnimatedResourceLocation("silentclient/cosmetics/capes/"+cape.getId(), cape.getFrames(), cape.getFrameDelay(), false, cape.getId() == Client.getInstance().getAccount().getSelectedCape()));
capesShoulders.put(cape.getId(), new StaticResourceLocation("silentclient/cosmetics/capes/"+cape.getId()+"/shoulders.png"));
});
@ -72,24 +74,24 @@ public class Cosmetics {
Client.logger.info("STARTING > cosmeitcs > wings");
wings.clear();
if(allCosmetics != null && allCosmetics.getCosmetics() != null && allCosmetics.getCosmetics().getWings() != null) {
allCosmetics.getCosmetics().getWings().forEach((wing) -> {
if(allCosmetics != null && allCosmetics.getWings() != null) {
allCosmetics.getWings().forEach((wing) -> {
wings.put(wing.getId(), new AnimatedResourceLocation("silentclient/cosmetics/wings/"+ wing.getId(), wing.getFrames(), wing.getFrameDelay(), false, wing.getId() == Client.getInstance().getAccount().getSelectedWings()));
});
}
Client.logger.info("STARTING > cosmeitcs > bandanas");
bandanas.clear();
if(allCosmetics != null && allCosmetics.getCosmetics() != null && allCosmetics.getCosmetics().getBandanas() != null) {
allCosmetics.getCosmetics().getBandanas().forEach((bandana) -> {
if(allCosmetics != null && allCosmetics.getBandanas() != null) {
allCosmetics.getBandanas().forEach((bandana) -> {
bandanas.put(bandana.getId(), new AnimatedResourceLocation("silentclient/cosmetics/bandanas/"+bandana.getId(), bandana.getFrames(), bandana.getFrameDelay(), false, bandana.getId() == Client.getInstance().getAccount().getSelectedBandana()));
});
}
Client.logger.info("STARTING > cosmeitcs > hats");
hats.clear();
if(allCosmetics != null && allCosmetics.getCosmetics() != null && allCosmetics.getCosmetics().getHats() != null) {
allCosmetics.getCosmetics().getHats().forEach((hat) -> {
if(allCosmetics != null && allCosmetics.getHats() != null) {
allCosmetics.getHats().forEach((hat) -> {
hats.put(hat.getId(), new HatData(new AnimatedResourceLocation("silentclient/cosmetics/hats/"+hat.getId(), hat.getFrames(), hat.getFrameDelay(), false, hat.getId() == Client.getInstance().getAccount().getSelectedHat()), hat.getModel()));
if(!hatModels.containsKey(hat.getModel())) {
try {
@ -106,8 +108,8 @@ public class Cosmetics {
}
Client.logger.info("STARTING > cosmeitcs > shields");
shields.clear();
if(allCosmetics != null && allCosmetics.getCosmetics() != null && allCosmetics.getCosmetics().getShields() != null) {
allCosmetics.getCosmetics().getShields().forEach((shield) -> {
if(allCosmetics != null && allCosmetics.getShields() != null) {
allCosmetics.getShields().forEach((shield) -> {
shields.put(shield.getId(), new ShieldData(new AnimatedResourceLocation("silentclient/cosmetics/shields/"+shield.getId(), shield.getFrames(), shield.getFrameDelay(), false, shield.getId() == Client.getInstance().getAccount().getSelectedShield()), shield.getModel()));
if(!hatModels.containsKey(shield.getModel())) {
try {
@ -125,8 +127,8 @@ public class Cosmetics {
Client.logger.info("STARTING > cosmeitcs > icons");
icons.clear();
if(allCosmetics != null && allCosmetics.getCosmetics() != null && allCosmetics.getCosmetics().getIcons() != null) {
allCosmetics.getCosmetics().getIcons().forEach((icon) -> {
if(allCosmetics != null && allCosmetics.getIcons() != null) {
allCosmetics.getIcons().forEach((icon) -> {
icons.put(icon.getId(), new StaticResourceLocation("silentclient/cosmetics/icons/"+ icon.getId() + "/0.png"));
});
}
@ -222,16 +224,23 @@ public class Cosmetics {
return myShields;
}
public static CosmeticsResponse getAllCosmetics() {
public static PlayerResponse.Account.Cosmetics getAllCosmetics() {
try {
String content = Requests.get("https://api.silentclient.net/_next/get_cosmetics");
InputStream in = Client.getInstance().getClass().getResourceAsStream("/assets/minecraft/silentclient/cosmetics.json");
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuffer content = new StringBuffer();
String inputLine;
while ((inputLine = reader.readLine()) != null) {
content.append(inputLine);
}
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
CosmeticsResponse response = gson.fromJson(content.toString(), CosmeticsResponse.class);
return response;
} catch (Exception e) {
e.printStackTrace();
in.close();
return gson.fromJson(content.toString(), PlayerResponse.Account.Cosmetics.class);
} catch (Exception e1) {
Client.logger.catching(e1);
return null;
}
}