From 8893053a130be0bf365f9fe6c851da2af1c0225a Mon Sep 17 00:00:00 2001 From: Elliot Thomas Date: Wed, 27 Jul 2022 11:33:23 +0100 Subject: [PATCH 1/7] Add cloth config dependency --- build.gradle.kts | 9 ++++++++- gradle.properties | 9 ++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 4af21ab..6e86cbf 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,5 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import java.net.URI val javaVersion = JavaVersion.VERSION_17 val minecraftVersion: String by project @@ -8,6 +9,8 @@ val fabricVersion: String by project val fabricVersionId: String by project val fabricKotlinVersion: String by project val fabricKotlinVersionId: String by project +val clothConfigVersion: String by project +val clothConfigVersionId: String by project val mavenGroup: String by project val modId: String by project val modVersion: String by project @@ -29,7 +32,9 @@ base { archivesName.set(modId) } group = mavenGroup version = modVersion -repositories {} +repositories { + maven { url = URI("https://maven.shedaniel.me/") } +} dependencies { minecraft("com.mojang", "minecraft", minecraftVersion) @@ -37,6 +42,7 @@ dependencies { modImplementation("net.fabricmc", "fabric-loader", loaderVersion) modImplementation("net.fabricmc.fabric-api", "fabric-api", fabricVersion) modImplementation("net.fabricmc", "fabric-language-kotlin", fabricKotlinVersion) + modApi("me.shedaniel.cloth", "cloth-config-fabric", clothConfigVersion) { exclude("net.fabricmc.fabric-api") } } tasks { @@ -74,6 +80,7 @@ tasks { dependencies { required.version(fabricVersionId) required.version(fabricKotlinVersionId) + required.version(clothConfigVersionId) } // syncBodyFrom.set(rootProject.file("README.md").toString()) } diff --git a/gradle.properties b/gradle.properties index b45daf0..70a6d4d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,9 +13,12 @@ loomVersion=0.12-SNAPSHOT systemProp.kotlinVersion=1.7.0 fabricKotlinVersion=1.8.2+kotlin.1.7.10 fabricKotlinVersionId=5Aq3SFbi +# Cloth Config +clothConfigVersion=7.0.73 +clothConfigVersionId=ehzvjLXC # Mod Properties mavenGroup=com.github.eth0net modId=enchant-menu -modVersion=1.1.1+fabric-1.19 -modVersionName=1.1.1 Fabric 1.19 -modVersionType=release +modVersion=1.2.0-alpha+fabric-1.19 +modVersionName=1.2.0 Alpha Fabric 1.19 +modVersionType=alpha From a56218d550d2241cdcecb03574baa02363d4da71 Mon Sep 17 00:00:00 2001 From: Elliot Thomas Date: Wed, 27 Jul 2022 14:40:39 +0100 Subject: [PATCH 2/7] Update texture placeholders --- assets/enchant-menu.aseprite | Bin 6531 -> 6392 bytes .../textures/gui/enchant_menu.png | Bin 4017 -> 4124 bytes 2 files changed, 0 insertions(+), 0 deletions(-) diff --git a/assets/enchant-menu.aseprite b/assets/enchant-menu.aseprite index a6b076cddef1091586e4fdb2e812e3f72586fc67..5e26e2732322227dcb8ae84eab5c96692b66fe5e 100644 GIT binary patch delta 263 zcmZoR{$a@ULt-LR9dCsM1H-S6S_~-+3=CQud-)g{87I$Syeh{Gh>g7td3aj}vBs)D*UhR6kNJgu&Yo3D>b;X+sZ~9( zPWodfaaujd;7m=_YeojuuS+T%z!q^a@G+<}{AU7kz(9yWh@oPRvAOyGe80&7qAHBs zlS@VI8F@Bu6_sFQj+a@If#KIjeTEbU1_u3&y?l(5r!omlUd?z6MDz17_+;j0mMAzC zr6y(<)y7l6b1O_c*QD%rv zE{3Hf>kI7|Qt;thjJ$z>QRyhWb6=^dZzzTUM zuM)9mzAAe>TM51K5>EhOun#mq+vfk`#i6L30i0q+}C1aA(qKIrws8ETqWG76> zlrW9u4vC=}l6@U!7~iXV&%NLGo%5Y@&-b49oaa5~{r`Xe-+y`D=l9+`ZfzngxJwWK zAZ%u8XbS)gdV~Q1K4@_ce(nh^yj})Y1^|@az05h041h?tnW2GQ*u$y8z#F^A&QRtU zlZTEDF?UWQP2Ce+V@27m`yL0PPRXf18J3hNH;&$2bv)KaDnww5yTLClvHHq*+7oke zx>Shcq7fqXH`lN8O-P-7qf}FGf5n)?7$bL1u7r#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kY}>S55gV%%FtUPv8_VmI)na=4&^TEnKdUQ~mW z5oj2EGynL+ILlvi-~UlHHjk{OzD?Hu{$0Ux(< A=l}o! From 923de23b244b45d7f6d285076e96c456ff6f2ec8 Mon Sep 17 00:00:00 2001 From: Elliot Thomas Date: Wed, 27 Jul 2022 14:55:05 +0100 Subject: [PATCH 3/7] Refactor some helpers --- .../github/eth0net/enchantmenu/EnchantMenu.kt | 16 +++++++++++----- .../enchantmenu/client/EnchantMenuClient.kt | 5 ++--- .../client/gui/screen/EnchantMenuScreen.kt | 4 ++-- .../enchantmenu/network/channel/Channel.kt | 14 +++++++------- .../screen/EnchantMenuScreenHandler.kt | 3 +-- .../com/github/eth0net/enchantmenu/util/Util.kt | 10 ---------- 6 files changed, 23 insertions(+), 29 deletions(-) delete mode 100644 src/main/kotlin/com/github/eth0net/enchantmenu/util/Util.kt diff --git a/src/main/kotlin/com/github/eth0net/enchantmenu/EnchantMenu.kt b/src/main/kotlin/com/github/eth0net/enchantmenu/EnchantMenu.kt index b759cfd..4753f94 100644 --- a/src/main/kotlin/com/github/eth0net/enchantmenu/EnchantMenu.kt +++ b/src/main/kotlin/com/github/eth0net/enchantmenu/EnchantMenu.kt @@ -3,21 +3,25 @@ package com.github.eth0net.enchantmenu import com.github.eth0net.enchantmenu.network.channel.* import com.github.eth0net.enchantmenu.screen.EnchantMenuScreenHandler import com.github.eth0net.enchantmenu.screen.EnchantMenuScreenHandlerFactory -import com.github.eth0net.enchantmenu.util.Identifier -import com.github.eth0net.enchantmenu.util.Logger import net.fabricmc.api.ModInitializer import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking import net.minecraft.screen.ScreenHandlerType +import net.minecraft.util.Identifier import net.minecraft.util.registry.Registry +import org.apache.logging.log4j.LogManager @Suppress("UNUSED") object EnchantMenu : ModInitializer { + private const val MOD_ID = "enchant-menu" + + internal val log = LogManager.getLogger(MOD_ID) + internal val SCREEN_HANDLER = Registry.register( - Registry.SCREEN_HANDLER, Identifier("enchant_menu"), ScreenHandlerType(::EnchantMenuScreenHandler) + Registry.SCREEN_HANDLER, id("enchant_menu"), ScreenHandlerType(::EnchantMenuScreenHandler) ) override fun onInitialize() { - Logger.info("EnchantMenu initializing...") + log.info("EnchantMenu initializing...") ServerPlayNetworking.registerGlobalReceiver(MenuChannel) { _, player, _, _, _ -> player.openHandledScreen(EnchantMenuScreenHandlerFactory) @@ -38,6 +42,8 @@ object EnchantMenu : ModInitializer { (player.currentScreenHandler as? EnchantMenuScreenHandler)?.toggleTreasure() } - Logger.info("EnchantMenu initialized.") + log.info("EnchantMenu initialized.") } + + internal fun id(path: String) = Identifier(MOD_ID, path) } diff --git a/src/main/kotlin/com/github/eth0net/enchantmenu/client/EnchantMenuClient.kt b/src/main/kotlin/com/github/eth0net/enchantmenu/client/EnchantMenuClient.kt index 4a3590c..9314147 100644 --- a/src/main/kotlin/com/github/eth0net/enchantmenu/client/EnchantMenuClient.kt +++ b/src/main/kotlin/com/github/eth0net/enchantmenu/client/EnchantMenuClient.kt @@ -4,7 +4,6 @@ import com.github.eth0net.enchantmenu.EnchantMenu import com.github.eth0net.enchantmenu.client.gui.screen.EnchantMenuScreen import com.github.eth0net.enchantmenu.client.keybinding.MenuKeyBinding import com.github.eth0net.enchantmenu.network.channel.MenuChannel -import com.github.eth0net.enchantmenu.util.Logger import net.fabricmc.api.ClientModInitializer import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking @@ -14,7 +13,7 @@ import net.minecraft.client.gui.screen.ingame.HandledScreens @Suppress("UNUSED") object EnchantMenuClient : ClientModInitializer { override fun onInitializeClient() { - Logger.info("EnchantMenuClient initializing...") + EnchantMenu.log.info("EnchantMenuClient initializing...") HandledScreens.register(EnchantMenu.SCREEN_HANDLER, ::EnchantMenuScreen) @@ -22,6 +21,6 @@ object EnchantMenuClient : ClientModInitializer { while (MenuKeyBinding.wasPressed()) ClientPlayNetworking.send(MenuChannel, PacketByteBufs.empty()) } - Logger.info("EnchantMenuClient initialized.") + EnchantMenu.log.info("EnchantMenuClient initialized.") } } diff --git a/src/main/kotlin/com/github/eth0net/enchantmenu/client/gui/screen/EnchantMenuScreen.kt b/src/main/kotlin/com/github/eth0net/enchantmenu/client/gui/screen/EnchantMenuScreen.kt index 166d851..37ba03b 100644 --- a/src/main/kotlin/com/github/eth0net/enchantmenu/client/gui/screen/EnchantMenuScreen.kt +++ b/src/main/kotlin/com/github/eth0net/enchantmenu/client/gui/screen/EnchantMenuScreen.kt @@ -1,9 +1,9 @@ package com.github.eth0net.enchantmenu.client.gui.screen +import com.github.eth0net.enchantmenu.EnchantMenu import com.github.eth0net.enchantmenu.client.keybinding.* import com.github.eth0net.enchantmenu.network.channel.* import com.github.eth0net.enchantmenu.screen.EnchantMenuScreenHandler -import com.github.eth0net.enchantmenu.util.Identifier import com.mojang.blaze3d.systems.RenderSystem import net.fabricmc.api.EnvType import net.fabricmc.api.Environment @@ -26,7 +26,7 @@ class EnchantMenuScreen(handler: EnchantMenuScreenHandler, playerInventory: Play override fun getDisplayName() = Text.empty() }, title) { - private val texture = Identifier("textures/gui/enchant_menu.png") + private val texture = EnchantMenu.id("textures/gui/enchant_menu.png") private var stack = ItemStack.EMPTY private var ticks = 0 diff --git a/src/main/kotlin/com/github/eth0net/enchantmenu/network/channel/Channel.kt b/src/main/kotlin/com/github/eth0net/enchantmenu/network/channel/Channel.kt index 8d4ea25..2a9f906 100644 --- a/src/main/kotlin/com/github/eth0net/enchantmenu/network/channel/Channel.kt +++ b/src/main/kotlin/com/github/eth0net/enchantmenu/network/channel/Channel.kt @@ -1,10 +1,10 @@ package com.github.eth0net.enchantmenu.network.channel -import com.github.eth0net.enchantmenu.util.Identifier +import com.github.eth0net.enchantmenu.EnchantMenu.id -internal val MenuChannel = Identifier("toggle_menu_channel") -internal val DecrementLevelChannel = Identifier("decrement_level_channel") -internal val IncrementLevelChannel = Identifier("increment_level_channel") -internal val ToggleIncompatibleChannel = Identifier("toggle_incompatible_channel") -internal val ToggleLevelChannel = Identifier("toggle_level_channel") -internal val ToggleTreasureChannel = Identifier("toggle_treasure_channel") +internal val MenuChannel = id("toggle_menu_channel") +internal val DecrementLevelChannel = id("decrement_level_channel") +internal val IncrementLevelChannel = id("increment_level_channel") +internal val ToggleIncompatibleChannel = id("toggle_incompatible_channel") +internal val ToggleLevelChannel = id("toggle_level_channel") +internal val ToggleTreasureChannel = id("toggle_treasure_channel") diff --git a/src/main/kotlin/com/github/eth0net/enchantmenu/screen/EnchantMenuScreenHandler.kt b/src/main/kotlin/com/github/eth0net/enchantmenu/screen/EnchantMenuScreenHandler.kt index 69e22a2..cda39bf 100644 --- a/src/main/kotlin/com/github/eth0net/enchantmenu/screen/EnchantMenuScreenHandler.kt +++ b/src/main/kotlin/com/github/eth0net/enchantmenu/screen/EnchantMenuScreenHandler.kt @@ -4,7 +4,6 @@ import com.github.eth0net.enchantmenu.EnchantMenu import com.github.eth0net.enchantmenu.screen.slot.ArmorSlot import com.github.eth0net.enchantmenu.screen.slot.EnchantSlot import com.github.eth0net.enchantmenu.screen.slot.OffhandSlot -import com.github.eth0net.enchantmenu.util.Logger import net.minecraft.enchantment.Enchantment import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.entity.player.PlayerEntity @@ -70,7 +69,7 @@ class EnchantMenuScreenHandler( override fun onButtonClick(player: PlayerEntity, id: Int): Boolean { if (id !in enchantments.indices) { - Logger.error("${player.name} tried to press invalid button $id") + EnchantMenu.log.error("${player.name} tried to press invalid button $id") return false } diff --git a/src/main/kotlin/com/github/eth0net/enchantmenu/util/Util.kt b/src/main/kotlin/com/github/eth0net/enchantmenu/util/Util.kt deleted file mode 100644 index 953f29e..0000000 --- a/src/main/kotlin/com/github/eth0net/enchantmenu/util/Util.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.github.eth0net.enchantmenu.util - -import net.minecraft.util.Identifier -import org.apache.logging.log4j.LogManager - -internal const val MOD_ID = "enchant-menu" - -internal val Logger = LogManager.getLogger(MOD_ID) - -internal fun Identifier(path: String) = Identifier(MOD_ID, path) From 81c847392a8e08375c7a3dbaa185f5bc64327b64 Mon Sep 17 00:00:00 2001 From: Elliot Thomas Date: Wed, 27 Jul 2022 14:55:48 +0100 Subject: [PATCH 4/7] Add config class --- .../github/eth0net/enchantmenu/EnchantMenu.kt | 3 ++ .../client/gui/screen/EnchantMenuScreen.kt | 10 ++-- .../enchantmenu/config/EnchantMenuConfig.kt | 48 ++++++++++++++++++ .../screen/EnchantMenuScreenHandler.kt | 50 +++++++++++++------ 4 files changed, 92 insertions(+), 19 deletions(-) create mode 100644 src/main/kotlin/com/github/eth0net/enchantmenu/config/EnchantMenuConfig.kt diff --git a/src/main/kotlin/com/github/eth0net/enchantmenu/EnchantMenu.kt b/src/main/kotlin/com/github/eth0net/enchantmenu/EnchantMenu.kt index 4753f94..73dde0e 100644 --- a/src/main/kotlin/com/github/eth0net/enchantmenu/EnchantMenu.kt +++ b/src/main/kotlin/com/github/eth0net/enchantmenu/EnchantMenu.kt @@ -1,5 +1,6 @@ package com.github.eth0net.enchantmenu +import com.github.eth0net.enchantmenu.config.EnchantMenuConfig import com.github.eth0net.enchantmenu.network.channel.* import com.github.eth0net.enchantmenu.screen.EnchantMenuScreenHandler import com.github.eth0net.enchantmenu.screen.EnchantMenuScreenHandlerFactory @@ -14,6 +15,8 @@ import org.apache.logging.log4j.LogManager object EnchantMenu : ModInitializer { private const val MOD_ID = "enchant-menu" + internal val config = EnchantMenuConfig() + internal val log = LogManager.getLogger(MOD_ID) internal val SCREEN_HANDLER = Registry.register( diff --git a/src/main/kotlin/com/github/eth0net/enchantmenu/client/gui/screen/EnchantMenuScreen.kt b/src/main/kotlin/com/github/eth0net/enchantmenu/client/gui/screen/EnchantMenuScreen.kt index 37ba03b..fecf2d4 100644 --- a/src/main/kotlin/com/github/eth0net/enchantmenu/client/gui/screen/EnchantMenuScreen.kt +++ b/src/main/kotlin/com/github/eth0net/enchantmenu/client/gui/screen/EnchantMenuScreen.kt @@ -106,10 +106,10 @@ class EnchantMenuScreen(handler: EnchantMenuScreenHandler, playerInventory: Play // level change buttons clearChildren() - if (handler.level < handler.maxLevel) addDrawableChild(TexturedButtonWidget( + if (handler.level < EnchantMenu.config.maxLevel) addDrawableChild(TexturedButtonWidget( x + 31, y + 18, 8, 13, 149, 166, texture ) { onIncrementLevelClick() }) - if (handler.level > handler.minLevel) addDrawableChild(TexturedButtonWidget( + if (handler.level > EnchantMenu.config.minLevel) addDrawableChild(TexturedButtonWidget( x + 6, y + 18, 8, 13, 141, 166, texture ) { onDecrementLevelClick() }) @@ -122,13 +122,13 @@ class EnchantMenuScreen(handler: EnchantMenuScreenHandler, playerInventory: Play } // limit breaks - addDrawableChild(TexturedButtonWidget( + if (!EnchantMenu.config.disableIncompatibleUnlock) addDrawableChild(TexturedButtonWidget( x + 152, y + 5, 11, 11, 168, if (handler.incompatibleUnlocked) 177 else 166, texture ) { onToggleIncompatibleClick() }) - addDrawableChild(TexturedButtonWidget( + if (!EnchantMenu.config.disableLevelUnlock) addDrawableChild(TexturedButtonWidget( x + 165, y + 5, 11, 11, 179, if (handler.levelUnlocked) 177 else 166, texture ) { onToggleLevelClick() }) - addDrawableChild(TexturedButtonWidget( + if (!EnchantMenu.config.disableTreasureUnlock) addDrawableChild(TexturedButtonWidget( x + 178, y + 5, 11, 11, 190, if (handler.treasureUnlocked) 177 else 166, texture ) { onToggleTreasureClick() }) diff --git a/src/main/kotlin/com/github/eth0net/enchantmenu/config/EnchantMenuConfig.kt b/src/main/kotlin/com/github/eth0net/enchantmenu/config/EnchantMenuConfig.kt new file mode 100644 index 0000000..463d762 --- /dev/null +++ b/src/main/kotlin/com/github/eth0net/enchantmenu/config/EnchantMenuConfig.kt @@ -0,0 +1,48 @@ +package com.github.eth0net.enchantmenu.config + +internal class EnchantMenuConfig { + var minLevel = 1 + var maxLevel = 10 + var defaultLevel = minLevel + set(value) { + field = if (value < minLevel) { + minLevel + } else if (value > maxLevel) { + maxLevel + } else { + value + } + } + + + var disableIncompatibleUnlock = false + fun toggleDisableIncompatibleUnlock() { + disableIncompatibleUnlock = !disableIncompatibleUnlock + } + + var disableLevelUnlock = false + fun toggleDisableLevelUnlock() { + disableLevelUnlock = !disableLevelUnlock + } + + var disableTreasureUnlock = false + fun toggleDisableTreasureUnlock() { + disableTreasureUnlock = !disableTreasureUnlock + } + + + var defaultIncompatibleUnlocked = false + fun toggleDefaultIncompatibleUnlocked() { + defaultIncompatibleUnlocked = !defaultIncompatibleUnlocked + } + + var defaultLevelUnlocked = false + fun toggleDefaultLevelUnlocked() { + defaultLevelUnlocked = !defaultLevelUnlocked + } + + var defaultTreasureUnlocked = false + fun toggleDefaultTreasureUnlocked() { + defaultTreasureUnlocked = !defaultTreasureUnlocked + } +} diff --git a/src/main/kotlin/com/github/eth0net/enchantmenu/screen/EnchantMenuScreenHandler.kt b/src/main/kotlin/com/github/eth0net/enchantmenu/screen/EnchantMenuScreenHandler.kt index cda39bf..cbcc37a 100644 --- a/src/main/kotlin/com/github/eth0net/enchantmenu/screen/EnchantMenuScreenHandler.kt +++ b/src/main/kotlin/com/github/eth0net/enchantmenu/screen/EnchantMenuScreenHandler.kt @@ -35,24 +35,46 @@ class EnchantMenuScreenHandler( } } - internal val minLevel = 1 - internal val maxLevel = 10 - internal var level = minLevel + internal var enchantments: List> = listOf() + + internal var level = EnchantMenu.config.defaultLevel set(value) { - field = if (value < minLevel) { - minLevel - } else if (value > maxLevel) { - maxLevel + field = if (value < EnchantMenu.config.minLevel) { + EnchantMenu.config.minLevel + } else if (value > EnchantMenu.config.maxLevel) { + EnchantMenu.config.maxLevel } else { value } } - internal var enchantments: List> = listOf() - - internal var incompatibleUnlocked = false - internal var levelUnlocked = false - internal var treasureUnlocked = false + internal var incompatibleUnlocked = EnchantMenu.config.defaultIncompatibleUnlocked + get() = !EnchantMenu.config.disableIncompatibleUnlock && field +// set(value) { +// field = if (!EnchantMenu.config.disableLevelLimitBreak) { +// value +// } else { +// false +// } +// } + internal var levelUnlocked = EnchantMenu.config.defaultLevelUnlocked + get() = !EnchantMenu.config.disableLevelUnlock && field +// set(value) { +// field = if (!EnchantMenu.config.disableLevelLimitBreak) { +// value +// } else { +// false +// } +// } + internal var treasureUnlocked = EnchantMenu.config.defaultTreasureUnlocked + get() = !EnchantMenu.config.disableTreasureUnlock && field +// set(value) { +// field = if (!EnchantMenu.config.disableTreasureLimitBreak) { +// value +// } else { +// false +// } +// } init { addSlot(EnchantSlot(inventory, 0, 15, 40)) @@ -182,11 +204,11 @@ class EnchantMenuScreenHandler( } internal fun incrementLevel() { - if (level < maxLevel) ++level + if (level < EnchantMenu.config.maxLevel) ++level } internal fun decrementLevel() { - if (level > minLevel) --level + if (level > EnchantMenu.config.minLevel) --level } internal fun toggleIncompatible() { From b53a56620a21dbaa2cea4dbc94bc34b5cf398ecb Mon Sep 17 00:00:00 2001 From: Elliot Thomas Date: Fri, 29 Jul 2022 17:06:26 +0100 Subject: [PATCH 5/7] Implement CompleteConfig --- build.gradle.kts | 11 +- gradle.properties | 3 + .../github/eth0net/enchantmenu/EnchantMenu.kt | 6 +- .../enchantmenu/client/EnchantMenuClient.kt | 7 ++ .../client/gui/screen/EnchantMenuScreen.kt | 11 +- .../enchantmenu/config/EnchantMenuConfig.kt | 118 +++++++++++++----- .../screen/EnchantMenuScreenHandler.kt | 50 +++----- .../assets/enchant-menu/lang/en_us.json | 12 ++ 8 files changed, 140 insertions(+), 78 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 6e86cbf..1dd0b33 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,6 +9,8 @@ val fabricVersion: String by project val fabricVersionId: String by project val fabricKotlinVersion: String by project val fabricKotlinVersionId: String by project +val completeConfigVersion: String by project +val completeConfigVersionId: String by project val clothConfigVersion: String by project val clothConfigVersionId: String by project val mavenGroup: String by project @@ -33,7 +35,10 @@ group = mavenGroup version = modVersion repositories { + maven { url = URI("https://jitpack.io") } + maven { url = URI("https://maven.terraformersmc.com/") } maven { url = URI("https://maven.shedaniel.me/") } + maven { url = URI("https://maven.siphalor.de/") } } dependencies { @@ -42,7 +47,8 @@ dependencies { modImplementation("net.fabricmc", "fabric-loader", loaderVersion) modImplementation("net.fabricmc.fabric-api", "fabric-api", fabricVersion) modImplementation("net.fabricmc", "fabric-language-kotlin", fabricKotlinVersion) - modApi("me.shedaniel.cloth", "cloth-config-fabric", clothConfigVersion) { exclude("net.fabricmc.fabric-api") } + modImplementation("com.gitlab.Lortseam.completeconfig", "base", completeConfigVersion) + modImplementation("com.gitlab.Lortseam.completeconfig", "gui-cloth", completeConfigVersion) } tasks { @@ -80,7 +86,8 @@ tasks { dependencies { required.version(fabricVersionId) required.version(fabricKotlinVersionId) - required.version(clothConfigVersionId) + required.version(completeConfigVersionId) + optional.version(clothConfigVersionId) } // syncBodyFrom.set(rootProject.file("README.md").toString()) } diff --git a/gradle.properties b/gradle.properties index 70a6d4d..dc93e2c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,6 +13,9 @@ loomVersion=0.12-SNAPSHOT systemProp.kotlinVersion=1.7.0 fabricKotlinVersion=1.8.2+kotlin.1.7.10 fabricKotlinVersionId=5Aq3SFbi +# Complete Config +completeConfigVersion=2.0.0 +completeConfigVersionId=zaC01d1T # Cloth Config clothConfigVersion=7.0.73 clothConfigVersionId=ehzvjLXC diff --git a/src/main/kotlin/com/github/eth0net/enchantmenu/EnchantMenu.kt b/src/main/kotlin/com/github/eth0net/enchantmenu/EnchantMenu.kt index 73dde0e..6b3b54a 100644 --- a/src/main/kotlin/com/github/eth0net/enchantmenu/EnchantMenu.kt +++ b/src/main/kotlin/com/github/eth0net/enchantmenu/EnchantMenu.kt @@ -13,9 +13,7 @@ import org.apache.logging.log4j.LogManager @Suppress("UNUSED") object EnchantMenu : ModInitializer { - private const val MOD_ID = "enchant-menu" - - internal val config = EnchantMenuConfig() + internal const val MOD_ID = "enchant-menu" internal val log = LogManager.getLogger(MOD_ID) @@ -26,6 +24,8 @@ object EnchantMenu : ModInitializer { override fun onInitialize() { log.info("EnchantMenu initializing...") + EnchantMenuConfig.load() + ServerPlayNetworking.registerGlobalReceiver(MenuChannel) { _, player, _, _, _ -> player.openHandledScreen(EnchantMenuScreenHandlerFactory) } diff --git a/src/main/kotlin/com/github/eth0net/enchantmenu/client/EnchantMenuClient.kt b/src/main/kotlin/com/github/eth0net/enchantmenu/client/EnchantMenuClient.kt index 9314147..e82c38d 100644 --- a/src/main/kotlin/com/github/eth0net/enchantmenu/client/EnchantMenuClient.kt +++ b/src/main/kotlin/com/github/eth0net/enchantmenu/client/EnchantMenuClient.kt @@ -4,10 +4,13 @@ import com.github.eth0net.enchantmenu.EnchantMenu import com.github.eth0net.enchantmenu.client.gui.screen.EnchantMenuScreen import com.github.eth0net.enchantmenu.client.keybinding.MenuKeyBinding import com.github.eth0net.enchantmenu.network.channel.MenuChannel +import me.lortseam.completeconfig.gui.ConfigScreenBuilder +import me.lortseam.completeconfig.gui.cloth.ClothConfigScreenBuilder import net.fabricmc.api.ClientModInitializer import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking import net.fabricmc.fabric.api.networking.v1.PacketByteBufs +import net.fabricmc.loader.api.FabricLoader import net.minecraft.client.gui.screen.ingame.HandledScreens @Suppress("UNUSED") @@ -15,6 +18,10 @@ object EnchantMenuClient : ClientModInitializer { override fun onInitializeClient() { EnchantMenu.log.info("EnchantMenuClient initializing...") + if (FabricLoader.getInstance().isModLoaded("cloth-config")) { + ConfigScreenBuilder.setMain(EnchantMenu.MOD_ID, ClothConfigScreenBuilder()) + } + HandledScreens.register(EnchantMenu.SCREEN_HANDLER, ::EnchantMenuScreen) ClientTickEvents.END_CLIENT_TICK.register { diff --git a/src/main/kotlin/com/github/eth0net/enchantmenu/client/gui/screen/EnchantMenuScreen.kt b/src/main/kotlin/com/github/eth0net/enchantmenu/client/gui/screen/EnchantMenuScreen.kt index fecf2d4..45a3e93 100644 --- a/src/main/kotlin/com/github/eth0net/enchantmenu/client/gui/screen/EnchantMenuScreen.kt +++ b/src/main/kotlin/com/github/eth0net/enchantmenu/client/gui/screen/EnchantMenuScreen.kt @@ -2,6 +2,7 @@ package com.github.eth0net.enchantmenu.client.gui.screen import com.github.eth0net.enchantmenu.EnchantMenu import com.github.eth0net.enchantmenu.client.keybinding.* +import com.github.eth0net.enchantmenu.config.EnchantMenuConfig import com.github.eth0net.enchantmenu.network.channel.* import com.github.eth0net.enchantmenu.screen.EnchantMenuScreenHandler import com.mojang.blaze3d.systems.RenderSystem @@ -106,10 +107,10 @@ class EnchantMenuScreen(handler: EnchantMenuScreenHandler, playerInventory: Play // level change buttons clearChildren() - if (handler.level < EnchantMenu.config.maxLevel) addDrawableChild(TexturedButtonWidget( + if (handler.level < EnchantMenuConfig.Levels.maximum) addDrawableChild(TexturedButtonWidget( x + 31, y + 18, 8, 13, 149, 166, texture ) { onIncrementLevelClick() }) - if (handler.level > EnchantMenu.config.minLevel) addDrawableChild(TexturedButtonWidget( + if (handler.level > EnchantMenuConfig.Levels.minimum) addDrawableChild(TexturedButtonWidget( x + 6, y + 18, 8, 13, 141, 166, texture ) { onDecrementLevelClick() }) @@ -122,13 +123,13 @@ class EnchantMenuScreen(handler: EnchantMenuScreenHandler, playerInventory: Play } // limit breaks - if (!EnchantMenu.config.disableIncompatibleUnlock) addDrawableChild(TexturedButtonWidget( + if (EnchantMenuConfig.AllowLimitBreaks.incompatible) addDrawableChild(TexturedButtonWidget( x + 152, y + 5, 11, 11, 168, if (handler.incompatibleUnlocked) 177 else 166, texture ) { onToggleIncompatibleClick() }) - if (!EnchantMenu.config.disableLevelUnlock) addDrawableChild(TexturedButtonWidget( + if (EnchantMenuConfig.AllowLimitBreaks.level) addDrawableChild(TexturedButtonWidget( x + 165, y + 5, 11, 11, 179, if (handler.levelUnlocked) 177 else 166, texture ) { onToggleLevelClick() }) - if (!EnchantMenu.config.disableTreasureUnlock) addDrawableChild(TexturedButtonWidget( + if (EnchantMenuConfig.AllowLimitBreaks.treasure) addDrawableChild(TexturedButtonWidget( x + 178, y + 5, 11, 11, 190, if (handler.treasureUnlocked) 177 else 166, texture ) { onToggleTreasureClick() }) diff --git a/src/main/kotlin/com/github/eth0net/enchantmenu/config/EnchantMenuConfig.kt b/src/main/kotlin/com/github/eth0net/enchantmenu/config/EnchantMenuConfig.kt index 463d762..2ce034c 100644 --- a/src/main/kotlin/com/github/eth0net/enchantmenu/config/EnchantMenuConfig.kt +++ b/src/main/kotlin/com/github/eth0net/enchantmenu/config/EnchantMenuConfig.kt @@ -1,48 +1,98 @@ package com.github.eth0net.enchantmenu.config -internal class EnchantMenuConfig { - var minLevel = 1 - var maxLevel = 10 - var defaultLevel = minLevel - set(value) { - field = if (value < minLevel) { - minLevel - } else if (value > maxLevel) { - maxLevel - } else { - value - } - } +import com.github.eth0net.enchantmenu.EnchantMenu +import me.lortseam.completeconfig.api.ConfigContainer +import me.lortseam.completeconfig.api.ConfigContainer.Transitive +import me.lortseam.completeconfig.api.ConfigEntries +import me.lortseam.completeconfig.api.ConfigEntry +import me.lortseam.completeconfig.api.ConfigEntry.BoundedInteger +import me.lortseam.completeconfig.api.ConfigEntry.Slider +import me.lortseam.completeconfig.api.ConfigGroup +import me.lortseam.completeconfig.data.Config +object EnchantMenuConfig : Config(EnchantMenu.MOD_ID), ConfigContainer { + @Transitive + @ConfigEntries(includeAll = true) + object Levels : ConfigGroup { + @BoundedInteger(min = 1, max = 100) + @Slider + var minimum = 1 + set(value) { + field = if (value < 1) { + 1 + } else if (value > maximum) { + maximum + } else { + value + } + } - var disableIncompatibleUnlock = false - fun toggleDisableIncompatibleUnlock() { - disableIncompatibleUnlock = !disableIncompatibleUnlock - } + @BoundedInteger(min = 1, max = 100) + @Slider + var maximum = 10 + set(value) { + field = if (value < minimum) { + minimum + } else if (value > 100) { + 100 + } else { + value + } + } - var disableLevelUnlock = false - fun toggleDisableLevelUnlock() { - disableLevelUnlock = !disableLevelUnlock + @BoundedInteger(min = 1, max = 100) + @Slider + var default = minimum + set(value) { + field = if (value < minimum) { + minimum + } else if (value > maximum) { + maximum + } else { + value + } + } } - var disableTreasureUnlock = false - fun toggleDisableTreasureUnlock() { - disableTreasureUnlock = !disableTreasureUnlock - } + @Transitive + object AllowLimitBreaks : ConfigGroup { + @ConfigEntry + var incompatible = true + fun toggleIncompatible() { + incompatible = !incompatible + } + @ConfigEntry + var level = true + fun toggleLevel() { + level = !level + } - var defaultIncompatibleUnlocked = false - fun toggleDefaultIncompatibleUnlocked() { - defaultIncompatibleUnlocked = !defaultIncompatibleUnlocked + @ConfigEntry + var treasure = true + fun toggleTreasure() { + treasure = !treasure + } } - var defaultLevelUnlocked = false - fun toggleDefaultLevelUnlocked() { - defaultLevelUnlocked = !defaultLevelUnlocked - } + @Transitive + object AutoLimitBreaks : ConfigGroup { + @ConfigEntry + var incompatible = false + fun toggleIncompatible() { + incompatible = !incompatible + } - var defaultTreasureUnlocked = false - fun toggleDefaultTreasureUnlocked() { - defaultTreasureUnlocked = !defaultTreasureUnlocked + @ConfigEntry + var level = false + fun toggleLevel() { + level = !level + } + + @ConfigEntry + var treasure = false + fun toggleTreasure() { + treasure = !treasure + } } } diff --git a/src/main/kotlin/com/github/eth0net/enchantmenu/screen/EnchantMenuScreenHandler.kt b/src/main/kotlin/com/github/eth0net/enchantmenu/screen/EnchantMenuScreenHandler.kt index cbcc37a..1beddc1 100644 --- a/src/main/kotlin/com/github/eth0net/enchantmenu/screen/EnchantMenuScreenHandler.kt +++ b/src/main/kotlin/com/github/eth0net/enchantmenu/screen/EnchantMenuScreenHandler.kt @@ -1,6 +1,7 @@ package com.github.eth0net.enchantmenu.screen import com.github.eth0net.enchantmenu.EnchantMenu +import com.github.eth0net.enchantmenu.config.EnchantMenuConfig import com.github.eth0net.enchantmenu.screen.slot.ArmorSlot import com.github.eth0net.enchantmenu.screen.slot.EnchantSlot import com.github.eth0net.enchantmenu.screen.slot.OffhandSlot @@ -37,44 +38,25 @@ class EnchantMenuScreenHandler( internal var enchantments: List> = listOf() - internal var level = EnchantMenu.config.defaultLevel + internal var level = EnchantMenuConfig.Levels.default set(value) { - field = if (value < EnchantMenu.config.minLevel) { - EnchantMenu.config.minLevel - } else if (value > EnchantMenu.config.maxLevel) { - EnchantMenu.config.maxLevel + field = if (value < EnchantMenuConfig.Levels.minimum) { + EnchantMenuConfig.Levels.minimum + } else if (value > EnchantMenuConfig.Levels.maximum) { + EnchantMenuConfig.Levels.maximum } else { value } } - internal var incompatibleUnlocked = EnchantMenu.config.defaultIncompatibleUnlocked - get() = !EnchantMenu.config.disableIncompatibleUnlock && field -// set(value) { -// field = if (!EnchantMenu.config.disableLevelLimitBreak) { -// value -// } else { -// false -// } -// } - internal var levelUnlocked = EnchantMenu.config.defaultLevelUnlocked - get() = !EnchantMenu.config.disableLevelUnlock && field -// set(value) { -// field = if (!EnchantMenu.config.disableLevelLimitBreak) { -// value -// } else { -// false -// } -// } - internal var treasureUnlocked = EnchantMenu.config.defaultTreasureUnlocked - get() = !EnchantMenu.config.disableTreasureUnlock && field -// set(value) { -// field = if (!EnchantMenu.config.disableTreasureLimitBreak) { -// value -// } else { -// false -// } -// } + internal var incompatibleUnlocked = EnchantMenuConfig.AutoLimitBreaks.incompatible + get() = EnchantMenuConfig.AllowLimitBreaks.incompatible && field + + internal var levelUnlocked = EnchantMenuConfig.AutoLimitBreaks.level + get() = EnchantMenuConfig.AllowLimitBreaks.level && field + + internal var treasureUnlocked = EnchantMenuConfig.AutoLimitBreaks.treasure + get() = EnchantMenuConfig.AllowLimitBreaks.treasure && field init { addSlot(EnchantSlot(inventory, 0, 15, 40)) @@ -204,11 +186,11 @@ class EnchantMenuScreenHandler( } internal fun incrementLevel() { - if (level < EnchantMenu.config.maxLevel) ++level + if (level < EnchantMenuConfig.Levels.maximum) ++level } internal fun decrementLevel() { - if (level > EnchantMenu.config.minLevel) --level + if (level > EnchantMenuConfig.Levels.minimum) --level } internal fun toggleIncompatible() { diff --git a/src/main/resources/assets/enchant-menu/lang/en_us.json b/src/main/resources/assets/enchant-menu/lang/en_us.json index fa51290..0670e0d 100644 --- a/src/main/resources/assets/enchant-menu/lang/en_us.json +++ b/src/main/resources/assets/enchant-menu/lang/en_us.json @@ -1,6 +1,18 @@ { "enchant-menu.title": "Enchant Menu", "category.enchant-menu.general": "Enchant Menu", + "config.enchant-menu.levels": "Levels", + "config.enchant-menu.levels.minimum": "Minimum Level", + "config.enchant-menu.levels.maximum": "Maximum Level", + "config.enchant-menu.levels.default": "Default Level", + "config.enchant-menu.allowLimitBreaks": "Allow Limit Breaks", + "config.enchant-menu.allowLimitBreaks.incompatible": "Allow Incompatible", + "config.enchant-menu.allowLimitBreaks.level": "Allow Level", + "config.enchant-menu.allowLimitBreaks.treasure": "Allow Treasure", + "config.enchant-menu.autoLimitBreaks": "Auto Limit Breaks", + "config.enchant-menu.autoLimitBreaks.incompatible": "Auto-enable Incompatible", + "config.enchant-menu.autoLimitBreaks.level": "Auto-enable Level", + "config.enchant-menu.autoLimitBreaks.treasure": "Auto-enable Treasure", "key.enchant-menu.menu": "Toggle Enchant Menu", "key.enchant-menu.increment_level": "Increment Level", "key.enchant-menu.decrement_level": "Decrement Level", From 099cd7158969f62f88139e174cdc4285bd2bb9b2 Mon Sep 17 00:00:00 2001 From: Elliot Thomas Date: Fri, 29 Jul 2022 23:42:07 +0100 Subject: [PATCH 6/7] Add server to client config syncing --- .../com/github/eth0net/enchantmenu/EnchantMenu.kt | 11 +++++++++++ .../enchantmenu/client/EnchantMenuClient.kt | 15 ++++++++++++++- .../enchantmenu/network/channel/Channel.kt | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/github/eth0net/enchantmenu/EnchantMenu.kt b/src/main/kotlin/com/github/eth0net/enchantmenu/EnchantMenu.kt index 6b3b54a..dad1e85 100644 --- a/src/main/kotlin/com/github/eth0net/enchantmenu/EnchantMenu.kt +++ b/src/main/kotlin/com/github/eth0net/enchantmenu/EnchantMenu.kt @@ -5,11 +5,15 @@ import com.github.eth0net.enchantmenu.network.channel.* import com.github.eth0net.enchantmenu.screen.EnchantMenuScreenHandler import com.github.eth0net.enchantmenu.screen.EnchantMenuScreenHandlerFactory import net.fabricmc.api.ModInitializer +import net.fabricmc.fabric.api.networking.v1.PacketByteBufs +import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking import net.minecraft.screen.ScreenHandlerType import net.minecraft.util.Identifier import net.minecraft.util.registry.Registry import org.apache.logging.log4j.LogManager +import java.io.BufferedWriter +import java.io.StringWriter @Suppress("UNUSED") object EnchantMenu : ModInitializer { @@ -26,6 +30,13 @@ object EnchantMenu : ModInitializer { EnchantMenuConfig.load() + ServerPlayConnectionEvents.JOIN.register { net, _, _ -> + val writer = StringWriter() + EnchantMenuConfig.serialize { BufferedWriter(writer) } + val buf = PacketByteBufs.create().writeString(writer.toString()) + ServerPlayNetworking.send(net.player, ConfigSyncChannel, buf) + } + ServerPlayNetworking.registerGlobalReceiver(MenuChannel) { _, player, _, _, _ -> player.openHandledScreen(EnchantMenuScreenHandlerFactory) } diff --git a/src/main/kotlin/com/github/eth0net/enchantmenu/client/EnchantMenuClient.kt b/src/main/kotlin/com/github/eth0net/enchantmenu/client/EnchantMenuClient.kt index e82c38d..8d11096 100644 --- a/src/main/kotlin/com/github/eth0net/enchantmenu/client/EnchantMenuClient.kt +++ b/src/main/kotlin/com/github/eth0net/enchantmenu/client/EnchantMenuClient.kt @@ -3,15 +3,21 @@ package com.github.eth0net.enchantmenu.client import com.github.eth0net.enchantmenu.EnchantMenu import com.github.eth0net.enchantmenu.client.gui.screen.EnchantMenuScreen import com.github.eth0net.enchantmenu.client.keybinding.MenuKeyBinding +import com.github.eth0net.enchantmenu.config.EnchantMenuConfig +import com.github.eth0net.enchantmenu.network.channel.ConfigSyncChannel import com.github.eth0net.enchantmenu.network.channel.MenuChannel import me.lortseam.completeconfig.gui.ConfigScreenBuilder import me.lortseam.completeconfig.gui.cloth.ClothConfigScreenBuilder +import me.shedaniel.clothconfig2.api.ConfigBuilder import net.fabricmc.api.ClientModInitializer import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking import net.fabricmc.fabric.api.networking.v1.PacketByteBufs import net.fabricmc.loader.api.FabricLoader +import net.minecraft.client.MinecraftClient import net.minecraft.client.gui.screen.ingame.HandledScreens +import java.io.BufferedReader +import java.io.StringReader @Suppress("UNUSED") object EnchantMenuClient : ClientModInitializer { @@ -19,7 +25,10 @@ object EnchantMenuClient : ClientModInitializer { EnchantMenu.log.info("EnchantMenuClient initializing...") if (FabricLoader.getInstance().isModLoaded("cloth-config")) { - ConfigScreenBuilder.setMain(EnchantMenu.MOD_ID, ClothConfigScreenBuilder()) + ConfigScreenBuilder.setMain(EnchantMenu.MOD_ID, ClothConfigScreenBuilder { + val editable = MinecraftClient.getInstance().currentServerEntry == null + ConfigBuilder.create().setEditable(editable) + }) } HandledScreens.register(EnchantMenu.SCREEN_HANDLER, ::EnchantMenuScreen) @@ -28,6 +37,10 @@ object EnchantMenuClient : ClientModInitializer { while (MenuKeyBinding.wasPressed()) ClientPlayNetworking.send(MenuChannel, PacketByteBufs.empty()) } + ClientPlayNetworking.registerGlobalReceiver(ConfigSyncChannel) { _, _, buf, _ -> + EnchantMenuConfig.deserialize { BufferedReader(StringReader(buf.readString())) } + } + EnchantMenu.log.info("EnchantMenuClient initialized.") } } diff --git a/src/main/kotlin/com/github/eth0net/enchantmenu/network/channel/Channel.kt b/src/main/kotlin/com/github/eth0net/enchantmenu/network/channel/Channel.kt index 2a9f906..1f100f7 100644 --- a/src/main/kotlin/com/github/eth0net/enchantmenu/network/channel/Channel.kt +++ b/src/main/kotlin/com/github/eth0net/enchantmenu/network/channel/Channel.kt @@ -3,6 +3,7 @@ package com.github.eth0net.enchantmenu.network.channel import com.github.eth0net.enchantmenu.EnchantMenu.id internal val MenuChannel = id("toggle_menu_channel") +internal val ConfigSyncChannel = id("config_sync_channel") internal val DecrementLevelChannel = id("decrement_level_channel") internal val IncrementLevelChannel = id("increment_level_channel") internal val ToggleIncompatibleChannel = id("toggle_incompatible_channel") From 8b0b8833956a43bff4a9bf2b3683567623f68f75 Mon Sep 17 00:00:00 2001 From: Elliot Thomas Date: Sat, 30 Jul 2022 00:21:59 +0100 Subject: [PATCH 7/7] Bump version and update docs for beta --- build.gradle.kts | 8 +++----- changelogs/1.2.0-beta+fabric-1.19.md | 10 ++++++++++ gradle.properties | 9 +++------ src/main/resources/fabric.mod.json | 5 +++++ 4 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 changelogs/1.2.0-beta+fabric-1.19.md diff --git a/build.gradle.kts b/build.gradle.kts index 1dd0b33..3660bfa 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,8 +11,6 @@ val fabricKotlinVersion: String by project val fabricKotlinVersionId: String by project val completeConfigVersion: String by project val completeConfigVersionId: String by project -val clothConfigVersion: String by project -val clothConfigVersionId: String by project val mavenGroup: String by project val modId: String by project val modVersion: String by project @@ -47,7 +45,6 @@ dependencies { modImplementation("net.fabricmc", "fabric-loader", loaderVersion) modImplementation("net.fabricmc.fabric-api", "fabric-api", fabricVersion) modImplementation("net.fabricmc", "fabric-language-kotlin", fabricKotlinVersion) - modImplementation("com.gitlab.Lortseam.completeconfig", "base", completeConfigVersion) modImplementation("com.gitlab.Lortseam.completeconfig", "gui-cloth", completeConfigVersion) } @@ -65,7 +62,7 @@ tasks { processResources { inputs.property("version", project.version) - filesMatching("fabric.mod.json") { expand(mutableMapOf("version" to project.version)) } + filesMatching("fabric.mod.json") { expand(mapOf("version" to project.version)) } } java { @@ -87,7 +84,8 @@ tasks { required.version(fabricVersionId) required.version(fabricKotlinVersionId) required.version(completeConfigVersionId) - optional.version(clothConfigVersionId) + optional.project("cloth-config") + optional.project("modmenu") } // syncBodyFrom.set(rootProject.file("README.md").toString()) } diff --git a/changelogs/1.2.0-beta+fabric-1.19.md b/changelogs/1.2.0-beta+fabric-1.19.md new file mode 100644 index 0000000..bd2ceb6 --- /dev/null +++ b/changelogs/1.2.0-beta+fabric-1.19.md @@ -0,0 +1,10 @@ +Now with config! + +**Added**: +- Implement CompleteConfig to allow players to configure levels and limit breaks. +- Configuration UI in game client for single player (using cloth config and mod menu) +- Configuration files in client config directory +- Configuration files in server config directory +- Server configuration synced to client during multiplayer sessions + +**Full Changelog**: https://github.com/eth0net/enchant-menu/compare/v1.1.1+fabric-1.19...v1.2.0-beta+fabric-1.19 diff --git a/gradle.properties b/gradle.properties index dc93e2c..8f6298c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,12 +16,9 @@ fabricKotlinVersionId=5Aq3SFbi # Complete Config completeConfigVersion=2.0.0 completeConfigVersionId=zaC01d1T -# Cloth Config -clothConfigVersion=7.0.73 -clothConfigVersionId=ehzvjLXC # Mod Properties mavenGroup=com.github.eth0net modId=enchant-menu -modVersion=1.2.0-alpha+fabric-1.19 -modVersionName=1.2.0 Alpha Fabric 1.19 -modVersionType=alpha +modVersion=1.2.0-beta+fabric-1.19 +modVersionName=1.2.0 Beta Fabric 1.19 +modVersionType=beta diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index b73d82f..d89cfd5 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -34,7 +34,12 @@ "fabricloader": ">=0.14.8", "fabric": "*", "fabric-language-kotlin": ">=1.8.2+kotlin.1.7.10", + "completeconfig": "^2.0.0", "minecraft": "1.19.x", "java": ">=17" + }, + "recommends": { + "cloth-config": "*", + "modmenu": "*" } }