@@ -7,6 +7,7 @@ import com.mojang.brigadier.arguments.FloatArgumentType
77import com.mojang.brigadier.arguments.IntegerArgumentType
88import com.mojang.brigadier.arguments.StringArgumentType
99import com.mojang.brigadier.context.CommandContext
10+ import com.mojang.brigadier.suggestion.SuggestionsBuilder
1011import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager
1112import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback
1213import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
@@ -39,6 +40,12 @@ object ConfigCommand {
3940 return (window.scaledHeight - 20 ).coerceAtLeast(0 )
4041 }
4142
43+ // Maximum X position - prevents rendering off-screen
44+ private fun getMaxX (): Int {
45+ val window = MinecraftClient .getInstance().window
46+ return (window.scaledWidth - ConfigManager .config.maxBoxWidth).coerceAtLeast(0 )
47+ }
48+
4249 fun register () {
4350 ClientCommandRegistrationCallback .EVENT .register { dispatcher, _ ->
4451 registerCommands(dispatcher)
@@ -52,6 +59,10 @@ object ConfigCommand {
5259 ClientCommandManager .literal(" color" )
5360 .then(
5461 ClientCommandManager .argument(" value" , StringArgumentType .string())
62+ .suggests { _, builder: SuggestionsBuilder ->
63+ COLOR_MAP .keys.forEach { builder.suggest(it) }
64+ builder.buildFuture()
65+ }
5566 .executes { ctx -> setColor(ctx, StringArgumentType .getString(ctx, " value" )) }
5667 )
5768 )
@@ -136,16 +147,24 @@ object ConfigCommand {
136147 // Validate Y position to prevent off-screen rendering
137148 val maxY = getMaxY()
138149 val clampedY = y.coerceAtMost(maxY)
139-
150+
140151 if (y > maxY) {
141152 ctx.source.sendFeedback(Text .literal(" §eY position clamped from $y to $maxY to prevent off-screen rendering" ))
142153 }
143-
154+
155+ // Validate X position to prevent off-screen rendering (skip for -1 which is auto right-align)
156+ val maxX = getMaxX()
157+ val clampedX = if (x >= 0 ) x.coerceAtMost(maxX) else x
158+
159+ if (x >= 0 && x > maxX) {
160+ ctx.source.sendFeedback(Text .literal(" §eX position clamped from $x to $maxX to prevent off-screen rendering" ))
161+ }
162+
144163 val config = ConfigManager .config
145- val newConfig = config.copy(x = x , y = clampedY)
164+ val newConfig = config.copy(x = clampedX , y = clampedY)
146165 ConfigManager .updateConfig(newConfig)
147-
148- val xText = if (x == - 1 ) " auto (right-aligned)" else x .toString()
166+
167+ val xText = if (clampedX == - 1 ) " auto (right-aligned)" else clampedX .toString()
149168 ctx.source.sendFeedback(Text .literal(" §aMusic display position set to: X=$xText , Y=$clampedY " ))
150169 return 1
151170 }
0 commit comments