diff --git a/build.gradle.kts b/build.gradle.kts index 761ed43..35f77ee 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -74,6 +74,7 @@ tasks { modrinth { token.set(System.getenv("MODRINTH_TOKEN")) + loaders.set(listOf("fabric", "quilt")) gameVersions.set(listOf("1.19", "1.19.1", "1.19.2")) projectId.set(base.archivesName) versionName.set(modVersionName) diff --git a/changelogs/1.4.0-beta.2+fabric-1.19.md b/changelogs/1.4.0-beta.2+fabric-1.19.md new file mode 100644 index 0000000..8f2a8f3 --- /dev/null +++ b/changelogs/1.4.0-beta.2+fabric-1.19.md @@ -0,0 +1,7 @@ +Now with permissions and optional config! + +**Changed**: +- Added Quilt to list of loaders +- Sync searchbox between client and server + +**Full Changelog**: https://github.com/eth0net/enchant-menu/compare/v1.4.0-beta.1+fabric-1.19...v1.4.0-beta.2+fabric-1.19 diff --git a/gradle.properties b/gradle.properties index 687f0b1..620a64c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,6 +19,6 @@ completeConfigVersionId=zaC01d1T # Mod Properties mavenGroup=com.github.eth0net modId=enchant-menu -modVersion=1.4.0-beta.1+fabric-1.19 -modVersionName=1.4.0 Beta 1 Fabric 1.19 +modVersion=1.4.0-beta.2+fabric-1.19 +modVersionName=1.4.0 Beta 2 Fabric 1.19 modVersionType=beta diff --git a/src/main/kotlin/com/github/eth0net/enchantmenu/EnchantMenu.kt b/src/main/kotlin/com/github/eth0net/enchantmenu/EnchantMenu.kt index 201e8c6..7ebe678 100644 --- a/src/main/kotlin/com/github/eth0net/enchantmenu/EnchantMenu.kt +++ b/src/main/kotlin/com/github/eth0net/enchantmenu/EnchantMenu.kt @@ -44,6 +44,9 @@ object EnchantMenu : ModInitializer { ServerPlayNetworking.registerGlobalReceiver(MenuChannel) { _, player, _, _, _ -> player.openHandledScreen(EnchantMenuScreenHandlerFactory) } + ServerPlayNetworking.registerGlobalReceiver(SearchChannel) { _, player, _, buf, _ -> + (player.currentScreenHandler as? EnchantMenuScreenHandler)?.search = buf.readString() + } ServerPlayNetworking.registerGlobalReceiver(IncrementLevelChannel) { _, player, _, _, _ -> (player.currentScreenHandler as? EnchantMenuScreenHandler)?.incrementLevel() } 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 572dc62..1a35afb 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 @@ -158,7 +158,7 @@ class EnchantMenuScreen(handler: EnchantMenuScreenHandler, playerInventory: Play // search box searchBox = TextFieldWidget(textRenderer, x + 78, y + 6, 71, 9, Text.translatable("enchant-menu.title")) - searchBox?.setChangedListener { handler.search = it } + searchBox?.setChangedListener { onSearchChanged(it) } searchBox?.text = handler.search addSelectableChild(searchBox) addDrawableChild(searchBox) @@ -228,4 +228,9 @@ class EnchantMenuScreen(handler: EnchantMenuScreenHandler, playerInventory: Play handler.toggleTreasure() ClientPlayNetworking.send(ToggleTreasureChannel, PacketByteBufs.empty()) } + + private fun onSearchChanged(search: String) { + handler.search = search + ClientPlayNetworking.send(SearchChannel, PacketByteBufs.create().writeString(search)) + } } 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 1f100f7..095c964 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 @@ -4,6 +4,7 @@ import com.github.eth0net.enchantmenu.EnchantMenu.id internal val MenuChannel = id("toggle_menu_channel") internal val ConfigSyncChannel = id("config_sync_channel") +internal val SearchChannel = id("search_channel") internal val DecrementLevelChannel = id("decrement_level_channel") internal val IncrementLevelChannel = id("increment_level_channel") internal val ToggleIncompatibleChannel = id("toggle_incompatible_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 4f452e8..6ff1be9 100644 --- a/src/main/kotlin/com/github/eth0net/enchantmenu/screen/EnchantMenuScreenHandler.kt +++ b/src/main/kotlin/com/github/eth0net/enchantmenu/screen/EnchantMenuScreenHandler.kt @@ -134,7 +134,7 @@ class EnchantMenuScreenHandler( if (inventory != this.inventory) return enchantments = listOf() val stack = inventory.getStack(0) - if (!stack.isEmpty) enchantments = stack.acceptableEnchantments.map { stack.enchantmentEntry(it) } + if (!stack.isEmpty) enchantments = acceptableEnchantments(stack).map { stack.enchantmentEntry(it) } sendContentUpdates() } @@ -180,15 +180,12 @@ class EnchantMenuScreenHandler( private fun PlayerEntity.canEnchant() = !checkPermission || hasPermissionLevel(2) - private fun Enchantment.acceptableStack(stack: ItemStack): Boolean { - val acceptable = isAcceptableItem(stack) - val allowed = !isTreasure || treasureUnlocked || stack.hasEnchantment(this) - val inSearch = getName(level).string.lowercase().contains(search.lowercase()) - return acceptable && allowed && inSearch + private fun acceptableEnchantments(stack: ItemStack) = Registry.ENCHANTMENT.filter { + val allowed = !it.isTreasure || treasureUnlocked || stack.hasEnchantment(it) + val inSearch = it.getName(level).string.lowercase().contains(search.lowercase()) + it.isAcceptableItem(stack) && allowed && inSearch } - private val ItemStack.acceptableEnchantments get() = Registry.ENCHANTMENT.filter { it.acceptableStack(this) } - private fun ItemStack.enchantmentCompatible(enchantment: Enchantment): Boolean { return EnchantmentHelper.fromNbt(enchantments).all { it.key.canCombine(enchantment) } }