use of com.bergerkiller.bukkit.common.map.util.Model in project BKCommonLib by bergerhealer.
the class MapResourcePack method getItemTexture.
/**
* Renders the item gui slot texture of an item
*
* @param item to render
* @param width of the produced icon image
* @param height of the produced icon image
* @return rendered item slot image
*/
public MapTexture getItemTexture(ItemStack item, int width, int height) {
Model model = this.getItemModel(item);
if (model == null || model.placeholder) {
return createPlaceholderTexture(width, height);
}
MapTexture texture = MapTexture.createEmpty(width, height);
Matrix4x4 transform = new Matrix4x4();
if (width != 16 || height != 16) {
transform.scale((double) width / 16.0, 1.0, (double) height / 16.0);
}
Model.Display display = model.display.get("gui");
if (display != null) {
display.apply(transform);
texture.setLightOptions(0.0f, 1.0f, new Vector3(-1, 1, -1));
} else {
// System.out.println("GUI DISPLAY ELEMENT NOT FOUND");
}
texture.drawModel(model, transform);
return texture;
}
use of com.bergerkiller.bukkit.common.map.util.Model in project BKCommonLib by bergerhealer.
the class MapResourcePack method getModel.
/**
* Loads a JSON-syntax model from this resource pack.
*
* @param path to the model, e.g. "block/stone"
* @return the model, a placeholder cube model if it could not be found
*/
public Model getModel(String path) {
Model model = modelCache.get(path);
if (model != null) {
return model;
}
model = this.loadModel(path);
if (model == null) {
// failed to load or find
model = this.createPlaceholderModel(BlockData.AIR.getDefaultRenderOptions());
model.name = path;
}
modelCache.put(path, model);
return model;
}
use of com.bergerkiller.bukkit.common.map.util.Model in project BKCommonLib by bergerhealer.
the class MapResourcePack method createPlaceholderModel.
/**
* Creates a placeholder model. Used when models can not be loaded.
*
* @return placeholder model
*/
protected final Model createPlaceholderModel(RenderOptions renderOptions) {
Model model = new Model();
Model.Element element = new Model.Element();
for (BlockFace face : FaceUtil.BLOCK_SIDES) {
element.faces.put(face, createPlaceholderFace());
}
element.buildQuads();
model.placeholder = true;
model.elements.add(element);
model.name = renderOptions.lookupModelName();
return model;
}
use of com.bergerkiller.bukkit.common.map.util.Model in project BKCommonLib by bergerhealer.
the class MapResourcePack method getItemModel.
/**
* Loads the model to be displayed for items displayed in the world, held in a player's hand
* or shown in a GUI item slot.
*
* @param item to get the model for
* @return item model for the item
*/
public Model getItemModel(ItemStack item) {
ItemRenderOptions options = ModelInfoLookup.lookupItemRenderOptions(item);
String itemModelName = options.lookupModelName();
Model m = this.loadModel("item/" + itemModelName, options);
if (m != null) {
m.buildBlock(options);
m.buildQuads();
}
if (m == null) {
m = this.createPlaceholderModel(options);
}
return m;
}
use of com.bergerkiller.bukkit.common.map.util.Model 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);
}
}
}
// Insert the parent model as required
if (model.getParentName() != null) {
Model parentModel = this.loadModel(model.getParentName(), 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;
}
Aggregations