Search in sources :

Example 21 with BufferBuilder

use of net.minecraft.client.renderer.BufferBuilder in project SilentGems by SilentChaos512.

the class GuiToolSouls method renderAPBarForItem.

private static void renderAPBarForItem(ItemStack stack, int xPosition, int yPosition) {
    if (!stack.isEmpty()) {
        ToolSoul soul = SoulManager.getSoul(stack);
        if (soul != null) {
            // SilentGems.logHelper.debug(soul);
            GlStateManager.disableLighting();
            GlStateManager.disableDepth();
            GlStateManager.disableTexture2D();
            GlStateManager.disableAlpha();
            GlStateManager.disableBlend();
            Tessellator tessellator = Tessellator.getInstance();
            BufferBuilder bufferbuilder = tessellator.getBuffer();
            double ap = 1.0 - ((double) soul.getActionPoints() / soul.getMaxActionPoints());
            int rgbfordisplay = new Color(0f, 0.75f * (1f - (float) ap), 1f).getColor();
            int i = Math.round(13.0F - (float) ap * 13.0F);
            int j = rgbfordisplay;
            draw(bufferbuilder, xPosition + 2, yPosition + 13, 13, 2, 0, 0, 0, 255);
            draw(bufferbuilder, xPosition + 2, yPosition + 13, i, 1, j >> 16 & 255, j >> 8 & 255, j & 255, 255);
            GlStateManager.enableBlend();
            GlStateManager.enableAlpha();
            GlStateManager.enableTexture2D();
            GlStateManager.enableLighting();
            GlStateManager.enableDepth();
        }
    // EntityPlayerSP entityplayersp = Minecraft.getMinecraft().player;
    // float f3 = entityplayersp == null ? 0.0F
    // : entityplayersp.getCooldownTracker().getCooldown(stack.getItem(),
    // Minecraft.getMinecraft().getRenderPartialTicks());
    // 
    // if (f3 > 0.0F) {
    // GlStateManager.disableLighting();
    // GlStateManager.disableDepth();
    // GlStateManager.disableTexture2D();
    // Tessellator tessellator1 = Tessellator.getInstance();
    // BufferBuilder bufferbuilder1 = tessellator1.getBuffer();
    // this.draw(bufferbuilder1, xPosition, yPosition + MathHelper.floor(16.0F * (1.0F - f3)), 16,
    // MathHelper.ceil(16.0F * f3), 255, 255, 255, 127);
    // //        GlStateManager.enableTexture2D();
    // //        GlStateManager.enableLighting();
    // //        GlStateManager.enableDepth();
    // }
    }
}
Also used : ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) Tessellator(net.minecraft.client.renderer.Tessellator) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) Color(net.silentchaos512.lib.util.Color)

Example 22 with BufferBuilder

use of net.minecraft.client.renderer.BufferBuilder 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 23 with BufferBuilder

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

the class RenderUtils method drawSelectionBoundingBox.

public static void drawSelectionBoundingBox(AxisAlignedBB box, int lineMask) {
    EntityPlayer player = Minecraft.getMinecraft().player;
    float partialTicks = Minecraft.getMinecraft().getRenderPartialTicks();
    Vec3d cameraPos = EntityUtils.interpolate(player, partialTicks);
    AxisAlignedBB boundingBox = box.grow(0.002).offset(cameraPos.scale(-1));
    GlStateManager.enableBlend();
    GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
    GlStateManager.color(0.0F, 0.0F, 0.0F, 0.4F);
    GL11.glLineWidth(2.0F);
    GlStateManager.disableTexture2D();
    GlStateManager.depthMask(false);
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder worldrenderer = tessellator.getBuffer();
    worldrenderer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION);
    if ((lineMask & /* getSelectionMask(0, 0, 0) */
    0x001) != 0) {
        drawLine(worldrenderer, tessellator, boundingBox.minX, boundingBox.minY, boundingBox.minZ, boundingBox.maxX, boundingBox.minY, boundingBox.minZ);
    }
    if ((lineMask & /* getSelectionMask(0, 0, 1) */
    0x002) != 0) {
        drawLine(worldrenderer, tessellator, boundingBox.minX, boundingBox.minY, boundingBox.maxZ, boundingBox.maxX, boundingBox.minY, boundingBox.maxZ);
    }
    if ((lineMask & /* getSelectionMask(0, 1, 0) */
    0x004) != 0) {
        drawLine(worldrenderer, tessellator, boundingBox.minX, boundingBox.minY, boundingBox.minZ, boundingBox.minX, boundingBox.minY, boundingBox.maxZ);
    }
    if ((lineMask & /* getSelectionMask(0, 1, 1) */
    0x008) != 0) {
        drawLine(worldrenderer, tessellator, boundingBox.maxX, boundingBox.minY, boundingBox.minZ, boundingBox.maxX, boundingBox.minY, boundingBox.maxZ);
    }
    if ((lineMask & /* getSelectionMask(1, 0, 0) */
    0x010) != 0) {
        drawLine(worldrenderer, tessellator, boundingBox.minX, boundingBox.minY, boundingBox.minZ, boundingBox.minX, boundingBox.maxY, boundingBox.minZ);
    }
    if ((lineMask & /* getSelectionMask(1, 0, 1) */
    0x020) != 0) {
        drawLine(worldrenderer, tessellator, boundingBox.minX, boundingBox.minY, boundingBox.maxZ, boundingBox.minX, boundingBox.maxY, boundingBox.maxZ);
    }
    if ((lineMask & /* getSelectionMask(1, 1, 0) */
    0x040) != 0) {
        drawLine(worldrenderer, tessellator, boundingBox.maxX, boundingBox.minY, boundingBox.minZ, boundingBox.maxX, boundingBox.maxY, boundingBox.minZ);
    }
    if ((lineMask & /* getSelectionMask(1, 1, 1) */
    0x080) != 0) {
        drawLine(worldrenderer, tessellator, boundingBox.maxX, boundingBox.minY, boundingBox.maxZ, boundingBox.maxX, boundingBox.maxY, boundingBox.maxZ);
    }
    if ((lineMask & /* getSelectionMask(2, 0, 0) */
    0x100) != 0) {
        drawLine(worldrenderer, tessellator, boundingBox.minX, boundingBox.maxY, boundingBox.minZ, boundingBox.maxX, boundingBox.maxY, boundingBox.minZ);
    }
    if ((lineMask & /* getSelectionMask(2, 0, 1) */
    0x200) != 0) {
        drawLine(worldrenderer, tessellator, boundingBox.minX, boundingBox.maxY, boundingBox.maxZ, boundingBox.maxX, boundingBox.maxY, boundingBox.maxZ);
    }
    if ((lineMask & /* getSelectionMask(2, 1, 0) */
    0x400) != 0) {
        drawLine(worldrenderer, tessellator, boundingBox.minX, boundingBox.maxY, boundingBox.minZ, boundingBox.minX, boundingBox.maxY, boundingBox.maxZ);
    }
    if ((lineMask & /* getSelectionMask(2, 1, 1) */
    0x800) != 0) {
        drawLine(worldrenderer, tessellator, boundingBox.maxX, boundingBox.maxY, boundingBox.minZ, boundingBox.maxX, boundingBox.maxY, boundingBox.maxZ);
    }
    tessellator.draw();
    GlStateManager.depthMask(true);
    GlStateManager.enableTexture2D();
    GlStateManager.disableBlend();
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Tessellator(net.minecraft.client.renderer.Tessellator) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Vec3d(net.minecraft.util.math.Vec3d)

Example 24 with BufferBuilder

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

the class NotifyProxyClient method renderMessage.

private void renderMessage(ClientMessage m, float partial, float opacity, Vec3d c) {
    int width = 0;
    String[] lines = m.msgRendered.split("\n");
    FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder worldrenderer = tessellator.getBuffer();
    for (String line : lines) {
        width = Math.max(width, fr.getStringWidth(line));
    }
    width += 2;
    int halfWidth = width / 2;
    float scaling = 1.6F / 60F;
    scaling *= 2F / 3F;
    GlStateManager.pushMatrix();
    int lineCount = lines.length;
    float centeringOffset = 0;
    if (m.show_item) {
        if (lineCount == 1) {
            centeringOffset = 5F;
        }
        lineCount = Math.max(2, lineCount);
    }
    Vec3d vec = m.getPosition(partial);
    float x = (float) vec.x;
    float y = (float) vec.y;
    float z = (float) vec.z;
    if (m.style.contains(NoticeStyle.SCALE_SIZE)) {
        double dx = x - c.x;
        double dy = y - c.y;
        double dz = z - c.z;
        double dist = Math.sqrt(dx * dx + dy * dy + dz * dz);
        scaling *= Math.sqrt(dist);
    }
    NotificationCoord co = m.asCoord();
    if (co != null && !m.position_important) {
        BlockPos pos = co.getPos();
        IBlockState bs = co.getWorld().getBlockState(pos);
        AxisAlignedBB bb = bs.getCollisionBoundingBox(co.getWorld(), pos);
        if (bb != null) {
            y = (float) Math.max(y, pos.getY() + bb.maxY);
        } else {
            y = (float) Math.max(y, pos.getY() + 0.5f);
        }
    }
    GlStateManager.translate(x + 0.5F, y, z + 0.5F);
    Minecraft mc = Minecraft.getMinecraft();
    float pvx = mc.getRenderManager().playerViewX;
    float pvy = -mc.getRenderManager().playerViewY;
    if (mc.gameSettings.thirdPersonView == 2) {
        pvx = -pvx;
    }
    GlStateManager.rotate(pvy, 0.0F, 1.0F, 0.0F);
    GlStateManager.rotate(pvx, 1.0F, 0.0F, 0.0F);
    GlStateManager.scale(-scaling, -scaling, scaling);
    GlStateManager.translate(0, -10 * lineCount, 0);
    {
        int lineHeight = (lineCount - 1) * 10;
        double item_add = 0;
        if (m.show_item) {
            item_add += 24;
        }
        float col = 0.0F;
        GlStateManager.disableTexture2D();
        GlStateManager.color(col, col, col, Math.min(opacity, 0.2F));
        double Z = 0.001D;
        // TODO: Use 2 tessellator + 2 draw calls to do all notice rendering
        worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);
        worldrenderer.pos(-halfWidth - 1, -1, Z).endVertex();
        worldrenderer.pos(-halfWidth - 1, 8 + lineHeight, Z).endVertex();
        worldrenderer.pos(halfWidth + 1 + item_add, 8 + lineHeight, Z).endVertex();
        worldrenderer.pos(halfWidth + 1 + item_add, -1, Z).endVertex();
        tessellator.draw();
        GlStateManager.enableTexture2D();
    }
    {
        int i = 0;
        int B = (int) (0xFF * Math.min(1, 0.5F + opacity));
        int color = (B << 16) + (B << 8) + B + ((int) (0xFF * opacity) << 24);
        GlStateManager.translate(0, centeringOffset, 0);
        for (String line : lines) {
            fr.drawString(line, -fr.getStringWidth(line) / 2, 10 * i, color);
            i++;
        }
    }
    {
        if (m.show_item) {
            // TODO: Add transparency support
            GlStateManager.translate(0, -centeringOffset, 0);
            GlStateManager.translate((float) (halfWidth + 4), -lineCount / 2, 0);
            // Undoes the effects of setupGuiTransform
            renderItem.zLevel -= 100;
            renderItem.renderItemIntoGUI(m.item, 0, 0);
            renderItem.zLevel += 100;
        }
    }
    GlStateManager.popMatrix();
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Tessellator(net.minecraft.client.renderer.Tessellator) IBlockState(net.minecraft.block.state.IBlockState) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) Minecraft(net.minecraft.client.Minecraft) Vec3d(net.minecraft.util.math.Vec3d) BlockPos(net.minecraft.util.math.BlockPos) FontRenderer(net.minecraft.client.gui.FontRenderer)

Example 25 with BufferBuilder

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

the class DualTileEntitySpecialRenderer method renderTileEntityFastFromSlow.

protected void renderTileEntityFastFromSlow(T part, double x, double y, double z, float partialTicks, int destroyStage, float todo_figure_me_out) {
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder builder = tessellator.getBuffer();
    this.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    RenderHelper.disableStandardItemLighting();
    GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GlStateManager.enableBlend();
    GlStateManager.disableCull();
    if (Minecraft.isAmbientOcclusionEnabled()) {
        GlStateManager.shadeModel(GL11.GL_SMOOTH);
    } else {
        GlStateManager.shadeModel(GL11.GL_FLAT);
    }
    builder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    renderTileEntityFast(part, x, y, z, partialTicks, destroyStage, todo_figure_me_out, builder);
    builder.setTranslation(0, 0, 0);
    tessellator.draw();
    RenderHelper.enableStandardItemLighting();
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) BufferBuilder(net.minecraft.client.renderer.BufferBuilder)

Aggregations

BufferBuilder (net.minecraft.client.renderer.BufferBuilder)358 Tessellator (net.minecraft.client.renderer.Tessellator)292 BlockPos (net.minecraft.util.math.BlockPos)37 Vec3d (net.minecraft.util.math.Vec3d)33 ResourceLocation (net.minecraft.util.ResourceLocation)25 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)23 IBlockState (net.minecraft.block.state.IBlockState)21 EnumFacing (net.minecraft.util.EnumFacing)21 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)17 Random (java.util.Random)14 Minecraft (net.minecraft.client.Minecraft)13 EntityPlayer (net.minecraft.entity.player.EntityPlayer)13 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)12 BlockRendererDispatcher (net.minecraft.client.renderer.BlockRendererDispatcher)11 EntityLivingBase (net.minecraft.entity.EntityLivingBase)11 World (net.minecraft.world.World)11 ArrayList (java.util.ArrayList)10 ItemStack (net.minecraft.item.ItemStack)10 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)10 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)9