From 7227def822d3423cb68987168f44355026a44f1d Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Fri, 30 Sep 2022 22:39:17 +0700 Subject: [PATCH] Get rid of appendComment --- .../kotlin/ru/dbotthepony/mc/otm/ConfigExt.kt | 30 ------------------- .../mc/otm/core/ImpreciseFraction.kt | 7 ++--- 2 files changed, 3 insertions(+), 34 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/ConfigExt.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/ConfigExt.kt index d58d45981..aedd29ba9 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/ConfigExt.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/ConfigExt.kt @@ -11,36 +11,6 @@ operator fun ForgeConfigSpec.ConfigValue.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 ?: 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) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/ImpreciseFraction.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/ImpreciseFraction.kt index 1e653dbe6..200bea576 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/ImpreciseFraction.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/ImpreciseFraction.kt @@ -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") } }