/*
* Skytils - Hypixel Skyblock Quality of Life Mod
* Copyright (C) 2021 Skytils
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
package skytils.skytilsmod.utils
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.Gui
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.RenderGlobal
import net.minecraft.client.renderer.RenderHelper
import net.minecraft.client.renderer.Tessellator
import net.minecraft.client.renderer.vertex.DefaultVertexFormats
import net.minecraft.entity.Entity
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.inventory.Slot
import net.minecraft.item.ItemStack
import net.minecraft.util.*
import org.lwjgl.opengl.GL11
import skytils.skytilsmod.Skytils
import skytils.skytilsmod.Skytils.Companion.mc
import skytils.skytilsmod.mixins.hooks.renderer.skipGlint
import skytils.skytilsmod.mixins.transformers.accessors.AccessorMinecraft
import java.awt.Color
import java.util.concurrent.locks.ReentrantLock
import kotlin.math.cos
import kotlin.math.roundToInt
import kotlin.math.sin
import kotlin.math.sqrt
object RenderUtil {
private val RARITY = ResourceLocation("skytils", "gui/rarity.png")
private val RARITY2 = ResourceLocation("skytils", "gui/rarity2.png")
private val RARITY3 = ResourceLocation("skytils", "gui/rarity3.png")
private val RARITY4 = ResourceLocation("skytils", "gui/rarity4.png")
private val CUSTOMRARITY = ResourceLocation("skytils", "gui/customrarity.png")
private val beaconBeam = ResourceLocation("textures/entity/beacon_beam.png")
private val mutex = ReentrantLock()
/**
* Taken from NotEnoughUpdates under Creative Commons Attribution-NonCommercial 3.0
* https://github.com/Moulberry/NotEnoughUpdates/blob/master/LICENSE
* @author Moulberry
*/
fun renderBeaconBeam(x: Double, y: Double, z: Double, rgb: Int, alphaMultiplier: Float, partialTicks: Float) {
val height = 300
val bottomOffset = 0
val topOffset = bottomOffset + height
val tessellator = Tessellator.getInstance()
val worldrenderer = tessellator.worldRenderer
Minecraft.getMinecraft().textureManager.bindTexture(beaconBeam)
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, 10497.0f)
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, 10497.0f)
GlStateManager.disableLighting()
GlStateManager.enableCull()
GlStateManager.enableTexture2D()
GlStateManager.tryBlendFuncSeparate(770, 1, 1, 0)
GlStateManager.enableBlend()
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0)
val time = Minecraft.getMinecraft().theWorld.totalWorldTime + partialTicks.toDouble()
val d1 = MathHelper.func_181162_h(
-time * 0.2 - MathHelper.floor_double(-time * 0.1)
.toDouble()
)
val r = (rgb shr 16 and 0xFF) / 255f
val g = (rgb shr 8 and 0xFF) / 255f
val b = (rgb and 0xFF) / 255f
val d2 = time * 0.025 * -1.5
val d4 = 0.5 + cos(d2 + 2.356194490192345) * 0.2
val d5 = 0.5 + sin(d2 + 2.356194490192345) * 0.2
val d6 = 0.5 + cos(d2 + Math.PI / 4.0) * 0.2
val d7 = 0.5 + sin(d2 + Math.PI / 4.0) * 0.2
val d8 = 0.5 + cos(d2 + 3.9269908169872414) * 0.2
val d9 = 0.5 + sin(d2 + 3.9269908169872414) * 0.2
val d10 = 0.5 + cos(d2 + 5.497787143782138) * 0.2
val d11 = 0.5 + sin(d2 + 5.497787143782138) * 0.2
val d14 = -1.0 + d1
val d15 = height.toDouble() * 2.5 + d14
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR)
worldrenderer.pos(x + d4, y + topOffset, z + d5).tex(1.0, d15).color(r, g, b, 1.0f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + d4, y + bottomOffset, z + d5).tex(1.0, d14).color(r, g, b, 1.0f).endVertex()
worldrenderer.pos(x + d6, y + bottomOffset, z + d7).tex(0.0, d14).color(r, g, b, 1.0f).endVertex()
worldrenderer.pos(x + d6, y + topOffset, z + d7).tex(0.0, d15).color(r, g, b, 1.0f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + d10, y + topOffset, z + d11).tex(1.0, d15).color(r, g, b, 1.0f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + d10, y + bottomOffset, z + d11).tex(1.0, d14).color(r, g, b, 1.0f).endVertex()
worldrenderer.pos(x + d8, y + bottomOffset, z + d9).tex(0.0, d14).color(r, g, b, 1.0f).endVertex()
worldrenderer.pos(x + d8, y + topOffset, z + d9).tex(0.0, d15).color(r, g, b, 1.0f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + d6, y + topOffset, z + d7).tex(1.0, d15).color(r, g, b, 1.0f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + d6, y + bottomOffset, z + d7).tex(1.0, d14).color(r, g, b, 1.0f).endVertex()
worldrenderer.pos(x + d10, y + bottomOffset, z + d11).tex(0.0, d14).color(r, g, b, 1.0f).endVertex()
worldrenderer.pos(x + d10, y + topOffset, z + d11).tex(0.0, d15).color(r, g, b, 1.0f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + d8, y + topOffset, z + d9).tex(1.0, d15).color(r, g, b, 1.0f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + d8, y + bottomOffset, z + d9).tex(1.0, d14).color(r, g, b, 1.0f).endVertex()
worldrenderer.pos(x + d4, y + bottomOffset, z + d5).tex(0.0, d14).color(r, g, b, 1.0f).endVertex()
worldrenderer.pos(x + d4, y + topOffset, z + d5).tex(0.0, d15).color(r, g, b, 1.0f * alphaMultiplier)
.endVertex()
tessellator.draw()
GlStateManager.disableCull()
val d12 = -1.0 + d1
val d13 = height + d12
worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR)
worldrenderer.pos(x + 0.2, y + topOffset, z + 0.2).tex(1.0, d13).color(r, g, b, 0.25f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + 0.2, y + bottomOffset, z + 0.2).tex(1.0, d12).color(r, g, b, 0.25f).endVertex()
worldrenderer.pos(x + 0.8, y + bottomOffset, z + 0.2).tex(0.0, d12).color(r, g, b, 0.25f).endVertex()
worldrenderer.pos(x + 0.8, y + topOffset, z + 0.2).tex(0.0, d13).color(r, g, b, 0.25f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + 0.8, y + topOffset, z + 0.8).tex(1.0, d13).color(r, g, b, 0.25f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + 0.8, y + bottomOffset, z + 0.8).tex(1.0, d12).color(r, g, b, 0.25f).endVertex()
worldrenderer.pos(x + 0.2, y + bottomOffset, z + 0.8).tex(0.0, d12).color(r, g, b, 0.25f).endVertex()
worldrenderer.pos(x + 0.2, y + topOffset, z + 0.8).tex(0.0, d13).color(r, g, b, 0.25f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + 0.8, y + topOffset, z + 0.2).tex(1.0, d13).color(r, g, b, 0.25f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + 0.8, y + bottomOffset, z + 0.2).tex(1.0, d12).color(r, g, b, 0.25f).endVertex()
worldrenderer.pos(x + 0.8, y + bottomOffset, z + 0.8).tex(0.0, d12).color(r, g, b, 0.25f).endVertex()
worldrenderer.pos(x + 0.8, y + topOffset, z + 0.8).tex(0.0, d13).color(r, g, b, 0.25f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + 0.2, y + topOffset, z + 0.8).tex(1.0, d13).color(r, g, b, 0.25f * alphaMultiplier)
.endVertex()
worldrenderer.pos(x + 0.2, y + bottomOffset, z + 0.8).tex(1.0, d12).color(r, g, b, 0.25f).endVertex()
worldrenderer.pos(x + 0.2, y + bottomOffset, z + 0.2).tex(0.0, d12).color(r, g, b, 0.25f).endVertex()
worldrenderer.pos(x + 0.2, y + topOffset, z + 0.2).tex(0.0, d13).color(r, g, b, 0.25f * alphaMultiplier)
.endVertex()
tessellator.draw()
}
/**
* Taken from NotEnoughUpdates under Creative Commons Attribution-NonCommercial 3.0
* https://github.com/Moulberry/NotEnoughUpdates/blob/master/LICENSE
* @author Moulberry
*/
fun drawFilledBoundingBox(aabb: AxisAlignedBB, c: Color, alphaMultiplier: Float = 1f) {
GlStateManager.enableBlend()
GlStateManager.disableLighting()
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0)
GlStateManager.disableTexture2D()
val tessellator = Tessellator.getInstance()
val worldRenderer = tessellator.worldRenderer
GlStateManager.color(c.red / 255f, c.green / 255f, c.blue / 255f, c.alpha / 255f * alphaMultiplier)
//vertical
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION)
worldRenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex()
worldRenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex()
worldRenderer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex()
worldRenderer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex()
tessellator.draw()
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION)
worldRenderer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex()
worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex()
worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex()
worldRenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex()
tessellator.draw()
GlStateManager.color(
c.red / 255f * 0.8f,
c.green / 255f * 0.8f,
c.blue / 255f * 0.8f,
c.alpha / 255f * alphaMultiplier
)
//x
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION)
worldRenderer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex()
worldRenderer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex()
worldRenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex()
worldRenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex()
tessellator.draw()
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION)
worldRenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex()
worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex()
worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex()
worldRenderer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex()
tessellator.draw()
GlStateManager.color(
c.red / 255f * 0.9f,
c.green / 255f * 0.9f,
c.blue / 255f * 0.9f,
c.alpha / 255f * alphaMultiplier
)
//z
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION)
worldRenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex()
worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex()
worldRenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex()
worldRenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex()
tessellator.draw()
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION)
worldRenderer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex()
worldRenderer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex()
worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex()
worldRenderer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex()
tessellator.draw()
GlStateManager.enableTexture2D()
GlStateManager.disableBlend()
}
/**
* Taken from Danker's Skyblock Mod under GPL 3.0 license
* https://github.com/bowser0000/SkyblockMod/blob/master/LICENSE
* @author bowser0000
*/
@JvmStatic
fun drawOutlinedBoundingBox(aabb: AxisAlignedBB?, color: Color, width: Float, partialTicks: Float) {
val render = Minecraft.getMinecraft().renderViewEntity
val realX = render.lastTickPosX + (render.posX - render.lastTickPosX) * partialTicks
val realY = render.lastTickPosY + (render.posY - render.lastTickPosY) * partialTicks
val realZ = render.lastTickPosZ + (render.posZ - render.lastTickPosZ) * partialTicks
GlStateManager.pushMatrix()
GlStateManager.translate(-realX, -realY, -realZ)
GlStateManager.disableTexture2D()
GlStateManager.enableBlend()
GlStateManager.disableLighting()
GlStateManager.disableAlpha()
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0)
GL11.glLineWidth(width)
RenderGlobal.drawOutlinedBoundingBox(aabb, color.red, color.green, color.blue, color.alpha)
GlStateManager.translate(realX, realY, realZ)
GlStateManager.disableBlend()
GlStateManager.enableAlpha()
GlStateManager.enableTexture2D()
GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f)
GlStateManager.popMatrix()
}
/**
* Taken from Skyblockcatia under MIT License
* Modified
* https://github.com/SteveKunG/SkyBlockcatia/blob/1.8.9/LICENSE.md
*
* @author SteveKunG
*/
@JvmStatic
fun renderItem(itemStack: ItemStack?, x: Int, y: Int) {
RenderHelper.enableGUIStandardItemLighting()
GlStateManager.enableRescaleNormal()
GlStateManager.enableBlend()
GlStateManager.enableDepth()
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0)
Minecraft.getMinecraft().renderItem.renderItemAndEffectIntoGUI(itemStack, x, y)
}
/**
* Taken from Skyblockcatia under MIT License
* Modified
* https://github.com/SteveKunG/SkyBlockcatia/blob/1.8.9/LICENSE.md
*
* @author SteveKunG
*/
@JvmStatic
fun renderTexture(
texture: ResourceLocation?,
x: Int,
y: Int,
width: Int = 16,
height: Int = 16,
enableLighting: Boolean = true
) {
if (enableLighting) RenderHelper.enableGUIStandardItemLighting()
GlStateManager.enableRescaleNormal()
GlStateManager.enableBlend()
GlStateManager.enableDepth()
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0)
GlStateManager.pushMatrix()
Minecraft.getMinecraft().textureManager.bindTexture(texture)
GlStateManager.enableRescaleNormal()
GlStateManager.enableAlpha()
GlStateManager.alphaFunc(516, 0.1f)
GlStateManager.enableBlend()
GlStateManager.blendFunc(770, 771)
GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f)
Gui.drawModalRectWithCustomSizedTexture(x, y, 0f, 0f, width, height, width.toFloat(), height.toFloat())
GlStateManager.disableAlpha()
GlStateManager.disableRescaleNormal()
GlStateManager.disableLighting()
GlStateManager.popMatrix()
}
/**
* Taken from Danker's Skyblock Mod under GPL 3.0 license
* https://github.com/bowser0000/SkyblockMod/blob/master/LICENSE
* @author bowser0000
*/
fun draw3DLine(pos1: Vec3, pos2: Vec3, width: Int, color: Color, partialTicks: Float) {
val render = Minecraft.getMinecraft().renderViewEntity
val worldRenderer = Tessellator.getInstance().worldRenderer
val realX = render.lastTickPosX + (render.posX - render.lastTickPosX) * partialTicks
val realY = render.lastTickPosY + (render.posY - render.lastTickPosY) * partialTicks
val realZ = render.lastTickPosZ + (render.posZ - render.lastTickPosZ) * partialTicks
GlStateManager.pushMatrix()
GlStateManager.translate(-realX, -realY, -realZ)
GlStateManager.disableTexture2D()
GlStateManager.enableBlend()
GlStateManager.disableAlpha()
GlStateManager.disableLighting()
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0)
GL11.glLineWidth(width.toFloat())
GlStateManager.color(color.red / 255f, color.green / 255f, color.blue / 255f, color.alpha / 255f)
worldRenderer.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION)
worldRenderer.pos(pos1.xCoord, pos1.yCoord, pos1.zCoord).endVertex()
worldRenderer.pos(pos2.xCoord, pos2.yCoord, pos2.zCoord).endVertex()
Tessellator.getInstance().draw()
GlStateManager.translate(realX, realY, realZ)
GlStateManager.disableBlend()
GlStateManager.enableAlpha()
GlStateManager.enableTexture2D()
GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f)
GlStateManager.popMatrix()
}
/**
* Taken from Danker's Skyblock Mod under GPL 3.0 license
* https://github.com/bowser0000/SkyblockMod/blob/master/LICENSE
* @author bowser0000
*/
fun draw3DString(pos: Vec3, text: String, color: Color, partialTicks: Float) {
val mc = Minecraft.getMinecraft()
val player: EntityPlayer = mc.thePlayer
val x =
pos.xCoord - player.lastTickPosX + (pos.xCoord - player.posX - (pos.xCoord - player.lastTickPosX)) * partialTicks
val y =
pos.yCoord - player.lastTickPosY + (pos.yCoord - player.posY - (pos.yCoord - player.lastTickPosY)) * partialTicks
val z =
pos.zCoord - player.lastTickPosZ + (pos.zCoord - player.posZ - (pos.zCoord - player.lastTickPosZ)) * partialTicks
val renderManager = mc.renderManager
val f = 1.6f
val f1 = 0.016666668f * f
val width = mc.fontRendererObj.getStringWidth(text) / 2
GlStateManager.pushMatrix()
GlStateManager.translate(x, y, z)
GL11.glNormal3f(0f, 1f, 0f)
GlStateManager.rotate(-renderManager.playerViewY, 0f, 1f, 0f)
GlStateManager.rotate(renderManager.playerViewX, 1f, 0f, 0f)
GlStateManager.scale(-f1, -f1, -f1)
GlStateManager.enableBlend()
GlStateManager.disableLighting()
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0)
mc.fontRendererObj.drawString(text, -width, 0, color.rgb)
GlStateManager.disableBlend()
GlStateManager.popMatrix()
}
/**
* Taken from NotEnoughUpdates under Creative Commons Attribution-NonCommercial 3.0
* https://github.com/Moulberry/NotEnoughUpdates/blob/master/LICENSE
* @author Moulberry
*/
fun renderWaypointText(str: String?, loc: BlockPos, partialTicks: Float) {
GlStateManager.alphaFunc(516, 0.1f)
GlStateManager.pushMatrix()
val viewer = Minecraft.getMinecraft().renderViewEntity
val viewerX = viewer.lastTickPosX + (viewer.posX - viewer.lastTickPosX) * partialTicks
val viewerY = viewer.lastTickPosY + (viewer.posY - viewer.lastTickPosY) * partialTicks
val viewerZ = viewer.lastTickPosZ + (viewer.posZ - viewer.lastTickPosZ) * partialTicks
var x = loc.x - viewerX
var y = loc.y - viewerY - viewer.eyeHeight
var z = loc.z - viewerZ
val distSq = x * x + y * y + z * z
val dist = sqrt(distSq)
if (distSq > 144) {
x *= 12 / dist
y *= 12 / dist
z *= 12 / dist
}
GlStateManager.translate(x, y, z)
GlStateManager.translate(0f, viewer.eyeHeight, 0f)
drawNametag(str)
GlStateManager.rotate(-Minecraft.getMinecraft().renderManager.playerViewY, 0.0f, 1.0f, 0.0f)
GlStateManager.rotate(Minecraft.getMinecraft().renderManager.playerViewX, 1.0f, 0.0f, 0.0f)
GlStateManager.translate(0f, -0.25f, 0f)
GlStateManager.rotate(-Minecraft.getMinecraft().renderManager.playerViewX, 1.0f, 0.0f, 0.0f)
GlStateManager.rotate(Minecraft.getMinecraft().renderManager.playerViewY, 0.0f, 1.0f, 0.0f)
drawNametag(EnumChatFormatting.YELLOW.toString() + dist.roundToInt() + "m")
GlStateManager.popMatrix()
GlStateManager.disableLighting()
}
/**
* Taken from NotEnoughUpdates under Creative Commons Attribution-NonCommercial 3.0
* Modified
* https://github.com/Moulberry/NotEnoughUpdates/blob/master/LICENSE
* @author Moulberry
*/
fun renderWaypointText(str: String?, X: Double, Y: Double, Z: Double, partialTicks: Float) {
GlStateManager.alphaFunc(516, 0.1f)
GlStateManager.pushMatrix()
val viewer = Minecraft.getMinecraft().renderViewEntity
val viewerX = viewer.lastTickPosX + (viewer.posX - viewer.lastTickPosX) * partialTicks
val viewerY = viewer.lastTickPosY + (viewer.posY - viewer.lastTickPosY) * partialTicks
val viewerZ = viewer.lastTickPosZ + (viewer.posZ - viewer.lastTickPosZ) * partialTicks
var x = X - viewerX
var y = Y - viewerY - viewer.eyeHeight
var z = Z - viewerZ
val distSq = x * x + y * y + z * z
val dist = sqrt(distSq)
if (distSq > 144) {
x *= 12 / dist
y *= 12 / dist
z *= 12 / dist
}
GlStateManager.translate(x, y, z)
GlStateManager.translate(0f, viewer.eyeHeight, 0f)
drawNametag(str)
GlStateManager.rotate(-Minecraft.getMinecraft().renderManager.playerViewY, 0.0f, 1.0f, 0.0f)
GlStateManager.rotate(Minecraft.getMinecraft().renderManager.playerViewX, 1.0f, 0.0f, 0.0f)
GlStateManager.translate(0f, -0.25f, 0f)
GlStateManager.rotate(-Minecraft.getMinecraft().renderManager.playerViewX, 1.0f, 0.0f, 0.0f)
GlStateManager.rotate(Minecraft.getMinecraft().renderManager.playerViewY, 0.0f, 1.0f, 0.0f)
drawNametag(EnumChatFormatting.YELLOW.toString() + dist.roundToInt() + "m")
GlStateManager.popMatrix()
GlStateManager.disableLighting()
}
/**
* Taken from NotEnoughUpdates under Creative Commons Attribution-NonCommercial 3.0
* https://github.com/Moulberry/NotEnoughUpdates/blob/master/LICENSE
* @author Moulberry
*/
private fun drawNametag(str: String?) {
val fontRenderer = Minecraft.getMinecraft().fontRendererObj
val f = 1.6f
val f1 = 0.016666668f * f
GlStateManager.pushMatrix()
GL11.glNormal3f(0.0f, 1.0f, 0.0f)
GlStateManager.rotate(-Minecraft.getMinecraft().renderManager.playerViewY, 0.0f, 1.0f, 0.0f)
GlStateManager.rotate(Minecraft.getMinecraft().renderManager.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)
val tessellator = Tessellator.getInstance()
val worldrenderer = tessellator.worldRenderer
val i = 0
val j = fontRenderer.getStringWidth(str) / 2
GlStateManager.disableTexture2D()
worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR)
worldrenderer.pos((-j - 1).toDouble(), (-1 + i).toDouble(), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex()
worldrenderer.pos((-j - 1).toDouble(), (8 + i).toDouble(), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex()
worldrenderer.pos((j + 1).toDouble(), (8 + i).toDouble(), 0.0).color(0.0f, 0.0f, 0.0f, 0.25f).endVertex()
worldrenderer.pos((j + 1).toDouble(), (-1 + i).toDouble(), 0.0).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()
}
@JvmStatic
fun renderRarity(itemStack: ItemStack?, xPos: Int, yPos: Int) {
if (itemStack != null) {
if (!Skytils.config.showPetRarity && ItemUtil.isPet(itemStack)) {
return
} else {
if (!mutex.isLocked) {
mutex.lock()
renderRarity(xPos, yPos, itemStack)
mutex.unlock()
}
}
}
}
/**
* Taken from Skyblockcatia under MIT License
* https://github.com/SteveKunG/SkyBlockcatia/blob/1.8.9/LICENSE.md
* @author SteveKunG
*/
@JvmStatic
fun renderRarity(xPos: Int, yPos: Int, rarity: ItemRarity) {
val alpha = Skytils.config.itemRarityOpacity
// save the states
val lightingEnabled = GL11.glIsEnabled(GL11.GL_LIGHTING)
val depthEnabled = GL11.glIsEnabled(GL11.GL_DEPTH_TEST)
val alphaEnabled = GL11.glIsEnabled(GL11.GL_ALPHA_TEST)
if (lightingEnabled) GlStateManager.disableLighting()
if (depthEnabled) GlStateManager.disableDepth()
GlStateManager.pushMatrix()
GlStateManager.enableBlend()
if (!alphaEnabled) GlStateManager.enableAlpha()
mc.textureManager.bindTexture(
when (Skytils.config.itemRarityShape) {
0 -> RARITY
1 -> RARITY2
2 -> RARITY3
3 -> RARITY4
4 -> CUSTOMRARITY
else -> RARITY
}
)
GlStateManager.color(
rarity.color.red / 255.0f,
rarity.color.green / 255.0f,
rarity.color.blue / 255.0f,
alpha
)
GlStateManager.popMatrix()
GlStateManager.blendFunc(770, 771)
GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_BLEND)
Gui.drawModalRectWithCustomSizedTexture(xPos, yPos, 0f, 0f, 16, 16, 16f, 16f)
GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE)
if (lightingEnabled) GlStateManager.enableLighting()
if (depthEnabled) GlStateManager.enableDepth()
if (!alphaEnabled) GlStateManager.disableAlpha()
}
private fun renderRarity(xPos: Int, yPos: Int, itemStack: ItemStack?) {
if (itemStack == null) return
val rarity = ItemUtil.getRarity(itemStack)
if (rarity != null) {
val alpha = Skytils.config.itemRarityOpacity
if (Skytils.config.itemRarityShape < 5) {
renderRarity(xPos, yPos, rarity)
} else {
GlStateManager.pushMatrix()
// save the states
val lightingEnabled = GL11.glIsEnabled(GL11.GL_LIGHTING)
val depthEnabled = GL11.glIsEnabled(GL11.GL_DEPTH_TEST)
val alphaEnabled = GL11.glIsEnabled(GL11.GL_ALPHA_TEST)
if (lightingEnabled) GlStateManager.disableLighting()
if (depthEnabled) GlStateManager.disableDepth()
GlStateManager.enableBlend()
if (!alphaEnabled) GlStateManager.enableAlpha()
GL11.glEnable(GL11.GL_STENCIL_TEST) // Turn on da test
val scissorState = GL11.glGetInteger(GL11.GL_SCISSOR_TEST) // check if scissor test was on
GL11.glStencilMask(0xFF)
GL11.glDisable(GL11.GL_SCISSOR_TEST)
GL11.glClear(GL11.GL_STENCIL_BUFFER_BIT) // Flush old data
if (scissorState == GL11.GL_TRUE) GL11.glEnable(GL11.GL_SCISSOR_TEST)
GL11.glStencilMask(0xFF) // Writing = ON
GL11.glStencilFunc(GL11.GL_ALWAYS, 1, 0xFF) // Always "add" to frame
GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_REPLACE) // Replace on success
GL11.glColorMask(false, false, false, false)
//Anything rendered here becomes "cut" frame.
val scale: Double = 1.2
GlStateManager.translate(
xPos.toDouble(),
yPos.toDouble(),
0.0
)
GlStateManager.pushMatrix()
GlStateManager.translate(8.0, 8.0, 0.0)
GlStateManager.scale(scale, scale, 0.0)
GlStateManager.translate(-8.0, -8.0, 0.0)
skipGlint = true
renderItem(itemStack, 0, 0)
skipGlint = false
GlStateManager.popMatrix()
GL11.glColorMask(true, true, true, true)
GL11.glStencilMask(0x00) // Writing = OFF
GL11.glStencilFunc(GL11.GL_NOTEQUAL, 0, 0xFF) // Anything that wasn't defined above will not be rendered.
//Anything rendered here will be cut if goes beyond frame defined before.
Gui.drawRect(
1, 1, 17, 17,
Color(
(rarity.color.red).coerceAtLeast(0) / 255f,
(rarity.color.green).coerceAtLeast(0) / 255f,
(rarity.color.blue).coerceAtLeast(0) / 255f,
alpha
).rgb
)
GL11.glDisable(GL11.GL_STENCIL_TEST); // Turn this shit off!
if (lightingEnabled) GlStateManager.enableLighting()
if (depthEnabled) GlStateManager.enableDepth()
if (!alphaEnabled) GlStateManager.disableAlpha()
GlStateManager.popMatrix()
}
}
}
/**
* Taken from SkyblockAddons under MIT License
* Modified
* https://github.com/BiscuitDevelopment/SkyblockAddons/blob/master/LICENSE
* @author BiscuitDevelopment
*
* Draws a solid color rectangle with the specified coordinates and color (ARGB format). Args: x1, y1, x2, y2, color
*/
fun drawRect(left: Double, top: Double, right: Double, bottom: Double, color: Int) {
var leftModifiable = left
var topModifiable = top
var rightModifiable = right
var bottomModifiable = bottom
if (leftModifiable < rightModifiable) {
val i = leftModifiable
leftModifiable = rightModifiable
rightModifiable = i
}
if (topModifiable < bottomModifiable) {
val j = topModifiable
topModifiable = bottomModifiable
bottomModifiable = j
}
val f3 = (color shr 24 and 255).toFloat() / 255.0f
val f = (color shr 16 and 255).toFloat() / 255.0f
val f1 = (color shr 8 and 255).toFloat() / 255.0f
val f2 = (color and 255).toFloat() / 255.0f
GlStateManager.color(f, f1, f2, f3)
val tessellator = Tessellator.getInstance()
val worldRenderer = tessellator.worldRenderer
GlStateManager.enableBlend()
GlStateManager.disableTexture2D()
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0)
worldRenderer.begin(7, DefaultVertexFormats.POSITION)
worldRenderer.pos(leftModifiable, bottomModifiable, 0.0).endVertex()
worldRenderer.pos(rightModifiable, bottomModifiable, 0.0).endVertex()
worldRenderer.pos(rightModifiable, topModifiable, 0.0).endVertex()
worldRenderer.pos(leftModifiable, topModifiable, 0.0).endVertex()
tessellator.draw()
GlStateManager.enableTexture2D()
GlStateManager.disableBlend()
}
/**
* Taken from SkyblockAddons under MIT License
* https://github.com/BiscuitDevelopment/SkyblockAddons/blob/master/LICENSE
* @author BiscuitDevelopment
*
*/
fun drawCylinderInWorld(x: Double, y: Double, z: Double, radius: Float, height: Float, partialTicks: Float) {
var x1 = x
var y1 = y
var z1 = z
val renderViewEntity = Minecraft.getMinecraft().renderViewEntity
val viewX =
renderViewEntity.prevPosX + (renderViewEntity.posX - renderViewEntity.prevPosX) * partialTicks.toDouble()
val viewY =
renderViewEntity.prevPosY + (renderViewEntity.posY - renderViewEntity.prevPosY) * partialTicks.toDouble()
val viewZ =
renderViewEntity.prevPosZ + (renderViewEntity.posZ - renderViewEntity.prevPosZ) * partialTicks.toDouble()
x1 -= viewX
y1 -= viewY
z1 -= viewZ
val tessellator = Tessellator.getInstance()
val worldrenderer = tessellator.worldRenderer
worldrenderer.begin(GL11.GL_QUAD_STRIP, DefaultVertexFormats.POSITION)
var currentAngle = 0f
val angleStep = 0.1f
while (currentAngle < 2 * Math.PI) {
val xOffset = radius * cos(currentAngle.toDouble()).toFloat()
val zOffset = radius * sin(currentAngle.toDouble()).toFloat()
worldrenderer.pos(x1 + xOffset, y1 + height, z1 + zOffset).endVertex()
worldrenderer.pos(x1 + xOffset, y1 + 0, z1 + zOffset).endVertex()
currentAngle += angleStep
}
worldrenderer.pos(x1 + radius, y1 + height, z1).endVertex()
worldrenderer.pos(x1 + radius, y1 + 0.0, z1).endVertex()
tessellator.draw()
}
// totally not modified Autumn Client's TargetStrafe
fun drawCircle(entity: Entity, partialTicks: Float, rad: Double, color: Color) {
var il = 0.0
val tessellator = Tessellator.getInstance()
val worldrenderer = tessellator.worldRenderer
while (il < 0.05) {
GlStateManager.pushMatrix()
GlStateManager.disableTexture2D()
GL11.glLineWidth(2F)
worldrenderer.begin(1, DefaultVertexFormats.POSITION)
val x: Double =
entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * partialTicks - mc.renderManager.viewerPosX
val y: Double =
entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * partialTicks - mc.renderManager.viewerPosY
val z: Double =
entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * partialTicks - mc.renderManager.viewerPosZ
val pix2 = Math.PI * 2.0
for (i in 0..90) {
color.bindColor()
worldrenderer.pos(x + rad * cos(i * pix2 / 45.0), y + il, z + rad * sin(i * pix2 / 45.0)).endVertex()
}
tessellator.draw()
GlStateManager.enableTexture2D()
GlStateManager.popMatrix()
il += 0.0006
}
}
fun getViewerPos(partialTicks: Float): Triple {
val viewer = Minecraft.getMinecraft().renderViewEntity
val viewerX = viewer.lastTickPosX + (viewer.posX - viewer.lastTickPosX) * partialTicks
val viewerY = viewer.lastTickPosY + (viewer.posY - viewer.lastTickPosY) * partialTicks
val viewerZ = viewer.lastTickPosZ + (viewer.posZ - viewer.lastTickPosZ) * partialTicks
return Triple(viewerX, viewerY, viewerZ)
}
fun getPartialTicks() = (mc as AccessorMinecraft).timer.renderPartialTicks
infix fun Slot.highlight(color: Color) {
Gui.drawRect(
this.xDisplayPosition,
this.yDisplayPosition,
this.xDisplayPosition + 16,
this.yDisplayPosition + 16,
color.rgb
)
}
fun drawDurabilityBar(xPos: Int, yPos: Int, durability: Double) {
val j = (13.0 - durability * 13.0).roundToInt()
val i = (255.0 - durability * 255.0).roundToInt()
GlStateManager.disableLighting()
GlStateManager.disableDepth()
GlStateManager.disableTexture2D()
GlStateManager.disableAlpha()
GlStateManager.disableBlend()
drawRect(xPos + 2, yPos + 13, 13, 2, 0, 0, 0, 255)
drawRect(xPos + 2, yPos + 13, 12, 1, (255 - i) / 4, 64, 0, 255)
drawRect(xPos + 2, yPos + 13, j, 1, 255 - i, i, 0, 255)
//GlStateManager.enableBlend()
GlStateManager.enableAlpha()
GlStateManager.enableTexture2D()
GlStateManager.enableLighting()
GlStateManager.enableDepth()
}
fun drawRect(x: Number, y: Number, width: Number, height: Number, red: Int, green: Int, blue: Int, alpha: Int) {
val tesselator = Tessellator.getInstance()
val renderer = tesselator.worldRenderer
renderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR)
renderer.pos(x.toDouble(), y.toDouble(), 0.0).color(red, green, blue, alpha).endVertex()
renderer.pos(x.toDouble(), y.toDouble() + height.toDouble(), 0.0).color(red, green, blue, alpha).endVertex()
renderer.pos(x.toDouble() + width.toDouble(), y.toDouble() + height.toDouble(), 0.0)
.color(red, green, blue, alpha).endVertex()
renderer.pos(x.toDouble() + width.toDouble(), y.toDouble(), 0.0).color(red, green, blue, alpha).endVertex()
tesselator.draw()
}
}
fun Color.bindColor() = GlStateManager.color(this.red / 255f, this.green / 255f, this.blue / 255f, this.alpha / 255f)
fun Color.withAlpha(alpha: Int): Int = (alpha.coerceIn(0, 255) shl 24) or (this.rgb and 0x00ffffff)