WardrobeModelLoader.java 文件源码

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

项目:Alchemy 作者:
@Alpha
@Override
public IModel loadModel(ResourceLocation resourceLocation) throws Exception {
    try {
        ModelResourceLocation modelLocation;
        if (resourceLocation instanceof ModelResourceLocation)
            modelLocation = (ModelResourceLocation) resourceLocation;
        else
            return null;
        if (!modelLocation.getVariant().equals("inventory") && !modelLocation.getResourcePath().endsWith("_loc")) {
            List<Variant> list = Lists.newLinkedList();
            ModelRotation rotation = ModelRotation.X0_Y0;
            switch (Tool.get(modelLocation.getVariant(), "facing=([a-z]*)")) {
                case "east":
                    rotation = ModelRotation.X0_Y270;
                    break;
                case "north":
                    rotation = ModelRotation.X0_Y180;
                    break;
                case "west":
                    rotation = ModelRotation.X0_Y90;
                    break;
            }
            list.add(new Variant(new ModelResourceLocation(modelLocation.getResourceDomain() + ":" +
                    modelLocation.getResourcePath() + "_loc", modelLocation.getVariant()),
                    rotation, false, 1));
            VariantList variantList = new VariantList(list);
            return new ModelLoader.WeightedRandomModel(modelLocation, variantList);
        }
        modelLocation = new ModelResourceLocation(modelLocation.getResourceDomain() + 
                modelLocation.getResourcePath().replace("_loc", ""), modelLocation.getVariant());
        String name = modelLocation.getVariant().contains("part=head") ? "head" : "foot";
        String rely = Tool.isEmptyOr(Tool.get(modelLocation.getVariant(), "rely=([a-z]*)"), "null");
        try (IResource resource = Minecraft.getMinecraft().getResourceManager()
                    .getResource(new ResourceLocation("skin:models/wardrobe_" + rely + "_" + name + ".json"))) {
            String json = Joiner.on('\n').join(IOUtils.readLines(resource.getInputStream(), Charsets.UTF_8));
            try (Reader reader = new StringReader(WoodType.conversion.apply(json, Tool.get(
                    modelLocation.getResourcePath(), "_(.*?_T_.*?_T_[0-9]*_T_.*?_T_.*?_T_[0-9]*)")))) {
                ModelBlock modelBlock = ModelBlock.deserialize(reader);
                return modelLocation.getVariant().equals("inventory") ? new ItemLayerModel(modelBlock) :
                    ModelLoader.VanillaLoader.INSTANCE.getLoader().new VanillaModelWrapper(modelLocation,
                            modelBlock, false, ModelBlockAnimation.defaultModelBlockAnimation);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号