Search in sources :

Example 1 with IItemColor

use of net.minecraft.client.renderer.color.IItemColor 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 ToolRenderHelper.getInstance().getColor(stack, ToolPartPosition.forRenderPass(tintIndex));
        }
    }, ModItems.tools.toArray(new Item[ModItems.tools.size()]));
    // Shields
    itemColors.registerItemColorHandler(new IItemColor() {

        int[] passes = { ToolRenderHelper.PASS_HEAD, ToolRenderHelper.PASS_ROD };

        @Override
        public int getColorFromItemstack(ItemStack stack, int tintIndex) {
            if (tintIndex < 0 || tintIndex >= passes.length)
                return 0xFFFFFF;
            return ToolRenderHelper.getInstance().getColor(stack, ToolPartPosition.forRenderPass(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, ArmorPartPosition.NORTH);
        }
    }, ModItems.gemHelmet, ModItems.gemChestplate, ModItems.gemLeggings, ModItems.gemBoots);
    // 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) {
            if (tintIndex == 0) {
                int meta = stack.getItemDamage();
                if (meta >= 0 && meta < EnumGem.values().length) {
                    EnumGem gem = EnumGem.values()[meta];
                    return gem.color;
                }
            }
            return 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 0xFFFFFF;
                // return state.getMapColor().colorValue;
                }
            }
            return 0xFFFFFF;
        }
    }, ModItems.holdingGem);
    // Soul Gems
    itemColors.registerItemColorHandler(new IItemColor() {

        @Override
        public int getColorFromItemstack(ItemStack stack, int tintIndex) {
            Soul soul = ModItems.soulGem.getSoul(stack);
            if (soul == null) {
                return 0xFFFFFF;
            } else if (tintIndex == 1) {
                return soul.colorSecondary;
            } else {
                return soul.colorPrimary;
            }
        }
    }, ModItems.soulGem);
    // Tool Soul
    itemColors.registerItemColorHandler(new IItemColor() {

        @Override
        public int getColorFromItemstack(ItemStack stack, int tintIndex) {
            // TODO Auto-generated method stub
            ToolSoul soul = ModItems.toolSoul.getSoul(stack);
            if (soul == null)
                return tintIndex == 1 ? 0xFF00FF : tintIndex == 2 ? 0x0 : 0xFFFFFF;
            switch(tintIndex) {
                case 0:
                    float ratio = 0.5f + MathHelper.sin((float) ClientTickHandler.ticksInGame / 15) / 6;
                    return Color.blend(soul.getPrimaryElement().color, soul.getSecondaryElement().color, ratio);
                case 1:
                    return soul.getPrimaryElement().color;
                case 2:
                    return soul.getSecondaryElement().color;
                default:
                    return 0xFFFFFF;
            }
        }
    }, ModItems.toolSoul);
    // Arrows
    itemColors.registerItemColorHandler(new IItemColor() {

        @Override
        public int getColorFromItemstack(ItemStack stack, int tintIndex) {
            // TODO Auto-generated method stub
            return 0xFFFFFF;
        }
    }, ModItems.arrow);
}
Also used : IItemColor(net.minecraft.client.renderer.color.IItemColor) Item(net.minecraft.item.Item) ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) IBlockState(net.minecraft.block.state.IBlockState) ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) Soul(net.silentchaos512.gems.item.ItemSoulGem.Soul) ItemColors(net.minecraft.client.renderer.color.ItemColors) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IItemColor

use of net.minecraft.client.renderer.color.IItemColor in project EnderIO by SleepyTrousers.

the class SmartModelAttacher method registerColoredBlocksAndItems.

@SideOnly(Side.CLIENT)
public static void registerColoredBlocksAndItems() {
    NNList<Block> blocklist = new NNList<Block>();
    NNList<Item> itemlist = new NNList<Item>();
    for (RegistrationHolder<?, ?> holder : blocks) {
        Block block = holder.block;
        Item item = Item.getItemFromBlock(block);
        if (block instanceof IPaintable || block instanceof ITintedBlock || block instanceof ITintedItem || item instanceof ITintedItem) {
            blocklist.add(block);
            if (item != Items.AIR) {
                itemlist.add(item);
            }
        } else {
            if (block instanceof IBlockColor) {
                Minecraft.getMinecraft().getBlockColors().registerBlockColorHandler((IBlockColor) block, block);
            }
            if (item instanceof IItemColor) {
                Minecraft.getMinecraft().getItemColors().registerItemColorHandler((IItemColor) item, item);
            }
        }
    }
    PaintTintHandler handler = new PaintTintHandler();
    Minecraft.getMinecraft().getBlockColors().registerBlockColorHandler(handler, blocklist.toArray(new Block[0]));
    Minecraft.getMinecraft().getItemColors().registerItemColorHandler(handler, itemlist.toArray(new Item[0]));
}
Also used : IItemColor(net.minecraft.client.renderer.color.IItemColor) Item(net.minecraft.item.Item) ITintedItem(crazypants.enderio.base.render.ITintedItem) IBlockColor(net.minecraft.client.renderer.color.IBlockColor) ITintedItem(crazypants.enderio.base.render.ITintedItem) IPaintable(crazypants.enderio.base.paint.IPaintable) NNList(com.enderio.core.common.util.NNList) ITintedBlock(crazypants.enderio.base.render.ITintedBlock) Block(net.minecraft.block.Block) ITintedBlock(crazypants.enderio.base.render.ITintedBlock) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with IItemColor

use of net.minecraft.client.renderer.color.IItemColor in project Minestuck by mraof.

the class ClientProxy method registerRenderers.

public static void registerRenderers() {
    Minecraft mc = Minecraft.getMinecraft();
    ClientRegistry.bindTileEntitySpecialRenderer(TileEntitySkaiaPortal.class, new RenderSkaiaPortal());
    ClientRegistry.bindTileEntitySpecialRenderer(TileEntityGate.class, new RenderGate());
    // MinecraftForgeClient.registerItemRenderer(Minestuck.captchaCard, new RenderCard());
    mc.getItemColors().registerItemColorHandler(new IItemColor() {

        @Override
        public int colorMultiplier(ItemStack stack, int tintIndex) {
            if (tintIndex == 0 || tintIndex == 1) {
                int color = stack.getMetadata() == 0 ? -1 : ColorCollector.getColor(stack.getMetadata() - 1);
                if (tintIndex == 1) {
                    int i0 = ((color & 255) + 255) / 2;
                    int i1 = (((color >> 8) & 255) + 255) / 2;
                    int i2 = (((color >> 16) & 255) + 255) / 2;
                    color = i0 | (i1 << 8) | (i2 << 16);
                }
                return color;
            } else
                return -1;
        }
    }, MinestuckItems.cruxiteDowel, MinestuckItems.cruxiteApple, MinestuckItems.cruxitePotion);
}
Also used : IItemColor(net.minecraft.client.renderer.color.IItemColor) RenderSkaiaPortal(com.mraof.minestuck.client.renderer.tileentity.RenderSkaiaPortal) RenderGate(com.mraof.minestuck.client.renderer.tileentity.RenderGate) ItemStack(net.minecraft.item.ItemStack) Minecraft(net.minecraft.client.Minecraft)

Example 4 with IItemColor

use of net.minecraft.client.renderer.color.IItemColor 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 5 with IItemColor

use of net.minecraft.client.renderer.color.IItemColor in project CompositeGear by TwilightWingsStudio.

the class CompositeGear method registerItemColorHandler.

@SideOnly(Side.CLIENT)
public void registerItemColorHandler() {
    modLog.info("Registering IItemColor handler for mod items.");
    Minecraft.getMinecraft().getItemColors().registerItemColorHandler(new IItemColor() {

        public int colorMultiplier(ItemStack stack, int tintIndex) {
            return tintIndex > 0 ? -1 : ((ItemArmor) stack.getItem()).getColor(stack);
        }
    }, ItemsCG.compositeHelmet, ItemsCG.compositeChestplate, ItemsCG.compositeLeggings, ItemsCG.compositeBoots, ItemsCG.compositeFaceplate, ItemsCG.ushankaHat, ItemsCG.balaclavaMask, ItemsCG.shemaghMask, ItemsCG.rubberGasmask, ItemsCG.respiratorMask, ItemsCG.respiratorMaskComposite, ItemsCG.compositeLightHelmet, ItemsCG.compositeLightVest, ItemsCG.compositeLightLeggings, ItemsCG.compositeLightBoots);
}
Also used : IItemColor(net.minecraft.client.renderer.color.IItemColor) ItemArmor(net.minecraft.item.ItemArmor) ItemStack(net.minecraft.item.ItemStack) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

IItemColor (net.minecraft.client.renderer.color.IItemColor)8 ItemStack (net.minecraft.item.ItemStack)7 IBlockState (net.minecraft.block.state.IBlockState)4 Item (net.minecraft.item.Item)4 IBlockColor (net.minecraft.client.renderer.color.IBlockColor)3 ItemColors (net.minecraft.client.renderer.color.ItemColors)3 IPaintable (crazypants.enderio.base.paint.IPaintable)2 ITintedBlock (crazypants.enderio.base.render.ITintedBlock)2 ITintedItem (crazypants.enderio.base.render.ITintedItem)2 Block (net.minecraft.block.Block)2 Minecraft (net.minecraft.client.Minecraft)2 BlockPos (net.minecraft.util.math.BlockPos)2 IBlockAccess (net.minecraft.world.IBlockAccess)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 EnumGlyphType (com.bewitchment.api.ritual.EnumGlyphType)1 ISpell (com.bewitchment.api.spell.ISpell)1 GuiHandler (com.bewitchment.common.core.net.GuiHandler)1 NNList (com.enderio.core.common.util.NNList)1 RenderGate (com.mraof.minestuck.client.renderer.tileentity.RenderGate)1 RenderSkaiaPortal (com.mraof.minestuck.client.renderer.tileentity.RenderSkaiaPortal)1