Search in sources :

Example 1 with Frustum

use of net.minecraft.client.renderer.culling.Frustum in project Charset by CharsetMC.

the class ProjectorRenderer method onRender.

@SubscribeEvent
public void onRender(RenderWorldLastEvent event) {
    Minecraft.getMinecraft().mcProfiler.startSection("projectors");
    GlStateManager.enableBlend();
    GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
    GlStateManager.glBlendEquation(GL14.GL_FUNC_ADD);
    GlStateManager.enableTexture2D();
    GlStateManager.enableAlpha();
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder worldrenderer = tessellator.getBuffer();
    worldrenderer.setTranslation(0, 0, 0);
    Entity cameraEntity = Minecraft.getMinecraft().getRenderViewEntity();
    Vec3d cameraPos = EntityUtils.interpolate(cameraEntity, event.getPartialTicks());
    ICamera camera = new Frustum();
    camera.setPosition(cameraPos.x, cameraPos.y, cameraPos.z);
    GlStateManager.pushMatrix();
    GlStateManager.translate(-cameraPos.x, -cameraPos.y, -cameraPos.z);
    for (TileEntity tileEntity : Minecraft.getMinecraft().world.loadedTileEntityList) {
        if (tileEntity instanceof TileProjector) {
            LaserColor color = LaserColor.NONE;
            Orientation orientation = ((TileProjector) tileEntity).getOrientation();
            if (CharsetProjector.useLasers) {
                for (int d = 0; d < 6; d++) {
                    LaserColor color2 = ((TileProjector) tileEntity).colors[d];
                    if (color2 != null && color2 != LaserColor.NONE) {
                        if (d == orientation.facing.getOpposite().ordinal()) {
                            // not rendering anything - laser in the way
                            color = LaserColor.NONE;
                            break;
                        } else {
                            color = color.union(color2);
                        }
                    }
                }
            } else {
                color = ((TileProjector) tileEntity).redstoneLevel > 0 ? LaserColor.WHITE : LaserColor.NONE;
            }
            if (color != LaserColor.NONE) {
                ItemStack stack = ((TileProjector) tileEntity).getStack();
                IProjectorHandler<ItemStack> handler = CharsetProjector.getHandler(stack);
                if (handler == null) {
                    continue;
                }
                Surface surface = getSurface(tileEntity.getWorld(), tileEntity.getPos(), orientation, 0.5f, handler.getAspectRatio(stack));
                if (surface == null) {
                    continue;
                }
                if (!camera.isBoundingBoxInFrustum(new AxisAlignedBB(surface.cornerStart, surface.cornerEnd))) {
                    continue;
                }
                surface.r = color.red ? 1.0f : 0.0f;
                surface.g = color.green ? 1.0f : 0.0f;
                surface.b = color.blue ? 1.0f : 0.0f;
                surface.a = 0.5f;
                if (!CharsetProjector.useLasers) {
                    surface.a *= ((TileProjector) tileEntity).redstoneLevel / 15.0f;
                }
                EnumDyeColor dyeColor = null;
                BlockPos inFrontPos = tileEntity.getPos().offset(((TileProjector) tileEntity).getOrientation().facing);
                IBlockState state = tileEntity.getWorld().getBlockState(inFrontPos);
                if (state.getBlock() instanceof BlockStainedGlass) {
                    dyeColor = state.getValue(BlockStainedGlass.COLOR);
                }
                if (dyeColor != null) {
                    float[] v = dyeColor.getColorComponentValues();
                    surface.r *= v[0];
                    surface.g *= v[1];
                    surface.b *= v[2];
                }
                surface.restoreGLColor();
                handler.render(stack, (IProjector) tileEntity, surface);
            }
        }
    }
    GlStateManager.popMatrix();
    GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GlStateManager.glBlendEquation(GL14.GL_FUNC_ADD);
    GlStateManager.disableBlend();
    Minecraft.getMinecraft().mcProfiler.endSection();
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) Frustum(net.minecraft.client.renderer.culling.Frustum) Tessellator(net.minecraft.client.renderer.Tessellator) IBlockState(net.minecraft.block.state.IBlockState) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) ICamera(net.minecraft.client.renderer.culling.ICamera) Orientation(pl.asie.charset.lib.utils.Orientation) EnumDyeColor(net.minecraft.item.EnumDyeColor) TileEntity(net.minecraft.tileentity.TileEntity) BlockStainedGlass(net.minecraft.block.BlockStainedGlass) LaserColor(pl.asie.charset.api.laser.LaserColor) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with Frustum

use of net.minecraft.client.renderer.culling.Frustum in project Bookshelf by Darkhax-Minecraft.

the class RenderUtils method getCamera.

/**
     * Gets the camera for a specific entity.
     *
     * @param entity The entity to get the camera for.
     * @param partialTicks The partial ticks for the camera.
     * @return The camera for the entity.
     */
public static Frustum getCamera(Entity entity, float partialTicks) {
    final double cameraX = entity.prevPosX + (entity.posX - entity.prevPosX) * partialTicks;
    final double cameraY = entity.prevPosY + (entity.posY - entity.prevPosY) * partialTicks;
    final double cameraZ = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * partialTicks;
    final Frustum camera = new Frustum();
    camera.setPosition(cameraX, cameraY, cameraZ);
    return camera;
}
Also used : Frustum(net.minecraft.client.renderer.culling.Frustum)

Example 3 with Frustum

use of net.minecraft.client.renderer.culling.Frustum in project Charset by CharsetMC.

the class LaserRenderer method onRender.

@SubscribeEvent
public void onRender(RenderWorldLastEvent event) {
    Minecraft mc = Minecraft.getMinecraft();
    World world = mc.world;
    Collection<LaserBeam> beams = CharsetLaser.laserStorage.getLaserBeams(world);
    renderedLasers = 0;
    totalLasers = beams.size();
    if (totalLasers == 0)
        return;
    Minecraft.getMinecraft().mcProfiler.startSection("lasers");
    GlStateManager.enableBlend();
    GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
    GlStateManager.glBlendEquation(GL14.GL_FUNC_ADD);
    GlStateManager.enableAlpha();
    GlStateManager.disableLighting();
    GlStateManager.disableTexture2D();
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder worldrenderer = tessellator.getBuffer();
    Entity cameraEntity = Minecraft.getMinecraft().getRenderViewEntity();
    Vec3d cameraPos = EntityUtils.interpolate(cameraEntity, event.getPartialTicks());
    ICamera camera = new Frustum();
    camera.setPosition(cameraPos.x, cameraPos.y, cameraPos.z);
    int maxDist = Minecraft.getMinecraft().gameSettings.renderDistanceChunks * 16 + 1;
    Collection<LaserBeam> beamsRender = beams;
    worldrenderer.setTranslation(-cameraPos.x, -cameraPos.y, -cameraPos.z);
    worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
    for (LaserBeam beam : beamsRender) {
        beam.vcstart = beam.calculateStartpoint();
        beam.vcend = beam.calculateEndpoint();
        beam.vcdist = MathUtils.linePointDistance(beam.vcstart, beam.vcend, cameraPos);
        if (beam.vcdist > maxDist) {
            continue;
        }
        Vec3d startVec = beam.vcstart;
        Vec3d endVec = beam.vcend;
        float t = THICKNESS;
        if (beam.getColor().red)
            t += 0.004f;
        if (beam.getColor().green)
            t += 0.002f;
        if (beam.getColor().blue)
            t += 0.001f;
        if (beam.getStart().getX() == beam.getEnd().getX()) {
            startVec = startVec.addVector(-t / 16.0, 0, 0);
            endVec = endVec.addVector(t / 16.0, 0, 0);
        }
        if (beam.getStart().getY() == beam.getEnd().getY()) {
            startVec = startVec.addVector(0, -t / 16.0, 0);
            endVec = endVec.addVector(0, t / 16.0, 0);
        }
        if (beam.getStart().getZ() == beam.getEnd().getZ()) {
            startVec = startVec.addVector(0, 0, -t / 16.0);
            endVec = endVec.addVector(0, 0, t / 16.0);
        }
        if (!camera.isBoundingBoxInFrustum(new AxisAlignedBB(startVec, endVec))) {
            continue;
        }
        renderedLasers++;
        int color = CharsetLaser.LASER_COLORS[beam.getColor().ordinal()];
        int r = (color >> 16) & 0xFF;
        int g = (color >> 8) & 0xFF;
        int b = color & 0xFF;
        int a = (color >> 24) & 0xFF;
        double[] data = new double[] { startVec.y, endVec.y, startVec.z, endVec.z, startVec.x, endVec.x };
        for (EnumFacing facing : EnumFacing.VALUES) {
            for (int i = 0; i < 4; i++) {
                EnumFaceDirection.VertexInformation vi = EnumFaceDirection.getFacing(facing).getVertexInformation(i);
                worldrenderer.pos(data[vi.xIndex], data[vi.yIndex], data[vi.zIndex]).color(r, g, b, a).endVertex();
            }
        }
    }
    if (Minecraft.getMinecraft().gameSettings.fancyGraphics) {
        tessellator.getBuffer().sortVertexData((float) cameraPos.x, (float) cameraPos.y, (float) cameraPos.z);
    }
    tessellator.draw();
    worldrenderer.setTranslation(0, 0, 0);
    GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GlStateManager.glBlendEquation(GL14.GL_FUNC_ADD);
    GlStateManager.enableTexture2D();
    GlStateManager.disableBlend();
    Minecraft.getMinecraft().mcProfiler.endSection();
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) Frustum(net.minecraft.client.renderer.culling.Frustum) Tessellator(net.minecraft.client.renderer.Tessellator) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) EnumFacing(net.minecraft.util.EnumFacing) ICamera(net.minecraft.client.renderer.culling.ICamera) World(net.minecraft.world.World) Minecraft(net.minecraft.client.Minecraft) EnumFaceDirection(net.minecraft.client.renderer.EnumFaceDirection) Vec3d(net.minecraft.util.math.Vec3d) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

Frustum (net.minecraft.client.renderer.culling.Frustum)3 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)2 Tessellator (net.minecraft.client.renderer.Tessellator)2 ICamera (net.minecraft.client.renderer.culling.ICamera)2 Entity (net.minecraft.entity.Entity)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 BlockStainedGlass (net.minecraft.block.BlockStainedGlass)1 IBlockState (net.minecraft.block.state.IBlockState)1 Minecraft (net.minecraft.client.Minecraft)1 EnumFaceDirection (net.minecraft.client.renderer.EnumFaceDirection)1 EnumDyeColor (net.minecraft.item.EnumDyeColor)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 Vec3d (net.minecraft.util.math.Vec3d)1 World (net.minecraft.world.World)1 LaserColor (pl.asie.charset.api.laser.LaserColor)1 Orientation (pl.asie.charset.lib.utils.Orientation)1