Search in sources :

Example 1 with BlockLamp

use of com.bluepowermod.block.lighting.BlockLamp in project BluePower by Qmunity.

the class RenderLamp method render.

@Override
public void render(TileLamp te, float v, MatrixStack matrixStack, IRenderTypeBuffer iRenderTypeBuffer, int partialTicks, int destroyStage) {
    if (// || Loader.isModLoaded("albedo"))
    !(te.getBlockState().getBlock() instanceof BlockLamp))
        return;
    BlockState stateLamp = te.getBlockState();
    BlockLamp bLamp = (BlockLamp) stateLamp.getBlock();
    if (te.getLevel() == null) {
        return;
    }
    int power = stateLamp.getValue(BlockLamp.POWER);
    int color = bLamp.getColor(stateLamp, te.getLevel(), te.getBlockPos(), 0);
    int redMask = 0xFF0000, greenMask = 0xFF00, blueMask = 0xFF;
    int r = (color & redMask) >> 16;
    int g = (color & greenMask) >> 8;
    int b = (color & blueMask);
    AxisAlignedBB box = stateLamp.getShape(te.getLevel(), te.getBlockPos()).bounds();
    // Define our base Glow
    box = box.equals(new AxisAlignedBB(0, 0, 0, 1, 1, 1)) ? box.inflate(0.05) : box.inflate(0.03125);
    boolean[] renderFaces = new boolean[] { true, true, true, true, true, true };
    // Remove overlapping Glow
    if (stateLamp.getShape(te.getLevel(), te.getBlockPos()).bounds().equals(new AxisAlignedBB(0, 0, 0, 1, 1, 1))) {
        for (Direction face : Direction.values()) {
            BlockState state = te.getLevel().getBlockState(te.getBlockPos().relative(face.getOpposite()));
            if (state.getBlock() instanceof BlockLamp && state.getShape(te.getLevel(), te.getBlockPos()).bounds().equals(new AxisAlignedBB(0, 0, 0, 1, 1, 1))) {
                if (state.getValue(BlockLamp.POWER) > 0) {
                    renderFaces[face.get3DDataValue()] = false;
                    double offsetx = (face.getStepX() * 0.05) > 0 ? (face.getStepX() * 0.05) : 0;
                    double offsety = (face.getStepY() * 0.05) > 0 ? (face.getStepY() * 0.05) : 0;
                    double offsetz = (face.getStepZ() * 0.05) > 0 ? (face.getStepZ() * 0.05) : 0;
                    double toffsetx = (face.getStepX() * 0.05) < 0 ? (face.getStepX() * 0.05) : 0;
                    double toffsety = (face.getStepY() * 0.05) < 0 ? (face.getStepY() * 0.05) : 0;
                    double toffsetz = (face.getStepZ() * 0.05) < 0 ? (face.getStepZ() * 0.05) : 0;
                    box = new AxisAlignedBB(box.minX + offsetx, box.minY + offsety, box.minZ + offsetz, box.maxX + toffsetx, box.maxY + toffsety, box.maxZ + toffsetz);
                }
            }
        }
    }
    matrixStack.pushPose();
    double powerDivision = power / 18D;
    com.bluepowermod.client.render.RenderHelper.drawColoredCube(box, iRenderTypeBuffer.getBuffer(BPRenderTypes.LAMP_GLOW), matrixStack, r, g, b, (int) (powerDivision * 200), 200, renderFaces);
    matrixStack.popPose();
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) BlockState(net.minecraft.block.BlockState) BlockLamp(com.bluepowermod.block.lighting.BlockLamp) Direction(net.minecraft.util.Direction)

Aggregations

BlockLamp (com.bluepowermod.block.lighting.BlockLamp)1 BlockState (net.minecraft.block.BlockState)1 Direction (net.minecraft.util.Direction)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1