Search in sources :

Example 1 with ItemRenderOptions

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;
}
Also used : BlockRenderOptions(com.bergerkiller.bukkit.common.wrappers.BlockRenderOptions) ItemRenderOptions(com.bergerkiller.bukkit.common.wrappers.ItemRenderOptions) CommonTagCompound(com.bergerkiller.bukkit.common.nbt.CommonTagCompound) Material(org.bukkit.Material)

Example 2 with ItemRenderOptions

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;
}
Also used : ItemRenderOptions(com.bergerkiller.bukkit.common.wrappers.ItemRenderOptions) Model(com.bergerkiller.bukkit.common.map.util.Model) GeneratedModel(com.bergerkiller.bukkit.common.internal.resources.builtin.GeneratedModel)

Aggregations

ItemRenderOptions (com.bergerkiller.bukkit.common.wrappers.ItemRenderOptions)2 GeneratedModel (com.bergerkiller.bukkit.common.internal.resources.builtin.GeneratedModel)1 Model (com.bergerkiller.bukkit.common.map.util.Model)1 CommonTagCompound (com.bergerkiller.bukkit.common.nbt.CommonTagCompound)1 BlockRenderOptions (com.bergerkiller.bukkit.common.wrappers.BlockRenderOptions)1 Material (org.bukkit.Material)1