diff --git a/CHANGELOG.md b/CHANGELOG.md index 464c85f07..06f171795 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,5 +5,13 @@ Make sure to clear this after each release Put changelog here: ----------------- -- Added support for an optional `tag` entry on Recipe results - - In the form of a `CompoundTag` +- Added support for Cloth Config's `Dependency` in `TypedEntryUtils` +- Added support for lists in `EntryBuilder` + - Via the new `StringList`, `IntList`, `LongList`, `FloatList`, and `DoubleList` data classes + - Kotlin only +- Added support for enums in `EntryBuilder` + - Via the new `EnumEntry` data class + - Kotlin only +- Added support for array selectors in `EntryBuilder` + - Via the new `SelectorEntry` data class + - Kotlin only \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index bbc290e21..44afcad09 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -35,7 +35,6 @@ plugins { `java-library` java kotlin("jvm") version("1.9.20") - kotlin("plugin.serialization") version("1.9.20") } val minecraft_version: String by project diff --git a/src/main/java/net/frozenblock/lib/weather/mixin/LightningOverrideMixin.java b/src/main/java/net/frozenblock/lib/weather/mixin/LightningOverrideMixin.java index bb5625cec..dbf5bf903 100644 --- a/src/main/java/net/frozenblock/lib/weather/mixin/LightningOverrideMixin.java +++ b/src/main/java/net/frozenblock/lib/weather/mixin/LightningOverrideMixin.java @@ -48,7 +48,10 @@ public final class LightningOverrideMixin { return false; } Holder biome = level.getBiome(position); - return ((biome.value().hasPrecipitation() && biome.value().warmEnoughToRain(position)) || biome.is(FrozenBiomeTags.CAN_LIGHTNING_OVERRIDE)) && !biome.is(FrozenBiomeTags.CANNOT_LIGHTNING_OVERRIDE); + return ( + (biome.value().hasPrecipitation() && biome.value().warmEnoughToRain(position)) + || biome.is(FrozenBiomeTags.CAN_LIGHTNING_OVERRIDE) + ) && !biome.is(FrozenBiomeTags.CANNOT_LIGHTNING_OVERRIDE); } } diff --git a/src/main/kotlin/net/frozenblock/lib/config/api/client/gui/EntryBuilder.kt b/src/main/kotlin/net/frozenblock/lib/config/api/client/gui/EntryBuilder.kt index 17e42ced2..ce1b015ff 100644 --- a/src/main/kotlin/net/frozenblock/lib/config/api/client/gui/EntryBuilder.kt +++ b/src/main/kotlin/net/frozenblock/lib/config/api/client/gui/EntryBuilder.kt @@ -168,6 +168,51 @@ data class EntryBuilder( else -> throw IllegalArgumentException("Unsupported slider type: ${usedValue.type}") } } + is StringList -> { + val consumer = saveConsumer as? Consumer ?: consumerError() + entryBuilder.startStrList(title, usedValue.list) + .setDefaultValue((defaultValue as StringList).list) + .setSaveConsumer { strList -> consumer.accept(StringList(strList)) } + .apply { + tooltip?.let { tooltip -> this.setTooltip(tooltip) } + requiresRestart?.let { requiresRestart -> this.requireRestart(requiresRestart) } + requirement?.let { requirement -> this.setRequirement(requirement) } + } + } + is IntList -> { + val consumer = saveConsumer as? Consumer ?: consumerError() + entryBuilder.startIntList(title, usedValue.list) + .setDefaultValue((defaultValue as IntList).list) + .setSaveConsumer { intList -> consumer.accept(IntList(intList)) } + .apply { + tooltip?.let { tooltip -> this.setTooltip(tooltip) } + requiresRestart?.let { requiresRestart -> this.requireRestart(requiresRestart) } + requirement?.let { requirement -> this.setRequirement(requirement) } + } + } + is LongList -> { + val consumer = saveConsumer as? Consumer ?: consumerError() + entryBuilder.startLongList(title, usedValue.list) + .setDefaultValue((defaultValue as LongList).list) + .setSaveConsumer { longList -> consumer.accept(LongList(longList)) } + .apply { + tooltip?.let { tooltip -> this.setTooltip(tooltip) } + requiresRestart?.let { requiresRestart -> this.requireRestart(requiresRestart) } + requirement?.let { requirement -> this.setRequirement(requirement) } + } + } + is FloatList -> { + val consumer = saveConsumer as? Consumer ?: consumerError() + entryBuilder.startFloatList(title, usedValue.list) + .setDefaultValue((defaultValue as FloatList).list) + .setSaveConsumer { floatList -> consumer.accept(FloatList(floatList)) } + .apply { + tooltip?.let { tooltip -> this.setTooltip(tooltip) } + requiresRestart?.let { requiresRestart -> this.requireRestart(requiresRestart) } + requirement?.let { requirement -> this.setRequirement(requirement) } + } + } + TODO("add the other new entries") else -> throw IllegalArgumentException("Unsupported type: ${usedValue!!::class.java}") } } diff --git a/src/main/kotlin/net/frozenblock/lib/config/api/client/gui/Color.kt b/src/main/kotlin/net/frozenblock/lib/config/api/client/gui/EntryTypes.kt similarity index 52% rename from src/main/kotlin/net/frozenblock/lib/config/api/client/gui/Color.kt rename to src/main/kotlin/net/frozenblock/lib/config/api/client/gui/EntryTypes.kt index e261032f3..5a188aba5 100644 --- a/src/main/kotlin/net/frozenblock/lib/config/api/client/gui/Color.kt +++ b/src/main/kotlin/net/frozenblock/lib/config/api/client/gui/EntryTypes.kt @@ -18,8 +18,6 @@ package net.frozenblock.lib.config.api.client.gui -import kotlinx.serialization.Serializable - /** * An [Int] wrapper that represents a color. * [

] @@ -27,8 +25,53 @@ import kotlinx.serialization.Serializable * @param color The [Int] representation of the color * @since 1.3.8 */ -@Serializable data class Color(@JvmField val color: Int) { override fun toString(): String = "Color[$color]" + +} + +// lists + +data class StringList(@JvmField val list: List) { + + override fun toString(): String = "StringList[$list]" +} + +data class IntList(@JvmField val list: List) { + + override fun toString(): String = "IntList[$list]" +} + +data class LongList(@JvmField val list: List) { + + override fun toString(): String = "LongList[$list]" } + +data class FloatList(@JvmField val list: List) { + + override fun toString(): String = "FloatList[$list]" +} + +data class DoubleList(@JvmField val list: List) { + + override fun toString(): String = "DoubleList[$list]" +} + +// not lists anymore + +data class EnumEntry>( + @JvmField val `class`: KClass, + @JvmField val value: T +) { + + override fun toString(): String = "EnumEntry[class=$`class`, value=$value]" +} + +data class SelectorEntry( + @JvmField val valuesArray: Array, + @JvmField val value: T +) { + + override fun toString(): String = "SelectorEntry[valuesArray=$valuesArray, value=$value]" +} \ No newline at end of file diff --git a/src/main/kotlin/net/frozenblock/lib/config/api/client/gui/Slider.kt b/src/main/kotlin/net/frozenblock/lib/config/api/client/gui/Slider.kt index 4a22e8471..91095107b 100644 --- a/src/main/kotlin/net/frozenblock/lib/config/api/client/gui/Slider.kt +++ b/src/main/kotlin/net/frozenblock/lib/config/api/client/gui/Slider.kt @@ -18,9 +18,6 @@ package net.frozenblock.lib.config.api.client.gui -import kotlinx.serialization.Contextual -import kotlinx.serialization.Serializable - /** * A wrapper of a value, minimum, and maximum that represents a slider. * [

] @@ -30,13 +27,9 @@ import kotlinx.serialization.Serializable * @param max The maximum [Int] of the slider * @since 1.4 */ -@Serializable data class Slider( - @Contextual val value: Number, - @Contextual val min: Number, - @Contextual val max: Number, val type: SliderType ) { @@ -44,7 +37,6 @@ data class Slider( override fun toString(): String = "Slider[value=$value, min=$min, max=$max]" } -@Serializable sealed class SliderType { data object INT : SliderType() diff --git a/src/main/kotlin/net/frozenblock/lib/config/api/client/gui/TypedEntryUtils.kt b/src/main/kotlin/net/frozenblock/lib/config/api/client/gui/TypedEntryUtils.kt index 3af49ac71..7ba7be6b8 100644 --- a/src/main/kotlin/net/frozenblock/lib/config/api/client/gui/TypedEntryUtils.kt +++ b/src/main/kotlin/net/frozenblock/lib/config/api/client/gui/TypedEntryUtils.kt @@ -35,7 +35,18 @@ import java.util.function.Supplier * Should only be used if Fabric Language Kotlin is installed. * @since 1.3.8 */ -fun makeTypedEntryList(entryBuilder: ConfigEntryBuilder, title: Component, entrySupplier: Supplier>?>?, defaultValue: Supplier>>, expandedByDefault: Boolean = false, tooltip: Component, setterConsumer: Consumer>>, cellCreator: BiFunction>, AbstractConfigListEntry>, requiresRestart: Boolean = false): NestedListListEntry> { +fun makeTypedEntryList( + entryBuilder: ConfigEntryBuilder, + title: Component, + entrySupplier: Supplier>?>?, + defaultValue: Supplier>>, + expandedByDefault: Boolean = false, + tooltip: Component, + setterConsumer: Consumer>>, + cellCreator: BiFunction>, AbstractConfigListEntry>, + requiresRestart: Boolean = false, + requirement: Requirement? = null +): NestedListListEntry> { val typedEntry: TypedEntry> = entrySupplier?.get() ?: defaultValue.get() return NestedListListEntry( @@ -63,14 +74,28 @@ fun makeTypedEntryList(entryBuilder: ConfigEntryBuilder, title: Component, e true, // New Cell Creation cellCreator - ).let {it.isRequiresRestart = requiresRestart; it} + ).apply { + this.isRequiresRestart = requiresRestart + this.requirement = requirement + } } /** * Should only be used if Fabric Language Kotlin is installed. * @since 1.3.8 */ -fun makeNestedList(entryBuilder: ConfigEntryBuilder, title: Component, entrySupplier: Supplier?>?, defaultValue: Supplier>, expandedByDefault: Boolean = false, tooltip: Component, setterConsumer: Consumer>, cellCreator: BiFunction>, AbstractConfigListEntry>, requiresRestart: Boolean = false): NestedListListEntry> { +fun makeNestedList( + entryBuilder: ConfigEntryBuilder, + title: Component, + entrySupplier: Supplier?>?, + defaultValue: Supplier>, + expandedByDefault: Boolean = false, + tooltip: Component, + setterConsumer: Consumer>, + cellCreator: BiFunction>, AbstractConfigListEntry>, + requiresRestart: Boolean = false, + requirement: Requirement? = null +): NestedListListEntry> { val value: List = entrySupplier?.get() ?: defaultValue.get() return NestedListListEntry( @@ -98,17 +123,30 @@ fun makeNestedList(entryBuilder: ConfigEntryBuilder, title: Component, entry true, // New Cell Creation cellCreator - ).let {it.isRequiresRestart = requiresRestart; it} + ).apply { + this.isRequiresRestart = requiresRestart + this.requirement = requirement + } } /** * Should only be used if Fabric Language Kotlin is installed. * @since 1.3.8 */ -fun makeMultiElementEntry(title: Component, value: T, defaultExpanded: Boolean = true, vararg entries: AbstractConfigListEntry, requiresRestart: Boolean = false): MultiElementListEntry = +fun makeMultiElementEntry( + title: Component, + value: T, + defaultExpanded: Boolean = true, + vararg entries: AbstractConfigListEntry, + requiresRestart: Boolean = false, + requirement: Requirement? = null +): MultiElementListEntry = MultiElementListEntry( title, value, // Default Value entries.asList(), defaultExpanded - ).let { it.isRequiresRestart = requiresRestart; it } + ).apply { + this.isRequiresRestart = requiresRestart + this.requirement = requirement + } diff --git a/src/main/kotlin/net/frozenblock/lib/util/ParameterUtils.kt b/src/main/kotlin/net/frozenblock/lib/util/ParameterUtils.kt index 24cebb82e..b53e82091 100644 --- a/src/main/kotlin/net/frozenblock/lib/util/ParameterUtils.kt +++ b/src/main/kotlin/net/frozenblock/lib/util/ParameterUtils.kt @@ -21,11 +21,9 @@ package net.frozenblock.lib.util import com.mojang.serialization.Codec import com.mojang.serialization.DataResult import com.mojang.serialization.codecs.RecordCodecBuilder -import kotlinx.serialization.Serializable import net.minecraft.util.ExtraCodecs import net.minecraft.world.level.biome.Climate -@Serializable data class MutableParameter( @JvmField var min: Long?, @JvmField var max: Long? @@ -52,7 +50,6 @@ data class MutableParameter( fun Climate.Parameter.mutable(): MutableParameter = MutableParameter(min, max) -@Serializable data class MutableParameterPoint( @JvmField var temperature: MutableParameter?, @JvmField var humidity: MutableParameter?, diff --git a/src/testmod/resources/fabric.mod.json b/src/testmod/resources/fabric.mod.json index 842e621c9..0696a5ccd 100644 --- a/src/testmod/resources/fabric.mod.json +++ b/src/testmod/resources/fabric.mod.json @@ -31,7 +31,7 @@ "depends": { "fabricloader": ">=0.14.22", "fabric-api": ">=0.90.0", - "minecraft": "~1.20-", + "minecraft": "~1.20.2-", "java": ">=17" }, "breaks": {