fix: Weird tools for BP 7; feat: Options for jade; fix: tools for glass blocks in jade

This commit is contained in:
Linnea Gräf
2025-03-10 22:24:01 +01:00
parent 034fc701ef
commit bb627157c2
9 changed files with 69 additions and 10 deletions

View File

@@ -15,8 +15,9 @@ class CustomFakeBlockProvider(val registration: IWailaClientRegistration) : Jade
accessor: Accessor<*>?, accessor: Accessor<*>?,
originalAccessor: Accessor<*>? originalAccessor: Accessor<*>?
): Accessor<*>? { ): Accessor<*>? {
if (!JadeIntegration.TConfig.blockDetection) return accessor
if (accessor !is BlockAccessor) return accessor if (accessor !is BlockAccessor) return accessor
val customBlock = CurrentCustomBlockHolder.customBlocks[accessor.block] val customBlock = JadeIntegration.customBlocks[accessor.block]
if (customBlock == null) return accessor if (customBlock == null) return accessor
return registration.blockAccessor() return registration.blockAccessor()
.from(accessor) .from(accessor)
@@ -25,6 +26,12 @@ class CustomFakeBlockProvider(val registration: IWailaClientRegistration) : Jade
} }
companion object { companion object {
@JvmStatic
fun hasCustomBlock(accessor: BlockAccessor): Boolean {
return getCustomBlock(accessor) != null
}
@JvmStatic
fun getCustomBlock(accessor: BlockAccessor): MiningRepoData.CustomMiningBlock? { fun getCustomBlock(accessor: BlockAccessor): MiningRepoData.CustomMiningBlock? {
if (!accessor.isFakeBlock) return null if (!accessor.isFakeBlock) return null
val item = accessor.fakeBlock val item = accessor.fakeBlock

View File

@@ -66,6 +66,7 @@ object CustomMiningHardnessProvider : IBlockComponentProvider {
@JvmStatic @JvmStatic
fun replaceBreakProgress(original: Float): Float { fun replaceBreakProgress(original: Float): Float {
if (!JadeIntegration.TConfig.miningProgress) return original
if (!isOnMiningIsland()) return original if (!isOnMiningIsland()) return original
val pos = MC.interactionManager?.currentBreakingPos ?: return original val pos = MC.interactionManager?.currentBreakingPos ?: return original
val info = currentBreakingInfo val info = currentBreakingInfo

View File

@@ -31,9 +31,8 @@ class DrillToolProvider : IBlockComponentProvider {
p2: IPluginConfig? p2: IPluginConfig?
) { ) {
val customBlock = CustomFakeBlockProvider.getCustomBlock(accessor) ?: return val customBlock = CustomFakeBlockProvider.getCustomBlock(accessor) ?: return
if (customBlock.breakingPower <= 0) return
val tool = RepoManager.miningData.getToolsThatCanBreak(customBlock.breakingPower).firstOrNull() val tool = RepoManager.miningData.getToolsThatCanBreak(customBlock.breakingPower).firstOrNull()
?.asItemStack() ?: return ?.asImmutableItemStack() ?: return
tooltip.replace(JadeIds.MC_HARVEST_TOOL, UnaryOperator { elements -> tooltip.replace(JadeIds.MC_HARVEST_TOOL, UnaryOperator { elements ->
elements.map { inner -> elements.map { inner ->
val lastItemIndex = inner.indexOfLast { it is ItemStackElement } val lastItemIndex = inner.indexOfLast { it is ItemStackElement }

View File

@@ -6,8 +6,15 @@ import moe.nea.firmament.repo.MiningRepoData
import moe.nea.firmament.repo.RepoManager import moe.nea.firmament.repo.RepoManager
import moe.nea.firmament.util.ErrorUtil import moe.nea.firmament.util.ErrorUtil
import net.minecraft.block.Block import net.minecraft.block.Block
import moe.nea.firmament.events.ReloadRegistrationEvent
import moe.nea.firmament.gui.config.ManagedConfig
object JadeIntegration {
object TConfig : ManagedConfig("jade-integration", Category.INTEGRATIONS) {
val miningProgress by toggle("progress") { true }
val blockDetection by toggle("blocks") { true }
}
object CurrentCustomBlockHolder {
var customBlocks: Map<Block, MiningRepoData.CustomMiningBlock> = mapOf() var customBlocks: Map<Block, MiningRepoData.CustomMiningBlock> = mapOf()
fun refreshBlockInfo() { fun refreshBlockInfo() {
@@ -31,6 +38,11 @@ object CurrentCustomBlockHolder {
}.toMap() }.toMap()
} }
@Subscribe
fun onRepoReload(event: ReloadRegistrationEvent) {
event.repo.registerReloadListener { refreshBlockInfo() }
}
@Subscribe @Subscribe
fun onWorldSwap(event: SkyblockServerUpdateEvent) { fun onWorldSwap(event: SkyblockServerUpdateEvent) {
refreshBlockInfo() refreshBlockInfo()

View File

@@ -0,0 +1,33 @@
package moe.nea.firmament.mixins.compat.jade;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Local;
import moe.nea.firmament.compat.jade.CustomFakeBlockProvider;
import net.minecraft.block.Blocks;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import snownee.jade.addon.harvest.HarvestToolProvider;
import snownee.jade.api.BlockAccessor;
import java.util.List;
@Mixin(HarvestToolProvider.class)
public class EnforceToolDisplayForCustomBlocksInHarvestToolProvider {
@ModifyExpressionValue(method = "getText", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;isToolRequired()Z"))
private boolean overwriteRequiresTool(boolean original, @Local(argsOnly = true) BlockAccessor accessor) {
if (CustomFakeBlockProvider.hasCustomBlock(accessor))
return true;
return original;
}
private static final List<ItemStack> REPLACEABLE_TOOL = List.of(new ItemStack(Blocks.ENCHANTING_TABLE));
@ModifyExpressionValue(method = "getText", at = @At(value = "INVOKE", target = "Lcom/google/common/cache/Cache;get(Ljava/lang/Object;Ljava/util/concurrent/Callable;)Ljava/lang/Object;"))
private Object overwriteAvailableTools(Object original, @Local(argsOnly = true) BlockAccessor accessor) {
var orig = (List<ItemStack>) original;
if (orig.isEmpty() && CustomFakeBlockProvider.hasCustomBlock(accessor))
return REPLACEABLE_TOOL;
return orig;
}
}

View File

@@ -30,7 +30,7 @@ class MiningRepoData : IReloadable {
private set private set
var customMiningBlocks: List<CustomMiningBlock> = listOf() var customMiningBlocks: List<CustomMiningBlock> = listOf()
private set private set
var toolsByBreakingPower: NavigableMap<BreakingPowerKey, NEUItem> = Collections.emptyNavigableMap() var toolsByBreakingPower: NavigableMap<BreakingPowerKey, SBItemStack> = Collections.emptyNavigableMap()
private set private set
@@ -44,7 +44,7 @@ class MiningRepoData : IReloadable {
.comparingInt<BreakingPowerKey> { it.breakingPower } .comparingInt<BreakingPowerKey> { it.breakingPower }
.thenComparing(Comparator.comparing( .thenComparing(Comparator.comparing(
{ it.itemId }, { it.itemId },
nullsFirst(Comparator.naturalOrder<SkyblockId>()))) nullsFirst(Comparator.comparing<SkyblockId, Boolean> { "PICK" in it.neuItem || "BING" in it.neuItem }.thenComparing(Comparator.naturalOrder<SkyblockId>()))))
} }
} }
@@ -60,13 +60,14 @@ class MiningRepoData : IReloadable {
repo.items.items repo.items.items
.values .values
.asSequence() .asSequence()
.map { SBItemStack(it.skyblockId) }
.filter { it.breakingPower > 0 } .filter { it.breakingPower > 0 }
.associateTo(TreeMap<BreakingPowerKey, NEUItem>(BreakingPowerKey.COMPARATOR)) { .associateTo(TreeMap<BreakingPowerKey, SBItemStack>(BreakingPowerKey.COMPARATOR)) {
BreakingPowerKey(it.breakingPower, it.skyblockId) to it BreakingPowerKey(it.breakingPower, it.skyblockId) to it
}) })
} }
fun getToolsThatCanBreak(breakingPower: Int): Collection<NEUItem> { fun getToolsThatCanBreak(breakingPower: Int): Collection<SBItemStack> {
return toolsByBreakingPower.tailMap(BreakingPowerKey(breakingPower, null), true).values return toolsByBreakingPower.tailMap(BreakingPowerKey(breakingPower, null), true).values
} }

View File

@@ -64,6 +64,7 @@ object RepoManager {
registerReloadListener(ItemNameLookup) registerReloadListener(ItemNameLookup)
registerReloadListener(ReforgeStore) registerReloadListener(ReforgeStore)
registerReloadListener(essenceRecipeProvider) registerReloadListener(essenceRecipeProvider)
registerReloadListener(recipeCache)
registerReloadListener(miningData) registerReloadListener(miningData)
ReloadRegistrationEvent.publish(ReloadRegistrationEvent(this)) ReloadRegistrationEvent.publish(ReloadRegistrationEvent(this))
registerReloadListener { registerReloadListener {
@@ -75,7 +76,6 @@ object RepoManager {
} }
} }
} }
registerReloadListener(recipeCache)
} }
} }

View File

@@ -34,6 +34,7 @@ import moe.nea.firmament.util.modifyExtraAttributes
import moe.nea.firmament.util.petData import moe.nea.firmament.util.petData
import moe.nea.firmament.util.prepend import moe.nea.firmament.util.prepend
import moe.nea.firmament.util.reconstitute import moe.nea.firmament.util.reconstitute
import moe.nea.firmament.util.removeColorCodes
import moe.nea.firmament.util.skyBlockId import moe.nea.firmament.util.skyBlockId
import moe.nea.firmament.util.skyblock.ItemType import moe.nea.firmament.util.skyblock.ItemType
import moe.nea.firmament.util.skyblock.Rarity import moe.nea.firmament.util.skyblock.Rarity
@@ -352,7 +353,7 @@ data class SBItemStack constructor(
val breakingPower: Int val breakingPower: Int
get() = get() =
BREAKING_POWER_REGEX.useMatch(asImmutableItemStack().loreAccordingToNbt.firstOrNull()?.string) { BREAKING_POWER_REGEX.useMatch(neuItem?.lore?.firstOrNull()?.removeColorCodes()) {
group("power").toInt() group("power").toInt()
} ?: 0 } ?: 0

View File

@@ -134,6 +134,11 @@
"firmament.config.item-rarity-cosmetics.background-hotbar": "Hotbar Background Rarity", "firmament.config.item-rarity-cosmetics.background-hotbar": "Hotbar Background Rarity",
"firmament.config.item-rarity-cosmetics.background-hotbar.description": "Show item rarity background in the hotbar.", "firmament.config.item-rarity-cosmetics.background-hotbar.description": "Show item rarity background in the hotbar.",
"firmament.config.item-rarity-cosmetics.background.description": "Show a background behind each item, depending on its rarity.", "firmament.config.item-rarity-cosmetics.background.description": "Show a background behind each item, depending on its rarity.",
"firmament.config.jade-integration": "Jade / WAILA",
"firmament.config.jade-integration.blocks": "Enable Custom Blocks",
"firmament.config.jade-integration.blocks.description": "Show custom block descriptions and hardness levels in Jade.",
"firmament.config.jade-integration.progress": "Enable Custom Mining Progress",
"firmament.config.jade-integration.progress.description": "Show the custom mining progress in Jade, when in a world with mining fatigue.",
"firmament.config.lore-timers": "Lore Timers", "firmament.config.lore-timers": "Lore Timers",
"firmament.config.lore-timers.format": "Time Format", "firmament.config.lore-timers.format": "Time Format",
"firmament.config.lore-timers.format.choice.american": "§9Ame§cri§fcan", "firmament.config.lore-timers.format.choice.american": "§9Ame§cri§fcan",