Search in sources :

Example 1 with IBlockColor

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

the class PaintTintHandler method colorMultiplier.

@Override
public int colorMultiplier(@Nonnull IBlockState state, @Nullable IBlockAccess world, @Nullable BlockPos pos, int tintIndex) {
    if (world == null || pos == null) {
        return -1;
    }
    Block block = state.getBlock();
    IBlockState paintSource = null;
    if (block instanceof IPaintable) {
        paintSource = ((IPaintable) block).getPaintSource(state, world, pos);
        if (paintSource != null && paintSource.getBlock() != block) {
            block = paintSource.getBlock();
            state = paintSource;
        } else {
            paintSource = null;
        }
    }
    if (block instanceof ITintedBlock) {
        return ((ITintedBlock) block).getBlockTint(state, world, pos, tintIndex);
    }
    if (block instanceof IBlockColor) {
        return ((IBlockColor) block).colorMultiplier(state, world, pos, tintIndex);
    }
    if (paintSource != null) {
        return Minecraft.getMinecraft().getBlockColors().colorMultiplier(paintSource, world, pos, tintIndex);
    }
    return -1;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IBlockColor(net.minecraft.client.renderer.color.IBlockColor) IPaintable(crazypants.enderio.base.paint.IPaintable) ITintedBlock(crazypants.enderio.base.render.ITintedBlock) Block(net.minecraft.block.Block) ITintedBlock(crazypants.enderio.base.render.ITintedBlock)

Example 2 with IBlockColor

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

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

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

use of net.minecraft.client.renderer.color.IBlockColor in project pnc-repressurized by TeamPneumatic.

the class BlockColorHandler method registerColorHandlers.

public static void registerColorHandlers() {
    final IBlockColor heatColor = (state, blockAccess, pos, tintIndex) -> {
        if (blockAccess != null && pos != null) {
            TileEntity te = blockAccess.getTileEntity(pos);
            int heatLevel = 10;
            if (te instanceof TileEntityCompressedIronBlock) {
                heatLevel = ((TileEntityCompressedIronBlock) te).getHeatLevel();
            } else if (te instanceof TileEntityVortexTube) {
                switch(tintIndex) {
                    case 0:
                        heatLevel = ((TileEntityVortexTube) te).getHotHeatLevel();
                        break;
                    case 1:
                        heatLevel = ((TileEntityVortexTube) te).getColdHeatLevel();
                        break;
                }
            }
            double[] color = TileEntityCompressedIronBlock.getColorForHeatLevel(heatLevel);
            return 0xFF000000 + ((int) (color[0] * 255) << 16) + ((int) (color[1] * 255) << 8) + (int) (color[2] * 255);
        }
        return 0xFFFFFFFF;
    };
    Minecraft.getMinecraft().getBlockColors().registerBlockColorHandler(heatColor, Blockss.COMPRESSED_IRON, Blockss.HEAT_SINK, Blockss.VORTEX_TUBE);
    final IBlockColor uvLightBoxLampColor = (state, blockAccess, pos, tintIndex) -> {
        if (blockAccess != null && pos != null) {
            TileEntity te = blockAccess.getTileEntity(pos);
            if (te instanceof TileEntityUVLightBox) {
                return ((TileEntityUVLightBox) te).areLightsOn ? 0xFF4000FF : 0xFFAFAFE4;
            }
        }
        return 0xFFAFAFE4;
    };
    Minecraft.getMinecraft().getBlockColors().registerBlockColorHandler(uvLightBoxLampColor, Blockss.UV_LIGHT_BOX);
    final IBlockColor camoColor = (state, worldIn, pos, tintIndex) -> {
        if (pos == null || worldIn == null)
            return 0xffffff;
        TileEntity te = worldIn.getTileEntity(pos);
        if (te instanceof ICamouflageableTE && ((ICamouflageableTE) te).getCamouflage() != null) {
            return Minecraft.getMinecraft().getBlockColors().colorMultiplier(((ICamouflageableTE) te).getCamouflage(), te.getWorld(), pos, tintIndex);
        } else {
            return 0xffffff;
        }
    };
    for (Block b : Blockss.blocks) {
        if (b instanceof BlockPneumaticCraftCamo) {
            Minecraft.getMinecraft().getBlockColors().registerBlockColorHandler(camoColor, b);
        }
    }
}
Also used : ICamouflageableTE(me.desht.pneumaticcraft.common.tileentity.ICamouflageableTE) TileEntityVortexTube(me.desht.pneumaticcraft.common.tileentity.TileEntityVortexTube) Block(net.minecraft.block.Block) Minecraft(net.minecraft.client.Minecraft) Side(net.minecraftforge.fml.relauncher.Side) IBlockColor(net.minecraft.client.renderer.color.IBlockColor) TileEntity(net.minecraft.tileentity.TileEntity) TileEntityCompressedIronBlock(me.desht.pneumaticcraft.common.tileentity.TileEntityCompressedIronBlock) TileEntityUVLightBox(me.desht.pneumaticcraft.common.tileentity.TileEntityUVLightBox) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) TileEntity(net.minecraft.tileentity.TileEntity) TileEntityCompressedIronBlock(me.desht.pneumaticcraft.common.tileentity.TileEntityCompressedIronBlock) IBlockColor(net.minecraft.client.renderer.color.IBlockColor) TileEntityUVLightBox(me.desht.pneumaticcraft.common.tileentity.TileEntityUVLightBox) TileEntityVortexTube(me.desht.pneumaticcraft.common.tileentity.TileEntityVortexTube) Block(net.minecraft.block.Block) TileEntityCompressedIronBlock(me.desht.pneumaticcraft.common.tileentity.TileEntityCompressedIronBlock) ICamouflageableTE(me.desht.pneumaticcraft.common.tileentity.ICamouflageableTE)

Aggregations

IBlockColor (net.minecraft.client.renderer.color.IBlockColor)5 Block (net.minecraft.block.Block)3 IBlockState (net.minecraft.block.state.IBlockState)3 IItemColor (net.minecraft.client.renderer.color.IItemColor)3 IPaintable (crazypants.enderio.base.paint.IPaintable)2 ITintedBlock (crazypants.enderio.base.render.ITintedBlock)2 ItemColors (net.minecraft.client.renderer.color.ItemColors)2 Item (net.minecraft.item.Item)2 ItemStack (net.minecraft.item.ItemStack)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 ITintedItem (crazypants.enderio.base.render.ITintedItem)1 RenderProjectedItem (lumien.randomthings.client.render.RenderProjectedItem)1 EntityProjectedItem (lumien.randomthings.entitys.EntityProjectedItem)1 IRTBlockColor (lumien.randomthings.lib.IRTBlockColor)1