Search in sources :

Example 1 with Vector4f

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

the class TankRenderHelper method mkTank.

/**
 * Generate a cube of liquid for a SmartTank.
 *
 * @param tank
 *          The tank that contains the liquid.
 * @param xzBorder
 *          How many pixels of space to leave around the y and z sides. (0-7.99)
 * @param miny
 *          Height to start the tank. (0-15.99)
 * @param maxy
 *          Height to end the tank (0.01-16)
 * @param renderBottom
 *          Render the bottom face?
 * @return A HalfBakedList with the tank content or null if the tank is empty
 */
public static HalfBakedList mkTank(SmartTank tank, double xzBorder, double miny, double maxy, boolean renderBottom) {
    if (tank != null) {
        float ratio = tank.getFilledRatio();
        final FluidStack fluid = tank.getFluid();
        if (fluid != null && ratio > 0) {
            float height = 1 - ratio;
            ResourceLocation still = fluid.getFluid().getStill(fluid);
            int color = fluid.getFluid().getColor(fluid);
            Vector4f vecC = new Vector4f((color >> 16 & 0xFF) / 255d, (color >> 8 & 0xFF) / 255d, (color & 0xFF) / 255d, 1);
            TextureAtlasSprite sprite = still == null ? null : Minecraft.getMinecraft().getTextureMapBlocks().getTextureExtry(still.toString());
            if (sprite == null) {
                sprite = Minecraft.getMinecraft().getTextureMapBlocks().getMissingSprite();
                vecC = null;
            }
            boolean gas = fluid.getFluid().isGaseous(fluid);
            BoundingBox bb = gas ? new BoundingBox(xzBorder * px, (maxy - (maxy - miny) * ratio) * px, xzBorder * px, (16 - xzBorder) * px, maxy * px, (16 - xzBorder) * px) : new BoundingBox(xzBorder * px, miny * px, xzBorder * px, (16 - xzBorder) * px, ((maxy - miny) * ratio + miny) * px, (16 - xzBorder) * px);
            HalfBakedList buffer = new HalfBakedList();
            buffer.add(bb, EnumFacing.NORTH, 0f, 1f, height, 1f, sprite, vecC, gas);
            buffer.add(bb, EnumFacing.EAST, 0f, 1f, height, 1f, sprite, vecC, gas);
            buffer.add(bb, EnumFacing.SOUTH, 0f, 1f, height, 1f, sprite, vecC, gas);
            buffer.add(bb, EnumFacing.WEST, 0f, 1f, height, 1f, sprite, vecC, gas);
            if (!gas || renderBottom) {
                buffer.add(bb, EnumFacing.UP, 0f, 1f, 0f, 1f, sprite, vecC);
            }
            if (gas || renderBottom) {
                buffer.add(bb, EnumFacing.DOWN, 0f, 1f, 0f, 1f, sprite, vecC);
            }
            return buffer;
        }
    }
    return null;
}
Also used : Vector4f(com.enderio.core.common.vecmath.Vector4f) FluidStack(net.minecraftforge.fluids.FluidStack) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ResourceLocation(net.minecraft.util.ResourceLocation) BoundingBox(com.enderio.core.client.render.BoundingBox) HalfBakedList(crazypants.enderio.base.render.util.HalfBakedQuad.HalfBakedList)

Example 2 with Vector4f

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

the class YetaWrenchOverlayRenderer method doRenderOverlay.

private void doRenderOverlay(@Nonnull RenderGameOverlayEvent event, @Nonnull ItemStack equippedWrench) {
    ConduitDisplayMode mode = ConduitDisplayMode.getDisplayMode(equippedWrench);
    if (mode != cachedMode) {
        cachedMode = mode;
        displayTickCount = 20;
        lastTick = ClientHandler.getTicksElapsed();
    }
    ScaledResolution res = event.getResolution();
    int modeCount = ConduitDisplayMode.registrySize();
    Iterable<ConduitDisplayMode> renderable = ConduitDisplayMode.getRenderableModes();
    switch(PersonalConfig.yetaOverlayMode.get()) {
        case 0:
            if (displayTickCount > 0) {
                if (lastTick < ClientHandler.getTicksElapsed()) {
                    lastTick++;
                    displayTickCount--;
                }
                int x = res.getScaledWidth() / 2 - 8;
                int y = res.getScaledHeight() / 2 - 24;
                IWidgetIcon widget = mode.getWidgetSelected();
                RenderUtil.bindTexture(widget.getMap().getTexture());
                widget.getMap().render(widget, x, y, true);
                int size = 12;
                widget = mode.previous().getWidgetSelected();
                RenderUtil.bindTexture(widget.getMap().getTexture());
                widget.getMap().render(widget, x - 18 + (16 - size), y + (16 - size), size, size, 0, true);
                widget = mode.next().getWidgetSelected();
                RenderUtil.bindTexture(widget.getMap().getTexture());
                widget.getMap().render(widget, x + 18, y + (16 - size), size, size, 0, true);
            } else {
                int x = res.getScaledWidth() - 20;
                int y = res.getScaledHeight() - 20;
                IWidgetIcon widget = mode.getWidgetSelected();
                RenderUtil.bindTexture(widget.getMap().getTexture());
                widget.getMap().render(widget, x, y, true);
            }
            break;
        case 1:
            int size = 16;
            int padding = 2;
            int inset = (int) (size / 1.5);
            int offsetX = res.getScaledWidth() - inset - 1;
            int offsetY = res.getScaledHeight() - modeCount * (size + padding) - padding;
            inset = size - inset;
            int x = offsetX + 2;
            int y = offsetY - (padding * 2);
            int height = (modeCount * (size + padding)) + (padding * 3);
            // FIXME
            GL11.glDisable(GL11.GL_TEXTURE_2D);
            GL11.glShadeModel(GL11.GL_SMOOTH);
            VertexFormat vf = DefaultVertexFormats.POSITION_COLOR;
            Tessellator tess = Tessellator.getInstance();
            BufferBuilder wr = tess.getBuffer();
            wr.begin(GL11.GL_QUADS, vf);
            wr.pos(x, y, -5).color(0, 0, 0, 0.2f).endVertex();
            ;
            wr.pos(x, y + height, -5).color(0, 0, 0, 0.2f).endVertex();
            ;
            Vector4f color = new Vector4f(0, 0, 0, 1);
            wr.pos(x + size, y + height, -5).color(color.x, color.y, color.z, color.w).endVertex();
            wr.pos(x + size, y, -5).color(color.x, color.y, color.z, color.w).endVertex();
            tess.draw();
            GlStateManager.color(1, 1, 1);
            GL11.glShadeModel(GL11.GL_FLAT);
            y += padding * 2;
            x -= 2;
            if (mode == ConduitDisplayMode.ALL) {
                x -= inset;
            }
            GL11.glEnable(GL11.GL_TEXTURE_2D);
            for (ConduitDisplayMode toRender : renderable) {
                IWidgetIcon widget = mode == ConduitDisplayMode.ALL ? toRender.getWidgetSelected() : toRender.getWidgetUnselected();
                RenderUtil.bindTexture(widget.getMap().getTexture());
                if (toRender == mode) {
                    widget = toRender.getWidgetSelected();
                    widget.getMap().render(widget, x - inset, y, true);
                } else {
                    widget.getMap().render(widget, x, y, true);
                }
                y += size + padding;
            }
            break;
        case 2:
            offsetX = res.getScaledWidth() - (modeCount * 8) - 16;
            y = res.getScaledHeight() - 40;
            x = offsetX;
            if (modeCount % 2 == 1) {
                x += 8;
            }
            int count = 0;
            for (ConduitDisplayMode toRender : renderable) {
                IWidgetIcon widget = mode == ConduitDisplayMode.ALL || toRender == mode ? toRender.getWidgetSelected() : toRender.getWidgetUnselected();
                RenderUtil.bindTexture(widget.getMap().getTexture());
                widget.getMap().render(widget, x, y, true);
                x += 16;
                if (count == modeCount / 2 - 1) {
                    x = offsetX;
                    y += 16;
                }
                count++;
            }
    }
}
Also used : ConduitDisplayMode(crazypants.enderio.base.conduit.ConduitDisplayMode) ScaledResolution(net.minecraft.client.gui.ScaledResolution) IWidgetIcon(com.enderio.core.api.client.render.IWidgetIcon) Tessellator(net.minecraft.client.renderer.Tessellator) Vector4f(com.enderio.core.common.vecmath.Vector4f) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat)

Example 3 with Vector4f

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

the class AdvancedLiquidConduitRenderer method addConduitQuads.

@Override
protected void addConduitQuads(@Nonnull IConduitBundle bundle, @Nonnull IConduit conduit, @Nonnull TextureAtlasSprite tex, @Nonnull CollidableComponent component, float selfIllum, BlockRenderLayer layer, @Nonnull List<BakedQuad> quads) {
    super.addConduitQuads(bundle, conduit, tex, component, selfIllum, layer, quads);
    if (!isNSEWUD(component.dir)) {
        return;
    }
    AdvancedLiquidConduit lc = (AdvancedLiquidConduit) conduit;
    for (EnumFacing dir : conduit.getExternalConnections()) {
        TextureAtlasSprite ioTex = null;
        if (conduit.getConnectionMode(dir) == ConnectionMode.INPUT) {
            ioTex = lc.getTextureForInputMode();
        } else if (conduit.getConnectionMode(dir) == ConnectionMode.OUTPUT) {
            ioTex = lc.getTextureForOutputMode();
        }
        if (ioTex != null) {
            Offset offset = bundle.getOffset(ILiquidConduit.class, dir);
            ConnectionModeGeometry.addModeConnectorQuads(dir, offset, ioTex, new Vector4f(1, 1, 1, 1), quads);
        }
    }
    FluidStack fluid = lc.getFluidType();
    @Nonnull TextureAtlasSprite texture = fluid != null ? RenderUtil.getStillTexture(fluid) : lc.getNotSetEdgeTexture();
    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);
    List<Vertex> vertices = new ArrayList<Vertex>();
    for (EnumFacing d : EnumFacing.VALUES) {
        if (d != component.dir && d != component.dir.getOpposite()) {
            EnumFacing vDir = RenderUtil.getVDirForFace(d);
            if (component.dir == EnumFacing.UP || component.dir == EnumFacing.DOWN) {
                vDir = RenderUtil.getUDirForFace(d);
            } else if ((component.dir == EnumFacing.NORTH || component.dir == EnumFacing.SOUTH) && d.getFrontOffsetY() != 0) {
                vDir = RenderUtil.getUDirForFace(d);
            }
            float minU = texture.getMinU();
            float maxU = texture.getMaxU();
            float minV = texture.getMinV();
            float maxV = texture.getMaxV();
            double sideScale = Math.max(bb.sizeX(), bb.sizeY()) * 2 / 16f;
            sideScale = Math.max(sideScale, bb.sizeZ() * 2 / 16f);
            double width = Math.min(bb.sizeX(), bb.sizeY()) * 15f / 16f;
            List<Vertex> corners = bb.getCornersWithUvForFace(d, minU, maxU, minV, maxV);
            moveEdgeCorners(corners, vDir, width);
            moveEdgeCorners(corners, component.dir.getOpposite(), sideScale);
            for (Vertex c : corners) {
                vertices.add(c);
            }
            corners = bb.getCornersWithUvForFace(d, minU, maxU, minV, maxV);
            moveEdgeCorners(corners, vDir.getOpposite(), width);
            moveEdgeCorners(corners, component.dir.getOpposite(), sideScale);
            for (Vertex c : corners) {
                vertices.add(c);
            }
        }
    }
    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());
        for (Vertex c : corners) {
            vertices.add(c);
        }
        // back face
        for (int i = corners.size() - 1; i >= 0; i--) {
            Vertex c = corners.get(i);
            vertices.add(c);
        }
    }
    BakedQuadBuilder.addBakedQuads(quads, vertices, texture, null);
}
Also used : Vertex(com.enderio.core.common.vecmath.Vertex) Nonnull(javax.annotation.Nonnull) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) FluidStack(net.minecraftforge.fluids.FluidStack) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) Offset(crazypants.enderio.base.conduit.geom.Offset) Vector4f(com.enderio.core.common.vecmath.Vector4f) BoundingBox(com.enderio.core.client.render.BoundingBox)

Example 4 with Vector4f

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

the class TravelEntitySpecialRenderer method renderBlock.

public void renderBlock(@Nonnull BlockPos pos, IBlockAccess blockAccess, double globalScale, boolean highlight) {
    BufferBuilder tes = Tessellator.getInstance().getBuffer();
    BlockRendererDispatcher blockrendererdispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher();
    GlStateManager.pushMatrix();
    GlStateManager.translate(0.5f, 0.5f, 0.5f);
    GlStateManager.scale(globalScale, globalScale, globalScale);
    GlStateManager.translate(-0.5f, -0.5f, -0.5f);
    IBlockState state = blockAccess.getBlockState(pos).getActualState(blockAccess, pos);
    IBakedModel ibakedmodel = blockrendererdispatcher.getModelForState(state);
    state = state.getBlock().getExtendedState(state, blockAccess, pos);
    tes.setTranslation(-pos.getX(), -pos.getY(), -pos.getZ());
    Vector4f color = highlight ? selectedBlockBlend : blockBlend;
    GlStateManager.color(1, 1, 1, 1);
    GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_CONSTANT_COLOR, GlStateManager.SourceFactor.ONE.factor, GlStateManager.DestFactor.ZERO.factor);
    GL14.glBlendColor(color.x, color.y, color.z, color.w);
    tes.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    for (BlockRenderLayer layer : BlockRenderLayer.values()) {
        if (state.getBlock().canRenderInLayer(state, NullHelper.notnullJ(layer, "BlockRenderLayer value was null!"))) {
            ForgeHooksClient.setRenderLayer(layer);
            blockrendererdispatcher.getBlockModelRenderer().renderModel(blockAccess, ibakedmodel, state, pos, tes, false);
        }
    }
    ForgeHooksClient.setRenderLayer(null);
    Tessellator.getInstance().draw();
    GL14.glBlendColor(1, 1, 1, 1);
    GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    tes.setTranslation(0, 0, 0);
    GlStateManager.popMatrix();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Vector4f(com.enderio.core.common.vecmath.Vector4f) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) BlockRendererDispatcher(net.minecraft.client.renderer.BlockRendererDispatcher)

Example 5 with Vector4f

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

the class BlockInfinity method randomDisplayTick.

@SideOnly(Side.CLIENT)
@Override
public void randomDisplayTick(@Nonnull IBlockState bs, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Random rnd) {
    int count = world.canBlockSeeSky(pos) ? 1 : 3;
    for (int i = 0; i < count; i++) {
        float offsetX = (.25f + .5f * rnd.nextFloat());
        float offsetY = (.25f + .5f * rnd.nextFloat());
        float offsetZ = (.25f + .5f * rnd.nextFloat());
        float maxSize = Math.min(Math.min(Math.min(1f - offsetX, offsetX), Math.min(1f - offsetY, offsetY)), Math.min(1f - offsetZ, offsetZ)) * (.5f + .5f * rnd.nextFloat()) * 2;
        float color = (i == 0 && !bs.getValue(HARMLESS) && count > 1) ? 0 : rnd.nextFloat();
        Minecraft.getMinecraft().effectRenderer.addEffect(new InfinityParticle(world, pos, new Vector4f(color, color, color, 0.4f), new Vector4f(offsetX, offsetY, offsetZ, maxSize)));
    }
}
Also used : Vector4f(com.enderio.core.common.vecmath.Vector4f) InfinityParticle(crazypants.enderio.base.render.ranged.InfinityParticle) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

Vector4f (com.enderio.core.common.vecmath.Vector4f)12 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)5 BoundingBox (com.enderio.core.client.render.BoundingBox)4 Vector3d (com.enderio.core.common.vecmath.Vector3d)2 Vertex (com.enderio.core.common.vecmath.Vertex)2 CollidableComponent (crazypants.enderio.base.conduit.geom.CollidableComponent)2 Offset (crazypants.enderio.base.conduit.geom.Offset)2 ArrayList (java.util.ArrayList)2 ScaledResolution (net.minecraft.client.gui.ScaledResolution)2 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)2 EnumFacing (net.minecraft.util.EnumFacing)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 IWidgetIcon (com.enderio.core.api.client.render.IWidgetIcon)1 Vector3f (com.enderio.core.common.vecmath.Vector3f)1 ConduitDisplayMode (crazypants.enderio.base.conduit.ConduitDisplayMode)1 ConnectionMode (crazypants.enderio.base.conduit.ConnectionMode)1 IoMode (crazypants.enderio.base.machine.modes.IoMode)1 PacketIoMode (crazypants.enderio.base.machine.modes.PacketIoMode)1 InfinityParticle (crazypants.enderio.base.render.ranged.InfinityParticle)1 HalfBakedList (crazypants.enderio.base.render.util.HalfBakedQuad.HalfBakedList)1