Get rid of appendComment
This commit is contained in:
parent
f4853ce09d
commit
7227def822
@ -11,36 +11,6 @@ operator fun <T : Any> ForgeConfigSpec.ConfigValue<T>.getValue(config: Any, prop
|
||||
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 {
|
||||
return defineInRange(path, value, minValue, Int.MAX_VALUE)
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import net.minecraft.nbt.Tag
|
||||
import net.minecraft.network.FriendlyByteBuf
|
||||
import net.minecraftforge.common.ForgeConfigSpec
|
||||
import ru.dbotthepony.mc.otm.ObservedConfigValue
|
||||
import ru.dbotthepony.mc.otm.appendComment
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
import java.math.BigDecimal
|
||||
@ -903,11 +902,11 @@ class ImpreciseFractionConfigValue(
|
||||
|
||||
private fun ForgeConfigSpec.Builder.commentRange(minimum: ImpreciseFraction?, maximum: ImpreciseFraction?) {
|
||||
if (minimum != null && maximum != null) {
|
||||
appendComment("Range: $minimum ~ $maximum")
|
||||
comment("Range: $minimum ~ $maximum")
|
||||
} else if (minimum != null) {
|
||||
appendComment("Range: >= $minimum")
|
||||
comment("Range: >= $minimum")
|
||||
} else if (maximum != null) {
|
||||
appendComment("Range: <= $maximum")
|
||||
comment("Range: <= $maximum")
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user