public IFlexibleBakedModel bake(
     IModelState state,
     VertexFormat format,
     Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
   if (!Attributes.moreSpecific(format, Attributes.DEFAULT_BAKED_FORMAT)) {
     throw new IllegalArgumentException(
         "can't bake vanilla weighted models to the format that doesn't fit into the default one: "
             + format);
   }
   if (variants.size() == 1) {
     Variant v = variants.get(0);
     IModel model = models.get(0);
     return model.bake(
         addUV(v.isUvLocked(), MultiModelState.getPartState(state, model, 0)),
         format,
         bakedTextureGetter);
   }
   WeightedBakedModel.Builder builder = new WeightedBakedModel.Builder();
   for (int i = 0; i < variants.size(); i++) {
     IModel model = models.get(i);
     Variant v = variants.get(i);
     builder.add(
         model.bake(
             addUV(v.isUvLocked(), MultiModelState.getPartState(state, model, i)),
             format,
             bakedTextureGetter),
         variants.get(i).getWeight());
   }
   return new FlexibleWeightedBakedModel(builder.build(), Attributes.DEFAULT_BAKED_FORMAT);
 }
    public WeightedRandomModel(ModelResourceLocation parent, Variants variants) {
      this.variants = variants.getVariants();
      ImmutableList.Builder<Pair<IModel, IModelState>> builder = ImmutableList.builder();
      for (Variant v : (List<Variant>) variants.getVariants()) {
        ResourceLocation loc = v.getModelLocation();
        locations.add(loc);

        IModel model = null;
        try {
          model = getModel(loc);
        } catch (Exception e) {
          /*
           * Vanilla eats this, which makes it only show variants that have models.
           * But that doesn't help debugging, so we maintain the missing model
           * so that resource pack makers have a hint that their states are broken.
           */
          FMLLog.warning(
              "Unable to load block model: \'"
                  + loc
                  + "\' for variant: \'"
                  + parent
                  + "\': "
                  + e.toString());
          model = getMissingModel();
        }

        if (v instanceof ISmartVariant) {
          model = ((ISmartVariant) v).process(model, ModelLoader.this);
          try {
            resolveDependencies(model);
          } catch (IOException e) {
            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.
      {
        IModel missing = getMissingModel();
        models.add(missing);
        builder.add(Pair.<IModel, IModelState>of(missing, TRSRTransformation.identity()));
      }

      defaultState = new MultiModelState(builder.build());
    }