feat(skin): custom model.

This commit is contained in:
huanghongxun
2021-10-09 17:49:17 +08:00
parent f528f3bf40
commit 20957106df
6 changed files with 64 additions and 13 deletions

View File

@@ -79,12 +79,14 @@ public class Skin {
private final Type type;
private final String cslApi;
private final TextureModel textureModel;
private final String localSkinPath;
private final String localCapePath;
public Skin(Type type, String cslApi, String localSkinPath, String localCapePath) {
public Skin(Type type, String cslApi, TextureModel textureModel, String localSkinPath, String localCapePath) {
this.type = type;
this.cslApi = cslApi;
this.textureModel = textureModel;
this.localSkinPath = localSkinPath;
this.localCapePath = localCapePath;
}
@@ -97,6 +99,10 @@ public class Skin {
return cslApi;
}
public TextureModel getTextureModel() {
return textureModel == null ? TextureModel.STEVE : textureModel;
}
public String getLocalSkinPath() {
return localSkinPath;
}
@@ -120,7 +126,7 @@ public class Skin {
Optional<Path> capePath = FileUtils.tryGetPath(localCapePath);
if (skinPath.isPresent()) skin = Texture.loadTexture(Files.newInputStream(skinPath.get()));
if (capePath.isPresent()) cape = Texture.loadTexture(Files.newInputStream(capePath.get()));
return new LoadedSkin(TextureModel.STEVE, skin, cape);
return new LoadedSkin(getTextureModel(), skin, cape);
});
case LITTLE_SKIN:
case CUSTOM_SKIN_LOADER_API:
@@ -167,6 +173,7 @@ public class Skin {
return mapOf(
pair("type", type.name().toLowerCase(Locale.ROOT)),
pair("cslApi", cslApi),
pair("textureModel", getTextureModel().modelName),
pair("localSkinPath", localSkinPath),
pair("localCapePath", localCapePath)
);
@@ -178,10 +185,20 @@ public class Skin {
Type type = tryCast(storage.get("type"), String.class).flatMap(t -> Optional.ofNullable(Type.fromStorage(t)))
.orElse(Type.DEFAULT);
String cslApi = tryCast(storage.get("cslApi"), String.class).orElse(null);
String textureModel = tryCast(storage.get("textureModel"), String.class).orElse("default");
String localSkinPath = tryCast(storage.get("localSkinPath"), String.class).orElse(null);
String localCapePath = tryCast(storage.get("localCapePath"), String.class).orElse(null);
return new Skin(type, cslApi, localSkinPath, localCapePath);
TextureModel model;
if ("default".equals(textureModel)) {
model = TextureModel.STEVE;
} else if ("slim".equals(textureModel)) {
model = TextureModel.ALEX;
} else {
model = TextureModel.STEVE;
}
return new Skin(type, cslApi, model, localSkinPath, localCapePath);
}
private static class FetchBytesTask extends FetchTask<InputStream> {

View File

@@ -19,6 +19,7 @@ package org.jackhuang.hmcl.auth.offline;
import com.google.gson.reflect.TypeToken;
import org.jackhuang.hmcl.auth.yggdrasil.GameProfile;
import org.jackhuang.hmcl.auth.yggdrasil.TextureModel;
import org.jackhuang.hmcl.util.KeyUtils;
import org.jackhuang.hmcl.util.Lang;
import org.jackhuang.hmcl.util.gson.JsonUtils;
@@ -163,7 +164,15 @@ public class YggdrasilServer extends HttpServer {
public Object toCompleteResponse(String rootUrl) {
Map<String, Object> realTextures = new HashMap<>();
if (skin != null && skin.getSkin() != null) {
realTextures.put("SKIN", mapOf(pair("url", rootUrl + "/textures/" + skin.getSkin().getHash())));
if (skin.getModel() == TextureModel.ALEX) {
realTextures.put("SKIN", mapOf(
pair("url", rootUrl + "/textures/" + skin.getSkin().getHash()),
pair("metadata", mapOf(
pair("model", "slim")
))));
} else {
realTextures.put("SKIN", mapOf(pair("url", rootUrl + "/textures/" + skin.getSkin().getHash())));
}
}
if (skin != null && skin.getCape() != null) {
realTextures.put("CAPE", mapOf(pair("url", rootUrl + "/textures/" + skin.getSkin().getHash())));