use of com.bergerkiller.bukkit.common.wrappers.ItemRenderOptions in project BKCommonLib by bergerhealer.
the class ModelInfoLookup method lookupItemRenderOptions.
public static ItemRenderOptions lookupItemRenderOptions(ItemStack item) {
// Blocks
Material type = (item == null) ? Material.AIR : item.getType();
if (item == null || type.isBlock()) {
BlockRenderOptions blockOpt = BlockData.fromItemStack(item).getDefaultRenderOptions();
return new ItemRenderOptions(item, blockOpt);
}
// Some items, like leather boots, require additional render options passed
ItemRenderOptions options = new ItemRenderOptions(item, "");
if (MaterialUtil.ISLEATHERARMOR.get(type)) {
// Check 'display.color' metadata tag for custom colors
// default brown
int color = 5190175;
CommonTagCompound nbt = ItemUtil.getMetaTag(item, false);
if (nbt != null) {
CommonTagCompound display = nbt.getValue("display", CommonTagCompound.class);
if (display != null) {
color = display.getValue("color", color);
}
}
// Convert color to hexadecimal and store it as an option
options.put("layer0tint", String.format("#%06x", color));
}
// Similarly, the liquid inside potion bottles have a color set
if (MaterialUtil.ISPOTION.get(type)) {
int color = getPotionColor(item.getDurability());
// Check 'CustomPotionColor' metadata tag for custom colors
CommonTagCompound nbt = ItemUtil.getMetaTag(item, false);
if (nbt != null) {
color = nbt.getValue("CustomPotionColor", color);
}
// Convert color to hexadecimal and store it as an option
options.put("layer0tint", String.format("#%06x", color));
}
// damage and damaged properties of weapons, armor and tools
if (ItemUtil.hasDurability(item)) {
boolean unbreakable = false;
CommonTagCompound nbt = ItemUtil.getMetaTag(item, false);
if (nbt != null) {
unbreakable = nbt.getValue("Unbreakable", unbreakable);
}
options.put("damaged", unbreakable ? "0" : "1");
options.put("damage", Double.toString((double) item.getDurability() / (double) (ItemUtil.getMaxDurability(item) + 1)));
}
return options;
}
use of com.bergerkiller.bukkit.common.wrappers.ItemRenderOptions 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;
}
Aggregations