void GameObjectFlashLight::applyTintColour(int colour)
{
	Ogre::ColourValue tint;
	tint.setAsRGBA(colour);
	Ogre::MaterialPtr mat=Ogre::MaterialManager::getSingleton().getByName(CONE_MATERIAL_NAME);
	Ogre::TextureUnitState* tex= mat->getTechnique(0)->getPass(0)->getTextureUnitState(0);
	if (tex)
	{
		tex->setColourOperationEx(Ogre::LBX_MODULATE,Ogre::LBS_MANUAL,Ogre::LBS_CURRENT,tint);
	}
}
void SubChunkMeshGenerator::generateSideMesh(Ogre::ManualObject * obj,
    const Int3D & absolute_position, const Block & block,
    const BlockData & block_data, BlockFaceDirection side_index)
{
    if (block_data.side_textures.at(side_index).isEmpty())
        return;


    // if the block on this side is opaque or the same block, skip
    Block neighbor_block = m_owner->game()->blockAt(absolute_position + c_side_offset[side_index]);
    Item::ItemType side_type = neighbor_block.type();
    if ((side_type == block.type() && (block_data.partial_alpha || side_type == Item::Glass)) ||
        ! m_block_data.value(side_type, m_air).see_through)
    {
        return;
    }

    // add this side to mesh
    Ogre::Vector3 abs_block_loc(absolute_position.x, absolute_position.y, absolute_position.z);

    // special cases for textures
    QString texture_name = block_data.side_textures.at(side_index);
    switch (block.type()) {
        case Item::Wood:
        if (side_index != NegativeZ && side_index != PositiveZ) {
            switch (block.woodMetadata()) {
            case Item::NormalTrunkTexture:
                texture_name = "WoodSide";
                break;
            case Item::RedwoodTrunkTexture:
                texture_name = "RedwoodTrunkSide";
                break;
            case Item::BirchTrunkTexture:
                texture_name = "BirchTrunkSide";
                break;
            }
        }
        break;
        case Item::Leaves:
        {
            switch (block.leavesMetadata()) {
            case Item::NormalLeavesTexture:
                texture_name = "LeavesRegular";
                break;
            case Item::RedwoodLeavesTexture:
                texture_name = "RedwoodLeaves";
                break;
            case Item::BirchLeavesTexture:
                texture_name = "BirchLeaves";
                break;
            }
        }
        break;
        case Item::Farmland:
        if (side_index == PositiveZ)
            texture_name = block.farmlandMetadata() == 0 ? "FarmlandDry" : "FarmlandWet";
        break;
        case Item::Crops:
        texture_name = QString("Crops") + QString::number(block.cropsMetadata());
        break;
        case Item::Wool:
        texture_name = c_wool_texture_names[block.woolMetadata()];
        break;
        case Item::Furnace:
        case Item::BurningFurnace:
        case Item::Dispenser:
        {
            if (side_index != NegativeZ && side_index != PositiveZ) {
                if ((block.furnaceMetadata() == Item::EastFacingFurnace && side_index == PositiveX) ||
                    (block.furnaceMetadata() == Item::WestFacingFurnace && side_index == NegativeX) ||
                    (block.furnaceMetadata() == Item::NorthFacingFurnace && side_index == PositiveY) ||
                    (block.furnaceMetadata() == Item::SouthFacingFurnace && side_index == NegativeY))
                {
                    texture_name = block_data.side_textures.value(NegativeY);
                } else {
                    texture_name = "FurnaceBack";
                }
            }
        }
        break;
        case Item::Pumpkin:
        case Item::JackOLantern:
        {
            if (side_index != NegativeZ && side_index != PositiveZ) {
                if ((block.pumpkinMetadata() == Item::EastFacingPumpkin && side_index == PositiveX) ||
                    (block.pumpkinMetadata() == Item::WestFacingPumpkin && side_index == NegativeX) ||
                    (block.pumpkinMetadata() == Item::NorthFacingPumpkin && side_index == PositiveY) ||
                    (block.pumpkinMetadata() == Item::SouthFacingPumpkin && side_index == NegativeY))
                {
                    texture_name = block_data.side_textures.value(NegativeY);
                } else {
                    texture_name = "PumpkinBack";
                }
            }
        }
        break;
        case Item::RedstoneWire_placed:
        {
            if (block.redstoneMetadata() == 0) {
                texture_name = "RedWire4wayOff";
            } else {
                texture_name = "RedWire4wayOn";
            }
        }
        break;
        default:;
    }
    MainWindow::BlockTextureCoord btc = m_owner->texCoords(texture_name);

    Ogre::Vector3 squish = block_data.squish_amount.at(side_index);

    float brightness;
    int night_darkness = 0;
    brightness = c_light_brightness[qMax(neighbor_block.skyLight() - night_darkness, neighbor_block.light())];

    Ogre::ColourValue color = Ogre::ColourValue::White;
    if (block.type() == Item::Grass && side_index == PositiveZ)
        color.setAsRGBA(0x8DD55EFF);
    else if (block.type() == Item::Leaves)
        color.setAsRGBA(0x8DD55EFF);

    color *= brightness;
    color *= c_brightness_bias[side_index];

    for (int triangle_index = 0; triangle_index < 2; triangle_index++) {
        for (int point_index = 0; point_index < 3; point_index++) {
            Ogre::Vector3 pos = c_side_coord[side_index][triangle_index][point_index] - squish;
            if (block_data.rotate) {
                pos -= 0.5f;
                pos = Ogre::Quaternion(Ogre::Degree(45), Ogre::Vector3::UNIT_Z) * pos;
                pos += 0.5f;
            }
            obj->position(pos + abs_block_loc);

            Ogre::Vector2 tex_coord = c_tex_coord[triangle_index][point_index];
            obj->textureCoord((btc.x+tex_coord.x*btc.w) / c_terrain_png_width, (btc.y+tex_coord.y*btc.h) / c_terrain_png_height);

            obj->colour(color);
        }
    }
}