package com.ambientaddons.utils.render import AmbientAddons.Companion.mc 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.util.AxisAlignedBB import net.minecraft.util.BlockPos import org.lwjgl.opengl.GL11.* import java.awt.Color // diretly stolen from Harry282/Skyblock-Client object EntityUtils { private fun drawFilledAABB(aabb: AxisAlignedBB, color: Color, alpha: Float = 0.5f) { val tessellator = Tessellator.getInstance() val worldRenderer = tessellator.worldRenderer glColor4f(color.red / 255f, color.green / 255f, color.blue / 255f, alpha) worldRenderer.begin(GL_QUADS, DefaultVertexFormats.POSITION) worldRenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex() worldRenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex() worldRenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex() worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex() worldRenderer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex() worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex() worldRenderer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex() worldRenderer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex() worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex() worldRenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex() worldRenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex() worldRenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex() worldRenderer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex() worldRenderer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex() worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex() worldRenderer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex() worldRenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex() worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex() worldRenderer.pos(aabb.maxX, aabb.maxY, 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.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.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() worldRenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex() worldRenderer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex() worldRenderer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex() worldRenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex() worldRenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex() worldRenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex() worldRenderer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex() worldRenderer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex() worldRenderer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex() worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex() worldRenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex() worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex() worldRenderer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex() worldRenderer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex() worldRenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex() worldRenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex() worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.minZ).endVertex() worldRenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex() worldRenderer.pos(aabb.maxX, aabb.maxY, aabb.maxZ).endVertex() worldRenderer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex() tessellator.draw() } private fun drawOutlinedAABB(aabb: AxisAlignedBB, color: Color, alpha: Float = 1.0f) { val tessellator = Tessellator.getInstance() val worldRenderer = tessellator.worldRenderer glColor4f(color.red / 255f, color.green / 255f, color.blue / 255f, alpha) worldRenderer.begin(GL_LINE_STRIP, DefaultVertexFormats.POSITION) worldRenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex() worldRenderer.pos(aabb.minX, aabb.minY, aabb.maxZ).endVertex() worldRenderer.pos(aabb.maxX, aabb.minY, aabb.maxZ).endVertex() worldRenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex() worldRenderer.pos(aabb.minX, aabb.minY, aabb.minZ).endVertex() worldRenderer.pos(aabb.minX, aabb.maxY, aabb.minZ).endVertex() 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() worldRenderer.pos(aabb.minX, aabb.maxY, aabb.maxZ).endVertex() 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.maxX, aabb.maxY, aabb.minZ).endVertex() worldRenderer.pos(aabb.maxX, aabb.minY, aabb.minZ).endVertex() tessellator.draw() } fun drawBlockBox(blockPos: BlockPos, color: Color, outline: Boolean, fill: Boolean, partialTicks: Float) { if (!outline && !fill) return val renderManager = mc.renderManager val x = blockPos.x - renderManager.viewerPosX val y = blockPos.y - renderManager.viewerPosY val z = blockPos.z - renderManager.viewerPosZ var axisAlignedBB = AxisAlignedBB(x, y, z, x + 1.0, y + 1.0, z + 1.0) val block = mc.theWorld.getBlockState(blockPos).block if (block != null) { val player: EntityPlayer = mc.thePlayer val posX = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks val posY = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks val posZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks block.setBlockBoundsBasedOnState(mc.theWorld, blockPos) axisAlignedBB = block.getSelectedBoundingBox(mc.theWorld, blockPos) .expand(0.0020000000949949026, 0.0020000000949949026, 0.0020000000949949026) .offset(-posX, -posY, -posZ) } glPushMatrix() glPushAttrib(GL_ALL_ATTRIB_BITS) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glDisable(GL_TEXTURE_2D) glDisable(GL_DEPTH_TEST) glDisable(GL_LIGHTING) glDepthMask(false) if (outline) { glLineWidth(1.5f) drawOutlinedAABB(axisAlignedBB, color) } if (fill) { drawFilledAABB(axisAlignedBB, color) } glDepthMask(true) glPopAttrib() glPopMatrix() } fun drawEntityBox(entity: Entity, color: Color, outline: Boolean, fill: Boolean, esp: Boolean, partialTicks: Float) { if (!outline && !fill) return val renderManager = mc.renderManager val x = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * partialTicks - renderManager.viewerPosX val y = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * partialTicks - renderManager.viewerPosY val z = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * partialTicks - renderManager.viewerPosZ var axisAlignedBB: AxisAlignedBB entity.entityBoundingBox.run { axisAlignedBB = AxisAlignedBB( minX - entity.posX, minY - entity.posY, minZ - entity.posZ, maxX - entity.posX, maxY - entity.posY, maxZ - entity.posZ ).offset(x, y, z) } glPushMatrix() glPushAttrib(GL_ALL_ATTRIB_BITS) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glEnable(GL_BLEND) glEnable(GL_LINE_SMOOTH) glDisable(GL_TEXTURE_2D) if (esp) { glDisable(GL_DEPTH_TEST) } glDisable(GL_LIGHTING) glDepthMask(false) if (outline) { glLineWidth(2.0f) drawOutlinedAABB(axisAlignedBB, color) } if (fill) { drawFilledAABB(axisAlignedBB, color) } if (esp) { glEnable(GL_DEPTH_TEST) } glDepthMask(true) glPopAttrib() glPopMatrix() } }