diff options
| author | Brady <thatgravyboat@gmail.com> | 2024-04-25 07:29:05 -0230 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-25 11:59:05 +0200 |
| commit | 44b86cc6b1ecde84632f9cf4f06f5c35aa4d8b6d (patch) | |
| tree | 668d43de7b7329eebd83fdafeba5389d15de0d0d /src/main/java/at/hannibal2/skyhanni/utils | |
| parent | 0eed4b0d2121a206d4eba81aa4a1888125acbe3e (diff) | |
| download | skyhanni-44b86cc6b1ecde84632f9cf4f06f5c35aa4d8b6d.tar.gz skyhanni-44b86cc6b1ecde84632f9cf4f06f5c35aa4d8b6d.tar.bz2 skyhanni-44b86cc6b1ecde84632f9cf4f06f5c35aa4d8b6d.zip | |
Backend: Improves performance of item backgrounds and borders (#1497)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Co-authored-by: Cal <cwolfson58@gmail.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt | 11 | ||||
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt | 60 |
2 files changed, 59 insertions, 12 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt index d33729ae3..f538f2d53 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt @@ -262,4 +262,15 @@ object CollectionUtils { addString("§a]") })) } + + inline fun <K, V, R : Any> Map<K, V>.mapKeysNotNull(transform: (Map.Entry<K, V>) -> R?): Map<R, V> { + val destination = LinkedHashMap<R, V>() + for (element in this) { + val newKey = transform(element) + if (newKey != null) { + destination[newKey] = element.value + } + } + return destination + } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt index 0c8b2b694..0ea8b76eb 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt @@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getAbsY import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getDummySize import at.hannibal2.skyhanni.events.GuiRenderItemEvent import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent +import at.hannibal2.skyhanni.events.RenderGuiItemOverlayEvent import at.hannibal2.skyhanni.features.misc.RoundedRectangleShader import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.renderables.Renderable @@ -66,22 +67,57 @@ object RenderUtils { } infix fun Slot.highlight(color: Color) { - GlStateManager.color(1f, 1f, 1f, 1f) - GlStateManager.pushAttrib() - GL11.glDisable(GL11.GL_LIGHTING) - GL11.glEnable(GL11.GL_DEPTH_TEST) + highlight(color, xDisplayPosition, yDisplayPosition) + } + + infix fun RenderGuiItemOverlayEvent.highlight(color: LorenzColor) { + highlight(color.toColor()) + } + + infix fun RenderGuiItemOverlayEvent.highlight(color: Color) { + highlight(color, x, y) + } + + fun highlight(color: Color, x: Int, y: Int) { + GlStateManager.disableLighting() + GlStateManager.disableDepth() GlStateManager.pushMatrix() // TODO don't use z GlStateManager.translate(0f, 0f, 110 + Minecraft.getMinecraft().renderItem.zLevel) - Gui.drawRect( - this.xDisplayPosition, - this.yDisplayPosition, - this.xDisplayPosition + 16, - this.yDisplayPosition + 16, - color.rgb - ) + Gui.drawRect(x, y, x + 16, y + 16, color.rgb) GlStateManager.popMatrix() - GlStateManager.popAttrib() + GlStateManager.enableDepth() + GlStateManager.enableLighting() + } + + infix fun Slot.drawBorder(color: LorenzColor) { + drawBorder(color.toColor()) + } + + infix fun Slot.drawBorder(color: Color) { + drawBorder(color, xDisplayPosition, yDisplayPosition) + } + + infix fun RenderGuiItemOverlayEvent.drawBorder(color: LorenzColor) { + drawBorder(color.toColor()) + } + + infix fun RenderGuiItemOverlayEvent.drawBorder(color: Color) { + drawBorder(color, x, y) + } + + fun drawBorder(color: Color, x: Int, y: Int) { + GlStateManager.disableLighting() + GlStateManager.disableDepth() + GlStateManager.pushMatrix() + GlStateManager.translate(0f, 0f, 110 + Minecraft.getMinecraft().renderItem.zLevel) + Gui.drawRect(x, y, x + 1, y + 16, color.rgb) + Gui.drawRect(x, y, x + 16, y + 1, color.rgb) + Gui.drawRect(x, y + 15, x + 16, y + 16, color.rgb) + Gui.drawRect(x + 15, y, x + 16, y + 16, color.rgb) + GlStateManager.popMatrix() + GlStateManager.enableDepth() + GlStateManager.enableLighting() } fun LorenzRenderWorldEvent.drawColor( |
