Get rid of appendComment

This commit is contained in:
DBotThePony 2022-09-30 22:39:17 +07:00
parent f4853ce09d
commit 7227def822
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 3 additions and 34 deletions

View File

@ -11,36 +11,6 @@ operator fun <T : Any> ForgeConfigSpec.ConfigValue<T>.getValue(config: Any, prop
return get() return get()
} }
private val builderField by lazy {
val field = ForgeConfigSpec.Builder::class.java.getDeclaredField("context")
field.isAccessible = true
field
}
private val builderContextField by lazy {
val clazz = ForgeConfigSpec::class.java.declaredClasses.firstOrNull { it.name == "net.minecraftforge.common.ForgeConfigSpec\$BuilderContext" } ?: throw NoSuchElementException("Unable to find ForgeConfigSpec.BuilderContext")
val field = clazz.getDeclaredField("comment")
field.isAccessible = true
field
}
fun ForgeConfigSpec.Builder.appendComment(vararg comments: String): ForgeConfigSpec.Builder {
val context = builderField.get(this) ?: throw NullPointerException("No builder context!")
val commentList = builderContextField.get(context) as? Array<String> ?: throw NullPointerException("BuilderContext.comment is null or not of right type!")
val reconstruct = Array(commentList.size + comments.size) {
if (it in commentList.indices) {
commentList[it]
} else {
comments[it - commentList.size]
}
}
builderContextField.set(context, reconstruct)
return this
}
fun ForgeConfigSpec.Builder.defineInRange(path: String, value: Int, minValue: Int): ForgeConfigSpec.IntValue { fun ForgeConfigSpec.Builder.defineInRange(path: String, value: Int, minValue: Int): ForgeConfigSpec.IntValue {
return defineInRange(path, value, minValue, Int.MAX_VALUE) return defineInRange(path, value, minValue, Int.MAX_VALUE)
} }

View File

@ -7,7 +7,6 @@ import net.minecraft.nbt.Tag
import net.minecraft.network.FriendlyByteBuf import net.minecraft.network.FriendlyByteBuf
import net.minecraftforge.common.ForgeConfigSpec import net.minecraftforge.common.ForgeConfigSpec
import ru.dbotthepony.mc.otm.ObservedConfigValue import ru.dbotthepony.mc.otm.ObservedConfigValue
import ru.dbotthepony.mc.otm.appendComment
import java.io.InputStream import java.io.InputStream
import java.io.OutputStream import java.io.OutputStream
import java.math.BigDecimal import java.math.BigDecimal
@ -903,11 +902,11 @@ class ImpreciseFractionConfigValue(
private fun ForgeConfigSpec.Builder.commentRange(minimum: ImpreciseFraction?, maximum: ImpreciseFraction?) { private fun ForgeConfigSpec.Builder.commentRange(minimum: ImpreciseFraction?, maximum: ImpreciseFraction?) {
if (minimum != null && maximum != null) { if (minimum != null && maximum != null) {
appendComment("Range: $minimum ~ $maximum") comment("Range: $minimum ~ $maximum")
} else if (minimum != null) { } else if (minimum != null) {
appendComment("Range: >= $minimum") comment("Range: >= $minimum")
} else if (maximum != null) { } else if (maximum != null) {
appendComment("Range: <= $maximum") comment("Range: <= $maximum")
} }
} }