Skip to content

Commit

Permalink
Update render utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry282 committed Aug 13, 2024
1 parent d77a4c7 commit be23a53
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
39 changes: 16 additions & 23 deletions src/main/kotlin/funnymap/features/dungeon/MapRender.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import funnymap.utils.Location.inBoss
import funnymap.utils.MapUtils
import funnymap.utils.MapUtils.mapRoomSize
import funnymap.utils.RenderUtils
import funnymap.utils.RenderUtils.darken
import funnymap.utils.RenderUtils.grayScale
import funnymap.utils.Utils.equalsOneOf
import net.minecraft.client.gui.ScaledResolution
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.util.ResourceLocation
import org.lwjgl.opengl.GL11
import java.awt.Color
import kotlin.math.roundToInt

object MapRender {

Expand Down Expand Up @@ -130,38 +131,30 @@ object MapRender {

if (tile.state.equalsOneOf(RoomState.UNDISCOVERED, RoomState.UNOPENED)) {
if (Config.mapDarkenUndiscovered) {
color = color.run {
Color(
(red * (1 - Config.mapDarkenPercent)).toInt(),
(green * (1 - Config.mapDarkenPercent)).toInt(),
(blue * (1 - Config.mapDarkenPercent)).toInt(),
alpha
)
}
color = color.darken(1 - Config.mapDarkenPercent)
}
if (Config.mapGrayUndiscovered && Dungeon.Info.startTime != 0L) {
val gray = (color.red * 0.299 + color.green * 0.587 + color.blue * 0.114).roundToInt()
color = Color(gray, gray, gray)
color = color.grayScale()
}
}

when {
xEven && yEven -> if (tile is Room) {
RenderUtils.renderRect(
xOffset.toDouble(),
yOffset.toDouble(),
mapRoomSize.toDouble(),
mapRoomSize.toDouble(),
xOffset,
yOffset,
mapRoomSize,
mapRoomSize,
color
)
}

!xEven && !yEven -> {
RenderUtils.renderRect(
xOffset.toDouble(),
yOffset.toDouble(),
(mapRoomSize + connectorSize).toDouble(),
(mapRoomSize + connectorSize).toDouble(),
xOffset,
yOffset,
(mapRoomSize + connectorSize),
(mapRoomSize + connectorSize),
color
)
}
Expand Down Expand Up @@ -306,10 +299,10 @@ object MapRender {
if (vertical) y1 += doorwayOffset else x1 += doorwayOffset
}
RenderUtils.renderRect(
x1.toDouble(),
y1.toDouble(),
(if (vertical) doorWidth else width).toDouble(),
(if (vertical) width else doorWidth).toDouble(),
x1,
y1,
if (vertical) doorWidth else width,
if (vertical) width else doorWidth,
color
)
}
Expand Down
14 changes: 12 additions & 2 deletions src/main/kotlin/funnymap/utils/RenderUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.lwjgl.opengl.GL11
import org.lwjgl.opengl.GL11.GL_LINE_STRIP
import org.lwjgl.opengl.GL11.GL_QUADS
import java.awt.Color
import kotlin.math.roundToInt

object RenderUtils {

Expand Down Expand Up @@ -73,13 +74,13 @@ object RenderUtils {
GlStateManager.popMatrix()
}

fun renderRect(x: Double, y: Double, w: Double, h: Double, color: Color) {
fun renderRect(x: Number, y: Number, w: Number, h: Number, color: Color) {
if (color.alpha == 0) return
preDraw()
color.bind()

worldRenderer.begin(GL_QUADS, DefaultVertexFormats.POSITION)
addQuadVertices(x, y, w, h)
addQuadVertices(x.toDouble(), y.toDouble(), w.toDouble(), h.toDouble())
tessellator.draw()

postDraw()
Expand Down Expand Up @@ -204,6 +205,15 @@ object RenderUtils {
GlStateManager.color(this.red / 255f, this.green / 255f, this.blue / 255f, this.alpha / 255f)
}

fun Color.grayScale(): Color {
val gray = (red * 0.299 + green * 0.587 + blue * 0.114).roundToInt()
return Color(gray, gray, gray, alpha)
}

fun Color.darken(factor: Float): Color {
return Color((red * factor).roundToInt(), (green * factor).roundToInt(), (blue * factor).roundToInt(), alpha)
}

fun Entity.getInterpolatedPosition(partialTicks: Float): Triple<Double, Double, Double> {
return Triple(
this.lastTickPosX + (this.posX - this.lastTickPosX) * partialTicks,
Expand Down

0 comments on commit be23a53

Please sign in to comment.