From 0184ab1eea9e1ee9b70f67208feb9d87de2e8f48 Mon Sep 17 00:00:00 2001 From: btwonion Date: Thu, 1 Aug 2024 16:46:31 +0200 Subject: [PATCH] use yacl3 kotlin dsl for config --- changelog.md | 3 +- .../config/TelekinesisConfigScreen.kt | 111 +++++++----------- .../assets/telekinesis/lang/en_us.json | 20 ++-- 3 files changed, 52 insertions(+), 82 deletions(-) diff --git a/changelog.md b/changelog.md index ae03e90..fe13692 100644 --- a/changelog.md +++ b/changelog.md @@ -1 +1,2 @@ -- fix enchantment not tradeable in >=1.20.6 \ No newline at end of file +- fix enchantment not tradeable in >=1.20.6 +- use yacl 3.5.x for config creation \ No newline at end of file diff --git a/src/main/kotlin/dev/nyon/telekinesis/config/TelekinesisConfigScreen.kt b/src/main/kotlin/dev/nyon/telekinesis/config/TelekinesisConfigScreen.kt index d7125c5..7c54daf 100644 --- a/src/main/kotlin/dev/nyon/telekinesis/config/TelekinesisConfigScreen.kt +++ b/src/main/kotlin/dev/nyon/telekinesis/config/TelekinesisConfigScreen.kt @@ -1,77 +1,46 @@ package dev.nyon.telekinesis.config -import dev.isxander.yacl3.api.ConfigCategory -import dev.isxander.yacl3.api.Option -import dev.isxander.yacl3.api.OptionDescription -import dev.isxander.yacl3.api.YetAnotherConfigLib -import dev.isxander.yacl3.api.controller.TickBoxControllerBuilder +import dev.isxander.yacl3.dsl.YetAnotherConfigLib +import dev.isxander.yacl3.dsl.controller +import dev.isxander.yacl3.dsl.descriptionBuilder +import dev.isxander.yacl3.dsl.tickBox import dev.nyon.konfig.config.saveConfig import net.minecraft.client.gui.screens.Screen -import net.minecraft.network.chat.Component -fun generateConfigScreen(parent: Screen? = null): Screen { - val configScreenBuilder = YetAnotherConfigLib.createBuilder() - configScreenBuilder.title(Component.translatable("menu.telekinesis.name")) - configScreenBuilder.appendOptionCategory() - configScreenBuilder.save { saveConfig(config) } - val configScreen = configScreenBuilder.build() - return configScreen.generateScreen(parent) -} +fun generateConfigScreen(parent: Screen? = null): Screen = YetAnotherConfigLib("telekinesis") { + val general by categories.registering { + val needEnchantment by rootOptions.registering { + binding(true, { config.needEnchantment }, { config.needEnchantment = it }) + controller = tickBox() + descriptionBuilder { + addDefaultText(1) + } + } -fun YetAnotherConfigLib.Builder.appendOptionCategory() { - this.category( - ConfigCategory.createBuilder() - .name(Component.translatable("menu.telekinesis.config.general")) - .option( - Option.createBuilder() - .name(Component.translatable("menu.telekinesis.config.general.needEnchantment")) - .description( - OptionDescription - .of(Component.translatable("menu.telekinesis.config.general.needEnchantment.description")) - ) - .binding(config.needEnchantment, { config.needEnchantment }, { config.needEnchantment = it }) - .controller { - TickBoxControllerBuilder.create(it) - }.build() - ) - .option( - Option.createBuilder() - .name(Component.translatable("menu.telekinesis.config.general.needSneak")) - .description( - OptionDescription - .of( - Component.translatable("menu.telekinesis.config.general.needSneak.description") - ) - ) - .binding(config.needSneak, { config.needSneak }, { config.needSneak = it }) - .controller { - TickBoxControllerBuilder.create(it) - }.build() - ) - .option( - Option.createBuilder() - .name(Component.translatable("menu.telekinesis.config.general.expAllowed")) - .description( - OptionDescription - .of(Component.translatable("menu.telekinesis.config.general.expAllowed.description")) - ) - .binding(config.expAllowed, { config.expAllowed }, { config.expAllowed = it }) - .controller { - TickBoxControllerBuilder.create(it) - }.build() - ) - .option( - Option.createBuilder() - .name(Component.translatable("menu.telekinesis.config.general.itemsAllowed")) - .description( - OptionDescription - .of(Component.translatable("menu.telekinesis.config.general.itemsAllowed.description")) - ) - .binding(config.itemsAllowed, { config.itemsAllowed }, { config.itemsAllowed = it }) - .controller { - TickBoxControllerBuilder.create(it) - }.build() - ) - .build() - ) -} + val needSneak by rootOptions.registering { + binding(false, { config.needSneak }, { config.needSneak = it }) + controller = tickBox() + descriptionBuilder { + addDefaultText(1) + } + } + + val expAllowed by rootOptions.registering { + binding(false, { config.expAllowed }, { config.expAllowed = it }) + controller = tickBox() + descriptionBuilder { + addDefaultText(1) + } + } + + val itemsAllowed by rootOptions.registering { + binding(false, { config.itemsAllowed }, { config.itemsAllowed = it }) + controller = tickBox() + descriptionBuilder { + addDefaultText(1) + } + } + } + + save { saveConfig(config) } +}.generateScreen(parent) diff --git a/src/main/resources/assets/telekinesis/lang/en_us.json b/src/main/resources/assets/telekinesis/lang/en_us.json index 9a89922..4c2bd44 100644 --- a/src/main/resources/assets/telekinesis/lang/en_us.json +++ b/src/main/resources/assets/telekinesis/lang/en_us.json @@ -1,13 +1,13 @@ { - "menu.telekinesis.name": "telekinesis", - "menu.telekinesis.config.general": "General", - "menu.telekinesis.config.general.needEnchantment": "Need enchantment", - "menu.telekinesis.config.general.needEnchantment.description": "Decides whether telekinesis should only work with the enchantment.", - "menu.telekinesis.config.general.needSneak": "Only while sneaking", - "menu.telekinesis.config.general.needSneak.description": "Decides whether players should have to sneak to use telekinesis.", - "menu.telekinesis.config.general.expAllowed": "Exp drops", - "menu.telekinesis.config.general.expAllowed.description": "Decides whether telekinesis should also work for exp drops.", - "menu.telekinesis.config.general.itemsAllowed": "Items", - "menu.telekinesis.config.general.itemsAllowed.description": "Decides whether telekinesis should also work for item drops.", + "yacl3.config.telekinesis.title": "telekinesis", + "yacl3.config.telekinesis.category.general": "General", + "yacl3.config.telekinesis.category.general.root.option.needEnchantment": "Need enchantment", + "yacl3.config.telekinesis.category.general.root.option.needEnchantment.description": "Decides whether telekinesis should only work with the enchantment.", + "yacl3.config.telekinesis.category.general.root.option.needSneak": "Only while sneaking", + "yacl3.config.telekinesis.category.general.root.option.needSneak.description": "Decides whether players should have to sneak to use telekinesis.", + "yacl3.config.telekinesis.category.general.root.option.expAllowed": "Exp drops", + "yacl3.config.telekinesis.category.general.root.option.expAllowed.description": "Decides whether telekinesis should also work for exp drops.", + "yacl3.config.telekinesis.category.general.root.option.itemsAllowed": "Items", + "yacl3.config.telekinesis.category.general.root.option.itemsAllowed.description": "Decides whether telekinesis should also work for item drops.", "enchantment.telekinesis.telekinesis.name": "Telekinesis" } \ No newline at end of file