diff options
author | Appability <appable@icloud.com> | 2022-10-13 18:58:00 -0700 |
---|---|---|
committer | Appability <appable@icloud.com> | 2022-10-13 18:58:00 -0700 |
commit | d0cbc11018c8126575117aaeb2b861957386fa9a (patch) | |
tree | c5419fb1f00b147604bded231c1388d6b391d27e /src/main/kotlin/com/ambientaddons/utils/render/EntityUtils.kt | |
parent | c599ee0d78ed8bc17488636f2d9b9b1d5b6dd4a8 (diff) | |
download | AmbientAddons-d0cbc11018c8126575117aaeb2b861957386fa9a.tar.gz AmbientAddons-d0cbc11018c8126575117aaeb2b861957386fa9a.tar.bz2 AmbientAddons-d0cbc11018c8126575117aaeb2b861957386fa9a.zip |
steal a bunch of code from sbc! +melodyhelper, kuudra ready, wither shield overlay
Diffstat (limited to 'src/main/kotlin/com/ambientaddons/utils/render/EntityUtils.kt')
-rw-r--r-- | src/main/kotlin/com/ambientaddons/utils/render/EntityUtils.kt | 195 |
1 files changed, 195 insertions, 0 deletions
diff --git a/src/main/kotlin/com/ambientaddons/utils/render/EntityUtils.kt b/src/main/kotlin/com/ambientaddons/utils/render/EntityUtils.kt new file mode 100644 index 0000000..b3abbcf --- /dev/null +++ b/src/main/kotlin/com/ambientaddons/utils/render/EntityUtils.kt @@ -0,0 +1,195 @@ +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() + } +}
\ No newline at end of file |