Search in sources :

Example 6 with Vertex

use of com.enderio.core.common.vecmath.Vertex in project EnderIO by SleepyTrousers.

the class IoDisplay method render.

@Override
public void render(@Nonnull TileCapBank cb, @Nonnull EnumFacing dir, float partialTick) {
    if (dir.getFrontOffsetY() != 0) {
        return;
    }
    CapBankClientNetwork nw = (CapBankClientNetwork) cb.getNetwork();
    if (nw == null) {
        return;
    }
    CapBankClientNetwork.IOInfo info = nw.getIODisplayInfo(cb.getPos(), dir);
    if (info.isInside()) {
        return;
    }
    int i = cb.getWorld().getCombinedLight(cb.getPos().offset(dir), 0);
    int j = i % 65536;
    int k = i / 65536;
    OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, j / 1.0F, k / 1.0F);
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    GlStateManager.enablePolygonOffset();
    GlStateManager.doPolygonOffset(-1.0f, -1.0f);
    boolean drawBackground = true;
    if (drawBackground) {
        RenderUtil.bindBlockTexture();
        float scale = 0.85f;
        float offset = (1 - scale) / 2;
        TextureAtlasSprite icon = BlockCapBank.getInfoPanelIcon();
        float minU = icon.getMinU();
        float maxU = icon.getMaxU();
        float minV = icon.getMinV();
        float maxV = icon.getMaxV();
        List<Vertex> vertices = new ArrayList<Vertex>();
        switch(dir) {
            case NORTH:
                {
                    float y0 = offset - (info.height - 1);
                    float y1 = 1 - offset;
                    float x0 = offset;
                    float x1 = info.width - offset;
                    float z0 = 0;
                    vertices.add(new Vertex(x1, y0, z0, minU, minV, 0f, 0f, -1f));
                    vertices.add(new Vertex(x0, y0, z0, maxU, minV, 0f, 0f, -1f));
                    vertices.add(new Vertex(x0, y1, z0, maxU, maxV, 0f, 0f, -1f));
                    vertices.add(new Vertex(x1, y1, z0, minU, maxV, 0f, 0f, -1f));
                    break;
                }
            case SOUTH:
                {
                    float y0 = offset - (info.height - 1);
                    float y1 = 1 - offset;
                    float x0 = offset - (info.width - 1);
                    float x1 = 1 - offset;
                    float z1 = 1;
                    vertices.add(new Vertex(x0, y0, z1, maxU, minV, 0f, 0f, 1f));
                    vertices.add(new Vertex(x1, y0, z1, minU, minV, 0f, 0f, 1f));
                    vertices.add(new Vertex(x1, y1, z1, minU, maxV, 0f, 0f, 1f));
                    vertices.add(new Vertex(x0, y1, z1, maxU, maxV, 0f, 0f, 1f));
                    break;
                }
            case EAST:
                {
                    float y0 = offset - (info.height - 1);
                    float y1 = 1 - offset;
                    float z0 = offset;
                    float z1 = info.width - offset;
                    float x1 = 1;
                    vertices.add(new Vertex(x1, y1, z0, maxU, maxV, 1f, 0f, 0f));
                    vertices.add(new Vertex(x1, y1, z1, minU, maxV, 1f, 0f, 0f));
                    vertices.add(new Vertex(x1, y0, z1, minU, minV, 1f, 0f, 0f));
                    vertices.add(new Vertex(x1, y0, z0, maxU, minV, 1f, 0f, 0f));
                    break;
                }
            case WEST:
                {
                    float y0 = offset - (info.height - 1);
                    float y1 = 1 - offset;
                    float z0 = offset - (info.width - 1);
                    float z1 = 1 - offset;
                    float x0 = 0;
                    vertices.add(new Vertex(x0, y0, z0, maxU, minV, -1f, 0f, 0f));
                    vertices.add(new Vertex(x0, y0, z1, minU, minV, -1f, 0f, 0f));
                    vertices.add(new Vertex(x0, y1, z1, minU, maxV, -1f, 0f, 0f));
                    vertices.add(new Vertex(x0, y1, z0, maxU, maxV, -1f, 0f, 0f));
                    break;
                }
            default:
                throw new AssertionError();
        }
        GlStateManager.color(1, 1, 1);
        RenderUtil.addVerticesToTessellator(vertices, DefaultVertexFormats.POSITION_TEX_NORMAL, true);
        Tessellator.getInstance().draw();
    }
    nw.requestPowerUpdate(cb, 20);
    HeadingText heading1 = HeadingText.STABLE;
    HeadingText heading2 = null;
    String text1;
    String text2 = "";
    FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
    float size = 0.15f * Math.min(info.width, info.height);
    float scale = size / fr.FONT_HEIGHT;
    float offset;
    if (info.height * 3 >= info.width * 4) {
        heading1 = HeadingText.INPUT;
        heading2 = HeadingText.OUTPUT;
        text1 = getChangeText(nw.getAverageInputPerTick(), fr);
        text2 = getChangeText(nw.getAverageOutputPerTick(), fr);
        offset = -size * 2.5f;
    } else {
        int change = Math.round(nw.getAverageChangePerTick());
        if (change > 0) {
            heading1 = HeadingText.GAIN;
        } else if (change < 0) {
            heading1 = HeadingText.LOSS;
        }
        text1 = getChangeText(change, fr);
        offset = -size;
    }
    EnumFacing right = dir.rotateAround(EnumFacing.Axis.Y);
    GlStateManager.pushMatrix();
    GlStateManager.translate((dir.getFrontOffsetX() * 1.02f) / 2 + 0.5f + right.getFrontOffsetX() * (info.width - 1) * 0.5f, 1 + size * 0.5f - info.height * 0.5f, (dir.getFrontOffsetZ() * 1.02f) / 2 + 0.5f + right.getFrontOffsetZ() * (info.width - 1) * 0.5f);
    GlStateManager.rotate(-180, 1, 0, 0);
    if (dir == EnumFacing.NORTH) {
        GlStateManager.rotate(-180, 0, 1, 0);
    } else if (dir == EnumFacing.EAST) {
        GlStateManager.rotate(-90, 0, 1, 0);
    } else if (dir == EnumFacing.WEST) {
        GlStateManager.rotate(90, 0, 1, 0);
    }
    GlStateManager.enableLighting();
    GlStateManager.enableBlend();
    GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
    offset = drawText(heading1, text1, offset, scale, size, fr);
    if (heading2 != null) {
        drawText(heading2, text2, offset, scale, size, fr);
    }
    RenderUtil.bindBlockTexture();
    GlStateManager.disableBlend();
    GlStateManager.disablePolygonOffset();
    GlStateManager.popMatrix();
}
Also used : CapBankClientNetwork(crazypants.enderio.powertools.machine.capbank.network.CapBankClientNetwork) Vertex(com.enderio.core.common.vecmath.Vertex) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) FontRenderer(net.minecraft.client.gui.FontRenderer)

Example 7 with Vertex

use of com.enderio.core.common.vecmath.Vertex in project EnderIO by SleepyTrousers.

the class LiquidConduitRenderer method computeFluidOutlineToCache.

public static List<CachableRenderStatement> computeFluidOutlineToCache(CollidableComponent component, Fluid fluid, double scaleFactor, float outlineWidth) {
    Map<Fluid, List<CachableRenderStatement>> cache0 = cache.get(component);
    if (cache0 == null) {
        cache0 = new HashMap<Fluid, List<CachableRenderStatement>>();
        cache.put(component, cache0);
    }
    List<CachableRenderStatement> data = cache0.get(fluid);
    if (data != null) {
        return data;
    }
    data = new ArrayList<CachableRenderStatement>();
    cache0.put(fluid, data);
    TextureAtlasSprite texture = RenderUtil.getStillTexture(fluid);
    if (texture == null) {
        return data;
    }
    int color = fluid.getColor();
    Vector4f colorv = new Vector4f((color >> 16 & 0xFF) / 255d, (color >> 8 & 0xFF) / 255d, (color & 0xFF) / 255d, 1);
    BoundingBox bbb;
    double width = outlineWidth;
    scaleFactor = scaleFactor - 0.05;
    double xScale = Math.abs(component.dir.getFrontOffsetX()) == 1 ? width : scaleFactor;
    double yScale = Math.abs(component.dir.getFrontOffsetY()) == 1 ? width : scaleFactor;
    double zScale = Math.abs(component.dir.getFrontOffsetZ()) == 1 ? width : scaleFactor;
    double offSize = (0.5 - width) / 2 - width / 2;
    double xOff = component.dir.getFrontOffsetX() * offSize;
    double yOff = component.dir.getFrontOffsetY() * offSize;
    double zOff = component.dir.getFrontOffsetZ() * offSize;
    bbb = component.bound.scale(xScale, yScale, zScale);
    bbb = bbb.translate(new Vector3d(xOff, yOff, zOff));
    for (EnumFacing face : EnumFacing.VALUES) {
        if (face != component.dir && face != component.dir.getOpposite()) {
            List<Vertex> corners = bbb.getCornersWithUvForFace(face, texture.getMinU(), texture.getMaxU(), texture.getMinV(), texture.getMaxV());
            for (Vertex corner : corners) {
                data.add(new CachableRenderStatement.AddVertexWithUV(corner.x(), corner.y(), corner.z(), corner.uv.x, corner.uv.y, colorv));
            }
        }
    }
    return data;
}
Also used : Vertex(com.enderio.core.common.vecmath.Vertex) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Fluid(net.minecraftforge.fluids.Fluid) EnumFacing(net.minecraft.util.EnumFacing) Vector4f(com.enderio.core.common.vecmath.Vector4f) Vector3d(com.enderio.core.common.vecmath.Vector3d) BoundingBox(com.enderio.core.client.render.BoundingBox) ArrayList(java.util.ArrayList) List(java.util.List)

Example 8 with Vertex

use of com.enderio.core.common.vecmath.Vertex in project EnderIO by SleepyTrousers.

the class DefaultConduitRenderer method renderConduitDynamic.

protected void renderConduitDynamic(TextureAtlasSprite tex, IClientConduit.WithDefaultRendering conduit, CollidableComponent component, float brightness) {
    GlStateManager.color(1, 1, 1);
    if (isNSEWUD(component.dir)) {
        float scaleFactor = 0.75f;
        float xLen = Math.abs(component.dir.getFrontOffsetX()) == 1 ? 1 : scaleFactor;
        float yLen = Math.abs(component.dir.getFrontOffsetY()) == 1 ? 1 : scaleFactor;
        float zLen = Math.abs(component.dir.getFrontOffsetZ()) == 1 ? 1 : scaleFactor;
        BoundingBox cube = component.bound;
        BoundingBox bb = cube.scale(xLen, yLen, zLen);
        drawDynamicSection(bb, tex.getMinU(), tex.getMaxU(), tex.getMinV(), tex.getMaxV(), component.dir, false, conduit.shouldMirrorTexture());
        if (conduit.getConnectionMode(component.dir) == ConnectionMode.DISABLED) {
            tex = ConduitBundleRenderManager.instance.getConnectorIcon(component.data);
            List<Vertex> corners = component.bound.getCornersWithUvForFace(component.dir, tex.getMinU(), tex.getMaxU(), tex.getMinV(), tex.getMaxV());
            RenderUtil.addVerticesToTessellator(corners, DefaultVertexFormats.POSITION_TEX, false);
        }
    } else {
        drawDynamicSection(component.bound, tex.getMinU(), tex.getMaxU(), tex.getMinV(), tex.getMaxV(), component.dir, true);
    }
}
Also used : Vertex(com.enderio.core.common.vecmath.Vertex) BoundingBox(com.enderio.core.client.render.BoundingBox)

Example 9 with Vertex

use of com.enderio.core.common.vecmath.Vertex in project EnderIO by SleepyTrousers.

the class ReservoirRenderer method renderFace.

public static void renderFace(@Nonnull BufferBuilder tes, @Nonnull BoundingBox bb, @Nonnull EnumFacing face, float minU, float maxU, float minV, float maxV, int color) {
    // LightUtil.diffuseLight(face);
    float d = 1f;
    float r = d * ((color >> 16) & 0xFF) / 255f, g = d * ((color >> 8) & 0xFF) / 255f, b = d * (color & 0xFF) / 255f, a = ((color >> 24) & 0xFF) / 255f;
    List<Vertex> corners = bb.getCornersWithUvForFace(face, minU, maxU, minV, maxV);
    for (Vertex v : corners) {
        tes.pos(v.x(), v.y(), v.z()).tex(v.u(), v.v()).color(r, g, b, a).normal(v.nx(), v.ny(), v.nz()).endVertex();
    }
}
Also used : Vertex(com.enderio.core.common.vecmath.Vertex)

Example 10 with Vertex

use of com.enderio.core.common.vecmath.Vertex in project EnderIO by SleepyTrousers.

the class AdvancedLiquidConduitRenderer method getClosest.

private int[] getClosest(EnumFacing edge, List<Vertex> vertices) {
    int[] res = new int[] { -1, -1 };
    boolean highest = edge.getFrontOffsetX() > 0 || edge.getFrontOffsetY() > 0 || edge.getFrontOffsetZ() > 0;
    double minMax = highest ? -Double.MAX_VALUE : Double.MAX_VALUE;
    int index = 0;
    for (Vertex v : vertices) {
        double val = get(v.xyz, edge);
        if (highest ? val >= minMax : val <= minMax) {
            if (val != minMax) {
                res[0] = index;
            } else {
                res[1] = index;
            }
            minMax = val;
        }
        index++;
    }
    return res;
}
Also used : Vertex(com.enderio.core.common.vecmath.Vertex)

Aggregations

Vertex (com.enderio.core.common.vecmath.Vertex)10 ArrayList (java.util.ArrayList)5 BoundingBox (com.enderio.core.client.render.BoundingBox)4 Vector3d (com.enderio.core.common.vecmath.Vector3d)4 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)4 EnumFacing (net.minecraft.util.EnumFacing)4 Vector4f (com.enderio.core.common.vecmath.Vector4f)2 Offset (crazypants.enderio.base.conduit.geom.Offset)1 CapBankClientNetwork (crazypants.enderio.powertools.machine.capbank.network.CapBankClientNetwork)1 List (java.util.List)1 Nonnull (javax.annotation.Nonnull)1 FontRenderer (net.minecraft.client.gui.FontRenderer)1 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)1 Fluid (net.minecraftforge.fluids.Fluid)1 FluidStack (net.minecraftforge.fluids.FluidStack)1