refactor: Use custom ray trace provider
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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}"))
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user