diff options
author | Linnea Gräf <nea@nea.moe> | 2025-03-06 21:43:11 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2025-03-08 16:01:00 +0100 |
commit | 8a4bfe24b364612e3e783ed9569082b130aa2bfc (patch) | |
tree | 5a98ab8ebecbde6e32e13479a8fb9e17632a93ba /src/compat | |
parent | 9099abe955d88f7e0f1a1a8feba519a8a098858d (diff) | |
download | Firmament-8a4bfe24b364612e3e783ed9569082b130aa2bfc.tar.gz Firmament-8a4bfe24b364612e3e783ed9569082b130aa2bfc.tar.bz2 Firmament-8a4bfe24b364612e3e783ed9569082b130aa2bfc.zip |
refactor: Use custom ray trace provider
Diffstat (limited to 'src/compat')
4 files changed, 74 insertions, 37 deletions
diff --git a/src/compat/jade/java/moe/nea/firmament/compat/jade/CurrentCustomBlockHolder.kt b/src/compat/jade/java/moe/nea/firmament/compat/jade/CurrentCustomBlockHolder.kt new file mode 100644 index 0000000..5fe2425 --- /dev/null +++ b/src/compat/jade/java/moe/nea/firmament/compat/jade/CurrentCustomBlockHolder.kt @@ -0,0 +1,38 @@ +package moe.nea.firmament.compat.jade + +import moe.nea.firmament.annotations.Subscribe +import moe.nea.firmament.events.SkyblockServerUpdateEvent +import moe.nea.firmament.repo.MiningRepoData +import moe.nea.firmament.repo.RepoManager +import moe.nea.firmament.util.ErrorUtil +import net.minecraft.block.Block + +object CurrentCustomBlockHolder { + var customBlocks: Map<Block, MiningRepoData.CustomMiningBlock> = mapOf() + + fun refreshBlockInfo() { + if (!isOnMiningIsland()) { + customBlocks = mapOf() + return + } + val blocks = RepoManager.miningData.customMiningBlocks + .flatMap { customBlock -> + // TODO: add a lifted helper method for this + customBlock.blocks189.filter { it.isCurrentlyActive } + .mapNotNull { it.block } + .map { customBlock to it } + } + .groupBy { it.second } + customBlocks = blocks.mapNotNull { (block, customBlocks) -> + val singleMatch = + ErrorUtil.notNullOr(customBlocks.singleOrNull()?.first, + "Two custom blocks both want to supply custom mining behaviour for $block.") { return@mapNotNull null } + block to singleMatch + }.toMap() + } + + @Subscribe + fun onWorldSwap(event: SkyblockServerUpdateEvent) { + refreshBlockInfo() + } +} diff --git a/src/compat/jade/java/moe/nea/firmament/compat/jade/CustomFakeBlockProvider.kt b/src/compat/jade/java/moe/nea/firmament/compat/jade/CustomFakeBlockProvider.kt new file mode 100644 index 0000000..3dc6101 --- /dev/null +++ b/src/compat/jade/java/moe/nea/firmament/compat/jade/CustomFakeBlockProvider.kt @@ -0,0 +1,34 @@ +package moe.nea.firmament.compat.jade + +import snownee.jade.api.Accessor +import snownee.jade.api.BlockAccessor +import snownee.jade.api.IWailaClientRegistration +import snownee.jade.api.callback.JadeRayTraceCallback +import net.minecraft.util.hit.HitResult +import moe.nea.firmament.repo.MiningRepoData +import moe.nea.firmament.util.mc.FirmamentDataComponentTypes + +class CustomFakeBlockProvider(val registration: IWailaClientRegistration) : JadeRayTraceCallback { + + override fun onRayTrace( + hitResult: HitResult, + accessor: Accessor<*>?, + originalAccessor: Accessor<*>? + ): Accessor<*>? { + if (accessor !is BlockAccessor) return accessor + val customBlock = CurrentCustomBlockHolder.customBlocks[accessor.block] + if (customBlock == null) return accessor + return registration.blockAccessor() + .from(accessor) + .fakeBlock(customBlock.getDisplayItem(accessor.block)) + .build() + } + + companion object { + fun getCustomBlock(accessor: BlockAccessor): MiningRepoData.CustomMiningBlock? { + if (!accessor.isFakeBlock) return null + val item = accessor.fakeBlock + return item.get(FirmamentDataComponentTypes.CUSTOM_MINING_BLOCK_DATA) + } + } +} diff --git a/src/compat/jade/java/moe/nea/firmament/compat/jade/CustomMiningHardnessProvider.kt b/src/compat/jade/java/moe/nea/firmament/compat/jade/CustomMiningHardnessProvider.kt index 49f5257..1a662a4 100644 --- a/src/compat/jade/java/moe/nea/firmament/compat/jade/CustomMiningHardnessProvider.kt +++ b/src/compat/jade/java/moe/nea/firmament/compat/jade/CustomMiningHardnessProvider.kt @@ -4,54 +4,18 @@ import snownee.jade.api.BlockAccessor import snownee.jade.api.IBlockComponentProvider import snownee.jade.api.ITooltip import snownee.jade.api.config.IPluginConfig -import net.minecraft.block.Block import net.minecraft.util.Identifier import moe.nea.firmament.Firmament -import moe.nea.firmament.annotations.Subscribe -import moe.nea.firmament.events.SkyblockServerUpdateEvent -import moe.nea.firmament.repo.MiningRepoData -import moe.nea.firmament.repo.RepoManager -import moe.nea.firmament.util.ErrorUtil import moe.nea.firmament.util.tr object CustomMiningHardnessProvider : IBlockComponentProvider { - var customBlocks: Map<Block, MiningRepoData.CustomMiningBlock> = mapOf() - - fun refreshBlockInfo() { - if (!isOnMiningIsland()) { - customBlocks = mapOf() - return - } - val blocks = RepoManager.miningData.customMiningBlocks - .flatMap { customBlock -> - // TODO: add a lifted helper method for this - customBlock.blocks189.filter { it.isCurrentlyActive } - .mapNotNull { it.block } - .map { customBlock to it } - } - .groupBy { it.second } - customBlocks = blocks.mapNotNull { (block, customBlocks) -> - val singleMatch = - ErrorUtil.notNullOr(customBlocks.singleOrNull()?.first, - "Two custom blocks both want to supply custom mining behaviour for $block.") { return@mapNotNull null } - block to singleMatch - }.toMap() - } - - @Subscribe - fun onWorldSwap(event: SkyblockServerUpdateEvent) { - refreshBlockInfo() - } - - override fun appendTooltip( tooltip: ITooltip, block: BlockAccessor, config: IPluginConfig? ) { - val customBlock = customBlocks[block.block] - ?: return + val customBlock = CustomFakeBlockProvider.getCustomBlock(block) ?: return if (customBlock.breakingPower > 0) tooltip.add(tr("firmament.jade.breaking_power", "Required Breaking Power: ${customBlock.breakingPower}")) } diff --git a/src/compat/jade/java/moe/nea/firmament/compat/jade/FirmamentJadePlugin.kt b/src/compat/jade/java/moe/nea/firmament/compat/jade/FirmamentJadePlugin.kt index 50c7b89..700aa70 100644 --- a/src/compat/jade/java/moe/nea/firmament/compat/jade/FirmamentJadePlugin.kt +++ b/src/compat/jade/java/moe/nea/firmament/compat/jade/FirmamentJadePlugin.kt @@ -18,5 +18,6 @@ class FirmamentJadePlugin : IWailaPlugin { override fun registerClient(registration: IWailaClientRegistration) { registration.registerBlockComponent(CustomMiningHardnessProvider, Block::class.java) registration.registerProgressClient(SkyblockProgressProvider()) + registration.addRayTraceCallback(CustomFakeBlockProvider(registration)) } } |