Search in sources :

Example 51 with BufferBuilder

use of net.minecraft.client.renderer.BufferBuilder in project minecolonies by Minecolonies.

the class Structure method renderQuads.

private void renderQuads(final World world, final IBlockState actualState, final BlockPos pos, final List<BakedQuad> quads, final int alpha) {
    final Tessellator tessellator = Tessellator.getInstance();
    final BufferBuilder buffer = tessellator.getBuffer();
    for (final BakedQuad quad : quads) {
        buffer.begin(GL11.GL_QUADS, quad.getFormat());
        final int color = quad.hasTintIndex() ? this.getTint(world, actualState, pos, alpha, quad.getTintIndex()) : (alpha | 0xffffff);
        LightUtil.renderQuadColor(buffer, quad, color);
        tessellator.draw();
    }
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) Tessellator(net.minecraft.client.renderer.Tessellator) BufferBuilder(net.minecraft.client.renderer.BufferBuilder)

Example 52 with BufferBuilder

use of net.minecraft.client.renderer.BufferBuilder in project minecolonies by Minecolonies.

the class TextField method drawSelf.

/**
 * Draw itself at positions mx and my.
 */
@Override
public void drawSelf(final int mx, final int my) {
    final int color = enabled ? textColor : textColorDisabled;
    final int drawWidth = getInternalWidth();
    final int drawX = x;
    final int drawY = y;
    // Determine the portion of the string that is visible on screen
    final String visibleString = mc.fontRenderer.trimStringToWidth(text.substring(scrollOffset), drawWidth);
    final int relativeCursorPosition = cursorPosition - scrollOffset;
    int relativeSelectionEnd = selectionEnd - scrollOffset;
    final boolean cursorVisible = relativeCursorPosition >= 0 && relativeCursorPosition <= visibleString.length();
    final boolean cursorBeforeEnd = cursorPosition < text.length() || text.length() >= maxTextLength;
    // Enforce selection to the length limit of the visible string
    if (relativeSelectionEnd > visibleString.length()) {
        relativeSelectionEnd = visibleString.length();
    }
    // Draw string up through cursor
    int textX = drawX;
    if (visibleString.length() > 0) {
        @NotNull final String s1 = cursorVisible ? visibleString.substring(0, relativeCursorPosition) : visibleString;
        mc.renderEngine.bindTexture(TEXTURE);
        textX = mc.fontRenderer.drawString(s1, textX, drawY, color, shadow);
    }
    int cursorX = textX;
    if (!cursorVisible) {
        cursorX = relativeCursorPosition > 0 ? (drawX + width) : drawX;
    } else if (cursorBeforeEnd && shadow) {
        textX -= 1;
        cursorX -= 1;
    }
    // Draw string after cursor
    if (visibleString.length() > 0 && cursorVisible && relativeCursorPosition < visibleString.length()) {
        mc.renderEngine.bindTexture(TEXTURE);
        mc.fontRenderer.drawString(visibleString.substring(relativeCursorPosition), textX, drawY, color, shadow);
    }
    // Should we draw the cursor this frame?
    if (isFocus() && cursorVisible && (cursorBlinkCounter / 6 % 2 == 0)) {
        if (cursorBeforeEnd) {
            drawRect(cursorX, drawY - 1, cursorX + 1, drawY + 1 + mc.fontRenderer.FONT_HEIGHT, RECT_COLOR);
        } else {
            mc.renderEngine.bindTexture(TEXTURE);
            mc.fontRenderer.drawString("_", cursorX, drawY, color, shadow);
        }
    }
    // Draw selection
    if (relativeSelectionEnd != relativeCursorPosition) {
        final int selectedDrawX = drawX + mc.fontRenderer.getStringWidth(visibleString.substring(0, relativeSelectionEnd));
        int selectionStartX = Math.min(cursorX, selectedDrawX - 1);
        int selectionEndX = Math.max(cursorX, selectedDrawX - 1);
        if (selectionStartX > (x + width)) {
            selectionStartX = x + width;
        }
        if (selectionEndX > (x + width)) {
            selectionEndX = x + width;
        }
        final Tessellator tessellator = Tessellator.getInstance();
        GlStateManager.color(0.0F, 0.0F, 255.0F, 255.0F);
        GlStateManager.disableTexture2D();
        GlStateManager.enableColorLogic();
        GlStateManager.colorLogicOp(GL11.GL_OR_REVERSE);
        final BufferBuilder vertexBuffer = tessellator.getBuffer();
        // There are several to choose from, look at DefaultVertexFormats for more info
        vertexBuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
        // Since our points do not have any u,v this seems to be the correct code
        vertexBuffer.pos((double) selectionStartX, (double) drawY + 1 + mc.fontRenderer.FONT_HEIGHT, 0.0D).endVertex();
        vertexBuffer.pos((double) selectionEndX, (double) drawY + 1 + mc.fontRenderer.FONT_HEIGHT, 0.0D).endVertex();
        vertexBuffer.pos((double) selectionEndX, (double) drawY - 1, 0.0D).endVertex();
        vertexBuffer.pos((double) selectionStartX, (double) drawY - 1, 0.0D).endVertex();
        tessellator.draw();
        GlStateManager.disableColorLogic();
        GlStateManager.enableTexture2D();
    }
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 53 with BufferBuilder

use of net.minecraft.client.renderer.BufferBuilder in project Minestuck by mraof.

the class RenderGrist method doRender.

@Override
public void doRender(EntityGrist grist, double d0, double d1, double d2, float f, float f1) {
    GlStateManager.pushMatrix();
    GlStateManager.translate((float) d0, (float) d1 + grist.getSizeByValue() / 2, (float) d2);
    this.bindEntityTexture(grist);
    BufferBuilder vertexbuffer = Tessellator.getInstance().getBuffer();
    int j = grist.getBrightnessForRender();
    int k = j % 65536;
    int l = j / 65536;
    OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float) k / 1.0F, (float) l / 1.0F);
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    GlStateManager.rotate(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
    GlStateManager.rotate(-this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
    float f11 = grist.getSizeByValue();
    GlStateManager.scale(f11, f11, f11);
    vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX_NORMAL);
    vertexbuffer.pos(-0.5D, -0.25D, 0.0D).tex(0.0D, 1.0D).normal(0.0F, 1.0F, 0.0F).endVertex();
    vertexbuffer.pos(0.5D, -0.25D, 0.0D).tex(1.0D, 1.0D).normal(0.0F, 1.0F, 0.0F).endVertex();
    vertexbuffer.pos(0.5D, 0.75D, 0.0D).tex(1.0D, 0.0D).normal(0.0F, 1.0F, 0.0F).endVertex();
    vertexbuffer.pos(-0.5D, 0.75D, 0.0D).tex(0.0D, 0.0D).normal(0.0F, 1.0F, 0.0F).endVertex();
    Tessellator.getInstance().draw();
    GlStateManager.disableBlend();
    GlStateManager.disableRescaleNormal();
    GlStateManager.popMatrix();
}
Also used : BufferBuilder(net.minecraft.client.renderer.BufferBuilder)

Example 54 with BufferBuilder

use of net.minecraft.client.renderer.BufferBuilder in project Minestuck by mraof.

the class RenderHangingArt method renderPainting.

private void renderPainting(T painting, int width, int height, int textureU, int textureV) {
    float renderOffsetU = (float) (-width) / 2.0F;
    float renderOffsetV = (float) (-height) / 2.0F;
    for (int blockU = 0; blockU < width / 16; blockU++) {
        for (int blockV = 0; blockV < height / 16; blockV++) {
            float lowerU = renderOffsetU + (float) (blockU * 16);
            float upperU = renderOffsetU + (float) ((blockU + 1) * 16);
            float lowerV = renderOffsetV + (float) (blockV * 16);
            float upperV = renderOffsetV + (float) ((blockV + 1) * 16);
            this.setLightmap(painting, (upperU + lowerU) / 2.0F, (upperV + lowerV) / 2.0F);
            float f19 = (float) (textureU + width - blockU * 16) / 256.0F;
            float f20 = (float) (textureU + width - (blockU + 1) * 16) / 256.0F;
            float f21 = (float) (textureV + height - blockV * 16) / 256.0F;
            float f22 = (float) (textureV + height - (blockV + 1) * 16) / 256.0F;
            Tessellator tessellator = Tessellator.getInstance();
            BufferBuilder vertexbuffer = tessellator.getBuffer();
            vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX_NORMAL);
            vertexbuffer.pos((double) upperU, (double) lowerV, -0.5D).tex((double) f20, (double) f21).normal(0.0F, 0.0F, -1.0F).endVertex();
            vertexbuffer.pos((double) lowerU, (double) lowerV, -0.5D).tex((double) f19, (double) f21).normal(0.0F, 0.0F, -1.0F).endVertex();
            vertexbuffer.pos((double) lowerU, (double) upperV, -0.5D).tex((double) f19, (double) f22).normal(0.0F, 0.0F, -1.0F).endVertex();
            vertexbuffer.pos((double) upperU, (double) upperV, -0.5D).tex((double) f20, (double) f22).normal(0.0F, 0.0F, -1.0F).endVertex();
            vertexbuffer.pos((double) upperU, (double) upperV, 0.5D).tex(0.75D, 0.0D).normal(0.0F, 0.0F, 1.0F).endVertex();
            vertexbuffer.pos((double) lowerU, (double) upperV, 0.5D).tex(0.8125D, 0.0D).normal(0.0F, 0.0F, 1.0F).endVertex();
            vertexbuffer.pos((double) lowerU, (double) lowerV, 0.5D).tex(0.8125D, 0.0625D).normal(0.0F, 0.0F, 1.0F).endVertex();
            vertexbuffer.pos((double) upperU, (double) lowerV, 0.5D).tex(0.75D, 0.0625D).normal(0.0F, 0.0F, 1.0F).endVertex();
            vertexbuffer.pos((double) upperU, (double) upperV, -0.5D).tex(0.75D, 0.001953125D).normal(0.0F, 1.0F, 0.0F).endVertex();
            vertexbuffer.pos((double) lowerU, (double) upperV, -0.5D).tex(0.8125D, 0.001953125D).normal(0.0F, 1.0F, 0.0F).endVertex();
            vertexbuffer.pos((double) lowerU, (double) upperV, 0.5D).tex(0.8125D, 0.001953125D).normal(0.0F, 1.0F, 0.0F).endVertex();
            vertexbuffer.pos((double) upperU, (double) upperV, 0.5D).tex(0.75D, 0.001953125D).normal(0.0F, 1.0F, 0.0F).endVertex();
            vertexbuffer.pos((double) upperU, (double) lowerV, 0.5D).tex(0.75D, 0.001953125D).normal(0.0F, -1.0F, 0.0F).endVertex();
            vertexbuffer.pos((double) lowerU, (double) lowerV, 0.5D).tex(0.8125D, 0.001953125D).normal(0.0F, -1.0F, 0.0F).endVertex();
            vertexbuffer.pos((double) lowerU, (double) lowerV, -0.5D).tex(0.8125D, 0.001953125D).normal(0.0F, -1.0F, 0.0F).endVertex();
            vertexbuffer.pos((double) upperU, (double) lowerV, -0.5D).tex(0.75D, 0.001953125D).normal(0.0F, -1.0F, 0.0F).endVertex();
            vertexbuffer.pos((double) upperU, (double) upperV, 0.5D).tex(0.751953125D, 0.0D).normal(-1.0F, 0.0F, 0.0F).endVertex();
            vertexbuffer.pos((double) upperU, (double) lowerV, 0.5D).tex(0.751953125D, 0.0625D).normal(-1.0F, 0.0F, 0.0F).endVertex();
            vertexbuffer.pos((double) upperU, (double) lowerV, -0.5D).tex(0.751953125D, 0.0625D).normal(-1.0F, 0.0F, 0.0F).endVertex();
            vertexbuffer.pos((double) upperU, (double) upperV, -0.5D).tex(0.751953125D, 0.0D).normal(-1.0F, 0.0F, 0.0F).endVertex();
            vertexbuffer.pos((double) lowerU, (double) upperV, -0.5D).tex(0.751953125D, 0.0D).normal(1.0F, 0.0F, 0.0F).endVertex();
            vertexbuffer.pos((double) lowerU, (double) lowerV, -0.5D).tex(0.751953125D, 0.0625D).normal(1.0F, 0.0F, 0.0F).endVertex();
            vertexbuffer.pos((double) lowerU, (double) lowerV, 0.5D).tex(0.751953125D, 0.0625D).normal(1.0F, 0.0F, 0.0F).endVertex();
            vertexbuffer.pos((double) lowerU, (double) upperV, 0.5D).tex(0.751953125D, 0.0D).normal(1.0F, 0.0F, 0.0F).endVertex();
            tessellator.draw();
        }
    }
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) BufferBuilder(net.minecraft.client.renderer.BufferBuilder)

Example 55 with BufferBuilder

use of net.minecraft.client.renderer.BufferBuilder in project Minestuck by mraof.

the class RenderVitalityGel method doRender.

@Override
public void doRender(EntityVitalityGel entity, double x, double y, double z, float entityYaw, float partialTicks) {
    GlStateManager.pushMatrix();
    GlStateManager.translate((float) x, (float) y + entity.getSizeByValue() / 2, (float) z);
    this.bindEntityTexture(entity);
    BufferBuilder vertexbuffer = Tessellator.getInstance().getBuffer();
    int j = entity.getBrightnessForRender();
    int k = j % 65536;
    int l = j / 65536;
    OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float) k / 1.0F, (float) l / 1.0F);
    GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
    GlStateManager.rotate(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
    GlStateManager.rotate(-this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
    float size = entity.getSizeByValue();
    GlStateManager.scale(size, size, size);
    float scaleFactor = MathHelper.sin((entity.age + partialTicks) / 10f + entity.animationOffset);
    GlStateManager.scale(1 + scaleFactor * 0.07f, 1 - scaleFactor * 0.05f, 1);
    vertexbuffer.begin(7, DefaultVertexFormats.POSITION_TEX_NORMAL);
    vertexbuffer.pos(-0.5D, -0.25D, 0.0D).tex(0.0D, 1.0D).normal(0.0F, 1.0F, 0.0F).endVertex();
    vertexbuffer.pos(0.5D, -0.25D, 0.0D).tex(1.0D, 1.0D).normal(0.0F, 1.0F, 0.0F).endVertex();
    vertexbuffer.pos(0.5D, 0.75D, 0.0D).tex(1.0D, 0.0D).normal(0.0F, 1.0F, 0.0F).endVertex();
    vertexbuffer.pos(-0.5D, 0.75D, 0.0D).tex(0.0D, 0.0D).normal(0.0F, 1.0F, 0.0F).endVertex();
    Tessellator.getInstance().draw();
    GlStateManager.disableBlend();
    GlStateManager.disableRescaleNormal();
    GlStateManager.popMatrix();
}
Also used : BufferBuilder(net.minecraft.client.renderer.BufferBuilder)

Aggregations

BufferBuilder (net.minecraft.client.renderer.BufferBuilder)319 Tessellator (net.minecraft.client.renderer.Tessellator)251 BlockPos (net.minecraft.util.math.BlockPos)35 Vec3d (net.minecraft.util.math.Vec3d)27 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 Minecraft (net.minecraft.client.Minecraft)14 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)14 EntityPlayer (net.minecraft.entity.player.EntityPlayer)11 ItemStack (net.minecraft.item.ItemStack)11 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)11 ArrayList (java.util.ArrayList)10 BlockRendererDispatcher (net.minecraft.client.renderer.BlockRendererDispatcher)10 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)9 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)9 World (net.minecraft.world.World)8 Random (java.util.Random)7 FontRenderer (net.minecraft.client.gui.FontRenderer)7