Search in sources :

Example 1 with GL_MODELVIEW

use of org.lwjgl.opengl.GL11.GL_MODELVIEW in project BuildCraft by BuildCraft.

the class GuiZonePlanner method drawForegroundLayer.

@SuppressWarnings("PointlessBitwiseExpression")
@Override
protected void drawForegroundLayer() {
    camY += scaleSpeed;
    scaleSpeed *= 0.7F;
    int posX = (int) positionX;
    int posZ = (int) positionZ;
    int dimension = mc.world.provider.getDimension();
    {
        ChunkPos chunkPos = new ChunkPos(posX >> 4, posZ >> 4);
        ZonePlannerMapChunk zonePlannerMapChunk = ZonePlannerMapDataClient.INSTANCE.getChunk(mc.world, new ZonePlannerMapChunkKey(chunkPos, dimension, container.tile.getLevel()));
        BlockPos pos = null;
        if (zonePlannerMapChunk != null) {
            MapColourData data = zonePlannerMapChunk.getData(posX, posZ);
            if (data != null) {
                pos = new BlockPos(posX, data.posY, posZ);
            }
        }
        if (pos != null && pos.getY() + 10 > camY) {
            camY = Math.max(camY, pos.getY() + 10);
        }
    }
    int x = guiLeft;
    int y = guiTop;
    if (lastSelected != null) {
        String text = "X: " + lastSelected.getX() + " Y: " + lastSelected.getY() + " Z: " + lastSelected.getZ();
        fontRenderer.drawString(text, x + 130, y + 130, 0x404040);
    }
    int offsetX = 8;
    int offsetY = 9;
    int sizeX = 213;
    int sizeY = 100;
    GlStateManager.pushMatrix();
    GlStateManager.matrixMode(GL11.GL_PROJECTION);
    GlStateManager.pushMatrix();
    GlStateManager.loadIdentity();
    ScaledResolution scaledResolution = new ScaledResolution(mc);
    int viewportX = (x + offsetX) * scaledResolution.getScaleFactor();
    int viewportY = mc.displayHeight - (sizeY + y + offsetY) * scaledResolution.getScaleFactor();
    int viewportWidth = sizeX * scaledResolution.getScaleFactor();
    int viewportHeight = sizeY * scaledResolution.getScaleFactor();
    GL11.glEnable(GL11.GL_SCISSOR_TEST);
    GL11.glScissor(viewportX, viewportY, viewportWidth, viewportHeight);
    GlStateManager.clear(GL11.GL_DEPTH_BUFFER_BIT);
    GL11.glDisable(GL11.GL_SCISSOR_TEST);
    GlStateManager.viewport(viewportX, viewportY, viewportWidth, viewportHeight);
    GlStateManager.scale(scaledResolution.getScaleFactor(), scaledResolution.getScaleFactor(), 1);
    GLU.gluPerspective(70.0F, (float) sizeX / sizeY, 1F, 10000.0F);
    GlStateManager.matrixMode(GL11.GL_MODELVIEW);
    GlStateManager.loadIdentity();
    RenderHelper.enableStandardItemLighting();
    GlStateManager.enableRescaleNormal();
    // look down
    GlStateManager.rotate(90, 1, 0, 0);
    GlStateManager.pushMatrix();
    GlStateManager.translate(-positionX, -camY, -positionZ);
    GlStateManager.disableBlend();
    GlStateManager.disableAlpha();
    GlStateManager.disableTexture2D();
    int minScreenX = (x + offsetX) * scaledResolution.getScaleFactor();
    int minScreenY = (scaledResolution.getScaledHeight() - (y + offsetY)) * scaledResolution.getScaleFactor();
    int maxScreenX = (x + offsetX + sizeX) * scaledResolution.getScaleFactor();
    int maxScreenY = (scaledResolution.getScaledHeight() - (y + offsetY + sizeY)) * scaledResolution.getScaleFactor();
    int minChunkX = (posX >> 4) - 8;
    int minChunkZ = (posZ >> 4) - 8;
    int maxChunkX = (posX >> 4) + 8;
    int maxChunkZ = (posZ >> 4) + 8;
    // noinspection SuspiciousNameCombination
    List<ChunkPos> chunkPosBounds = Stream.of(Pair.of(minScreenX, minScreenY), Pair.of(minScreenX, maxScreenY), Pair.of(maxScreenX, minScreenY), Pair.of(maxScreenX, maxScreenY)).map(p -> rayTrace(p.getLeft(), p.getRight())).filter(Objects::nonNull).map(ChunkPos::new).collect(Collectors.toList());
    for (ChunkPos chunkPos : chunkPosBounds) {
        if (chunkPos.x < minChunkX) {
            minChunkX = chunkPos.x;
        }
        if (chunkPos.z < minChunkZ) {
            minChunkZ = chunkPos.z;
        }
        if (chunkPos.x > maxChunkX) {
            maxChunkX = chunkPos.x;
        }
        if (chunkPos.z > maxChunkZ) {
            maxChunkZ = chunkPos.z;
        }
    }
    minChunkX--;
    minChunkZ--;
    maxChunkX++;
    maxChunkZ++;
    for (int chunkX = minChunkX; chunkX <= maxChunkX; chunkX++) {
        for (int chunkZ = minChunkZ; chunkZ <= maxChunkZ; chunkZ++) {
            ZonePlannerMapRenderer.INSTANCE.getChunkGlList(new ZonePlannerMapChunkKey(new ChunkPos(chunkX, chunkZ), dimension, container.tile.getLevel())).ifPresent(GlStateManager::callList);
        }
    }
    BlockPos found = null;
    int foundColor = 0;
    if (Mouse.getX() >= minScreenX && Mouse.getY() <= minScreenY && Mouse.getX() <= maxScreenX && Mouse.getY() >= maxScreenY) {
        found = rayTrace(Mouse.getX(), Mouse.getY());
    }
    if (found != null) {
        ZonePlannerMapChunk zonePlannerMapChunk = ZonePlannerMapDataClient.INSTANCE.getChunk(mc.world, new ZonePlannerMapChunkKey(new ChunkPos(found), mc.world.provider.getDimension(), container.tile.getLevel()));
        if (zonePlannerMapChunk != null) {
            MapColourData data = zonePlannerMapChunk.getData(found.getX(), found.getZ());
            if (data != null) {
                foundColor = data.colour;
            }
        }
    }
    if (found != null) {
        GlStateManager.disableDepth();
        GlStateManager.enableBlend();
        GlStateManager.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
        GlStateManager.glLineWidth(2);
        int r = (int) (((foundColor >> 16) & 0xFF) * 0.7);
        int g = (int) (((foundColor >> 8) & 0xFF) * 0.7);
        int b = (int) (((foundColor >> 0) & 0xFF) * 0.7);
        int a = 0x77;
        ZonePlannerMapRenderer.INSTANCE.setColor(r << 16 | g << 8 | b << 0 | a << 24);
        BufferBuilder builder = Tessellator.getInstance().getBuffer();
        builder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
        ZonePlannerMapRenderer.INSTANCE.drawBlockCuboid(builder, found.getX(), found.getY(), found.getZ());
        Tessellator.getInstance().draw();
        GlStateManager.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
        GlStateManager.disableBlend();
        GlStateManager.enableDepth();
    }
    GlStateManager.disableLighting();
    GlStateManager.enableBlend();
    for (int i = 0; i < container.tile.layers.length; i++) {
        if (getPaintbrushBrush() != null && getPaintbrushBrush().colour.getMetadata() != i) {
            continue;
        }
        ZonePlan layer = container.tile.layers[i];
        if (getPaintbrushBrush() != null && getPaintbrushBrush().colour.getMetadata() == i && bufferLayer != null) {
            layer = bufferLayer;
        }
        if (!layer.getChunkPoses().isEmpty()) {
            Tessellator.getInstance().getBuffer().begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
            for (int chunkX = minChunkX; chunkX <= maxChunkX; chunkX++) {
                for (int chunkZ = minChunkZ; chunkZ <= maxChunkZ; chunkZ++) {
                    ChunkPos chunkPos = new ChunkPos(chunkX, chunkZ);
                    for (int blockX = chunkPos.getXStart(); blockX <= chunkPos.getXEnd(); blockX++) {
                        for (int blockZ = chunkPos.getZStart(); blockZ <= chunkPos.getZEnd(); blockZ++) {
                            if (!layer.get(blockX - container.tile.getPos().getX(), blockZ - container.tile.getPos().getZ())) {
                                continue;
                            }
                            int height;
                            ZonePlannerMapChunk zonePlannerMapChunk = ZonePlannerMapDataClient.INSTANCE.getChunk(mc.world, new ZonePlannerMapChunkKey(chunkPos, dimension, container.tile.getLevel()));
                            if (zonePlannerMapChunk != null) {
                                MapColourData data = zonePlannerMapChunk.getData(blockX, blockZ);
                                if (data != null) {
                                    height = data.posY;
                                } else {
                                    continue;
                                }
                            } else {
                                continue;
                            }
                            int color = EnumDyeColor.byMetadata(i).getColorValue();
                            int r = (color >> 16) & 0xFF;
                            int g = (color >> 8) & 0xFF;
                            int b = (color >> 0) & 0xFF;
                            int a = 0x55;
                            ZonePlannerMapRenderer.INSTANCE.setColor(r << 16 | g << 8 | b << 0 | a << 24);
                            ZonePlannerMapRenderer.INSTANCE.drawBlockCuboid(Tessellator.getInstance().getBuffer(), blockX, height + 0.1, blockZ, height, 0.6);
                        }
                    }
                }
            }
            Tessellator.getInstance().draw();
        }
    }
    GlStateManager.disableBlend();
    GlStateManager.disableLighting();
    GlStateManager.enableTexture2D();
    lastSelected = found;
    GlStateManager.popMatrix();
    GlStateManager.disableRescaleNormal();
    GlStateManager.matrixMode(GL11.GL_PROJECTION);
    GlStateManager.viewport(0, 0, mc.displayWidth, mc.displayHeight);
    GlStateManager.popMatrix();
    GlStateManager.matrixMode(GL11.GL_MODELVIEW);
    GlStateManager.popMatrix();
    RenderHelper.disableStandardItemLighting();
    GlStateManager.disableBlend();
}
Also used : ItemPaintbrush_BC8(buildcraft.core.item.ItemPaintbrush_BC8) FloatBuffer(java.nio.FloatBuffer) ZonePlannerMapChunkKey(buildcraft.robotics.zone.ZonePlannerMapChunkKey) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) Vector3d(javax.vecmath.Vector3d) GuiIcon(buildcraft.lib.gui.GuiIcon) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) ItemStack(net.minecraft.item.ItemStack) GuiBC8(buildcraft.lib.gui.GuiBC8) BCCoreItems(buildcraft.core.BCCoreItems) Pair(org.apache.commons.lang3.tuple.Pair) IntBuffer(java.nio.IntBuffer) RenderHelper(net.minecraft.client.renderer.RenderHelper) GL11(org.lwjgl.opengl.GL11) GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle) ZonePlan(buildcraft.robotics.zone.ZonePlan) GLU(org.lwjgl.util.glu.GLU) ZonePlannerMapChunk(buildcraft.robotics.zone.ZonePlannerMapChunk) ScaledResolution(net.minecraft.client.gui.ScaledResolution) GlStateManager(net.minecraft.client.renderer.GlStateManager) ContainerZonePlanner(buildcraft.robotics.container.ContainerZonePlanner) ZonePlannerMapRenderer(buildcraft.robotics.zone.ZonePlannerMapRenderer) ChunkPos(net.minecraft.util.math.ChunkPos) IOException(java.io.IOException) BlockPos(net.minecraft.util.math.BlockPos) Mouse(org.lwjgl.input.Mouse) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) BufferUtils(org.lwjgl.BufferUtils) List(java.util.List) Stream(java.util.stream.Stream) EnumDyeColor(net.minecraft.item.EnumDyeColor) Tessellator(net.minecraft.client.renderer.Tessellator) ResourceLocation(net.minecraft.util.ResourceLocation) MapColourData(buildcraft.robotics.zone.ZonePlannerMapChunk.MapColourData) ZonePlannerMapDataClient(buildcraft.robotics.zone.ZonePlannerMapDataClient) ZonePlannerMapChunkKey(buildcraft.robotics.zone.ZonePlannerMapChunkKey) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) ZonePlannerMapChunk(buildcraft.robotics.zone.ZonePlannerMapChunk) GlStateManager(net.minecraft.client.renderer.GlStateManager) ScaledResolution(net.minecraft.client.gui.ScaledResolution) ZonePlan(buildcraft.robotics.zone.ZonePlan) Objects(java.util.Objects) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) MapColourData(buildcraft.robotics.zone.ZonePlannerMapChunk.MapColourData)

Aggregations

BCCoreItems (buildcraft.core.BCCoreItems)1 ItemPaintbrush_BC8 (buildcraft.core.item.ItemPaintbrush_BC8)1 GuiBC8 (buildcraft.lib.gui.GuiBC8)1 GuiIcon (buildcraft.lib.gui.GuiIcon)1 GuiRectangle (buildcraft.lib.gui.pos.GuiRectangle)1 ContainerZonePlanner (buildcraft.robotics.container.ContainerZonePlanner)1 ZonePlan (buildcraft.robotics.zone.ZonePlan)1 ZonePlannerMapChunk (buildcraft.robotics.zone.ZonePlannerMapChunk)1 MapColourData (buildcraft.robotics.zone.ZonePlannerMapChunk.MapColourData)1 ZonePlannerMapChunkKey (buildcraft.robotics.zone.ZonePlannerMapChunkKey)1 ZonePlannerMapDataClient (buildcraft.robotics.zone.ZonePlannerMapDataClient)1 ZonePlannerMapRenderer (buildcraft.robotics.zone.ZonePlannerMapRenderer)1 IOException (java.io.IOException)1 FloatBuffer (java.nio.FloatBuffer)1 IntBuffer (java.nio.IntBuffer)1 List (java.util.List)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Vector3d (javax.vecmath.Vector3d)1