@Override public IModel process(IModel base) { boolean hasBase = base != ModelLoaderRegistry.getMissingModel(); if (hasBase) { base = baseVariant.process(base); } List<IModel> subModels = new LinkedList<>(); for (Variant variant : finalVariants) { if (!variant.getModelLocation().equals(new ResourceLocation("builtin/missing"))) { IModel subModel = ModelLoaderRegistry.getModelOrLogError(variant.getModelLocation(), "Unable to load subModel's Model: " + variant.getModelLocation()); subModels.add(variant.process(new StateOverrideIModel(subModel, variant.getState()))); } } return new CCMultiModel(hasBase ? base : null, baseProperties, subModels); }
private static Variant makeFinalVariant(CCVariant variant, String textureDomain) { boolean uvLock = variant.uvLock.orElse(false); boolean smooth = variant.smooth.orElse(true); boolean gui3d = variant.gui3d.orElse(true); int weight = variant.weight.orElse(1); if (variant.hasModel() && !variant.hasTextures() && !variant.hasCustomData() && variant.state.get() instanceof ModelRotation) { return new Variant(variant.model, ((ModelRotation) variant.state.get()), uvLock, weight); } else { return new CCFinalVariant(variant.model, variant.state, uvLock, smooth, gui3d, weight, variant.textures, textureDomain, variant.customData); } }
public WeightedRandomModel(ResourceLocation parent, VariantList variants) throws Exception { this.variants = variants.getVariantList(); ImmutableList.Builder<Pair<IModel, IModelState>> builder = ImmutableList.builder(); for (Variant v : this.variants) { ResourceLocation loc = v.getModelLocation(); locations.add(loc); /* * Vanilla eats this, which makes it only show variants that have models. * But that doesn't help debugging, so throw the exception */ IModel model; if(loc.equals(MODEL_MISSING)) { // explicit missing location, happens if blockstate has "model"=null model = ModelLoaderRegistry.getMissingModel(); } else { model = ModelLoaderRegistry.getModel(loc); } // FIXME: is this the place? messes up dependency and texture resolution model = v.process(model); for(ResourceLocation location : model.getDependencies()) { ModelLoaderRegistry.getModelOrMissing(location); } //FMLLog.getLogger().error("Exception resolving indirect dependencies for model" + loc, e); textures.addAll(model.getTextures()); // Kick this, just in case. models.add(model); builder.add(Pair.of(model, v.getState())); } if (models.size() == 0) //If all variants are missing, add one with the missing model and default rotation. { // FIXME: log this? IModel missing = ModelLoaderRegistry.getMissingModel(); models.add(missing); builder.add(Pair.<IModel, IModelState>of(missing, TRSRTransformation.identity())); } defaultState = new MultiModelState(builder.build()); }
@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; } }