From a3a447bd118aa45c14ec30d16ad1f516d8424f51 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sun, 5 Feb 2023 17:22:09 +0100 Subject: Add support for different tiers of items in MinionCraftHelper. --- .../skyhanni/features/minion/MinionCraftHelper.kt | 80 +++++++++++++++------- 1 file changed, 57 insertions(+), 23 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni') diff --git a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionCraftHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionCraftHelper.kt index cfaa2fe10..3181141fd 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionCraftHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionCraftHelper.kt @@ -18,9 +18,9 @@ import java.util.regex.Pattern class MinionCraftHelper { private var minionNamePattern = Pattern.compile("(.*) Minion (.*)") - - var tick = 0 - var display = mutableListOf() + private var tick = 0 + private var display = mutableListOf() + private var hasMinionInInventory = false @SubscribeEvent fun onTick(event: TickEvent.ClientTickEvent) { @@ -29,7 +29,18 @@ class MinionCraftHelper { if (!SkyHanniMod.feature.minions.minionCraftHelperEnabled) return tick++ + + if (tick % 60 == 0) { + val mainInventory = Minecraft.getMinecraft()?.thePlayer?.inventory?.mainInventory ?: return + hasMinionInInventory = mainInventory + .mapNotNull { it?.name?.removeColor() } + .any { it.contains(" Minion ") } + } + + if (!hasMinionInInventory) return + if (tick % 5 != 0) return +// if (tick % 60 != 0) return val mainInventory = Minecraft.getMinecraft()?.thePlayer?.inventory?.mainInventory ?: return @@ -38,15 +49,15 @@ class MinionCraftHelper { for (item in mainInventory) { val name = item?.name?.removeColor() ?: continue + val rawId = NotEnoughUpdates.INSTANCE.manager.createItemResolutionQuery() + .withItemStack(item) + .resolveInternalName() ?: continue if (name.contains(" Minion ")) { - val minionId = NotEnoughUpdates.INSTANCE.manager.createItemResolutionQuery() - .withItemStack(item) - .resolveInternalName() ?: continue - minions[name] = minionId + minions[name] = rawId } else { - val (itemName, multiplier) = getMultiplier(name) - val old = otherItems.getOrDefault(itemName, 0) - otherItems[itemName] = old + item.stackSize * multiplier + val (itemId, multiplier) = getMultiplier(rawId) + val old = otherItems.getOrDefault(itemId, 0) + otherItems[itemId] = old + item.stackSize * multiplier } } @@ -60,12 +71,6 @@ class MinionCraftHelper { } } - private fun getMultiplier(name: String) = if (name.startsWith("Enchanted")) { - Pair(name.substring(10), 160) - } else { - Pair(name, 1) - } - private fun addMinion( minionName: String, minionNumber: Int, @@ -84,21 +89,24 @@ class MinionCraftHelper { for (input in recipe.inputs) { val itemId = input.internalItemId if (minionId != itemId) { - val itemName = input.itemStack.name?.removeColor()!! val count = input.count.toInt() - val old = map.getOrDefault(itemName, 0) - map[itemName] = old + count + val old = map.getOrDefault(itemId, 0) + map[itemId] = old + count } } - for ((name, need) in map) { - val (itemName, multiplier) = getMultiplier(name) + for ((rawId, need) in map) { +// println("need rawId: $rawId") + val (itemId, multiplier) = getMultiplier(rawId) val needAmount = need * multiplier - val have = otherItems.getOrDefault(itemName, 0) + val have = otherItems.getOrDefault(itemId, 0) val percentage = have.toDouble() / needAmount + val itemName = NotEnoughUpdates.INSTANCE.manager.createItemResolutionQuery() + .withKnownInternalName(rawId) + .resolveToItemStack()?.name ?: "§cName??§f" if (percentage >= 1) { display.add(" $itemName§8: §aDONE") display.add(" ") - otherItems[itemName] = have - needAmount + otherItems[itemId] = have - needAmount addMinion(minionName, minionNumber + 1, minionId.addOneToId(), otherItems) } else { val format = LorenzUtils.formatPercentage(percentage) @@ -128,3 +136,29 @@ private fun String.addOneToId(): String { val result = replace(lastText, "" + next) return result } + +private fun getMultiplier(rawId: String): Pair { + if (rawId == "MELON_BLOCK") { + return Pair("MELON", 9) + } + if (rawId == "HAY_BLOCK") { + return Pair("WHEAT", 9) + } + if (rawId == "ENCHANTED_HAY_BLOCK") { + return Pair("WHEAT", 9 * 16 * 9) + } + if (rawId == "PACKED_ICE") { + return Pair("ICE", 9) + } + if (rawId == "ENCHANTED_MITHRIL") { + return Pair("MITHRIL_ORE", 160) + } + if (rawId == "ENCHANTED_GOLD") { + return Pair("GOLD_INGOT", 160) + } + return if (rawId.startsWith("ENCHANTED_")) { + Pair(rawId.substring(10), 160) + } else { + Pair(rawId, 1) + } +} -- cgit