ModelDescription.java 文件源码

java
阅读 28 收藏 0 点赞 0 评论 0

项目:MCAnm 作者:
@Override
public ModelDescription deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    JsonObject jsonObject = json.getAsJsonObject();
    int version = jsonObject.get("version").getAsInt();
    // Currently version is ignored
    if (version != 0 && version != 1) {
        throw new JsonParseException("Unsupported model version");
    }
    boolean isLegacy = version == 0;
    ISkeleton skeleton = loadSkeleton(isLegacy, jsonObject);

    ResourceLocation modelLocation = new ResourceLocation(jsonObject.get("mesh").getAsString());
    ModelMCMD mesh = ClientLoader.loadModel(modelLocation, skeleton);

    ImmutableMap<String, ResourceLocation> textureLocatons = ImmutableMap.of();
    if (version != 0) {
        Builder<String, ResourceLocation> builder = ImmutableMap.builder();
        JsonObject textureMap = jsonObject.getAsJsonObject("textures");
        for (Entry<String, JsonElement> texEntry : textureMap.entrySet()) {
            String slotName = texEntry.getKey();
            if (!slotName.startsWith("#")) {
                throw new JsonParseException("Slot names must begin with '#'");
            }
            ResourceLocation textureLocation = new ResourceLocation(texEntry.getValue().getAsString());
            builder.put(slotName, textureLocation);
        }
        textureLocatons = builder.build();
    }
    ImmutableMap<TransformType, TRSRTransformation> viewMapping = parseViewMapping(jsonObject, context);
    List<ItemOverride> itemOverrides = getItemOverrides(jsonObject, context);
    return new ModelDescription(mesh, skeleton, textureLocatons, viewMapping, itemOverrides);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号