aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt93
1 files changed, 59 insertions, 34 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
index 58e000ce7..cade8b0fe 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
@@ -93,28 +93,52 @@ object RenderUtils {
* @author Moulberry
* @author Mojang
*/
- fun drawFilledBoundingBox(aabb: AxisAlignedBB, c: Color, alphaMultiplier: Float = 1f) {
+ fun drawFilledBoundingBox(
+ aabb: AxisAlignedBB,
+ c: Color,
+ alphaMultiplier: Float = 1f,
+ /**
+ * If set to `true`, renders the box relative to the camera instead of relative to the world.
+ * If set to `false`, will be relativized to [RenderUtils.getViewerPos]. Setting this to `false` requires
+ * specifying [partialTicks]]
+ */
+ renderRelativeToCamera: Boolean = true,
+ drawVerticalBarriers: Boolean = true,
+ partialTicks: Float = 0F
+ ) {
GlStateManager.enableBlend()
GlStateManager.disableLighting()
- GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0)
+ GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0)
GlStateManager.disableTexture2D()
+ GlStateManager.disableCull()
+ val effectiveAABB = if (!renderRelativeToCamera) {
+ val vp = getViewerPos(partialTicks)
+ AxisAlignedBB(
+ aabb.minX - vp.x, aabb.minY - vp.y, aabb.minZ - vp.z,
+ aabb.maxX - vp.x, aabb.maxY - vp.y, aabb.maxZ - vp.z,
+ )
+ } else {
+ aabb
+ }
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()
+ if (drawVerticalBarriers) {
+ GlStateManager.color(c.red / 255f, c.green / 255f, c.blue / 255f, c.alpha / 255f * alphaMultiplier)
+ worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION)
+ worldRenderer.pos(effectiveAABB.minX, effectiveAABB.minY, effectiveAABB.minZ).endVertex()
+ worldRenderer.pos(effectiveAABB.maxX, effectiveAABB.minY, effectiveAABB.minZ).endVertex()
+ worldRenderer.pos(effectiveAABB.maxX, effectiveAABB.minY, effectiveAABB.maxZ).endVertex()
+ worldRenderer.pos(effectiveAABB.minX, effectiveAABB.minY, effectiveAABB.maxZ).endVertex()
+ tessellator.draw()
+ worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION)
+ worldRenderer.pos(effectiveAABB.minX, effectiveAABB.maxY, effectiveAABB.maxZ).endVertex()
+ worldRenderer.pos(effectiveAABB.maxX, effectiveAABB.maxY, effectiveAABB.maxZ).endVertex()
+ worldRenderer.pos(effectiveAABB.maxX, effectiveAABB.maxY, effectiveAABB.minZ).endVertex()
+ worldRenderer.pos(effectiveAABB.minX, effectiveAABB.maxY, effectiveAABB.minZ).endVertex()
+ tessellator.draw()
+ }
GlStateManager.color(
c.red / 255f * 0.8f,
c.green / 255f * 0.8f,
@@ -124,16 +148,16 @@ object RenderUtils {
//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()
+ worldRenderer.pos(effectiveAABB.minX, effectiveAABB.minY, effectiveAABB.maxZ).endVertex()
+ worldRenderer.pos(effectiveAABB.minX, effectiveAABB.maxY, effectiveAABB.maxZ).endVertex()
+ worldRenderer.pos(effectiveAABB.minX, effectiveAABB.maxY, effectiveAABB.minZ).endVertex()
+ worldRenderer.pos(effectiveAABB.minX, effectiveAABB.minY, effectiveAABB.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()
+ worldRenderer.pos(effectiveAABB.maxX, effectiveAABB.minY, effectiveAABB.minZ).endVertex()
+ worldRenderer.pos(effectiveAABB.maxX, effectiveAABB.maxY, effectiveAABB.minZ).endVertex()
+ worldRenderer.pos(effectiveAABB.maxX, effectiveAABB.maxY, effectiveAABB.maxZ).endVertex()
+ worldRenderer.pos(effectiveAABB.maxX, effectiveAABB.minY, effectiveAABB.maxZ).endVertex()
tessellator.draw()
GlStateManager.color(
c.red / 255f * 0.9f,
@@ -143,18 +167,19 @@ object RenderUtils {
)
//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()
+ worldRenderer.pos(effectiveAABB.minX, effectiveAABB.maxY, effectiveAABB.minZ).endVertex()
+ worldRenderer.pos(effectiveAABB.maxX, effectiveAABB.maxY, effectiveAABB.minZ).endVertex()
+ worldRenderer.pos(effectiveAABB.maxX, effectiveAABB.minY, effectiveAABB.minZ).endVertex()
+ worldRenderer.pos(effectiveAABB.minX, effectiveAABB.minY, effectiveAABB.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()
+ worldRenderer.pos(effectiveAABB.minX, effectiveAABB.minY, effectiveAABB.maxZ).endVertex()
+ worldRenderer.pos(effectiveAABB.maxX, effectiveAABB.minY, effectiveAABB.maxZ).endVertex()
+ worldRenderer.pos(effectiveAABB.maxX, effectiveAABB.maxY, effectiveAABB.maxZ).endVertex()
+ worldRenderer.pos(effectiveAABB.minX, effectiveAABB.maxY, effectiveAABB.maxZ).endVertex()
tessellator.draw()
GlStateManager.enableTexture2D()
+ GlStateManager.enableCull()
GlStateManager.disableBlend()
}
@@ -180,7 +205,7 @@ object RenderUtils {
GlStateManager.enableTexture2D()
GlStateManager.tryBlendFuncSeparate(770, 1, 1, 0)
GlStateManager.enableBlend()
- GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0)
+ GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 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)
@@ -321,7 +346,7 @@ object RenderUtils {
GlStateManager.disableLighting()
GlStateManager.depthMask(false)
GlStateManager.enableBlend()
- GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0)
+ GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0)
val tessellator = Tessellator.getInstance()
val worldrenderer = tessellator.worldRenderer
val i = 0
@@ -591,7 +616,7 @@ object RenderUtils {
GlStateManager.enableBlend()
GlStateManager.depthFunc(GL11.GL_LEQUAL)
GlStateManager.disableCull()
- GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0)
+ GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0)
GlStateManager.enableAlpha()
GlStateManager.disableTexture2D()
color.bindColor()