Skip to content

Commit 6e4d4be

Browse files
committed
feat: add Axiom compatibility for Custom Blocks
1 parent 245dbf7 commit 6e4d4be

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

.github/workflows/publish.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ jobs:
1818

1919
- uses: MineInAbyss/publish-action@v3
2020
with:
21+
maven-username: ${{ secrets.MAVEN_PUBLISH_USERNAME }}
22+
maven-password: ${{ secrets.MAVEN_PUBLISH_PASSWORD }}
2123
release-files: |
2224
${{ github.workspace }}/publish/*.jar

src/main/kotlin/com/mineinabyss/blocky/BlockyPlugin.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ class BlockyPlugin : JavaPlugin() {
5353
BlockyCopperListener()
5454
)
5555
CustomBlockData.registerListener(this)
56+
runCatching {
57+
with(gearyPaper.worldManager.global, AxiomCompatibility::registerCustomBlocks)
58+
}.onFailure { it.printStackTrace() }
5659

5760
blocky.config.run {
5861
if (noteBlocks.isEnabled) {
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.mineinabyss.blocky.systems
2+
3+
import com.mineinabyss.blocky.blocky
4+
import com.mineinabyss.blocky.components.features.blocks.BlockyDirectional
5+
import com.mineinabyss.blocky.helpers.blockyNoteBlock
6+
import com.mineinabyss.blocky.helpers.blockyTripWire
7+
import com.mineinabyss.geary.modules.Geary
8+
import com.mineinabyss.geary.papermc.gearyPaper
9+
import com.mineinabyss.geary.papermc.tracking.blocks.components.SetBlock
10+
import com.mineinabyss.geary.prefabs.PrefabKey
11+
import com.mineinabyss.idofront.textcomponents.serialize
12+
import com.moulberry.axiom.paperapi.AxiomCustomBlocksAPI
13+
import io.papermc.paper.datacomponent.DataComponentTypes
14+
import net.kyori.adventure.key.Key
15+
16+
object AxiomCompatibility {
17+
18+
enum class DirectionalType {
19+
NONE, AXIS, FACING, HORIZONTAL_FACING
20+
}
21+
22+
data class DirectionalBlocks(val type: DirectionalType, val blocks: List<PrefabKey>) {
23+
constructor(parent: BlockyDirectional) : this(
24+
when {
25+
parent.isLogType -> DirectionalType.AXIS
26+
parent.isDropperType -> DirectionalType.FACING
27+
parent.isFurnaceType -> DirectionalType.HORIZONTAL_FACING
28+
else -> DirectionalType.NONE
29+
}, listOfNotNull(
30+
parent.xBlock, parent.yBlock, parent.zBlock,
31+
parent.northBlock, parent.eastBlock, parent.southBlock, parent.westBlock,
32+
parent.upBlock, parent.downBlock
33+
)
34+
)
35+
}
36+
37+
context(Geary)
38+
fun registerCustomBlocks() {
39+
AxiomCustomBlocksAPI.getAPI().unregisterAll(blocky.plugin)
40+
blocky.blockQuery.forEach { (prefab, block, directional, itemstack) ->
41+
if (block.blockType == SetBlock.BlockType.NOTEBLOCK && directional != null) return@forEach
42+
43+
val key = Key.key(prefab.full)
44+
val translationKey = itemstack?.getData(DataComponentTypes.ITEM_NAME)?.serialize() ?: prefab.full
45+
val blockData = prefab.blockyNoteBlock()
46+
val builder = AxiomCustomBlocksAPI.getAPI().createSingle(key, translationKey, blockData)
47+
48+
builder.preventShapeUpdates(true)
49+
builder.pickBlockItemStack(itemstack)
50+
AxiomCustomBlocksAPI.getAPI().register(blocky.plugin, builder)
51+
}
52+
53+
blocky.blockQuery.mapNotNullWithEntity { (prefab, block, directional, itemstack) ->
54+
if (block.blockType != SetBlock.BlockType.NOTEBLOCK) return@mapNotNullWithEntity null
55+
if (directional?.isParentBlock != true) return@mapNotNullWithEntity null
56+
57+
val key = Key.key(prefab.full)
58+
val translationKey = itemstack?.getData(DataComponentTypes.ITEM_NAME)?.serialize() ?: prefab.full
59+
val directionalBlocks = AxiomCompatibility.DirectionalBlocks(directional)
60+
val builder = when(directionalBlocks.type) {
61+
AxiomCompatibility.DirectionalType.AXIS -> {
62+
val (x, y, z) = directionalBlocks.blocks.take(3).map { it.blockyNoteBlock() }
63+
AxiomCustomBlocksAPI.getAPI().createAxis(key, translationKey, x, y, z)
64+
}
65+
AxiomCompatibility.DirectionalType.HORIZONTAL_FACING -> {
66+
val (n,e,s,w) = directionalBlocks.blocks.take(4).map { it.blockyNoteBlock() }
67+
AxiomCustomBlocksAPI.getAPI().createHorizontalFacing(key, translationKey, n, e, s, w)
68+
}
69+
AxiomCompatibility.DirectionalType.FACING -> {
70+
val (n,e,s,w) = directionalBlocks.blocks.take(4).map { it.blockyNoteBlock() }
71+
val (u,d) = directionalBlocks.blocks.takeLast(2).map { it.blockyNoteBlock() }
72+
AxiomCustomBlocksAPI.getAPI().createFacing(key, translationKey, n,e,s,w,u,d)
73+
}
74+
else -> return@mapNotNullWithEntity null
75+
}
76+
77+
builder.preventShapeUpdates(true)
78+
builder.pickBlockItemStack(itemstack)
79+
AxiomCustomBlocksAPI.getAPI().register(blocky.plugin, builder)
80+
}
81+
}
82+
}

src/main/kotlin/com/mineinabyss/blocky/systems/BlockyQueries.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.mineinabyss.blocky.components.features.blocks.BlockyDirectional
66
import com.mineinabyss.blocky.components.features.furniture.BlockyModelEngine
77
import com.mineinabyss.geary.modules.Geary
88
import com.mineinabyss.geary.papermc.tracking.blocks.components.SetBlock
9+
import com.mineinabyss.geary.papermc.tracking.items.ItemTracking
910
import com.mineinabyss.geary.prefabs.PrefabKey
1011
import com.mineinabyss.geary.prefabs.configuration.components.Prefab
1112
import com.mineinabyss.geary.systems.query.GearyQuery
@@ -38,6 +39,11 @@ class BlockyBlockQuery(world: Geary) : GearyQuery(world) {
3839
has<BlockyModelEngine>()
3940
}
4041
}
42+
43+
operator fun component1() = prefabKey
44+
operator fun component2() = block
45+
operator fun component3() = directional
46+
operator fun component4() = world.getAddon(ItemTracking).itemProvider.serializePrefabToItemStack(prefabKey)
4147
}
4248

4349
class BlockyFurnitureQuery(world: Geary) : GearyQuery(world) {

0 commit comments

Comments
 (0)