package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.config.core.config.Position
import at.hannibal2.skyhanni.data.GuiEditManager
import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getAbsX
import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getAbsY
import at.hannibal2.skyhanni.events.GuiRenderItemEvent
import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent
import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.renderables.Renderable
import io.github.moulberry.moulconfig.internal.TextRenderUtils
import io.github.moulberry.notenoughupdates.util.Utils
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.FontRenderer
import net.minecraft.client.gui.Gui
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.Tessellator
import net.minecraft.client.renderer.vertex.DefaultVertexFormats
import net.minecraft.entity.Entity
import net.minecraft.inventory.Slot
import net.minecraft.util.AxisAlignedBB
import net.minecraft.util.MathHelper
import net.minecraft.util.ResourceLocation
import org.lwjgl.opengl.GL11
import java.awt.Color
import kotlin.math.cos
import kotlin.math.sin
import kotlin.math.sqrt
import kotlin.time.Duration
import kotlin.time.DurationUnit
object RenderUtils {
private val beaconBeam = ResourceLocation("textures/entity/beacon_beam.png")
infix fun Slot.highlight(color: LorenzColor) {
highlight(color.toColor())
}
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)
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
)
GlStateManager.popMatrix()
GlStateManager.popAttrib()
}
fun LorenzRenderWorldEvent.drawColor(
location: LorenzVec,
color: LorenzColor,
beacon: Boolean = false,
alpha: Float = -1f,
) {
drawColor(location, color.toColor(), beacon, alpha)
}
fun LorenzRenderWorldEvent.drawColor(
location: LorenzVec,
color: Color,
beacon: Boolean = false,
alpha: Float = -1f,
) {
val (viewerX, viewerY, viewerZ) = getViewerPos(partialTicks)
val x = location.x - viewerX
val y = location.y - viewerY
val z = location.z - viewerZ
val distSq = x * x + y * y + z * z
val realAlpha = if (alpha == -1f) {
(0.1f + 0.005f * distSq.toFloat()).coerceAtLeast(0.2f)
} else {
alpha
}
GlStateManager.disableDepth()
GlStateManager.disableCull()
drawFilledBoundingBox(
AxisAlignedBB(x, y, z, x + 1, y + 1, z + 1).expandBlock(),
color,
realAlpha
)
GlStateManager.disableTexture2D()
if (distSq > 5 * 5 && beacon) renderBeaconBeam(x, y + 1, z, color.rgb, 1.0f, partialTicks)
GlStateManager.disableLighting()
GlStateManager.enableTexture2D()
GlStateManager.enableDepth()
GlStateManager.enableCull()
}
fun getViewerPos(partialTicks: Float) = exactLocation(Minecraft.getMinecraft().renderViewEntity, partialTicks)
fun AxisAlignedBB.expandBlock() = expand(0.0020000000949949026, 0.0020000000949949026, 0.0020000000949949026)
/**
* Taken from NotEnoughUpdates under Creative Commons Attribution-NonCommercial 3.0
* https://github.com/Moulberry/NotEnoughUpdates/blob/master/LICENSE
* @author Moulberry
* @author Mojang
*/
fun