Search in sources :

Example 1 with WorldRenderer

use of net.minecraft.client.renderer.WorldRenderer in project watson by totemo.

the class Annotation method drawBillboard.

// --------------------------------------------------------------------------
/**
   * Draw a camera-facing text billboard in three dimensions.
   *
   * @param x the x world coordinate.
   * @param y the y world coordinate.
   * @param z the z world coordinate.
   * @param bgARGB the background colour of the billboard, with alpha in the top
   *          8 bits, then red, green, blue in less significant octets (blue in
   *          the least significant 8 bits).
   * @param fgARGB the foreground (text) colour of the billboard, with alpha in
   *          the top 8 bits, then red, green, blue in less significant octets
   *          (blue in the least significant 8 bits).
   * @param scaleFactor a scale factor to adjust the size of the billboard. Try
   *          0.02.
   * @param text the text on the billboard.
   */
public static void drawBillboard(double x, double y, double z, int bgARGB, int fgARGB, double scaleFactor, String text) {
    RenderManager renderManager = Minecraft.getMinecraft().getRenderManager();
    FontRenderer fontRenderer = renderManager.getFontRenderer();
    if (fontRenderer == null) {
        // Not ready yet.
        return;
    }
    Minecraft mc = Minecraft.getMinecraft();
    // (512 >> mc.gameSettings.renderDistance) * 0.8;
    double far = mc.gameSettings.renderDistanceChunks * 16;
    double dx = x - PrivateFieldsWatson.renderPosX.get(renderManager) + 0.5d;
    double dy = y - PrivateFieldsWatson.renderPosY.get(renderManager) + 0.5d;
    double dz = z - PrivateFieldsWatson.renderPosZ.get(renderManager) + 0.5d;
    double distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
    double dl = distance;
    if (dl > far) {
        double d = far / dl;
        dx *= d;
        dy *= d;
        dz *= d;
        dl = far;
    }
    GlStateManager.pushMatrix();
    double scale = (0.05 * dl + 1.0) * scaleFactor;
    GlStateManager.translate(dx, dy, dz);
    GlStateManager.rotate(-renderManager.playerViewY, 0.0f, 1.0f, 0.0f);
    GlStateManager.rotate(mc.gameSettings.thirdPersonView != 2 ? renderManager.playerViewX : -renderManager.playerViewX, 1.0f, 0.0f, 0.0f);
    GlStateManager.scale(-scale, -scale, scale);
    GlStateManager.disableLighting();
    GlStateManager.enableBlend();
    GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    Tessellator tessellator = Tessellator.getInstance();
    WorldRenderer wr = tessellator.getWorldRenderer();
    int textWidth = fontRenderer.getStringWidth(text) >> 1;
    if (textWidth != 0) {
        GlStateManager.disableTexture2D();
        GlStateManager.disableDepth();
        GlStateManager.depthMask(false);
        // Draw background plate.
        wr.startDrawingQuads();
        wr.setColorRGBA_I(bgARGB & 0x00FFFFFF, (bgARGB >>> 24) & 0xFF);
        wr.addVertex(-textWidth - 1, -6, 0.0);
        wr.addVertex(-textWidth - 1, 4, 0.0);
        wr.addVertex(textWidth + 1, 4, 0.0);
        wr.addVertex(textWidth + 1, -6, 0.0);
        tessellator.draw();
        // Draw text.
        GlStateManager.enableTexture2D();
        GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
        fontRenderer.drawString(text, -textWidth, -5, fgARGB);
        GlStateManager.enableDepth();
        GlStateManager.depthMask(true);
    }
    GlStateManager.disableBlend();
    GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
    GlStateManager.enableTexture2D();
    GlStateManager.enableLighting();
    GlStateManager.popMatrix();
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) FontRenderer(net.minecraft.client.gui.FontRenderer) RenderManager(net.minecraft.client.renderer.entity.RenderManager) Minecraft(net.minecraft.client.Minecraft) WorldRenderer(net.minecraft.client.renderer.WorldRenderer)

Example 2 with WorldRenderer

use of net.minecraft.client.renderer.WorldRenderer in project watson by totemo.

the class PlantBlockModel method render.

// --------------------------------------------------------------------------
/**
   * @see watson.model.BlockModel#render(watson.db.BlockType, int, int, int)
   */
@Override
public void render(BlockType blockType, int x, int y, int z) {
    Tessellator tess = Tessellator.getInstance();
    WorldRenderer wr = tess.getWorldRenderer();
    double x1 = x + blockType.getX1();
    double y1 = y + blockType.getY1();
    double z1 = z + blockType.getZ1();
    double x2 = x + blockType.getX2();
    double y2 = y + blockType.getY2();
    double z2 = z + blockType.getZ2();
    // First rectangle.
    wr.startDrawing(GL11.GL_LINE_LOOP);
    wr.setColorRGBA(blockType.getARGB().getRed(), blockType.getARGB().getGreen(), blockType.getARGB().getBlue(), blockType.getARGB().getAlpha());
    GL11.glLineWidth(blockType.getLineWidth());
    wr.addVertex(x1, y1, z1);
    wr.addVertex(x2, y1, z2);
    wr.addVertex(x2, y2, z2);
    wr.addVertex(x1, y2, z1);
    tess.draw();
    // Second rectangle.
    wr.startDrawing(GL11.GL_LINE_LOOP);
    wr.setColorRGBA(blockType.getARGB().getRed(), blockType.getARGB().getGreen(), blockType.getARGB().getBlue(), blockType.getARGB().getAlpha());
    GL11.glLineWidth(blockType.getLineWidth());
    wr.addVertex(x1, y1, z2);
    wr.addVertex(x2, y1, z1);
    wr.addVertex(x2, y2, z1);
    wr.addVertex(x1, y2, z2);
    tess.draw();
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) WorldRenderer(net.minecraft.client.renderer.WorldRenderer)

Example 3 with WorldRenderer

use of net.minecraft.client.renderer.WorldRenderer in project watson by totemo.

the class StairBlockModel method render.

// --------------------------------------------------------------------------
/**
   * @see watson.model.BlockModel#render(watson.db.BlockType, int, int, int)
   */
@Override
public void render(BlockType blockType, int x, int y, int z) {
    Tessellator tess = Tessellator.getInstance();
    WorldRenderer wr = tess.getWorldRenderer();
    // Opposite corners.
    double x1 = x + blockType.getX1();
    double y1 = y + blockType.getY1();
    double z1 = z + blockType.getZ1();
    double x2 = x + blockType.getX2();
    double y2 = y + blockType.getY2();
    double z2 = z + blockType.getZ2();
    // Concave corner, mid-stair.
    double yMid = y + 0.5 * (blockType.getY1() + blockType.getY2());
    double zMid = z + 0.5 * (blockType.getZ1() + blockType.getZ2());
    // x1 side.
    wr.startDrawing(GL11.GL_LINE_LOOP);
    wr.setColorRGBA(blockType.getARGB().getRed(), blockType.getARGB().getGreen(), blockType.getARGB().getBlue(), blockType.getARGB().getAlpha());
    GL11.glLineWidth(blockType.getLineWidth());
    wr.addVertex(x1, y1, z1);
    wr.addVertex(x1, y1, z2);
    wr.addVertex(x1, y2, z2);
    wr.addVertex(x1, y2, zMid);
    wr.addVertex(x1, yMid, zMid);
    wr.addVertex(x1, yMid, z1);
    tess.draw();
    // x2 side.
    wr.startDrawing(GL11.GL_LINE_LOOP);
    wr.setColorRGBA(blockType.getARGB().getRed(), blockType.getARGB().getGreen(), blockType.getARGB().getBlue(), blockType.getARGB().getAlpha());
    GL11.glLineWidth(blockType.getLineWidth());
    wr.addVertex(x2, y1, z1);
    wr.addVertex(x2, y1, z2);
    wr.addVertex(x2, y2, z2);
    wr.addVertex(x2, y2, zMid);
    wr.addVertex(x2, yMid, zMid);
    wr.addVertex(x2, yMid, z1);
    tess.draw();
    // Horizontal lines joining the two sides.
    wr.startDrawing(GL11.GL_LINES);
    wr.setColorRGBA(blockType.getARGB().getRed(), blockType.getARGB().getGreen(), blockType.getARGB().getBlue(), blockType.getARGB().getAlpha());
    GL11.glLineWidth(blockType.getLineWidth());
    wr.addVertex(x1, y1, z1);
    wr.addVertex(x2, y1, z1);
    wr.addVertex(x1, y1, z2);
    wr.addVertex(x2, y1, z2);
    wr.addVertex(x1, y2, z2);
    wr.addVertex(x2, y2, z2);
    wr.addVertex(x1, y2, zMid);
    wr.addVertex(x2, y2, zMid);
    wr.addVertex(x1, yMid, zMid);
    wr.addVertex(x2, yMid, zMid);
    wr.addVertex(x1, yMid, z1);
    wr.addVertex(x2, yMid, z1);
    tess.draw();
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) WorldRenderer(net.minecraft.client.renderer.WorldRenderer)

Example 4 with WorldRenderer

use of net.minecraft.client.renderer.WorldRenderer in project watson by totemo.

the class Controller method drawSelection.

// --------------------------------------------------------------------------
/**
   * Draw a cursor at the currently selected position.
   */
public void drawSelection() {
    if (_selection != null && getDisplaySettings().isSelectionShown()) {
        Tessellator tess = Tessellator.getInstance();
        WorldRenderer wr = tess.getWorldRenderer();
        wr.startDrawing(GL11.GL_LINES);
        wr.setColorRGBA(255, 0, 255, 128);
        GL11.glLineWidth(4.0f);
        final float halfSize = 0.3f;
        float x = _selection.x + 0.5f;
        float y = _selection.y + 0.5f;
        float z = _selection.z + 0.5f;
        wr.addVertex(x - halfSize, y, z);
        wr.addVertex(x + halfSize, y, z);
        wr.addVertex(x, y - halfSize, z);
        wr.addVertex(x, y + halfSize, z);
        wr.addVertex(x, y, z - halfSize);
        wr.addVertex(x, y, z + halfSize);
        tess.draw();
        if (_selection.playerEditSet != null) {
            BlockEdit predecessor = _selection.playerEditSet.getEditBefore(_selection);
            if (predecessor != null) {
                wr.startDrawing(GL11.GL_LINES);
                wr.setColorRGBA(255, 0, 255, 128);
                GL11.glEnable(GL11.GL_LINE_STIPPLE);
                GL11.glLineStipple(8, (short) 0xAAAA);
                GL11.glLineWidth(3.0f);
                wr.addVertex(predecessor.x + 0.5f, predecessor.y + 0.5f, predecessor.z + 0.5f);
                wr.addVertex(x, y, z);
                tess.draw();
                GL11.glDisable(GL11.GL_LINE_STIPPLE);
            }
        }
    }
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) BlockEdit(watson.db.BlockEdit) WorldRenderer(net.minecraft.client.renderer.WorldRenderer)

Example 5 with WorldRenderer

use of net.minecraft.client.renderer.WorldRenderer in project CodeChickenLib by Chicken-Bones.

the class RenderUtils method renderFluidQuad.

/**
     * Draws a tessellated quadrilateral bottom to top, left to right
     *
     * @param base The bottom left corner of the quad
     * @param wide The bottom of the quad
     * @param high The left side of the quad
     * @param res  Units per icon
     */
public static void renderFluidQuad(Vector3 base, Vector3 wide, Vector3 high, TextureAtlasSprite icon, double res) {
    WorldRenderer r = Tessellator.getInstance().getWorldRenderer();
    double u1 = icon.getMinU();
    double du = icon.getMaxU() - icon.getMinU();
    double v2 = icon.getMaxV();
    double dv = icon.getMaxV() - icon.getMinV();
    double wlen = wide.mag();
    double hlen = high.mag();
    double x = 0;
    while (x < wlen) {
        double rx = wlen - x;
        if (rx > res)
            rx = res;
        double y = 0;
        while (y < hlen) {
            double ry = hlen - y;
            if (ry > res)
                ry = res;
            Vector3 dx1 = vectors[2].set(wide).multiply(x / wlen);
            Vector3 dx2 = vectors[3].set(wide).multiply((x + rx) / wlen);
            Vector3 dy1 = vectors[4].set(high).multiply(y / hlen);
            Vector3 dy2 = vectors[5].set(high).multiply((y + ry) / hlen);
            r.pos(base.x + dx1.x + dy2.x, base.y + dx1.y + dy2.y, base.z + dx1.z + dy2.z).tex(u1, v2 - ry / res * dv).endVertex();
            r.pos(base.x + dx1.x + dy1.x, base.y + dx1.y + dy1.y, base.z + dx1.z + dy1.z).tex(u1, v2).endVertex();
            r.pos(base.x + dx2.x + dy1.x, base.y + dx2.y + dy1.y, base.z + dx2.z + dy1.z).tex(u1 + rx / res * du, v2).endVertex();
            r.pos(base.x + dx2.x + dy2.x, base.y + dx2.y + dy2.y, base.z + dx2.z + dy2.z).tex(u1 + rx / res * du, v2 - ry / res * dv).endVertex();
            y += ry;
        }
        x += rx;
    }
}
Also used : Vector3(codechicken.lib.vec.Vector3) WorldRenderer(net.minecraft.client.renderer.WorldRenderer)

Aggregations

WorldRenderer (net.minecraft.client.renderer.WorldRenderer)12 Tessellator (net.minecraft.client.renderer.Tessellator)8 Vector3 (codechicken.lib.vec.Vector3)1 Minecraft (net.minecraft.client.Minecraft)1 FontRenderer (net.minecraft.client.gui.FontRenderer)1 RenderManager (net.minecraft.client.renderer.entity.RenderManager)1 Vec3 (net.minecraft.util.Vec3)1 DisplaySettings (watson.DisplaySettings)1 BlockEdit (watson.db.BlockEdit)1