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+ }
0 commit comments