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.utils.renderables.Renderable
import io.github.moulberry.moulconfig.internal.TextRenderUtils
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 net.minecraftforge.client.event.RenderWorldLastEvent
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 {
val beaconBeam = ResourceLocation("textures/entity/beacon_beam.png")
infix fun Slot.highlight(color: LorenzColor) {
highlight(color.toColor())
}
infix fun Slot.highlight(color: Color) {
val lightingState = GL11.glIsEnabled(GL11.GL_LIGHTING)
GlStateManager.disableLighting()
GlStateManager.color(1f, 1f, 1f, 1f)
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()
if (lightingState) GlStateManager.enableLighting()
}
fun RenderWorldLastEvent.drawColor(
location: LorenzVec,
color: LorenzColor,
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.toColor(),
realAlpha
)
GlStateManager.disableTexture2D()
if (distSq > 5 * 5 && beacon) renderBeaconBeam(x, y + 1, z, color.toColor().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 renderBeaconBeam(x: Double, y: Double, z: Double, rgb: Int, alphaMultiplier: Float, partialTicks: Float) {
val height = 300
val bottomOffset = 0
val topOffset = bottomOffset + height
val tessellator = Tessellator.getInstance()
val worldrenderer = tessellator.worldRenderer
Minecraft.getMinecraft().textureManager.bindTexture(beaconBeam)
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, 10497.0f)
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, 10497.0f)
GlStateManager.disableLighting()
GlStateManager.enableCull()
GlStateManager.enableTexture2D()
GlStateM