Search in sources :

Example 1 with MapColor

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();
}
Also used : Entity(net.minecraft.entity.Entity) Biome(net.minecraft.world.biome.Biome) MapColor(net.minecraft.block.material.MapColor) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) MapColor(net.minecraft.block.material.MapColor) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with MapColor

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;
}
Also used : MapColor(net.minecraft.block.material.MapColor)

Example 3 with MapColor

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;
    }
}
Also used : Item(net.minecraft.item.Item) IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemBlock(net.minecraft.item.ItemBlock) MapColor(net.minecraft.block.material.MapColor)

Example 4 with MapColor

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;
}
Also used : Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) MapColor(net.minecraft.block.material.MapColor)

Aggregations

MapColor (net.minecraft.block.material.MapColor)4 Block (net.minecraft.block.Block)2 BlockPos (net.minecraft.util.math.BlockPos)2 IBlockState (net.minecraft.block.state.IBlockState)1 Entity (net.minecraft.entity.Entity)1 Item (net.minecraft.item.Item)1 ItemBlock (net.minecraft.item.ItemBlock)1 World (net.minecraft.world.World)1 Biome (net.minecraft.world.biome.Biome)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1