package rosegoldaddons.utils; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.*; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL14; import rosegoldaddons.Main; import java.awt.*; import java.util.HashMap; import java.util.Map; import static java.lang.Math.*; import static org.lwjgl.opengl.GL11.*; public class RenderUtils { private static final Map glCapMap = new HashMap<>(); private static final int[] DISPLAY_LISTS_2D = new int[4]; private static final Minecraft mc = Main.mc; static { for (int i = 0; i < DISPLAY_LISTS_2D.length; i++) { DISPLAY_LISTS_2D[i] = glGenLists(1); } glNewList(DISPLAY_LISTS_2D[0], GL_COMPILE); quickDrawRect(-7F, 2F, -4F, 3F); quickDrawRect(4F, 2F, 7F, 3F); quickDrawRect(-7F, 0.5F, -6F, 3F); quickDrawRect(6F, 0.5F, 7F, 3F); glEndList(); glNewList(DISPLAY_LISTS_2D[1], GL_COMPILE); quickDrawRect(-7F, 3F, -4F, 3.3F); quickDrawRect(4F, 3F, 7F, 3.3F); quickDrawRect(-7.3F, 0.5F, -7F, 3.3F); quickDrawRect(7F, 0.5F, 7.3F, 3.3F); glEndList(); glNewList(DISPLAY_LISTS_2D[2], GL_COMPILE); quickDrawRect(4F, -20F, 7F, -19F); quickDrawRect(-7F, -20F, -4F, -19F); quickDrawRect(6F, -20F, 7F, -17.5F); quickDrawRect(-7F, -20F, -6F, -17.5F); glEndList(); glNewList(DISPLAY_LISTS_2D[3], GL_COMPILE); quickDrawRect(7F, -20F, 7.3F, -17.5F); quickDrawRect(-7.3F, -20F, -7F, -17.5F); quickDrawRect(4F, -20.3F, 7.3F, -20F); quickDrawRect(-7.3F, -20.3F, -4F, -20F); glEndList(); } public static void drawBlockBox(final BlockPos blockPos, final Color color, final int width, float partialTicks) { if(width == 0) return; final RenderManager renderManager = mc.getRenderManager(); final double x = blockPos.getX() - renderManager.viewerPosX; final double y = blockPos.getY() - renderManager.viewerPosY; final double z = blockPos.getZ() - renderManager.viewerPosZ; AxisAlignedBB axisAlignedBB = new AxisAlignedBB(x, y, z, x + 1.0, y + 1.0, z + 1.0); final Block block = mc.theWorld.getBlockState(blockPos).getBlock(); if (block != null) { final EntityPlayer player = mc.thePlayer; final double posX = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks; final double posY = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks; final double posZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks; block.setBlockBoundsBasedOnState(mc.theWorld, blockPos); axisAlignedBB = block.getSelectedBoundingBox(mc.theWorld, blockPos) .expand(0.0020000000949949026D, 0.0020000000949949026D, 0.0020000000949949026D) .offset(-posX, -posY, -posZ); } glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); enableGlCap(GL_BLEND); disableGlCap(GL_TEXTURE_2D, GL_DEPTH_TEST); glDepthMask(false); glColor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha() != 255 ? color.getAlpha() : 26); //drawFilledBox(axisAlignedBB); glLineWidth((float) width); enableGlCap(GL_LINE_SMOOTH); glColor(color); drawSelectionBoundingBox(axisAlignedBB); GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glDepthMask(true); resetCaps(); } public static void drawPixelBox(final Vec3 vec, final Color color, final double size, float partialTicks) { final RenderManager renderManager = mc.getRenderManager(); final double x = vec.xCoord - renderManager.viewerPosX; final double y = vec.yCoord - renderManager.viewerPosY; final double z = vec.zCoord - renderManager.viewerPosZ; AxisAlignedBB axisAlignedBB = new AxisAlignedBB(x, y, z, x + size, y + size, z + size); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); enableGlCap(GL_BLEND); disableGlCap(GL_TEXTURE_2D, GL_DEPTH_TEST); glDepthMask(false); glColor(color.getRed(), color.getGreen(), color.getBlue(), 35); //drawFilledBox(axisAlignedBB); glLineWidth(3F); enableGlCap(GL_LINE_SMOOTH); glColor(color); drawSelectionBoundingBox(axisAlignedBB); GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glDepthMask(true); resetCaps(); } public static void drawSelectionBoundingBox(AxisAlignedBB boundingBox) { Tessellator tessellator = Tessellator.getInstance(); WorldRenderer worldrenderer = tessellator.getWorldRenderer(); worldrenderer.begin(GL_LINE_STRIP, DefaultVertexFormats.POSITION); // Lower Rectangle worldrenderer.pos(boundingBox.minX, boundingBox.minY, boundingBox.minZ).endVertex(); worldrenderer.pos(boundingBox.minX, boundingBox.minY, boundingBox.maxZ).endVertex(); worldrenderer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.maxZ).endVertex(); worldrenderer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.minZ).endVertex(); worldrenderer.pos(boundingBox.minX, boundingBox.minY, boundingBox.minZ).endVertex(); // Upper Rectangle worldrenderer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.minZ).endVertex(); worldrenderer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.maxZ).endVertex(); worldrenderer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.maxZ).endVertex(); worldrenderer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.minZ).endVertex(); worldrenderer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.minZ).endVertex(); // Upper Rectangle worldrenderer.pos(boundingBox.minX, boundingBox.maxY, boundingBox.maxZ).endVertex(); worldrenderer.pos(boundingBox.minX, boundingBox.minY, boundingBox.maxZ).endVertex(); worldrenderer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.maxZ).endVertex(); worldrenderer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.maxZ).endVertex(); worldrenderer.pos(boundingBox.maxX, boundingBox.maxY, boundingBox.minZ).endVertex(); worldrenderer.pos(boundingBox.maxX, boundingBox.minY, boundingBox.minZ).endVertex(); tessellator.draw(); } public static void drawEntityBox(final Entity entity, final Color color, final int width, float partialTicks) { if(width == 0) return; final RenderManager renderManager = mc.getRenderManager(); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); enableGlCap(GL_BLEND); disableGlCap(GL_TEXTURE_2D, GL_DEPTH_TEST); glDepthMask(false); final double x = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * partialTicks - renderManager.viewerPosX; final double y = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * partialTicks - renderManager.viewerPosY; final double z = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * partialTicks - renderManager.viewerPosZ; final AxisAlignedBB entityBox = entity.getEntityBoundingBox(); final AxisAlignedBB axisAlignedBB = new AxisAlignedBB( entityBox.minX - entity.posX + x - 0.05D, entityBox.minY - entity.posY + y, entityBox.minZ - entity.posZ + z - 0.05D, entityBox.maxX - entity.posX + x + 0.05D, entityBox.maxY - entity.posY + y + 0.15D, entityBox.maxZ - entity.posZ + z + 0.05D ); glLineWidth((float) width); enableGlCap(GL_LINE_SMOOTH); glColor(color.getRed(), color.getGreen(), color.getBlue(), 95); drawSelectionBoundingBox(axisAlignedBB); glColor(color.getRed(), color.getGreen(), color.getBlue(), 26); //drawFilledBox(axisAlignedBB); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glDepthMask(true); resetCaps(); } public static void drawAxisAlignedBB(final AxisAlignedBB axisAlignedBB, final Color color) { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glLineWidth(2F); glDisable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); glDepthMask(false); glColor(color); drawFilledBox(axisAlignedBB); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glEnable(GL_TEXTURE_2D); glEnable(GL_DEPTH_TEST); glDepthMask(true); glDisable(GL_BLEND); } public static void drawPlatform(final double y, final Color color, final double size) { final RenderManager renderManager = mc.getRenderManager(); final double renderY = y - renderManager.viewerPosY; drawAxisAlignedBB(new AxisAlignedBB(size, renderY + 0.02D, size, -size, renderY, -size), color); } public static void drawPlatform(final Entity entity, final Color color, float partialTicks) { final RenderManager renderManager = mc.getRenderManager(); final double x = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * partialTicks - renderManager.viewerPosX; final double y = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * partialTicks - renderManager.viewerPosY; final double z = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * partialTicks - renderManager.viewerPosZ; final AxisAlignedBB axisAlignedBB = entity.getEntityBoundingBox() .offset(-entity.posX, -entity.posY, -entity.posZ) .offset(x, y, z); drawAxisAlignedBB( new AxisAlignedBB(axisAlignedBB.minX, axisAlignedBB.maxY + 0.2, axisAlignedBB.minZ, axisAlignedBB.maxX, axisAlignedBB.maxY + 0.26, axisAlignedBB.maxZ), color ); } public static void drawFilledBox(final AxisAlignedBB axisAlignedBB) { final Tessellator tessellator = Tessellator.getInstance(); final WorldRenderer worldRenderer = tessellator.getWorldRenderer(); worldRenderer.begin(7, DefaultVertexFormats.POSITION); worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.minZ).endVertex(); worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.maxY, axisAlignedBB.minZ).endVertex(); worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.minZ).endVertex(); worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.minZ).endVertex(); worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.maxZ).endVertex(); worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.maxZ).endVertex(); worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.maxZ).endVertex(); worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.maxY, axisAlignedBB.maxZ).endVertex(); worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.minZ).endVertex(); worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.minZ).endVertex(); worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.maxY, axisAlignedBB.minZ).endVertex(); worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.minZ).endVertex(); worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.maxY, axisAlignedBB.maxZ).endVertex(); worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.maxZ).endVertex(); worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.maxZ).endVertex(); worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.maxZ).endVertex(); worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.maxY, axisAlignedBB.minZ).endVertex(); worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.minZ).endVertex(); worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.maxZ).endVertex(); worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.maxY, axisAlignedBB.maxZ).endVertex(); worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.maxY, axisAlignedBB.minZ).endVertex(); worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.maxY, axisAlignedBB.maxZ).endVertex(); worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.maxZ).endVertex(); worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.minZ).endVertex(); worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.minZ).endVertex(); worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.minZ).endVertex(); worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.maxZ).endVertex(); worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.maxZ).endVertex(); worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.minZ).endVertex(); worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.maxZ).endVertex(); worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.maxZ).endVertex(); worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.minZ).endVertex(); worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.minZ).endVertex(); worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.maxY, axisAlignedBB.minZ).endVertex(); worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.maxZ).endVertex(); worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.maxY, axisAlignedBB.maxZ).endVertex(); worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.maxZ).endVertex(); worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.maxZ).endVertex(); worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.minZ).endVertex(); worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.minZ).endVertex(); worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.maxY, axisAlignedBB.maxZ).endVertex(); worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.maxZ).endVertex(); worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.maxY, axisAlignedBB.minZ).endVertex(); worldRenderer.pos(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.minZ).endVertex(); worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.minZ).endVertex(); worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.minZ).endVertex(); worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.maxZ).endVertex(); worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.maxZ).endVertex(); tessellator.draw(); } public static void quickDrawRect(final float x, final float y, final float x2, final float y2) { glBegin(GL_QUADS); glVertex2d(x2, y); glVertex2d(x, y); glVertex2d(x, y2); glVertex2d(x2, y2); glEnd(); } public static void drawRect(final float x, final float y, final float x2, final float y2, final int color) { glEnable(GL_BLEND); glDisable(GL_TEXTURE_2D); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_LINE_SMOOTH); glColor(color); glBegin(GL_QUADS); glVertex2f(x2, y); glVertex2f(x, y); glVertex2f(x, y2); glVertex2f(x2, y2); glEnd(); glEnable(GL_TEXTURE_2D); glDisable(GL_BLEND); glDisable(GL_LINE_SMOOTH); } public static void drawRect(final int x, final int y, final int x2, final int y2, final int color) { glEnable(GL_BLEND); glDisable(GL_TEXTURE_2D); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_LINE_SMOOTH); glColor(color); glBegin(GL_QUADS); glVertex2i(x2, y); glVertex2i(x, y); glVertex2i(x, y2); glVertex2i(x2, y2); glEnd(); glEnable(GL_TEXTURE_2D); glDisable(GL_BLEND); glDisable(GL_LINE_SMOOTH); } /** * Like {@link #drawRect(float, float, float, float, int)}, but without setup */ public static void quickDrawRect(final float x, final float y, final float x2, final float y2, final int color) { glColor(color); glBegin(GL_QUADS); glVertex2d(x2, y); glVertex2d(x, y); glVertex2d(x, y2); glVertex2d(x2, y2); glEnd(); } public static void drawRect(final float x, final float y, final float x2, final float y2, final Color color) { drawRect(x, y, x2, y2, color.getRGB()); } public static void drawBorderedRect(final float x, final float y, final float x2, final float y2, final float width, final int color1, final int color2) { drawRect(x, y, x2, y2, color2); drawBorder(x, y, x2, y2, width, color1); } public static void drawBorder(float x, float y, float x2, float y2, float width, int color1) { glEnable(GL_BLEND); glDisable(GL_TEXTURE_2D); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_LINE_SMOOTH); glColor(color1); glLineWidth(width); glBegin(GL_LINE_LOOP); glVertex2d(x2, y); glVertex2d(x, y); glVertex2d(x, y2); glVertex2d(x2, y2); glEnd(); glEnable(GL_TEXTURE_2D); glDisable(GL_BLEND); glDisable(GL_LINE_SMOOTH); } public static void quickDrawBorderedRect(final float x, final float y, final float x2, final float y2, final float width, final int color1, final int color2) { quickDrawRect(x, y, x2, y2, color2); glColor(color1); glLineWidth(width); glBegin(GL_LINE_LOOP); glVertex2d(x2, y); glVertex2d(x, y); glVertex2d(x, y2); glVertex2d(x2, y2); glEnd(); } public static void drawLoadingCircle(float x, float y) { for (int i = 0; i < 4; i++) { int rot = (int) ((System.nanoTime() / 5000000 * i) % 360); drawCircle(x, y, i * 10, rot - 180, rot); } } public static void drawCircle(float x, float y, float radius, int start, int end) { GlStateManager.enableBlend(); GlStateManager.disableTexture2D(); GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); glColor(Color.WHITE); glEnable(GL_LINE_SMOOTH); glLineWidth(2F); glBegin(GL_LINE_STRIP); for (float i = end; i >= start; i -= (360 / 90.0f)) { glVertex2f((float) (x + (cos(i * PI / 180) * (radius * 1.001F))), (float) (y + (sin(i * PI / 180) * (radius * 1.001F)))); } glEnd(); glDisable(GL_LINE_SMOOTH); GlStateManager.enableTexture2D(); GlStateManager.disableBlend(); } public static void drawFilledCircle(final int xx, final int yy, final float radius, final Color color) { int sections = 50; double dAngle = 2 * Math.PI / sections; float x, y; glPushAttrib(GL_ENABLE_BIT); glEnable(GL_BLEND); glDisable(GL_TEXTURE_2D); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_LINE_SMOOTH); glBegin(GL_TRIANGLE_FAN); for (int i = 0; i < sections; i++) { x = (float) (radius * Math.sin((i * dAngle))); y = (float) (radius * Math.cos((i * dAngle))); glColor4f(color.getRed() / 255F, color.getGreen() / 255F, color.getBlue() / 255F, color.getAlpha() / 255F); glVertex2f(xx + x, yy + y); } glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glEnd(); glPopAttrib(); } public static void drawImage(ResourceLocation image, int x, int y, int width, int height) { glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glDepthMask(false); GL14.glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); glColor4f(1.0F, 1.0F, 1.0F, 1.0F); mc.getTextureManager().bindTexture(image); drawModalRectWithCustomSizedTexture(x, y, 0, 0, width, height, width, height); glDepthMask(true); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); } /** * Draws a textured rectangle at z = 0. Args: x, y, u, v, width, height, textureWidth, textureHeight */ public static void drawModalRectWithCustomSizedTexture(float x, float y, float u, float v, float width, float height, float textureWidth, float textureHeight) { float f = 1.0F / textureWidth; float f1 = 1.0F / textureHeight; Tessellator tessellator = Tessellator.getInstance(); WorldRenderer worldrenderer = tessellator.getWorldRenderer(); worldrenderer.begin(7, DefaultVertexFormats.POSITION); worldrenderer.pos(x, y + height, 0.0D).tex(u * f, (v + height) * f1).endVertex(); worldrenderer.pos(x + width, y + height, 0.0D).tex((u + width) * f, (v + height) * f1).endVertex(); worldrenderer.pos(x + width, y, 0.0D).tex((u + width) * f, v * f1).endVertex(); worldrenderer.pos(x, y, 0.0D).tex(u * f, v * f1).endVertex(); tessellator.draw(); } public static void glColor(final int red, final int green, final int blue, final int alpha) { GL11.glColor4f(red / 255F, green / 255F, blue / 255F, alpha / 255F); } public static void glColor(final Color color) { glColor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); } private static void glColor(final int hex) { glColor(hex >> 16 & 0xFF, hex >> 8 & 0xFF, hex & 0xFF, hex >> 24 & 0xFF); } public static void draw2D(final EntityLivingBase entity, final double posX, final double posY, final double posZ, final int color, final int backgroundColor) { GL11.glPushMatrix(); GL11.glTranslated(posX, posY, posZ); GL11.glRotated(-mc.getRenderManager().viewerPosY, 0F, 1F, 0F); GL11.glScaled(-0.1D, -0.1D, 0.1D); glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glDisable(GL_TEXTURE_2D); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); GL11.glDepthMask(true); glColor(color); glCallList(DISPLAY_LISTS_2D[0]); glColor(backgroundColor); glCallList(DISPLAY_LISTS_2D[1]); GL11.glTranslated(0, 21 + -(entity.getEntityBoundingBox().maxY - entity.getEntityBoundingBox().minY) * 12, 0); glColor(color); glCallList(DISPLAY_LISTS_2D[2]); glColor(backgroundColor); glCallList(DISPLAY_LISTS_2D[3]); // Stop render glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); glDisable(GL_BLEND); GL11.glPopMatrix(); } public static void draw2D(final BlockPos blockPos, final int color, final int backgroundColor) { final RenderManager renderManager = mc.getRenderManager(); final double posX = (blockPos.getX() + 0.5) - renderManager.viewerPosX; final double posY = blockPos.getY() - renderManager.viewerPosY; final double posZ = (blockPos.getZ() + 0.5) - renderManager.viewerPosZ; GL11.glPushMatrix(); GL11.glTranslated(posX, posY, posZ); GL11.glRotated(-mc.getRenderManager().playerViewY, 0F, 1F, 0F); GL11.glScaled(-0.1D, -0.1D, 0.1D); glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glDisable(GL_TEXTURE_2D); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); GL11.glDepthMask(true); glColor(color); glCallList(DISPLAY_LISTS_2D[0]); glColor(backgroundColor); glCallList(DISPLAY_LISTS_2D[1]); GL11.glTranslated(0, 9, 0); glColor(color); glCallList(DISPLAY_LISTS_2D[2]); glColor(backgroundColor); glCallList(DISPLAY_LISTS_2D[3]); // Stop render glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); glDisable(GL_BLEND); GL11.glPopMatrix(); } public static void renderNameTag(final String string, final double x, final double y, final double z) { final RenderManager renderManager = mc.getRenderManager(); glPushMatrix(); glTranslated(x - renderManager.viewerPosX, y - renderManager.viewerPosY, z - renderManager.viewerPosZ); glNormal3f(0F, 1F, 0F); glRotatef(-mc.getRenderManager().playerViewY, 0F, 1F, 0F); glRotatef(mc.getRenderManager().playerViewX, 1F, 0F, 0F); glScalef(-0.05F, -0.05F, 0.05F); setGlCap(GL_LIGHTING, false); setGlCap(GL_DEPTH_TEST, false); setGlCap(GL_BLEND, true); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); final int width = mc.fontRendererObj.getStringWidth(string) / 2; drawRect(-width - 1, -1, width + 1, mc.fontRendererObj.FONT_HEIGHT, Integer.MIN_VALUE); mc.fontRendererObj.drawString(string, -width, 1.5F, Color.WHITE.getRGB(), true); resetCaps(); glColor4f(1F, 1F, 1F, 1F); glPopMatrix(); } public static void drawLine(final double x, final double y, final double x1, final double y1, final float width) { glDisable(GL_TEXTURE_2D); glLineWidth(width); glBegin(GL_LINES); glVertex2d(x, y); glVertex2d(x1, y1); glEnd(); glEnable(GL_TEXTURE_2D); } public static void makeScissorBox(final float x, final float y, final float x2, final float y2) { final ScaledResolution scaledResolution = new ScaledResolution(mc); final int factor = scaledResolution.getScaleFactor(); glScissor((int) (x * factor), (int) ((scaledResolution.getScaledHeight() - y2) * factor), (int) ((x2 - x) * factor), (int) ((y2 - y) * factor)); } /** * Modified from NotEnoughUpdates under Creative Commons Attribution-NonCommercial 3.0 * https://github.com/Moulberry/NotEnoughUpdates/blob/master/LICENSE */ public static void renderWaypointText(String str, double X, double Y, double Z, float partialTicks) { GlStateManager.alphaFunc(516, 0.1F); GlStateManager.pushMatrix(); Entity viewer = Main.mc.getRenderViewEntity(); double viewerX = viewer.lastTickPosX + (viewer.posX - viewer.lastTickPosX) * partialTicks; double viewerY = viewer.lastTickPosY + (viewer.posY - viewer.lastTickPosY) * partialTicks; double viewerZ = viewer.lastTickPosZ + (viewer.posZ - viewer.lastTickPosZ) * partialTicks; double x = X - viewerX; double y = Y - viewerY - viewer.getEyeHeight(); double z = Z - viewerZ; double distSq = x * x + y * y + z * z; double dist = Math.sqrt(distSq); if (distSq > 144) { x *= 12 / dist; y *= 12 / dist; z *= 12 / dist; } GlStateManager.translate(x, y, z); GlStateManager.translate(0, viewer.getEyeHeight(), 0); drawNametag(str); GlStateManager.rotate(-Main.mc.getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F); GlStateManager.rotate(Main.mc.getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F); GlStateManager.translate(0, -0.25f, 0); GlStateManager.rotate(-Main.mc.getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F); GlStateManager.rotate(Main.mc.getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F); drawNametag(EnumChatFormatting.YELLOW.toString() + Math.round(dist) + " blocks"); GlStateManager.popMatrix(); GlStateManager.disableLighting(); } public static void drawNametag(String str) { FontRenderer fontrenderer = Main.mc.fontRendererObj; float f = 1.6F; float f1 = 0.016666668F * f; GlStateManager.pushMatrix(); GL11.glNormal3f(0.0F, 1.0F, 0.0F); GlStateManager.rotate(-Main.mc.getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F); GlStateManager.rotate(Main.mc.getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F); GlStateManager.scale(-f1, -f1, f1); GlStateManager.disableLighting(); GlStateManager.depthMask(false); GlStateManager.disableDepth(); GlStateManager.enableBlend(); GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); Tessellator tessellator = Tessellator.getInstance(); WorldRenderer worldrenderer = tessellator.getWorldRenderer(); int i = 0; int j = fontrenderer.getStringWidth(str) / 2; GlStateManager.disableTexture2D(); worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR); worldrenderer.pos(-j - 1, -1 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); worldrenderer.pos(-j - 1, 8 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); worldrenderer.pos(j + 1, 8 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); worldrenderer.pos(j + 1, -1 + i, 0.0D).color(0.0F, 0.0F, 0.0F, 0.25F).endVertex(); tessellator.draw(); GlStateManager.enableTexture2D(); fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, 553648127); GlStateManager.depthMask(true); fontrenderer.drawString(str, -fontrenderer.getStringWidth(str) / 2, i, -1); GlStateManager.enableDepth(); GlStateManager.enableBlend(); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); GlStateManager.popMatrix(); } /** * GL CAP MANAGER *

* TODO: Remove gl cap manager and replace by something better */ public static void resetCaps() { glCapMap.forEach(RenderUtils::setGlState); } public static void enableGlCap(final int cap) { setGlCap(cap, true); } public static void enableGlCap(final int... caps) { for (final int cap : caps) setGlCap(cap, true); } public static void disableGlCap(final int cap) { setGlCap(cap, true); } public static void disableGlCap(final int... caps) { for (final int cap : caps) setGlCap(cap, false); } public static void setGlCap(final int cap, final boolean state) { glCapMap.put(cap, glGetBoolean(cap)); setGlState(cap, state); } public static void setGlState(final int cap, final boolean state) { if (state) glEnable(cap); else glDisable(cap); } public static void drawScaledCustomSizeModalRect(int x, int y, float u, float v, int uWidth, int vHeight, int width, int height, float tileWidth, float tileHeight) { float f = 1.0F / tileWidth; float f1 = 1.0F / tileHeight; Tessellator tessellator = Tessellator.getInstance(); WorldRenderer worldrenderer = tessellator.getWorldRenderer(); worldrenderer.begin(7, DefaultVertexFormats.POSITION); worldrenderer.pos(x, y + height, 0.0D).tex(u * f, (v + (float) vHeight) * f1).endVertex(); worldrenderer.pos(x + width, y + height, 0.0D).tex((u + (float) uWidth) * f, (v + (float) vHeight) * f1).endVertex(); worldrenderer.pos(x + width, y, 0.0D).tex((u + (float) uWidth) * f, v * f1).endVertex(); worldrenderer.pos(x, y, 0.0D).tex(u * f, v * f1).endVertex(); tessellator.draw(); } public static void enableChams() { GL11.glEnable(32823); GlStateManager.enablePolygonOffset(); GlStateManager.doPolygonOffset(1.0F, -1000000.0F); } public static void disableChams() { GL11.glDisable(32823); GlStateManager.doPolygonOffset(1.0F, 1000000.0F); GlStateManager.disablePolygonOffset(); } }