Search in sources :

Example 6 with ItemColors

use of net.minecraft.client.renderer.color.ItemColors in project Random-Things by lumien231.

the class ClientProxy method registerColors.

private void registerColors() {
    for (Entry<Object, Object> entry : scheduledColorRegister.entrySet()) {
        if (entry.getKey() instanceof IRTBlockColor) {
            final IRTBlockColor blockColor = (IRTBlockColor) entry.getKey();
            Minecraft.getMinecraft().getBlockColors().registerBlockColorHandler(new IBlockColor() {

                @Override
                public int colorMultiplier(IBlockState state, IBlockAccess p_186720_2_, BlockPos pos, int tintIndex) {
                    return blockColor.colorMultiplier(state, p_186720_2_, pos, tintIndex);
                }
            }, (Block) entry.getValue());
        } else if (entry.getKey() instanceof IRTItemColor) {
            final IRTItemColor itemColor = (IRTItemColor) entry.getKey();
            try {
                ItemColors itemColors = (ItemColors) itemColorsField.get(Minecraft.getMinecraft());
                itemColors.registerItemColorHandler(new IItemColor() {

                    @Override
                    public int colorMultiplier(ItemStack stack, int tintIndex) {
                        return itemColor.getColorFromItemstack(stack, tintIndex);
                    }
                }, (Item) entry.getValue());
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : IRTBlockColor(lumien.randomthings.lib.IRTBlockColor) IBlockState(net.minecraft.block.state.IBlockState) IBlockAccess(net.minecraft.world.IBlockAccess) IRTItemColor(lumien.randomthings.lib.IRTItemColor) IItemColor(net.minecraft.client.renderer.color.IItemColor) Item(net.minecraft.item.Item) EntityProjectedItem(lumien.randomthings.entitys.EntityProjectedItem) RenderProjectedItem(lumien.randomthings.client.render.RenderProjectedItem) IBlockColor(net.minecraft.client.renderer.color.IBlockColor) ItemColors(net.minecraft.client.renderer.color.ItemColors) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 7 with ItemColors

use of net.minecraft.client.renderer.color.ItemColors in project SilentGems by SilentChaos512.

the class ColorHandlers method init.

public static void init() {
    ItemColors itemColors = Minecraft.getMinecraft().getItemColors();
    // Tools
    itemColors.registerItemColorHandler(new IItemColor() {

        @Override
        public int getColorFromItemstack(ItemStack stack, int tintIndex) {
            return ToolHelper.getColorForPass(stack, tintIndex);
        }
    }, ModItems.tools.toArray(new Item[ModItems.tools.size()]));
    // Shields
    itemColors.registerItemColorHandler(new IItemColor() {

        // 5 & 6 unused
        int[] passes = { 2, 1, 3, 0, 4, 5, 6 };

        @Override
        public int getColorFromItemstack(ItemStack stack, int tintIndex) {
            if (tintIndex < 0 || tintIndex >= passes.length)
                return 0xFFFFFF;
            return ToolHelper.getColorForPass(stack, passes[tintIndex]);
        }
    }, ModItems.shield);
    // Armor (temp)
    itemColors.registerItemColorHandler(new IItemColor() {

        @Override
        public int getColorFromItemstack(ItemStack stack, int tintIndex) {
            // FIXME: Multiple passes needed?
            return ArmorHelper.getRenderColor(stack, EnumDecoPos.NORTH);
        }
    }, ModItems.gemHelmet, ModItems.gemChestplate, ModItems.gemLeggings, ModItems.gemBoots);
    // Gem Shards
    itemColors.registerItemColorHandler(new IItemColor() {

        @Override
        public int getColorFromItemstack(ItemStack stack, int tintIndex) {
            return stack.getItemDamage() > 15 ? 0x999999 : 0xFFFFFF;
        }
    }, ModItems.gemShard);
    // Enchantment Tokens
    itemColors.registerItemColorHandler(new IItemColor() {

        @Override
        public int getColorFromItemstack(ItemStack stack, int tintIndex) {
            if (tintIndex == 1)
                return ModItems.enchantmentToken.getOutlineColor(stack);
            return 0xFFFFFF;
        }
    }, ModItems.enchantmentToken);
    // Return Home Charm
    itemColors.registerItemColorHandler(new IItemColor() {

        @Override
        public int getColorFromItemstack(ItemStack stack, int tintIndex) {
            return stack.getItemDamage() > 15 && tintIndex == 1 ? 0x999999 : 0xFFFFFF;
        }
    }, ModItems.returnHomeCharm);
    // Node Mover
    itemColors.registerItemColorHandler(new IItemColor() {

        @Override
        public int getColorFromItemstack(ItemStack stack, int tintIndex) {
            return tintIndex != 1 ? 0xFFFFFF : ClientTickHandler.nodeMoverColor.getColor();
        }
    }, ModItems.nodeMover);
    // Drawing Compass
    itemColors.registerItemColorHandler(new IItemColor() {

        @Override
        public int getColorFromItemstack(ItemStack stack, int tintIndex) {
            return tintIndex == 0 ? ModItems.drawingCompass.getColor(stack).getColor() : 0xFFFFFF;
        }
    }, ModItems.drawingCompass);
    // Chaos Runes
    itemColors.registerItemColorHandler(new IItemColor() {

        @Override
        public int getColorFromItemstack(ItemStack stack, int tintIndex) {
            if (tintIndex == 1) {
                ChaosBuff buff = ModItems.chaosRune.getBuff(stack);
                if (buff != null) {
                    return buff.getColor();
                }
            }
            return 0xFFFFFF;
        }
    }, ModItems.chaosRune);
    // Holding Gem
    itemColors.registerItemColorHandler(new IItemColor() {

        @Override
        public int getColorFromItemstack(ItemStack stack, int tintIndex) {
            if (tintIndex == 1) {
                if (stack.hasTagCompound()) {
                    int id = stack.getTagCompound().getShort(ItemHoldingGem.NBT_GEM_ID);
                    if (id >= 0 && id < EnumGem.values().length)
                        return EnumGem.values()[id].color;
                }
            } else if (tintIndex == 2) {
                IBlockState state = ModItems.holdingGem.getBlockPlaced(stack);
                if (state != null)
                    return state.getMapColor().colorValue;
            }
            return 0xFFFFFF;
        }
    }, ModItems.holdingGem);
}
Also used : IItemColor(net.minecraft.client.renderer.color.IItemColor) Item(net.minecraft.item.Item) IBlockState(net.minecraft.block.state.IBlockState) ItemColors(net.minecraft.client.renderer.color.ItemColors) ItemStack(net.minecraft.item.ItemStack)

Example 8 with ItemColors

use of net.minecraft.client.renderer.color.ItemColors in project Bewitchment by Um-Mitternacht.

the class ClientProxy method init.

@Override
public void init(FMLInitializationEvent event) {
    Keybinds.registerKeys();
    BlockColors blocks = Minecraft.getMinecraft().getBlockColors();
    // Block Colors
    blocks.registerBlockColorHandler(new BlockCandleColorHandler(), ModBlocks.candle_medium, ModBlocks.candle_small, ModBlocks.candle_medium_lit, ModBlocks.candle_small_lit);
    blocks.registerBlockColorHandler(new IBlockColor() {

        @Override
        public int colorMultiplier(IBlockState state, IBlockAccess worldIn, BlockPos pos, int tintIndex) {
            EnumGlyphType type = state.getValue(BlockCircleGlyph.TYPE);
            switch(type) {
                case ENDER:
                    return 0x770077;
                case GOLDEN:
                    return 0xe3dc3c;
                case NETHER:
                    return 0xbb0000;
                default:
                case NORMAL:
                    return 0xFFFFFF;
                case ANY:
                    // A green one should never happen!
                    return 0x00FF00;
            }
        }
    }, ModBlocks.ritual_glyphs);
    blocks.registerBlockColorHandler(new IBlockColor() {

        @Override
        public int colorMultiplier(IBlockState state, IBlockAccess worldIn, BlockPos pos, int tintIndex) {
            if (tintIndex == 1) {
                return Color.HSBtoRGB((pos.getX() + pos.getY() + pos.getZ()) % 50 / 50f, 0.4f, 1f);
            }
            return -1;
        }
    }, ModBlocks.crystal_ball);
    ItemColors items = Minecraft.getMinecraft().getItemColors();
    // Item Colors
    items.registerItemColorHandler(new ItemCandleColorHandler(), Item.getItemFromBlock(ModBlocks.candle_medium), Item.getItemFromBlock(ModBlocks.candle_small));
    items.registerItemColorHandler(new BrewItemColorHandler(), ModItems.brew_phial_drink, ModItems.brew_phial_splash, ModItems.brew_phial_linger);
    items.registerItemColorHandler(new IItemColor() {

        @Override
        public int colorMultiplier(ItemStack stack, int tintIndex) {
            if (tintIndex == 0) {
                ISpell s = ItemSpellPage.getSpellFromItemStack(stack);
                if (s != null)
                    return s.getColor();
            }
            return -1;
        }
    }, ModItems.spell_page);
    NetworkRegistry.INSTANCE.registerGuiHandler(Bewitchment.instance, new GuiHandler());
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ISpell(com.bewitchment.api.spell.ISpell) IBlockAccess(net.minecraft.world.IBlockAccess) GuiHandler(com.bewitchment.common.core.net.GuiHandler) BlockColors(net.minecraft.client.renderer.color.BlockColors) IItemColor(net.minecraft.client.renderer.color.IItemColor) IBlockColor(net.minecraft.client.renderer.color.IBlockColor) ItemColors(net.minecraft.client.renderer.color.ItemColors) EnumGlyphType(com.bewitchment.api.ritual.EnumGlyphType) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 9 with ItemColors

use of net.minecraft.client.renderer.color.ItemColors in project artisan-worktables by codetaylor.

the class ModuleTools method onClientInitializationEvent.

@Override
public void onClientInitializationEvent(FMLInitializationEvent event) {
    super.onClientInitializationEvent(event);
    if (this.registeredToolList.isEmpty()) {
        // No tools were registered.
        return;
    }
    // Register item color handlers to colorize layer 1 of each item model
    // using the color stored in the material enum.
    ItemColors itemColors = Minecraft.getMinecraft().getItemColors();
    itemColors.registerItemColorHandler((stack, tintIndex) -> (tintIndex == 1) ? ((ItemWorktableTool) stack.getItem()).getMaterial().getColor() : 0xFFFFFF, this.registeredToolList.toArray(new ItemWorktableTool[this.registeredToolList.size()]));
}
Also used : ItemColors(net.minecraft.client.renderer.color.ItemColors) ItemWorktableTool(com.codetaylor.mc.artisanworktables.modules.tools.item.ItemWorktableTool)

Example 10 with ItemColors

use of net.minecraft.client.renderer.color.ItemColors in project HorsePower by GoryMoon.

the class ColorGetter method getItemColors.

private static List<Color> getItemColors(ItemStack itemStack, int colorCount) {
    final ItemColors itemColors = Minecraft.getMinecraft().getItemColors();
    final int renderColor = itemColors.colorMultiplier(itemStack, 0);
    final TextureAtlasSprite textureAtlasSprite = getTextureAtlasSprite(itemStack);
    if (textureAtlasSprite == null) {
        return Collections.emptyList();
    }
    return getColors(textureAtlasSprite, renderColor, colorCount);
}
Also used : ItemColors(net.minecraft.client.renderer.color.ItemColors) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite)

Aggregations

ItemColors (net.minecraft.client.renderer.color.ItemColors)13 BlockColors (net.minecraft.client.renderer.color.BlockColors)7 IItemColor (net.minecraft.client.renderer.color.IItemColor)4 Item (net.minecraft.item.Item)4 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)4 IBlockState (net.minecraft.block.state.IBlockState)3 ItemStack (net.minecraft.item.ItemStack)3 IColoredBlock (forestry.core.blocks.IColoredBlock)2 IColoredItem (forestry.core.items.IColoredItem)2 Block (net.minecraft.block.Block)2 Minecraft (net.minecraft.client.Minecraft)2 IBlockColor (net.minecraft.client.renderer.color.IBlockColor)2 BlockPos (net.minecraft.util.math.BlockPos)2 IBlockAccess (net.minecraft.world.IBlockAccess)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 EnumGlyphType (com.bewitchment.api.ritual.EnumGlyphType)1 ISpell (com.bewitchment.api.spell.ISpell)1 GuiHandler (com.bewitchment.common.core.net.GuiHandler)1 ItemWorktableTool (com.codetaylor.mc.artisanworktables.modules.tools.item.ItemWorktableTool)1 ModBlocks (com.oitsjustjose.geolosys.common.blocks.ModBlocks)1