Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 lowercased: `nexo:ruby_ore`. Note blocks, string blocks and chorus blocks are supported.

## [v0.10.0] (2026-11-15)

### Levels API
Expand Down
4 changes: 2 additions & 2 deletions MODRINTH.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" }
Expand Down Expand Up @@ -92,4 +94,5 @@ rpgplugins = [
"rpgplugins-fabled",
"rpgplugins-codex",
"rpgplugins-valhallammo",
"rpgplugins-nexo",
]
14 changes: 14 additions & 0 deletions mimic-bukkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]`, Nexo ID is lowercased and characters not allowed in IDs are replaced with `_`\
**Payload:** *Not supported*

#### [MMOItems]

**ID Format:** `mmoitems:[type]/[id]`, for example `mmoitems:sword/excalibur`\
Expand Down Expand Up @@ -138,6 +143,14 @@ 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.
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
[minecraft-inv]: https://minecraft.fandom.com/wiki/Inventory
[item-components]: https://minecraft.wiki/w/Data_component_format
Expand All @@ -150,6 +163,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/
Expand Down
7 changes: 7 additions & 0 deletions mimic-bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ bukkit {
"Jobs",
"Fabled",
"ValhallaMMO",
"Nexo",
)
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions mimic-bukkit/src/main/kotlin/MimicPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
73 changes: 73 additions & 0 deletions mimic-bukkit/src/main/kotlin/impl/nexo/NexoBlockProvider.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// 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, 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 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,
* so [breakBlock] doesn't pass it to the drops consumer.
*/
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<String> get() = ids.mimicIds

override fun hasBlock(blockId: String): Boolean = ids.findNexoId(blockId) != null

override fun getBlockId(block: Block): String? = nexo.getBlockId(block)?.toMimicId()

override fun getBlockIdFromItem(item: ItemStack): String? =
nexo.getItemId(item)?.let(nexo::getBlockIdOfItem)?.toMimicId()

override fun createBlockItem(blockId: String, amount: Int): ItemStack? {
val nexoId = ids.findNexoId(blockId) ?: return null
return nexo.createItem(nexoId, amount)
}

override fun setBlock(block: Block, blockId: String, state: String?): Boolean {
val nexoId = ids.findNexoId(blockId) ?: return false
if (state != null) {
Log.w("[$TAG] Invalid state for block $blockId: $state")
return false
}

nexo.placeBlock(block, nexoId)
// 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"
}
}
44 changes: 44 additions & 0 deletions mimic-bukkit/src/main/kotlin/impl/nexo/NexoIds.kt
Original file line number Diff line number Diff line change
@@ -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<String>,
) {

private val reportedDuplicates = ConcurrentHashMap.newKeySet<String>()

val mimicIds: List<String>
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 '_')
}
38 changes: 38 additions & 0 deletions mimic-bukkit/src/main/kotlin/impl/nexo/NexoItemProvider.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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.
* 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<String> get() = ids.mimicIds

override fun hasItem(itemId: String): Boolean = ids.findNexoId(itemId) != null

override fun getItemId(item: ItemStack): String? = nexo.getItemId(item)?.toMimicId()

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"
}
}
69 changes: 69 additions & 0 deletions mimic-bukkit/src/main/kotlin/impl/nexo/NexoWrapper.kt
Original file line number Diff line number Diff line change
@@ -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. 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 {

val isEnabled: Boolean get() = Bukkit.getPluginManager().isPluginEnabled("Nexo")

val itemIds: List<String> get() = NexoItems.itemNames().toList()
val blockIds: List<String> 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)?.blockId
fun getBlockIdOfItem(itemId: String): String? = NexoBlocks.customBlockMechanic(itemId)?.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. */
fun getDrops(block: Block, tool: ItemStack?): List<ItemStack>? =
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())
}

/** 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

/**
* 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<ItemStack> {
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<ItemStack> = loots
.filter { Random.nextDouble() <= it.probability }
.map { it.getItem(fortuneMultiplier) }
.filter { it.amount > 0 }
Loading