Java examples for 2D Graphics:Color RGB
Computes a 20-bit lighting word, containing red, green, blue, and brightness settings.
//package com.java2s; public class Main { public static void main(String[] argv) throws Exception { int r = 2; int g = 2; int b = 2; int brightness = 2; System.out.println(makeRGBLightValue(r, g, b, brightness)); }//w ww.j a va 2 s . com /** * Computes a 20-bit lighting word, containing red, green, blue, and brightness settings. * Allows overriding of the Minecraft brightness value. * This value can be used directly for Block.lightValue * * Word format: 0RRRR 0GGGG 0BBBB 0LLLL * * @param r Red intensity, 0 to 15. Resolution is 4 bits. * @param g Green intensity, 0 to 15. Resolution is 4 bits. * @param b Blue intensity, 0 to 15. Resolution is 4 bits. * @param brightness The existing lightValue of a block. Only the lower-most 4 bits of this parameter are used. * @return Integer describing RGBL color for a block * * @author CptSpaceToaster */ public static int makeRGBLightValue(int r, int g, int b, int brightness) { // Clamp color channels if (r < 0) r = 0; else if (r > 15) r = 15; if (g < 0) g = 0; else if (g > 15) g = 15; if (b < 0) b = 0; else if (b > 15) b = 15; brightness &= 0xf; return brightness | ((b << 15) + (g << 10) + (r << 5)); } }