From 857f7ee7d7ffa7edf6506cf53b30f8414e54698b Mon Sep 17 00:00:00 2001 From: Osip Fatkullin Date: Mon, 16 Nov 2026 11:55:59 +0100 Subject: [PATCH 1/3] feat: Add Nexo item and block providers Closes #50 Co-Authored-By: Claude Fable 5.2 --- CHANGELOG.md | 5 + MODRINTH.md | 4 +- gradle/libs.versions.toml | 3 + mimic-bukkit/README.md | 12 ++ mimic-bukkit/build.gradle.kts | 7 + mimic-bukkit/src/main/kotlin/MimicPlugin.kt | 7 + .../kotlin/impl/nexo/NexoBlockProvider.kt | 67 ++++++++ .../main/kotlin/impl/nexo/NexoItemProvider.kt | 33 ++++ .../src/main/kotlin/impl/nexo/NexoWrapper.kt | 69 +++++++++ .../kotlin/impl/nexo/NexoBlockProviderTest.kt | 144 ++++++++++++++++++ .../kotlin/impl/nexo/NexoItemProviderTest.kt | 64 ++++++++ 11 files changed, 413 insertions(+), 2 deletions(-) create mode 100644 mimic-bukkit/src/main/kotlin/impl/nexo/NexoBlockProvider.kt create mode 100644 mimic-bukkit/src/main/kotlin/impl/nexo/NexoItemProvider.kt create mode 100644 mimic-bukkit/src/main/kotlin/impl/nexo/NexoWrapper.kt create mode 100644 mimic-bukkit/src/test/kotlin/impl/nexo/NexoBlockProviderTest.kt create mode 100644 mimic-bukkit/src/test/kotlin/impl/nexo/NexoItemProviderTest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a4e5adc..b9d04328 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,11 @@ See [Blocks](https://github.com/EndlessCodeGroup/Mimic/blob/develop/mimic-bukkit - Config option `disabled-block-registries` is renamed to `disabled-block-providers`, the old value is moved automatically. - `/mimic blocks` requires block IDs with a namespace, `payload` argument of `/mimic blocks set` is renamed to `state`. +### Integrations + +- Added Nexo integration: item provider and block provider ([#50](https://github.com/EndlessCodeGroup/Mimic/issues/50)). + Nexo IDs are used as is: `nexo:ruby_ore`. Note blocks, string blocks and chorus blocks are supported. + ## [v0.10.0] (2026-11-15) ### Levels API diff --git a/MODRINTH.md b/MODRINTH.md index 8c91f29b..2b51f092 100644 --- a/MODRINTH.md +++ b/MODRINTH.md @@ -20,8 +20,8 @@ That's it. Mimic detects installed RPG plugins automatically. | **Levels** | Vanilla experience, AuraSkills, mcMMO, ValhallaMMO, Jobs Reborn, MMOCore, Heroes, Fabled | | **Classes** | MMOCore, Heroes, Fabled | | **Resources** | Vanilla health, food and air, MMOCore, Heroes, AuraSkills, Fabled | -| **Items** | Vanilla items, CraftEngine, MMOItems, CustomItems, ItemsAdder¹, RPGInventory¹ | -| **Blocks** | Vanilla blocks, CraftEngine | +| **Items** | Vanilla items, CraftEngine, MMOItems, CustomItems, Nexo, ItemsAdder¹, RPGInventory¹ | +| **Blocks** | Vanilla blocks, CraftEngine, Nexo | | **Inventory** | Vanilla inventory, RPGInventory¹ | ¹ Support is provided by the plugin itself. diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f864590e..a9150f0e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -21,6 +21,7 @@ fabled = "1.1.0" codex = "1.2.0" valhallammo = "premium_1.14.1" valhallammo-free = "1.10.4" +nexo = "1.30.2" junit = "6.1.3" kotest = "6.2.6" @@ -56,6 +57,7 @@ rpgplugins-cmilib = { module = "com.github.Zrips:CMILib", version.ref = "cmilib" rpgplugins-fabled = { module = "studio.magemonkey:fabled", version.ref = "fabled" } rpgplugins-codex = { module = "studio.magemonkey:codex", version.ref = "codex" } rpgplugins-valhallammo = { module = "me.athlaeos:valhallammo-core", version.ref = "valhallammo" } +rpgplugins-nexo = { module = "com.nexomc:nexo", version.ref = "nexo" } # Test dependencies junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" } @@ -92,4 +94,5 @@ rpgplugins = [ "rpgplugins-fabled", "rpgplugins-codex", "rpgplugins-valhallammo", + "rpgplugins-nexo", ] diff --git a/mimic-bukkit/README.md b/mimic-bukkit/README.md index 3e281bc7..fa69afaa 100644 --- a/mimic-bukkit/README.md +++ b/mimic-bukkit/README.md @@ -101,6 +101,11 @@ Providers marked with _(deprecated API)_ are provided by the plugin itself via t **ID Format:** `customitems:[id]`\ **Payload:** *Not supported* +#### [Nexo] + +**ID Format:** `nexo:[id]`\ +**Payload:** *Not supported* + #### [MMOItems] **ID Format:** `mmoitems:[type]/[id]`, for example `mmoitems:sword/excalibur`\ @@ -138,6 +143,12 @@ A block belongs to the provider with the highest priority that recognizes it, va **ID Format:** `craftengine:[namespace]/[id]`\ **State:** Block state properties, for example `[facing=north]` +#### [Nexo] + +**ID Format:** `nexo:[id]`, the same as the ID of the item placing the block\ +**State:** *Not supported*\ +Note blocks, string blocks and chorus blocks are supported. Furniture is not a block. + [minecraft-exp]: https://minecraft.fandom.com/wiki/Experience [minecraft-inv]: https://minecraft.fandom.com/wiki/Inventory [item-components]: https://minecraft.wiki/w/Data_component_format @@ -150,6 +161,7 @@ A block belongs to the provider with the highest priority that recognizes it, va [rpginventory]: https://www.spigotmc.org/resources/12498/ [itemsadder]: https://www.spigotmc.org/resources/73355/ [craftengine]: https://modrinth.com/plugin/craftengine +[nexo]: https://nexomc.com/ [auraskills]: https://modrinth.com/plugin/auraskills [mcmmo]: https://www.spigotmc.org/resources/64348/ [jobs reborn]: https://www.spigotmc.org/resources/4216/ diff --git a/mimic-bukkit/build.gradle.kts b/mimic-bukkit/build.gradle.kts index 840c3097..ce2f7a3f 100644 --- a/mimic-bukkit/build.gradle.kts +++ b/mimic-bukkit/build.gradle.kts @@ -33,6 +33,7 @@ bukkit { "Jobs", "Fabled", "ValhallaMMO", + "Nexo", ) } @@ -76,6 +77,11 @@ repositories { includeGroup("me.athlaeos") } } + maven(url = "https://repo.nexomc.com/releases/") { + content { + includeGroup("com.nexomc") + } + } aikar() codemc() // Uncomment if you want to get Heroes from maven repo @@ -109,6 +115,7 @@ dependencies { testImplementation(libs.rpgplugins.mythiclib) { isTransitive = false } testImplementation(libs.rpgplugins.fabled) { isTransitive = false } testImplementation(libs.rpgplugins.codex) { isTransitive = false } + testImplementation(libs.rpgplugins.nexo) { isTransitive = false } } kotlin { diff --git a/mimic-bukkit/src/main/kotlin/MimicPlugin.kt b/mimic-bukkit/src/main/kotlin/MimicPlugin.kt index 7f50b192..dc6d4158 100644 --- a/mimic-bukkit/src/main/kotlin/MimicPlugin.kt +++ b/mimic-bukkit/src/main/kotlin/MimicPlugin.kt @@ -41,6 +41,8 @@ import ru.endlesscode.mimic.impl.mmocore.MmoCoreLevelSystem import ru.endlesscode.mimic.impl.mmocore.MmoCoreResourceProvider import ru.endlesscode.mimic.impl.mmoitems.MmoItemsItemProvider import ru.endlesscode.mimic.impl.mmoitems.MmoItemsRegistry +import ru.endlesscode.mimic.impl.nexo.NexoBlockProvider +import ru.endlesscode.mimic.impl.nexo.NexoItemProvider import ru.endlesscode.mimic.impl.valhallammo.ValhallaMmoLevelProvider import ru.endlesscode.mimic.impl.vanilla.* import ru.endlesscode.mimic.internal.Log @@ -126,6 +128,11 @@ public class MimicPlugin : JavaPlugin() { hookBlocks(::CraftEngineBlockProvider) } + pluginHooks("Nexo", "com.nexomc.nexo.api.NexoBlocks") { + hookItems(::NexoItemProvider) + hookBlocks(::NexoBlockProvider) + } + pluginHooks("AuraSkills", "dev.aurelium.auraskills.api.AuraSkillsApi") { hookLevels(::AuraSkillsLevelProvider) hookResources(::AuraSkillsResourceProvider) diff --git a/mimic-bukkit/src/main/kotlin/impl/nexo/NexoBlockProvider.kt b/mimic-bukkit/src/main/kotlin/impl/nexo/NexoBlockProvider.kt new file mode 100644 index 00000000..be8041b9 --- /dev/null +++ b/mimic-bukkit/src/main/kotlin/impl/nexo/NexoBlockProvider.kt @@ -0,0 +1,67 @@ +// Copyright (c) 2026 Osip Fatkullin, EndlessCode Group and contributors +// SPDX-License-Identifier: MIT + +package ru.endlesscode.mimic.impl.nexo + +import org.bukkit.block.Block +import org.bukkit.inventory.ItemStack +import ru.endlesscode.mimic.blocks.BlockProvider +import ru.endlesscode.mimic.blocks.DropsConsumer +import ru.endlesscode.mimic.internal.Log + +/** + * Block provider for Nexo custom blocks: note blocks, string blocks and chorus blocks. Furniture is not a block. + * Block ID is the ID of the Nexo item placing the block. + * Every variant of a directional block is a separate block with its own ID. + * Nexo blocks have no states, so [setBlock] with a state always fails. + * + * Content of a storage block is dropped on the ground by Nexo when the block is removed, + * so [breakBlock] doesn't pass it to the drops consumer. + */ +internal class NexoBlockProvider( + private val nexo: NexoWrapper = NexoWrapper(), +) : BlockProvider { + + override val id: String = ID + override val isEnabled: Boolean get() = nexo.isEnabled + + override val allBlocks: Collection get() = nexo.blockIds + + override fun hasBlock(blockId: String): Boolean = nexo.hasBlock(blockId) + + override fun getBlockId(block: Block): String? = nexo.getBlockId(block) + + override fun getBlockIdFromItem(item: ItemStack): String? = nexo.getItemId(item)?.takeIf(nexo::hasBlock) + + override fun createBlockItem(blockId: String, amount: Int): ItemStack? { + if (!nexo.hasBlock(blockId)) return null + return nexo.createItem(blockId, amount) + } + + override fun setBlock(block: Block, blockId: String, state: String?): Boolean { + if (!nexo.hasBlock(blockId)) return false + if (state != null) { + Log.w("[$TAG] Invalid state for block $blockId: $state. Nexo blocks have no states.") + return false + } + + nexo.placeBlock(block, blockId) + // Nexo doesn't tell if the block was placed + return nexo.getBlockId(block) != null + } + + override fun breakBlock(block: Block, tool: ItemStack?, dropsConsumer: DropsConsumer): Boolean { + val drops = nexo.getDrops(block, tool) ?: return false + if (!nexo.removeBlock(block)) return false + + for (item in dropsConsumer.consume(drops)) { + block.world.dropItemNaturally(block.location, item) + } + return true + } + + companion object { + const val ID: String = "nexo" + private const val TAG = "NexoBlockProvider" + } +} diff --git a/mimic-bukkit/src/main/kotlin/impl/nexo/NexoItemProvider.kt b/mimic-bukkit/src/main/kotlin/impl/nexo/NexoItemProvider.kt new file mode 100644 index 00000000..ae527f5e --- /dev/null +++ b/mimic-bukkit/src/main/kotlin/impl/nexo/NexoItemProvider.kt @@ -0,0 +1,33 @@ +// Copyright (c) 2026 Osip Fatkullin, EndlessCode Group and contributors +// SPDX-License-Identifier: MIT + +package ru.endlesscode.mimic.impl.nexo + +import org.bukkit.entity.Player +import org.bukkit.inventory.ItemStack +import ru.endlesscode.mimic.items.ItemProvider + +/** + * Item provider for Nexo items. Item IDs are the same as in Nexo. + * Takes no payload, items don't depend on a player. + */ +internal class NexoItemProvider( + private val nexo: NexoWrapper = NexoWrapper(), +) : ItemProvider { + + override val id: String = ID + override val isEnabled: Boolean get() = nexo.isEnabled + + override val allItems: Collection get() = nexo.itemIds + + override fun hasItem(itemId: String): Boolean = nexo.hasItem(itemId) + + override fun getItemId(item: ItemStack): String? = nexo.getItemId(item) + + override fun createItem(itemId: String, amount: Int, player: Player?, payload: String?): ItemStack? = + nexo.createItem(itemId, amount) + + companion object { + const val ID: String = "nexo" + } +} diff --git a/mimic-bukkit/src/main/kotlin/impl/nexo/NexoWrapper.kt b/mimic-bukkit/src/main/kotlin/impl/nexo/NexoWrapper.kt new file mode 100644 index 00000000..45c44a4a --- /dev/null +++ b/mimic-bukkit/src/main/kotlin/impl/nexo/NexoWrapper.kt @@ -0,0 +1,69 @@ +// Copyright (c) 2026 Osip Fatkullin, EndlessCode Group and contributors +// SPDX-License-Identifier: MIT + +package ru.endlesscode.mimic.impl.nexo + +import com.nexomc.nexo.api.NexoBlocks +import com.nexomc.nexo.api.NexoItems +import com.nexomc.nexo.mechanics.custom_block.CustomBlockMechanic +import com.nexomc.nexo.mechanics.custom_block.noteblock.NoteBlockMechanic +import com.nexomc.nexo.utils.drops.Drop +import org.bukkit.Bukkit +import org.bukkit.block.Block +import org.bukkit.inventory.ItemStack +import kotlin.random.Random + +/** + * Wraps Nexo static API. + * [getDrops] repeats the logic Nexo uses to drop loot, because Nexo can only drop it on the ground. + */ +internal class NexoWrapper { + + val isEnabled: Boolean get() = Bukkit.getPluginManager().isPluginEnabled("Nexo") + + val itemIds: List get() = NexoItems.itemNames().toList() + val blockIds: List get() = NexoBlocks.blockIDs().asList() + + fun hasItem(id: String): Boolean = NexoItems.exists(id) + fun getItemId(item: ItemStack): String? = NexoItems.idFromItem(item)?.takeIf(NexoItems::exists) + + /** Creates item with the given [amount], limited to the item's maximum stack size. */ + fun createItem(id: String, amount: Int): ItemStack? = + NexoItems.createItem(id)?.also { it.amount = amount.coerceIn(1, it.maxStackSize) } + + fun hasBlock(id: String): Boolean = NexoBlocks.isCustomBlock(id) + fun getBlockId(block: Block): String? = NexoBlocks.customBlockMechanic(block)?.itemID + + fun placeBlock(block: Block, id: String) { + NexoBlocks.place(id, block.location) + } + + /** + * Returns items dropped by the custom [block] broken with the [tool], or `null` if it isn't a custom block. + * If the tool is `null`, the block drops its loot regardless of the required tool. + */ + fun getDrops(block: Block, tool: ItemStack?): List? { + val drop = NexoBlocks.customBlockMechanic(block)?.drop ?: return null + + if (tool == null) return drop.rollLoot(fortuneMultiplier = 1) + if (!drop.canDrop(tool)) return emptyList() + + val silkTouchItem = if (drop.isSilkTouchDrop(tool)) NexoItems.createItem(drop.sourceID) else null + return if (silkTouchItem != null) listOf(silkTouchItem) else drop.rollLoot(drop.fortuneMultiplier(tool)) + } + + /** Removes the custom [block] without dropping its loot. */ + fun removeBlock(block: Block): Boolean = NexoBlocks.remove(block.location, null, Drop.emptyDrop()) + + /** Directional blocks take the drop from their parent block. */ + private val CustomBlockMechanic.drop: Drop + get() { + val mechanic = (this as? NoteBlockMechanic)?.directional?.parentMechanic ?: this + return mechanic.breakable.drop + } + + private fun Drop.rollLoot(fortuneMultiplier: Int): List = loots + .filter { Random.nextDouble() <= it.probability } + .map { it.getItem(fortuneMultiplier) } + .filter { it.amount > 0 } +} diff --git a/mimic-bukkit/src/test/kotlin/impl/nexo/NexoBlockProviderTest.kt b/mimic-bukkit/src/test/kotlin/impl/nexo/NexoBlockProviderTest.kt new file mode 100644 index 00000000..2f19db91 --- /dev/null +++ b/mimic-bukkit/src/test/kotlin/impl/nexo/NexoBlockProviderTest.kt @@ -0,0 +1,144 @@ +// Copyright (c) 2026 Osip Fatkullin, EndlessCode Group and contributors +// SPDX-License-Identifier: MIT + +package ru.endlesscode.mimic.impl.nexo + +import io.kotest.matchers.booleans.shouldBeFalse +import io.kotest.matchers.booleans.shouldBeTrue +import io.kotest.matchers.collections.shouldContainExactly +import io.kotest.matchers.nulls.shouldBeNull +import io.kotest.matchers.shouldBe +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import io.mockk.verifyOrder +import org.bukkit.Location +import org.bukkit.Material +import org.bukkit.World +import org.bukkit.block.Block +import org.bukkit.inventory.ItemStack +import ru.endlesscode.mimic.BukkitTestBase +import ru.endlesscode.mimic.blocks.DropsConsumer +import kotlin.test.Test + +internal class NexoBlockProviderTest : BukkitTestBase() { + + private val blockWorld: World = mockk { + every { dropItemNaturally(any(), any()) } returns mockk() + } + private val blockLocation: Location = mockk() + private val block: Block = mockk { + every { world } returns blockWorld + every { location } returns blockLocation + } + private val tool: ItemStack = mockk() + private val ruby: ItemStack = mockk() + + private val nexo: NexoWrapper = mockk(relaxUnitFun = true) { + every { blockIds } returns listOf("ruby_ore") + every { hasBlock(any()) } answers { firstArg() in blockIds } + every { getItemId(any()) } returns null + every { getBlockId(any()) } returns null + every { getDrops(any(), any()) } returns null + every { createItem("ruby_ore", any()) } answers { ItemStack(Material.PAPER, secondArg()) } + } + + // SUT + private val provider = NexoBlockProvider(nexo) + + @Test + fun `when get all blocks - should return Nexo block ids`() { + provider.allBlocks shouldContainExactly listOf("ruby_ore") + } + + @Test + fun `when get block id from block item - should return item id`() { + every { nexo.getItemId(any()) } returns "ruby_ore" + + provider.getBlockIdFromItem(ItemStack(Material.PAPER)) shouldBe "ruby_ore" + } + + @Test + fun `when get block id from not block item - should return null`() { + every { nexo.getItemId(any()) } returns "ruby" + + provider.getBlockIdFromItem(ruby).shouldBeNull() + } + + @Test + fun `when create block item - should create Nexo item`() { + val item = provider.createBlockItem("ruby_ore", amount = 3) + + item?.type shouldBe Material.PAPER + item?.amount shouldBe 3 + } + + @Test + fun `when create block item of not block - should return null`() { + provider.createBlockItem("ruby", amount = 1).shouldBeNull() + verify(exactly = 0) { nexo.createItem(any(), any()) } + } + + @Test + fun `when set block - should place Nexo block`() { + every { nexo.placeBlock(block, "ruby_ore") } answers { + every { nexo.getBlockId(block) } returns "ruby_ore" + } + + provider.setBlock(block, "ruby_ore", state = null).shouldBeTrue() + } + + @Test + fun `when set block and Nexo doesn't place it - should return false`() { + provider.setBlock(block, "ruby_ore", state = null).shouldBeFalse() + } + + @Test + fun `when set block with state or unknown block - should not place block`() { + provider.setBlock(block, "ruby_ore", state = "[facing=north]").shouldBeFalse() + provider.setBlock(block, "ruby", state = null).shouldBeFalse() + + verify(exactly = 0) { nexo.placeBlock(any(), any()) } + } + + @Test + fun `when break block - should remove block and drop consumed items`() { + every { nexo.getDrops(block, tool) } returns listOf(ruby) + every { nexo.removeBlock(block) } returns true + + provider.breakBlock(block, tool, DropsConsumer.drop()).shouldBeTrue() + + verifyOrder { + nexo.getDrops(block, tool) + nexo.removeBlock(block) + blockWorld.dropItemNaturally(blockLocation, ruby) + } + } + + @Test + fun `when break block and drops disappear - should drop nothing`() { + every { nexo.getDrops(block, null) } returns listOf(ruby) + every { nexo.removeBlock(block) } returns true + + provider.breakBlock(block, tool = null, DropsConsumer.disappear()).shouldBeTrue() + + verify(exactly = 0) { blockWorld.dropItemNaturally(any(), any()) } + } + + @Test + fun `when break not Nexo block - should return false`() { + provider.breakBlock(block, tool, DropsConsumer.drop()).shouldBeFalse() + + verify(exactly = 0) { nexo.removeBlock(any()) } + } + + @Test + fun `when break block and Nexo doesn't remove it - should drop nothing`() { + every { nexo.getDrops(block, tool) } returns listOf(ruby) + every { nexo.removeBlock(block) } returns false + + provider.breakBlock(block, tool, DropsConsumer.drop()).shouldBeFalse() + + verify(exactly = 0) { blockWorld.dropItemNaturally(any(), any()) } + } +} diff --git a/mimic-bukkit/src/test/kotlin/impl/nexo/NexoItemProviderTest.kt b/mimic-bukkit/src/test/kotlin/impl/nexo/NexoItemProviderTest.kt new file mode 100644 index 00000000..c835304b --- /dev/null +++ b/mimic-bukkit/src/test/kotlin/impl/nexo/NexoItemProviderTest.kt @@ -0,0 +1,64 @@ +// Copyright (c) 2026 Osip Fatkullin, EndlessCode Group and contributors +// SPDX-License-Identifier: MIT + +package ru.endlesscode.mimic.impl.nexo + +import io.kotest.matchers.collections.shouldContainExactly +import io.kotest.matchers.nulls.shouldBeNull +import io.kotest.matchers.shouldBe +import io.mockk.every +import io.mockk.mockk +import org.bukkit.Material +import org.bukkit.inventory.ItemStack +import ru.endlesscode.mimic.BukkitTestBase +import kotlin.test.Test + +internal class NexoItemProviderTest : BukkitTestBase() { + + private val nexo: NexoWrapper = mockk { + every { itemIds } returns listOf("ruby", "ruby_ore") + every { hasItem(any()) } answers { firstArg() in itemIds } + every { getItemId(any()) } returns null + every { createItem(any(), any()) } returns null + every { createItem("ruby", any()) } answers { ItemStack(Material.EMERALD, secondArg()) } + } + + // SUT + private val provider = NexoItemProvider(nexo) + + @Test + fun `when get all items - should return Nexo ids`() { + provider.allItems shouldContainExactly listOf("ruby", "ruby_ore") + } + + @Test + fun `when check item exists - should ask Nexo`() { + provider.hasItem("ruby") shouldBe true + provider.hasItem("unknown") shouldBe false + } + + @Test + fun `when create item - should ignore player and payload`() { + val item = provider.createItem("ruby", amount = 2, player, payload = "payload") + + item?.type shouldBe Material.EMERALD + item?.amount shouldBe 2 + } + + @Test + fun `when create unknown item - should return null`() { + provider.createItem("unknown", amount = 1, player = null, payload = null).shouldBeNull() + } + + @Test + fun `when get item id - should return Nexo id`() { + every { nexo.getItemId(any()) } returns "ruby" + + provider.getItemId(ItemStack(Material.EMERALD)) shouldBe "ruby" + } + + @Test + fun `when get id of not Nexo item - should return null`() { + provider.getItemId(ItemStack(Material.EMERALD)).shouldBeNull() + } +} From 8de1e489fdbb547dbcb184a3b7ca814885625640 Mon Sep 17 00:00:00 2001 From: Osip Fatkullin Date: Mon, 16 Nov 2026 12:13:30 +0100 Subject: [PATCH 2/3] feat: Convert Nexo IDs and report parent ID of directional blocks Co-Authored-By: Claude Fable 5.2 --- CHANGELOG.md | 2 +- mimic-bukkit/README.md | 4 +- .../kotlin/impl/nexo/NexoBlockProvider.kt | 28 +++++---- .../src/main/kotlin/impl/nexo/NexoIds.kt | 44 ++++++++++++++ .../main/kotlin/impl/nexo/NexoItemProvider.kt | 17 ++++-- .../src/main/kotlin/impl/nexo/NexoWrapper.kt | 49 ++++++++------- .../kotlin/impl/nexo/NexoBlockProviderTest.kt | 23 +++++++ .../kotlin/impl/nexo/NexoItemProviderTest.kt | 29 +++++++++ .../test/kotlin/impl/nexo/NexoWrapperTest.kt | 60 +++++++++++++++++++ 9 files changed, 212 insertions(+), 44 deletions(-) create mode 100644 mimic-bukkit/src/main/kotlin/impl/nexo/NexoIds.kt create mode 100644 mimic-bukkit/src/test/kotlin/impl/nexo/NexoWrapperTest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index b9d04328..af047819 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,7 +51,7 @@ See [Blocks](https://github.com/EndlessCodeGroup/Mimic/blob/develop/mimic-bukkit ### Integrations - Added Nexo integration: item provider and block provider ([#50](https://github.com/EndlessCodeGroup/Mimic/issues/50)). - Nexo IDs are used as is: `nexo:ruby_ore`. Note blocks, string blocks and chorus blocks are supported. + Nexo IDs are lowercased: `nexo:ruby_ore`. Note blocks, string blocks and chorus blocks are supported. ## [v0.10.0] (2026-11-15) diff --git a/mimic-bukkit/README.md b/mimic-bukkit/README.md index fa69afaa..0e2485f7 100644 --- a/mimic-bukkit/README.md +++ b/mimic-bukkit/README.md @@ -103,7 +103,7 @@ Providers marked with _(deprecated API)_ are provided by the plugin itself via t #### [Nexo] -**ID Format:** `nexo:[id]`\ +**ID Format:** `nexo:[id]`, Nexo ID is lowercased and characters not allowed in IDs are replaced with `_`\ **Payload:** *Not supported* #### [MMOItems] @@ -148,6 +148,8 @@ A block belongs to the provider with the highest priority that recognizes it, va **ID Format:** `nexo:[id]`, the same as the ID of the item placing the block\ **State:** *Not supported*\ Note blocks, string blocks and chorus blocks are supported. Furniture is not a block. +Every variant of a directional block has the ID of its parent block. +Content of a storage block is dropped on the ground when the block is broken. [minecraft-exp]: https://minecraft.fandom.com/wiki/Experience [minecraft-inv]: https://minecraft.fandom.com/wiki/Inventory diff --git a/mimic-bukkit/src/main/kotlin/impl/nexo/NexoBlockProvider.kt b/mimic-bukkit/src/main/kotlin/impl/nexo/NexoBlockProvider.kt index be8041b9..23bd964e 100644 --- a/mimic-bukkit/src/main/kotlin/impl/nexo/NexoBlockProvider.kt +++ b/mimic-bukkit/src/main/kotlin/impl/nexo/NexoBlockProvider.kt @@ -11,8 +11,11 @@ import ru.endlesscode.mimic.internal.Log /** * Block provider for Nexo custom blocks: note blocks, string blocks and chorus blocks. Furniture is not a block. - * Block ID is the ID of the Nexo item placing the block. - * Every variant of a directional block is a separate block with its own ID. + * Block ID is the ID of the Nexo item placing the block, converted the same way as item IDs: + * lowercased, with characters not allowed in block IDs replaced with `_`. + * + * Every variant of a directional block is listed as a separate block and can be set by its own ID, + * but a placed variant has the ID of its parent block. * Nexo blocks have no states, so [setBlock] with a state always fails. * * Content of a storage block is dropped on the ground by Nexo when the block is removed, @@ -22,30 +25,33 @@ internal class NexoBlockProvider( private val nexo: NexoWrapper = NexoWrapper(), ) : BlockProvider { + private val ids = NexoIds(nexo::hasBlock) { nexo.blockIds } + override val id: String = ID override val isEnabled: Boolean get() = nexo.isEnabled - override val allBlocks: Collection get() = nexo.blockIds + override val allBlocks: Collection get() = ids.mimicIds - override fun hasBlock(blockId: String): Boolean = nexo.hasBlock(blockId) + override fun hasBlock(blockId: String): Boolean = ids.findNexoId(blockId) != null - override fun getBlockId(block: Block): String? = nexo.getBlockId(block) + override fun getBlockId(block: Block): String? = nexo.getBlockId(block)?.toMimicId() - override fun getBlockIdFromItem(item: ItemStack): String? = nexo.getItemId(item)?.takeIf(nexo::hasBlock) + override fun getBlockIdFromItem(item: ItemStack): String? = + nexo.getItemId(item)?.takeIf(nexo::hasBlock)?.toMimicId() override fun createBlockItem(blockId: String, amount: Int): ItemStack? { - if (!nexo.hasBlock(blockId)) return null - return nexo.createItem(blockId, amount) + val nexoId = ids.findNexoId(blockId) ?: return null + return nexo.createItem(nexoId, amount) } override fun setBlock(block: Block, blockId: String, state: String?): Boolean { - if (!nexo.hasBlock(blockId)) return false + val nexoId = ids.findNexoId(blockId) ?: return false if (state != null) { - Log.w("[$TAG] Invalid state for block $blockId: $state. Nexo blocks have no states.") + Log.w("[$TAG] Invalid state for block $blockId: $state") return false } - nexo.placeBlock(block, blockId) + nexo.placeBlock(block, nexoId) // Nexo doesn't tell if the block was placed return nexo.getBlockId(block) != null } diff --git a/mimic-bukkit/src/main/kotlin/impl/nexo/NexoIds.kt b/mimic-bukkit/src/main/kotlin/impl/nexo/NexoIds.kt new file mode 100644 index 00000000..24e6159f --- /dev/null +++ b/mimic-bukkit/src/main/kotlin/impl/nexo/NexoIds.kt @@ -0,0 +1,44 @@ +// Copyright (c) 2026 Osip Fatkullin, EndlessCode Group and contributors +// SPDX-License-Identifier: MIT + +package ru.endlesscode.mimic.impl.nexo + +import net.kyori.adventure.key.Key +import ru.endlesscode.mimic.internal.Log +import java.util.concurrent.ConcurrentHashMap + +/** + * Converts Nexo IDs to Mimic IDs and back. + * Nexo IDs are lowercased and characters not allowed in Mimic IDs are replaced with `_`: `Ruby Ore` -> `ruby_ore`. + * If several Nexo IDs become the same Mimic ID, the one equal to the Mimic ID is used, otherwise the first one. + * + * @param exists Checks that the given Nexo ID exists. + * @param nexoIds Returns all Nexo IDs. + */ +internal class NexoIds( + private val exists: (String) -> Boolean, + private val nexoIds: () -> List, +) { + + private val reportedDuplicates = ConcurrentHashMap.newKeySet() + + val mimicIds: List + get() { + val idsByMimicId = nexoIds().groupBy(String::toMimicId) + for ((mimicId, sameIds) in idsByMimicId) { + if (sameIds.size > 1 && reportedDuplicates.add(mimicId)) { + val usedId = if (mimicId in sameIds) mimicId else sameIds.first() + Log.w("[Nexo] IDs $sameIds have the same Mimic ID '$mimicId', only '$usedId' is used.") + } + } + return idsByMimicId.keys.toList() + } + + /** Returns Nexo ID for the given [mimicId], or `null` if there is no such ID. */ + fun findNexoId(mimicId: String): String? = + mimicId.takeIf(exists) ?: nexoIds().find { it.toMimicId() == mimicId } +} + +internal fun String.toMimicId(): String = buildString { + for (char in this@toMimicId.lowercase()) append(if (Key.allowedInValue(char)) char else '_') +} diff --git a/mimic-bukkit/src/main/kotlin/impl/nexo/NexoItemProvider.kt b/mimic-bukkit/src/main/kotlin/impl/nexo/NexoItemProvider.kt index ae527f5e..1e66e84b 100644 --- a/mimic-bukkit/src/main/kotlin/impl/nexo/NexoItemProvider.kt +++ b/mimic-bukkit/src/main/kotlin/impl/nexo/NexoItemProvider.kt @@ -8,24 +8,29 @@ import org.bukkit.inventory.ItemStack import ru.endlesscode.mimic.items.ItemProvider /** - * Item provider for Nexo items. Item IDs are the same as in Nexo. + * Item provider for Nexo items. + * Nexo IDs are lowercased and characters not allowed in item IDs are replaced with `_`: `Ruby Sword` -> `ruby_sword`. * Takes no payload, items don't depend on a player. */ internal class NexoItemProvider( private val nexo: NexoWrapper = NexoWrapper(), ) : ItemProvider { + private val ids = NexoIds(nexo::hasItem) { nexo.itemIds } + override val id: String = ID override val isEnabled: Boolean get() = nexo.isEnabled - override val allItems: Collection get() = nexo.itemIds + override val allItems: Collection get() = ids.mimicIds - override fun hasItem(itemId: String): Boolean = nexo.hasItem(itemId) + override fun hasItem(itemId: String): Boolean = ids.findNexoId(itemId) != null - override fun getItemId(item: ItemStack): String? = nexo.getItemId(item) + override fun getItemId(item: ItemStack): String? = nexo.getItemId(item)?.toMimicId() - override fun createItem(itemId: String, amount: Int, player: Player?, payload: String?): ItemStack? = - nexo.createItem(itemId, amount) + override fun createItem(itemId: String, amount: Int, player: Player?, payload: String?): ItemStack? { + val nexoId = ids.findNexoId(itemId) ?: return null + return nexo.createItem(nexoId, amount) + } companion object { const val ID: String = "nexo" diff --git a/mimic-bukkit/src/main/kotlin/impl/nexo/NexoWrapper.kt b/mimic-bukkit/src/main/kotlin/impl/nexo/NexoWrapper.kt index 45c44a4a..741fa2f9 100644 --- a/mimic-bukkit/src/main/kotlin/impl/nexo/NexoWrapper.kt +++ b/mimic-bukkit/src/main/kotlin/impl/nexo/NexoWrapper.kt @@ -14,7 +14,7 @@ import org.bukkit.inventory.ItemStack import kotlin.random.Random /** - * Wraps Nexo static API. + * Wraps Nexo static API. All IDs are Nexo IDs. * [getDrops] repeats the logic Nexo uses to drop loot, because Nexo can only drop it on the ground. */ internal class NexoWrapper { @@ -32,38 +32,37 @@ internal class NexoWrapper { NexoItems.createItem(id)?.also { it.amount = amount.coerceIn(1, it.maxStackSize) } fun hasBlock(id: String): Boolean = NexoBlocks.isCustomBlock(id) - fun getBlockId(block: Block): String? = NexoBlocks.customBlockMechanic(block)?.itemID + fun getBlockId(block: Block): String? = NexoBlocks.customBlockMechanic(block)?.blockId fun placeBlock(block: Block, id: String) { NexoBlocks.place(id, block.location) } - /** - * Returns items dropped by the custom [block] broken with the [tool], or `null` if it isn't a custom block. - * If the tool is `null`, the block drops its loot regardless of the required tool. - */ - fun getDrops(block: Block, tool: ItemStack?): List? { - val drop = NexoBlocks.customBlockMechanic(block)?.drop ?: return null - - if (tool == null) return drop.rollLoot(fortuneMultiplier = 1) - if (!drop.canDrop(tool)) return emptyList() - - val silkTouchItem = if (drop.isSilkTouchDrop(tool)) NexoItems.createItem(drop.sourceID) else null - return if (silkTouchItem != null) listOf(silkTouchItem) else drop.rollLoot(drop.fortuneMultiplier(tool)) - } + /** Returns items dropped by the custom [block] broken with the [tool], or `null` if it isn't a custom block. */ + fun getDrops(block: Block, tool: ItemStack?): List? = + NexoBlocks.customBlockMechanic(block)?.breakable?.drop?.rollDrops(tool, NexoItems::createItem) /** Removes the custom [block] without dropping its loot. */ fun removeBlock(block: Block): Boolean = NexoBlocks.remove(block.location, null, Drop.emptyDrop()) +} - /** Directional blocks take the drop from their parent block. */ - private val CustomBlockMechanic.drop: Drop - get() { - val mechanic = (this as? NoteBlockMechanic)?.directional?.parentMechanic ?: this - return mechanic.breakable.drop - } +/** ID of the block: all variants of a directional block have the ID of their parent block. */ +internal val CustomBlockMechanic.blockId: String + get() = (this as? NoteBlockMechanic)?.directional?.parentBlock ?: itemID - private fun Drop.rollLoot(fortuneMultiplier: Int): List = loots - .filter { Random.nextDouble() <= it.probability } - .map { it.getItem(fortuneMultiplier) } - .filter { it.amount > 0 } +/** + * Returns items dropped for the [tool]. If the tool is `null`, tool requirements are satisfied + * and the loot is rolled as for a tool without enchantments. + */ +internal fun Drop.rollDrops(tool: ItemStack?, createItem: (String) -> ItemStack?): List { + if (tool == null) return rollLoot(fortuneMultiplier = 1) + if (!canDrop(tool)) return emptyList() + + val silkTouchItem = if (isSilkTouchDrop(tool)) createItem(sourceID) else null + return if (silkTouchItem != null) listOf(silkTouchItem) else rollLoot(fortuneMultiplier(tool)) } + +private fun Drop.rollLoot(fortuneMultiplier: Int): List = loots + .filter { Random.nextDouble() <= it.probability } + .map { it.getItem(fortuneMultiplier) } + .filter { it.amount > 0 } diff --git a/mimic-bukkit/src/test/kotlin/impl/nexo/NexoBlockProviderTest.kt b/mimic-bukkit/src/test/kotlin/impl/nexo/NexoBlockProviderTest.kt index 2f19db91..aac08f59 100644 --- a/mimic-bukkit/src/test/kotlin/impl/nexo/NexoBlockProviderTest.kt +++ b/mimic-bukkit/src/test/kotlin/impl/nexo/NexoBlockProviderTest.kt @@ -65,6 +65,29 @@ internal class NexoBlockProviderTest : BukkitTestBase() { provider.getBlockIdFromItem(ruby).shouldBeNull() } + @Test + fun `when get id of directional block - should return id reported by Nexo wrapper`() { + every { nexo.getBlockId(block) } returns "ruby_log" + + provider.getBlockId(block) shouldBe "ruby_log" + } + + @Test + fun `when Nexo ids are not valid - should convert them`() { + every { nexo.blockIds } returns listOf("Ruby Ore") + every { nexo.getItemId(any()) } returns "Ruby Ore" + every { nexo.getBlockId(block) } returns "Ruby Ore" + every { nexo.createItem("Ruby Ore", any()) } answers { ItemStack(Material.PAPER) } + + provider.allBlocks shouldContainExactly listOf("ruby_ore") + provider.hasBlock("ruby_ore").shouldBeTrue() + provider.getBlockId(block) shouldBe "ruby_ore" + provider.getBlockIdFromItem(ruby) shouldBe "ruby_ore" + provider.createBlockItem("ruby_ore", amount = 1)?.type shouldBe Material.PAPER + provider.setBlock(block, "ruby_ore", state = null).shouldBeTrue() + verify { nexo.placeBlock(block, "Ruby Ore") } + } + @Test fun `when create block item - should create Nexo item`() { val item = provider.createBlockItem("ruby_ore", amount = 3) diff --git a/mimic-bukkit/src/test/kotlin/impl/nexo/NexoItemProviderTest.kt b/mimic-bukkit/src/test/kotlin/impl/nexo/NexoItemProviderTest.kt index c835304b..376af196 100644 --- a/mimic-bukkit/src/test/kotlin/impl/nexo/NexoItemProviderTest.kt +++ b/mimic-bukkit/src/test/kotlin/impl/nexo/NexoItemProviderTest.kt @@ -57,6 +57,35 @@ internal class NexoItemProviderTest : BukkitTestBase() { provider.getItemId(ItemStack(Material.EMERALD)) shouldBe "ruby" } + @Test + fun `when Nexo ids are not valid - should convert them`() { + every { nexo.itemIds } returns listOf("ruby", "Ruby Sword") + every { nexo.getItemId(any()) } returns "Ruby Sword" + every { nexo.createItem("Ruby Sword", any()) } answers { ItemStack(Material.DIAMOND_SWORD) } + + provider.allItems shouldContainExactly listOf("ruby", "ruby_sword") + provider.hasItem("ruby_sword") shouldBe true + provider.getItemId(ItemStack(Material.DIAMOND_SWORD)) shouldBe "ruby_sword" + provider.createItem("ruby_sword", amount = 1, player = null, payload = null)?.type shouldBe Material.DIAMOND_SWORD + } + + @Test + fun `when Nexo ids become the same - should use the exact one`() { + every { nexo.itemIds } returns listOf("Ruby", "ruby", "RUBY") + + provider.allItems shouldContainExactly listOf("ruby") + provider.createItem("ruby", amount = 1, player = null, payload = null)?.type shouldBe Material.EMERALD + } + + @Test + fun `when Nexo ids become the same and none is exact - should use the first one`() { + every { nexo.itemIds } returns listOf("Ruby", "RUBY") + every { nexo.createItem("Ruby", any()) } answers { ItemStack(Material.REDSTONE) } + + provider.allItems shouldContainExactly listOf("ruby") + provider.createItem("ruby", amount = 1, player = null, payload = null)?.type shouldBe Material.REDSTONE + } + @Test fun `when get id of not Nexo item - should return null`() { provider.getItemId(ItemStack(Material.EMERALD)).shouldBeNull() diff --git a/mimic-bukkit/src/test/kotlin/impl/nexo/NexoWrapperTest.kt b/mimic-bukkit/src/test/kotlin/impl/nexo/NexoWrapperTest.kt new file mode 100644 index 00000000..f9e160bf --- /dev/null +++ b/mimic-bukkit/src/test/kotlin/impl/nexo/NexoWrapperTest.kt @@ -0,0 +1,60 @@ +// Copyright (c) 2026 Osip Fatkullin, EndlessCode Group and contributors +// SPDX-License-Identifier: MIT + +package ru.endlesscode.mimic.impl.nexo + +import com.nexomc.nexo.utils.drops.Drop +import com.nexomc.nexo.utils.drops.Loot +import io.kotest.matchers.collections.shouldBeEmpty +import io.kotest.matchers.collections.shouldContainExactly +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import org.bukkit.inventory.ItemStack +import kotlin.test.Test + +internal class NexoWrapperTest { + + private val tool: ItemStack = mockk() + private val lootItem: ItemStack = mockk { every { amount } returns 1 } + private val silkTouchItem: ItemStack = mockk() + private val loot: Loot = mockk { + every { probability } returns 1.0 + every { getItem(any()) } returns lootItem + } + private val drop: Drop = mockk { + every { loots } returns mutableListOf(loot) + every { sourceID } returns "ruby_ore" + every { canDrop(any()) } returns true + every { isSilkTouchDrop(any()) } returns false + every { fortuneMultiplier(any()) } returns 3 + } + + @Test + fun `when roll drops without tool - should ignore tool requirements and enchantments`() { + every { drop.canDrop(any()) } returns false + + drop.rollDrops(tool = null) { silkTouchItem } shouldContainExactly listOf(lootItem) + verify { loot.getItem(1) } + } + + @Test + fun `when roll drops with not suitable tool - should drop nothing`() { + every { drop.canDrop(tool) } returns false + + drop.rollDrops(tool) { silkTouchItem }.shouldBeEmpty() + } + + @Test + fun `when roll drops with fortune tool - should multiply loot`() { + drop.rollDrops(tool) { silkTouchItem } shouldContainExactly listOf(lootItem) + verify { loot.getItem(3) } + } + + @Test + fun `when roll drops with silk touch tool - should drop the block item`() { + every { drop.isSilkTouchDrop(tool) } returns true + + drop.rollDrops(tool) { silkTouchItem } shouldContainExactly listOf(silkTouchItem) + } +} From 34ad6bc8018c3dba544723b9afbcae0e62f22e89 Mon Sep 17 00:00:00 2001 From: Osip Fatkullin Date: Mon, 16 Nov 2026 13:46:49 +0100 Subject: [PATCH 3/3] fix: Report parent ID for Nexo directional variant items Co-Authored-By: Claude Opus 5.5 --- mimic-bukkit/README.md | 2 +- .../src/main/kotlin/impl/nexo/NexoBlockProvider.kt | 4 ++-- mimic-bukkit/src/main/kotlin/impl/nexo/NexoWrapper.kt | 1 + .../src/test/kotlin/impl/nexo/NexoBlockProviderTest.kt | 9 +++++++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/mimic-bukkit/README.md b/mimic-bukkit/README.md index 0e2485f7..e19fada3 100644 --- a/mimic-bukkit/README.md +++ b/mimic-bukkit/README.md @@ -148,7 +148,7 @@ A block belongs to the provider with the highest priority that recognizes it, va **ID Format:** `nexo:[id]`, the same as the ID of the item placing the block\ **State:** *Not supported*\ Note blocks, string blocks and chorus blocks are supported. Furniture is not a block. -Every variant of a directional block has the ID of its parent block. +Variants of a directional block and their items have the ID of their parent block. Content of a storage block is dropped on the ground when the block is broken. [minecraft-exp]: https://minecraft.fandom.com/wiki/Experience diff --git a/mimic-bukkit/src/main/kotlin/impl/nexo/NexoBlockProvider.kt b/mimic-bukkit/src/main/kotlin/impl/nexo/NexoBlockProvider.kt index 23bd964e..da553bc3 100644 --- a/mimic-bukkit/src/main/kotlin/impl/nexo/NexoBlockProvider.kt +++ b/mimic-bukkit/src/main/kotlin/impl/nexo/NexoBlockProvider.kt @@ -15,7 +15,7 @@ import ru.endlesscode.mimic.internal.Log * lowercased, with characters not allowed in block IDs replaced with `_`. * * Every variant of a directional block is listed as a separate block and can be set by its own ID, - * but a placed variant has the ID of its parent block. + * but a placed variant and its item have the ID of the parent block. * Nexo blocks have no states, so [setBlock] with a state always fails. * * Content of a storage block is dropped on the ground by Nexo when the block is removed, @@ -37,7 +37,7 @@ internal class NexoBlockProvider( override fun getBlockId(block: Block): String? = nexo.getBlockId(block)?.toMimicId() override fun getBlockIdFromItem(item: ItemStack): String? = - nexo.getItemId(item)?.takeIf(nexo::hasBlock)?.toMimicId() + nexo.getItemId(item)?.let(nexo::getBlockIdOfItem)?.toMimicId() override fun createBlockItem(blockId: String, amount: Int): ItemStack? { val nexoId = ids.findNexoId(blockId) ?: return null diff --git a/mimic-bukkit/src/main/kotlin/impl/nexo/NexoWrapper.kt b/mimic-bukkit/src/main/kotlin/impl/nexo/NexoWrapper.kt index 741fa2f9..21e7394d 100644 --- a/mimic-bukkit/src/main/kotlin/impl/nexo/NexoWrapper.kt +++ b/mimic-bukkit/src/main/kotlin/impl/nexo/NexoWrapper.kt @@ -33,6 +33,7 @@ internal class NexoWrapper { fun hasBlock(id: String): Boolean = NexoBlocks.isCustomBlock(id) fun getBlockId(block: Block): String? = NexoBlocks.customBlockMechanic(block)?.blockId + fun getBlockIdOfItem(itemId: String): String? = NexoBlocks.customBlockMechanic(itemId)?.blockId fun placeBlock(block: Block, id: String) { NexoBlocks.place(id, block.location) diff --git a/mimic-bukkit/src/test/kotlin/impl/nexo/NexoBlockProviderTest.kt b/mimic-bukkit/src/test/kotlin/impl/nexo/NexoBlockProviderTest.kt index aac08f59..1b4c3378 100644 --- a/mimic-bukkit/src/test/kotlin/impl/nexo/NexoBlockProviderTest.kt +++ b/mimic-bukkit/src/test/kotlin/impl/nexo/NexoBlockProviderTest.kt @@ -39,6 +39,7 @@ internal class NexoBlockProviderTest : BukkitTestBase() { every { hasBlock(any()) } answers { firstArg() in blockIds } every { getItemId(any()) } returns null every { getBlockId(any()) } returns null + every { getBlockIdOfItem(any()) } answers { firstArg().takeIf { it in blockIds } } every { getDrops(any(), any()) } returns null every { createItem("ruby_ore", any()) } answers { ItemStack(Material.PAPER, secondArg()) } } @@ -72,6 +73,14 @@ internal class NexoBlockProviderTest : BukkitTestBase() { provider.getBlockId(block) shouldBe "ruby_log" } + @Test + fun `when get block id from directional variant item - should return id reported by Nexo wrapper`() { + every { nexo.getItemId(any()) } returns "ruby_log_x" + every { nexo.getBlockIdOfItem("ruby_log_x") } returns "ruby_log" + + provider.getBlockIdFromItem(ruby) shouldBe "ruby_log" + } + @Test fun `when Nexo ids are not valid - should convert them`() { every { nexo.blockIds } returns listOf("Ruby Ore")