Search in sources :

Example 1 with GeneratedModel

use of com.bergerkiller.bukkit.common.internal.resources.builtin.GeneratedModel in project BKCommonLib by bergerhealer.

the class MapResourcePack method loadModel.

/**
 * Loads a model, always fetching it from the resource pack instead of the cache
 *
 * @param path to find the model at
 * @param options to apply when building the model
 * @return the model, or <i>null</i> if not found
 */
protected final Model loadModel(String path, RenderOptions options) {
    // Builtin models
    if (path.equals("builtin/generated")) {
        return new GeneratedModel();
    }
    Model model = openGsonObject(Model.class, ResourceType.MODELS, path);
    if (model == null) {
        Logging.LOGGER_MAPDISPLAY.once(Level.WARNING, "Failed to load model " + path);
        return null;
    }
    // Handle overrides first
    if (model.overrides != null && !model.overrides.isEmpty()) {
        for (Model.ModelOverride override : model.overrides) {
            if (override.matches(options) && !override.model.equals(path)) {
                // System.out.println("MATCH " + override.model + "  " + options);
                return this.loadModel(override.model, options);
            }
        }
    }
    // On Minecraft 1.8-1.8.8 the base block/block model is not defined, here we add it ourselves
    // This fixes several display render bugs
    String parentModelName = model.getParentName();
    if (parentModelName == null && !CommonCapabilities.RESOURCE_PACK_MODEL_BASE_TRANSFORMS && !path.equals("block/block")) {
        parentModelName = "block/block";
    }
    // Insert the parent model as required
    if (parentModelName != null) {
        Model parentModel = this.loadModel(parentModelName, options);
        if (parentModel == null || parentModel.placeholder) {
            Logging.LOGGER_MAPDISPLAY.once(Level.WARNING, "Parent of model " + path + " not found: " + model.getParentName());
            return null;
        }
        model.loadParent(parentModel);
    }
    // Make all texture paths absolute
    model.build(this, options);
    return model;
}
Also used : GeneratedModel(com.bergerkiller.bukkit.common.internal.resources.builtin.GeneratedModel) Model(com.bergerkiller.bukkit.common.map.util.Model) GeneratedModel(com.bergerkiller.bukkit.common.internal.resources.builtin.GeneratedModel)

Aggregations

GeneratedModel (com.bergerkiller.bukkit.common.internal.resources.builtin.GeneratedModel)1 Model (com.bergerkiller.bukkit.common.map.util.Model)1