use of net.minecraft.block.material.MapColor in project BetterWithAddons by DaedalusGame.
the class StormHandler method fogColor.
@SubscribeEvent
public void fogColor(EntityViewRenderEvent.FogColors fogEvent) {
if (!InteractionBWA.OBVIOUS_SAND_STORMS)
return;
Entity entity = fogEvent.getEntity();
World world = entity.world;
BlockPos pos = entity.getPosition();
Color desiredcolor = new Color(Math.min(fogEvent.getRed(), 1.0f), Math.min(fogEvent.getGreen(), 1.0f), Math.min(fogEvent.getBlue(), 1.0f));
if (world.isRaining()) {
float red = 0;
float green = 0;
float blue = 0;
int totalweight = 0;
BlockPos[] probes = new BlockPos[] { pos, pos.add(1, 0, 0), pos.add(0, 0, 1), pos.add(-1, 0, 0), pos.add(0, 0, -1) };
for (BlockPos probepos : probes) {
boolean aboveground = false;
if (isDesert(world, probepos) && (aboveground = world.canSeeSky(probepos))) {
Biome biome = world.getBiome(probepos);
MapColor mapcolor = biome.topBlock.getMapColor(world, probepos);
Color color = new Color(mapcolor.colorValue);
red += 2 * (color.getRed() / 255.0f);
green += 2 * (color.getGreen() / 255.0f);
blue += 2 * (color.getBlue() / 255.0f);
totalweight += 2;
} else if (aboveground) {
red += fogEvent.getRed();
green += fogEvent.getGreen();
blue += fogEvent.getBlue();
totalweight += 1;
}
}
desiredcolor = new Color(Math.min(red / totalweight, 1.0f), Math.min(green / totalweight, 1.0f), Math.min(blue / totalweight, 1.0f));
fogEvent.setRed(currentRed / 255.0f);
fogEvent.setGreen(currentGreen / 255.0f);
fogEvent.setBlue(currentBlue / 255.0f);
}
desiredRed = desiredcolor.getRed();
desiredGreen = desiredcolor.getGreen();
desiredBlue = desiredcolor.getBlue();
}
use of net.minecraft.block.material.MapColor in project BuildCraft by BuildCraft.
the class BCEnergyFluids method getMapColor.
private static MapColor getMapColor(int color) {
MapColor bestMapColor = MapColor.BLACK;
int currentDifference = Integer.MAX_VALUE;
int r = (color >> 16) & 0xFF;
int g = (color >> 8) & 0xFF;
int b = color & 0xFF;
for (MapColor mapColor : MapColor.COLORS) {
if (mapColor == null || mapColor.colorValue == 0) {
continue;
}
int mr = (mapColor.colorValue >> 16) & 0xFF;
int mg = (mapColor.colorValue >> 8) & 0xFF;
int mb = mapColor.colorValue & 0xFF;
int dr = mr - r;
int dg = mg - g;
int db = mb - b;
int difference = dr * dr + dg * dg + db * db;
if (difference < currentDifference) {
currentDifference = difference;
bestMapColor = mapColor;
}
}
return bestMapColor;
}
use of net.minecraft.block.material.MapColor in project Galacticraft by micdoodle8.
the class TileEntityPainter method takeColorFromItem.
public void takeColorFromItem(ItemStack itemStack) {
if (itemStack == null) {
return;
}
Item item = itemStack.getItem();
int color = -1;
if (item == Items.dye) {
color = ItemDye.dyeColors[itemStack.getItemDamage()];
} else if (item instanceof ItemBlock) {
Block b = ((ItemBlock) item).getBlock();
IBlockState bs = b.getStateFromMeta(itemStack.getItemDamage());
MapColor mc = b.getMapColor(bs);
color = mc.colorValue;
} else {
color = tryOtherModDyes(itemStack);
}
if (color >= 0) {
color = ColorUtil.addColorsBasic(color, this.guiColor);
this.guiColor = color;
}
}
use of net.minecraft.block.material.MapColor in project RFTools by McJty.
the class ShapeBlockInfo method getColor.
private static Col getColor(IBlockState state) {
if (state == null) {
return COL_DEFAULT;
}
Col col;
Block block = state.getBlock();
// The given world and pos are wrong but they help to avoid crashes for some code
MapColor mapColor = null;
try {
mapColor = block.getMapColor(state, Minecraft.getMinecraft().world, new BlockPos(0, 0, 0));
} catch (Exception e) {
mapColor = MapColor.RED;
}
if (block == Blocks.LAVA || block == Blocks.FLOWING_LAVA) {
col = COL_LAVA;
} else if (block == Blocks.NETHER_BRICK || block == Blocks.NETHER_BRICK_FENCE || block == Blocks.NETHER_BRICK_STAIRS) {
col = COL_NETHERBRICK;
} else if (block == BuilderSetup.scannerBlock) {
col = COL_SCANNER;
} else if (mapColor != null) {
col = new Col(((mapColor.colorValue >> 16) & 0xff) / 255.0f, ((mapColor.colorValue >> 8) & 0xff) / 255.0f, (mapColor.colorValue & 0xff) / 255.0f);
} else {
col = COL_DEFAULT;
}
float r = col.getR();
float g = col.getG();
float b = col.getB();
if (r * 1.2f > 1.0f) {
r = 0.99f / 1.2f;
}
if (g * 1.2f > 1.0f) {
g = 0.99f / 1.2f;
}
if (b * 1.2f > 1.0f) {
b = 0.99f / 1.2f;
}
col = new Col(r, g, b);
return col;
}
Aggregations