diff options
author | Roman / Linnea Gräf <nea@nea.moe> | 2023-06-24 19:03:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-24 19:03:52 +0200 |
commit | 847100cb50dea171d494e541bc3a19bf8438ba3d (patch) | |
tree | c5f3064dc3c4beeab793c7e78eab36bf1ce655ea /src/main/java/at/hannibal2/skyhanni/utils | |
parent | 105bc5ee1593a8c16842026c600fc9ffcd2977e5 (diff) | |
download | skyhanni-847100cb50dea171d494e541bc3a19bf8438ba3d.tar.gz skyhanni-847100cb50dea171d494e541bc3a19bf8438ba3d.tar.bz2 skyhanni-847100cb50dea171d494e541bc3a19bf8438ba3d.zip |
Merge pull request #256
* Remove old update data after each update
* VoltHighlighter
* VoltHighlighter
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
3 files changed, 98 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() diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt b/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt new file mode 100644 index 000000000..bd682b913 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/utils/SimpleTimeMark.kt @@ -0,0 +1,26 @@ +package at.hannibal2.skyhanni.utils + +import java.time.Instant +import kotlin.time.Duration +import kotlin.time.Duration.Companion.milliseconds + +@JvmInline +value class SimpleTimeMark(val millis: Long) { + operator fun minus(other: SimpleTimeMark) = + (millis - other.millis).milliseconds + + operator fun plus(other: Duration) = + SimpleTimeMark(millis + other.inWholeMilliseconds) + + fun passedSince() = if (millis == 0L) Duration.INFINITE else now() - this + + override fun toString(): String { + if (millis == 0L) return "The Far Past" + return Instant.ofEpochMilli(millis).toString() + } + + companion object { + fun now() = SimpleTimeMark(System.currentTimeMillis()) + fun farPast() = SimpleTimeMark(0) + } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt index f7cd79b40..a0b6e91d8 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt @@ -2,11 +2,23 @@ package at.hannibal2.skyhanni.utils import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import kotlin.time.Duration object TimeUtils { private val pattern = "(?:(?<y>\\d+) ?y(?:\\w* ?)?)?(?:(?<d>\\d+) ?d(?:\\w* ?)?)?(?:(?<h>\\d+) ?h(?:\\w* ?)?)?(?:(?<m>\\d+) ?m(?:\\w* ?)?)?(?:(?<s>\\d+) ?s(?:\\w* ?)?)?".toPattern() + + fun formatDuration( + duration: Duration, + biggestUnit: TimeUnit = TimeUnit.YEAR, + showMilliSeconds: Boolean = false, + longName: Boolean = false, + maxUnits: Int = -1 + ): String = formatDuration( + duration.inWholeMilliseconds - 999, biggestUnit, showMilliSeconds, longName, maxUnits + ) + fun formatDuration( millis: Long, biggestUnit: TimeUnit = TimeUnit.YEAR, @@ -14,6 +26,7 @@ object TimeUtils { longName: Boolean = false, maxUnits: Int = -1 ): String { + // TODO: if this weird offset gets removed, also remove that subtraction from formatDuration(kotlin.time.Duration) var milliseconds = millis + 999 val map = mutableMapOf<TimeUnit, Int>() for (unit in TimeUnit.values()) { |