Skip to content
This repository has been archived by the owner on Apr 22, 2021. It is now read-only.

Commit

Permalink
impr: size option for TextComponents (#2159)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avanatiker authored Mar 25, 2021
1 parent 19238e2 commit 76c1740
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/main/kotlin/org/kamiblue/client/util/EntityUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ import org.kamiblue.client.util.items.id
import org.kamiblue.client.util.math.VectorUtils.toBlockPos
import org.kamiblue.commons.extension.ceilToInt
import org.kamiblue.commons.extension.floorToInt
import kotlin.math.floor

object EntityUtils {
private val mc = Minecraft.getMinecraft()

val Entity.flooredPosition get() = BlockPos(floor(posX).toInt(), floor(posY).toInt(), floor(posZ).toInt())
val Entity.flooredPosition get() = BlockPos(posX.floorToInt(), posY.floorToInt(), posZ.floorToInt())
val Entity.prevPosVector get() = Vec3d(this.prevPosX, this.prevPosY, this.prevPosZ)

val Entity.isPassive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class TextComponent(val separator: String = " ") {
/**
* Adds new text element to [currentLine], and goes to the next line
*/
fun addLine(text: String, color: ColorHolder = ColorHolder(255, 255, 255), style: Style = Style.REGULAR) {
add(text, color, style)
fun addLine(text: String, color: ColorHolder = ColorHolder(255, 255, 255), style: Style = Style.REGULAR, scale: Float = 1f) {
add(text, color, style, scale)
currentLine++
}

Expand All @@ -55,8 +55,8 @@ class TextComponent(val separator: String = " ") {
/**
* Adds new text element to [currentLine]
*/
fun add(text: String, color: ColorHolder = ColorHolder(255, 255, 255), style: Style = Style.REGULAR) {
add(TextElement(text, color, style))
fun add(text: String, color: ColorHolder = ColorHolder(255, 255, 255), style: Style = Style.REGULAR, scale: Float = 1f) {
add(TextElement(text, color, style, scale))
}

/**
Expand Down Expand Up @@ -145,7 +145,7 @@ class TextComponent(val separator: String = " ") {
for (textElement in textElementList) {
val color = textElement.color.clone()
color.a = (color.a * alpha).toInt()
FontRenderAdapter.drawString(textElement.text, drawShadow = drawShadow, color = color, customFont = customFont)
FontRenderAdapter.drawString(textElement.text, drawShadow = drawShadow, color = color, customFont = customFont, scale = textElement.scale)
val adjustedSeparator = if (separator == " " && customFont) " " else " "
glTranslatef(FontRenderAdapter.getStringWidth(textElement.text + adjustedSeparator, customFont = customFont), 0f, 0f)
}
Expand All @@ -165,7 +165,7 @@ class TextComponent(val separator: String = " ") {

}

class TextElement(textIn: String, val color: ColorHolder = ColorHolder(255, 255, 255), val style: Style = Style.REGULAR) {
class TextElement(textIn: String, val color: ColorHolder = ColorHolder(255, 255, 255), val style: Style = Style.REGULAR, val scale: Float = 1f) {
val text = "${style.code}$textIn"

override fun toString(): String {
Expand Down

0 comments on commit 76c1740

Please sign in to comment.