Skip to content

Commit

Permalink
use yacl3 kotlin dsl for config
Browse files Browse the repository at this point in the history
  • Loading branch information
btwonion committed Aug 1, 2024
1 parent 1ac6e60 commit 0184ab1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 82 deletions.
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- fix enchantment not tradeable in >=1.20.6
- fix enchantment not tradeable in >=1.20.6
- use yacl 3.5.x for config creation
111 changes: 40 additions & 71 deletions src/main/kotlin/dev/nyon/telekinesis/config/TelekinesisConfigScreen.kt
Original file line number Diff line number Diff line change
@@ -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<Boolean>()
.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<Boolean>()
.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<Boolean>()
.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<Boolean>()
.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)
20 changes: 10 additions & 10 deletions src/main/resources/assets/telekinesis/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit 0184ab1

Please sign in to comment.