Search in sources :

Example 16 with VertexBuffer

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

the class RenderFishHook method doRender.

/**
     * Render a fishing hook entity in the world
     * This class uses some GL11 stuff
     * and seems hard to document...
     *
     * @param entity    the hook to render
     * @param x         the x position
     * @param y         the y position
     * @param z         the z position
     * @param entityYaw the angle thrown
     */
@Override
public void doRender(@NotNull final EntityFishHook entity, final double x, final double y, final double z, final float entityYaw, final float partialTicks) {
    GlStateManager.pushMatrix();
    GlStateManager.translate((float) x, (float) y, (float) z);
    GlStateManager.enableRescaleNormal();
    GlStateManager.scale(0.5F, 0.5F, 0.5F);
    this.bindEntityTexture(entity);
    final Tessellator tessellator = Tessellator.getInstance();
    final VertexBuffer vertexBuffer = tessellator.getBuffer();
    GlStateManager.rotate((float) (180.0D - this.renderManager.playerViewY), 0.0F, 1.0F, 0.0F);
    GlStateManager.rotate(-this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
    vertexBuffer.begin(7, DefaultVertexFormats.POSITION_TEX_NORMAL);
    vertexBuffer.pos(-0.5D, -0.5D, 0.0D).tex(0.0625D, 0.1875D).normal(0.0F, 1.0F, 0.0F).endVertex();
    vertexBuffer.pos(0.5D, -0.5D, 0.0D).tex(0.125D, 0.1875D).normal(0.0F, 1.0F, 0.0F).endVertex();
    vertexBuffer.pos(0.5D, 0.5D, 0.0D).tex(0.125D, 0.125D).normal(0.0F, 1.0F, 0.0F).endVertex();
    vertexBuffer.pos(-0.5D, 0.5D, 0.0D).tex(0.0625D, 0.125D).normal(0.0F, 1.0F, 0.0F).endVertex();
    tessellator.draw();
    GlStateManager.disableRescaleNormal();
    GlStateManager.popMatrix();
    EntityCitizen citizen = entity.getCitizen();
    //Check if he is a fisherman -> Through his texture
    if (citizen == null) {
        for (@NotNull final Object citizenX : entity.world.getEntitiesWithinAABB(EntityCitizen.class, entity.getEntityBoundingBox().expand(10, 10, 10))) {
            if (((EntityCitizen) citizenX).getModelID().textureBase.contains("Fisherman")) {
                citizen = (EntityCitizen) citizenX;
                break;
            }
        }
    }
    if (citizen != null) {
        final double orientation = citizen.getSwingProgress(partialTicks);
        final double finalOrientation = Math.sin(Math.sqrt(orientation) * Math.PI);
        @NotNull final Vec3d Vec3d = new Vec3d(-0.36D, 0.03D, 0.35D);
        Vec3d.rotatePitch((float) (-((double) citizen.prevRotationPitch + ((double) citizen.rotationPitch - (double) citizen.prevRotationPitch) * partialTicks) * Math.PI / Literals.HALF_CIRCLE));
        Vec3d.rotateYaw((float) (-((double) citizen.prevRotationYaw + ((double) citizen.rotationYaw - (double) citizen.prevRotationYaw) * partialTicks) * Math.PI / Literals.HALF_CIRCLE));
        Vec3d.rotateYaw((float) (finalOrientation * 0.5D));
        Vec3d.rotatePitch((float) (-finalOrientation * 0.7D));
        final double thirdPersonOffset = (citizen.prevRenderYawOffset + ((double) citizen.renderYawOffset - citizen.prevRenderYawOffset) * partialTicks) * Math.PI / Literals.HALF_CIRCLE;
        final double correctedPosX = citizen.prevPosX + (citizen.posX - citizen.prevPosX) * (double) partialTicks - MathHelper.cos((float) thirdPersonOffset) * 0.35D - MathHelper.sin((float) thirdPersonOffset) * 0.8D;
        final double correctedPosY = citizen.prevPosY + citizen.getEyeHeight() + (citizen.posY - citizen.prevPosY) * (double) partialTicks - 0.45D;
        final double correctedPosZ = citizen.prevPosZ + (citizen.posZ - citizen.prevPosZ) * (double) partialTicks - MathHelper.sin((float) thirdPersonOffset) * 0.35D + MathHelper.cos((float) thirdPersonOffset) * 0.8D;
        final double eyeHeight = citizen.isSneaking() ? -0.1875D : 0.0D;
        final double distX = entity.prevPosX + (entity.posX - entity.prevPosX) * partialTicks;
        final double distY = entity.posY + 0.25;
        final double distZ = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * partialTicks;
        final double correctionX = correctedPosX - distX;
        final double correctionY = correctedPosY - distY + eyeHeight;
        final double correctionZ = correctedPosZ - distZ;
        GlStateManager.disableTexture2D();
        GlStateManager.disableLighting();
        vertexBuffer.begin(3, DefaultVertexFormats.POSITION_COLOR);
        for (int l = 0; l <= 16; ++l) {
            final double var = (double) l / 16.0;
            vertexBuffer.pos(x + correctionX * var, y + correctionY * (var * var + var) * 0.5D + 0.25D, z + correctionZ * var).color(0, 0, 0, 255).endVertex();
        }
        tessellator.draw();
        GlStateManager.enableLighting();
        GlStateManager.enableTexture2D();
        super.doRender(entity, x, y, z, entityYaw, partialTicks);
    }
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) VertexBuffer(net.minecraft.client.renderer.VertexBuffer) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) NotNull(org.jetbrains.annotations.NotNull) Vec3d(net.minecraft.util.math.Vec3d)

Example 17 with VertexBuffer

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

the class Pathfinding method debugDrawNode.

@SideOnly(Side.CLIENT)
private static void debugDrawNode(@NotNull final Node n, final float r, final float g, final float b) {
    GlStateManager.pushMatrix();
    GlStateManager.translate((double) n.pos.getX() + 0.375, (double) n.pos.getY() + 0.375, (double) n.pos.getZ() + 0.375);
    final Entity entity = Minecraft.getMinecraft().getRenderViewEntity();
    final double dx = n.pos.getX() - entity.posX;
    final double dy = n.pos.getY() - entity.posY;
    final double dz = n.pos.getZ() - entity.posZ;
    if (Math.sqrt(dx * dx + dy * dy + dz * dz) <= 5D) {
        renderDebugText(n);
    }
    GlStateManager.scale(0.25D, 0.25D, 0.25D);
    final Tessellator tessellator = Tessellator.getInstance();
    final VertexBuffer vertexBuffer = tessellator.getBuffer();
    vertexBuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);
    GlStateManager.color(r, g, b);
    //  X+
    vertexBuffer.pos(1.0, 0.0, 0.0).endVertex();
    vertexBuffer.pos(1.0, 1.0, 0.0).endVertex();
    vertexBuffer.pos(1.0, 1.0, 1.0).endVertex();
    vertexBuffer.pos(1.0, 0.0, 1.0).endVertex();
    //  X-
    vertexBuffer.pos(0.0, 0.0, 1.0).endVertex();
    vertexBuffer.pos(0.0, 1.0, 1.0).endVertex();
    vertexBuffer.pos(0.0, 1.0, 0.0).endVertex();
    vertexBuffer.pos(0.0, 0.0, 0.0).endVertex();
    //  Z-
    vertexBuffer.pos(0.0, 0.0, 0.0).endVertex();
    vertexBuffer.pos(0.0, 1.0, 0.0).endVertex();
    vertexBuffer.pos(1.0, 1.0, 0.0).endVertex();
    vertexBuffer.pos(1.0, 0.0, 0.0).endVertex();
    //  Z+
    vertexBuffer.pos(1.0, 0.0, 1.0).endVertex();
    vertexBuffer.pos(1.0, 1.0, 1.0).endVertex();
    vertexBuffer.pos(0.0, 1.0, 1.0).endVertex();
    vertexBuffer.pos(0.0, 0.0, 1.0).endVertex();
    //  Y+
    vertexBuffer.pos(1.0, 1.0, 1.0).endVertex();
    vertexBuffer.pos(1.0, 1.0, 0.0).endVertex();
    vertexBuffer.pos(0.0, 1.0, 0.0).endVertex();
    vertexBuffer.pos(0.0, 1.0, 1.0).endVertex();
    //  Y-
    vertexBuffer.pos(0.0, 0.0, 1.0).endVertex();
    vertexBuffer.pos(0.0, 0.0, 0.0).endVertex();
    vertexBuffer.pos(1.0, 0.0, 0.0).endVertex();
    vertexBuffer.pos(1.0, 0.0, 1.0).endVertex();
    tessellator.draw();
    if (n.parent != null) {
        final double pdx = n.parent.pos.getX() - n.pos.getX() + 0.125;
        final double pdy = n.parent.pos.getY() - n.pos.getY() + 0.125;
        final double pdz = n.parent.pos.getZ() - n.pos.getZ() + 0.125;
        vertexBuffer.begin(GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR);
        vertexBuffer.pos(0.5D, 0.5D, 0.5D).color(0.75F, 0.75F, 0.75F, 1.0F).endVertex();
        vertexBuffer.pos(pdx / 0.25, pdy / 0.25, pdz / 0.25).color(0.75F, 0.75F, 0.75F, 1.0F).endVertex();
        tessellator.draw();
    }
    GlStateManager.popMatrix();
}
Also used : Entity(net.minecraft.entity.Entity) Tessellator(net.minecraft.client.renderer.Tessellator) VertexBuffer(net.minecraft.client.renderer.VertexBuffer) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 18 with VertexBuffer

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

the class TextField method drawSelf.

/**
     * Draw itself at positions mx and my.
     */
@Override
protected 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.fontRendererObj.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.fontRendererObj.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.fontRendererObj.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.fontRendererObj.FONT_HEIGHT, RECT_COLOR);
        } else {
            mc.renderEngine.bindTexture(TEXTURE);
            mc.fontRendererObj.drawString("_", cursorX, drawY, color, shadow);
        }
    }
    //  Draw selection
    if (relativeSelectionEnd != relativeCursorPosition) {
        final int selectedDrawX = drawX + mc.fontRendererObj.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 VertexBuffer 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.fontRendererObj.FONT_HEIGHT, 0.0D).endVertex();
        vertexBuffer.pos((double) selectionEndX, (double) drawY + 1 + mc.fontRendererObj.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) VertexBuffer(net.minecraft.client.renderer.VertexBuffer) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with VertexBuffer

use of net.minecraft.client.renderer.VertexBuffer in project VoodooCraft by Mod-DevCafeTeam.

the class TileTotemRender method renderTileEntityAt.

public void renderTileEntityAt(TileTotem te, double x, double y, double z, float partialTicks, int destroyStage) {
    for (EnumFacing side : EnumFacing.HORIZONTALS) {
        //Get the glyph on the given side
        EnumGlyphType glyph = te.getSide(side);
        if (glyph == null)
            continue;
        GlStateManager.pushMatrix();
        GlStateManager.translate(x, y, z);
        GlStateManager.enableAlpha();
        GlStateManager.enableBlend();
        GlStateManager.color(0.25f, 0.1f, 0.1f, 0.4f);
        //Fix the lighting
        int i = te.getWorld().getCombinedLight(te.getPos().offset(side), 0);
        int j = i % 65536;
        int k = i / 65536;
        OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, j / 1.0F, k / 1.0F);
        //Bind the glyph texture to use to render
        bindTexture(glyph.getTextureLocation());
        Tessellator tes = Tessellator.getInstance();
        VertexBuffer buf = tes.getBuffer();
        buf.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
        float offset = (1f / 16f) * 0.9f;
        switch(side) {
            case //-Z
            NORTH:
                buf.pos(1, 0, offset).tex(0, 1).endVertex();
                buf.pos(0, 0, offset).tex(1, 1).endVertex();
                buf.pos(0, 1, offset).tex(1, 0).endVertex();
                buf.pos(1, 1, offset).tex(0, 0).endVertex();
                break;
            case //+Z
            SOUTH:
                buf.pos(0, 0, 1 - offset).tex(0, 1).endVertex();
                buf.pos(1, 0, 1 - offset).tex(1, 1).endVertex();
                buf.pos(1, 1, 1 - offset).tex(1, 0).endVertex();
                buf.pos(0, 1, 1 - offset).tex(0, 0).endVertex();
                break;
            case //-X
            WEST:
                buf.pos(offset, 0, 0).tex(0, 1).endVertex();
                buf.pos(offset, 0, 1).tex(1, 1).endVertex();
                buf.pos(offset, 1, 1).tex(1, 0).endVertex();
                buf.pos(offset, 1, 0).tex(0, 0).endVertex();
                break;
            case //+X
            EAST:
                buf.pos(1 - offset, 0, 0).tex(1, 1).endVertex();
                buf.pos(1 - offset, 1, 0).tex(1, 0).endVertex();
                buf.pos(1 - offset, 1, 1).tex(0, 0).endVertex();
                buf.pos(1 - offset, 0, 1).tex(0, 1).endVertex();
        }
        tes.draw();
        GlStateManager.popMatrix();
    }
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) VertexBuffer(net.minecraft.client.renderer.VertexBuffer) EnumFacing(net.minecraft.util.EnumFacing) EnumGlyphType(mdc.voodoocraft.util.EnumGlyphType)

Example 20 with VertexBuffer

use of net.minecraft.client.renderer.VertexBuffer in project NetherEx by LogicTechCorp.

the class RenderGhastlingFireball method doRender.

@Override
public void doRender(EntityGhastlingFireball fireball, double x, double y, double z, float entityYaw, float partialTicks) {
    GlStateManager.pushMatrix();
    bindEntityTexture(fireball);
    GlStateManager.translate((float) x, (float) y, (float) z);
    GlStateManager.enableRescaleNormal();
    GlStateManager.scale(2.0F, 2.0F, 2.0F);
    Tessellator tessellator = Tessellator.getInstance();
    VertexBuffer vertexbuffer = tessellator.getBuffer();
    GlStateManager.rotate(180.0F - renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
    GlStateManager.rotate((float) (renderManager.options.thirdPersonView == 2 ? -1 : 1) * -renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
    if (renderOutlines) {
        GlStateManager.enableColorMaterial();
        GlStateManager.enableOutlineMode(getTeamColor(fireball));
    }
    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.draw();
    if (renderOutlines) {
        GlStateManager.disableOutlineMode();
        GlStateManager.disableColorMaterial();
    }
    GlStateManager.disableRescaleNormal();
    GlStateManager.popMatrix();
    super.doRender(fireball, x, y, z, entityYaw, partialTicks);
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) VertexBuffer(net.minecraft.client.renderer.VertexBuffer)

Aggregations

VertexBuffer (net.minecraft.client.renderer.VertexBuffer)52 Tessellator (net.minecraft.client.renderer.Tessellator)50 BlockPos (net.minecraft.util.math.BlockPos)8 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)6 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)5 EnumFacing (net.minecraft.util.EnumFacing)5 PhysicsWrapperEntity (ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity)3 Minecraft (net.minecraft.client.Minecraft)3 BlockRendererDispatcher (net.minecraft.client.renderer.BlockRendererDispatcher)3 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)3 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)3 Entity (net.minecraft.entity.Entity)3 Vec3i (net.minecraft.util.math.Vec3i)3 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3 FontRenderer (net.minecraft.client.gui.FontRenderer)2 RenderManager (net.minecraft.client.renderer.entity.RenderManager)2 Vec3d (net.minecraft.util.math.Vec3d)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 NotNull (org.jetbrains.annotations.NotNull)2 IImmersiveConnectable (blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable)1