Skip to content

Commit

Permalink
core: Support modifying font and insertion text
Browse files Browse the repository at this point in the history
This adds the `font` and `insertion` fields to
`literalText` builders.
  • Loading branch information
jakobkmar committed Jun 21, 2023
1 parent 9d32b6c commit 792bcc8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions silk-core/src/main/kotlin/net/silkmc/silk/core/text/TextBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package net.silkmc.silk.core.text

import net.minecraft.ChatFormatting
import net.minecraft.network.chat.*
import net.minecraft.resources.ResourceLocation

/**
* Opens a [LiteralTextBuilder].
Expand Down Expand Up @@ -44,6 +45,19 @@ class LiteralTextBuilder(
*/
var color: Int? = null

/**
* The resource location of the font for this component in the
* resource pack or mod resources within `assets/<namespace>/font`.
* Defaults to "minecraft:default".
*/
var font: ResourceLocation? = null

/**
* When the text is shift-clicked by a player, this string is inserted in their chat input.
* It does not overwrite any existing text the player was writing. This only works in chat messages.
*/
var insertion: String? = null

var clickEvent: ClickEvent? = null
var hoverEvent: HoverEvent? = null

Expand All @@ -55,6 +69,8 @@ class LiteralTextBuilder(
.let { if (strikethrough == true) it.applyFormat(ChatFormatting.STRIKETHROUGH) else it }
.let { if (obfuscated == true) it.applyFormat(ChatFormatting.OBFUSCATED) else it }
.let { if (color != null) it.withColor(TextColor.fromRgb(color ?: 0xFFFFFF)) else it }
.withFont(font)
.withInsertion(insertion)
.withClickEvent(clickEvent)
.withHoverEvent(hoverEvent)
.let { if (inheritStyle) it.applyTo(parentStyle) else it }
Expand Down

0 comments on commit 792bcc8

Please sign in to comment.