aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-02-03 13:54:38 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-02-03 13:54:38 +0100
commitc52288a82a8b4db9fd47ce2a46ebc94ff51fda7d (patch)
treed859f5888061d1eda3521cdc2d23a8b285f49c30 /src/main
parent9ed03f2b5168f07b355ff33a33f1359a395a5fa3 (diff)
downloadskyhanni-c52288a82a8b4db9fd47ce2a46ebc94ff51fda7d.tar.gz
skyhanni-c52288a82a8b4db9fd47ce2a46ebc94ff51fda7d.tar.bz2
skyhanni-c52288a82a8b4db9fd47ce2a46ebc94ff51fda7d.zip
MinionCraftHelper
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/Features.java5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/Minions.java16
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/minion/MinionCraftHelper.kt130
4 files changed, 153 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
index d2c427ff5..e4b190fe2 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
@@ -26,6 +26,7 @@ import at.hannibal2.skyhanni.features.fishing.*;
import at.hannibal2.skyhanni.features.inventory.*;
import at.hannibal2.skyhanni.features.itemabilities.FireVeilWandParticles;
import at.hannibal2.skyhanni.features.itemabilities.abilitycooldown.ItemAbilityCooldown;
+import at.hannibal2.skyhanni.features.minion.MinionCraftHelper;
import at.hannibal2.skyhanni.features.minion.MinionFeatures;
import at.hannibal2.skyhanni.features.misc.*;
import at.hannibal2.skyhanni.features.misc.tiarelay.TiaRelayHelper;
@@ -183,6 +184,7 @@ public class SkyHanniMod {
loadModule(new TiaRelayWaypoints());
loadModule(new BingoCardDisplay());
loadModule(new BingoNextStepHelper());
+ loadModule(new MinionCraftHelper());
Commands.INSTANCE.init();
diff --git a/src/main/java/at/hannibal2/skyhanni/config/Features.java b/src/main/java/at/hannibal2/skyhanni/config/Features.java
index effa92726..40fce3437 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/Features.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/Features.java
@@ -126,6 +126,11 @@ public class Features extends Config {
editOverlay(activeConfigCategory, 200, 16, fishing.sharkFishCounterPos);
return;
}
+
+ if (runnableId.equals("minionCraftHelper")) {
+ editOverlay(activeConfigCategory, 200, 16, minions.minionCraftHelperPos);
+ return;
+ }
}
@Expose
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Minions.java b/src/main/java/at/hannibal2/skyhanni/config/features/Minions.java
index d29eb45bd..8d2963ea8 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/Minions.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/Minions.java
@@ -82,6 +82,22 @@ public class Minions {
@ConfigAccordionId(id = 2)
public Position hopperProfitPos = new Position(10, 10, false, true);
+ @ConfigOption(name = "Minion Craft Helper", desc = "")
+ @ConfigEditorAccordion(id = 3)
+ public boolean minionCraftHelper = false;
+
+ @Expose
+ @ConfigOption(name = "Minion Craft Helper", desc = "Show how many more items you need to upgrade the minion in your inventory. Especially useful for bingo.")
+ @ConfigEditorBoolean
+ @ConfigAccordionId(id = 3)
+ public boolean minionCraftHelperEnabled = false;
+
+ @Expose
+ @ConfigOption(name = "Minion Craft Helper Position", desc = "")
+ @ConfigEditorButton(runnableId = "minionCraftHelper", buttonText = "Edit")
+ @ConfigAccordionId(id = 3)
+ public Position minionCraftHelperPos = new Position(10, 10, false, true);
+
@Expose
@ConfigOption(name = "Hide Mob Nametag", desc = "Hiding the nametag of mobs close to minions")
@ConfigEditorBoolean
diff --git a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionCraftHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionCraftHelper.kt
new file mode 100644
index 000000000..cfaa2fe10
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionCraftHelper.kt
@@ -0,0 +1,130 @@
+package at.hannibal2.skyhanni.features.minion
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.utils.ItemUtils.name
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal
+import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
+import at.hannibal2.skyhanni.utils.StringUtils.removeColor
+import io.github.moulberry.notenoughupdates.NotEnoughUpdates
+import io.github.moulberry.notenoughupdates.recipes.CraftingRecipe
+import io.github.moulberry.notenoughupdates.recipes.NeuRecipe
+import net.minecraft.client.Minecraft
+import net.minecraftforge.client.event.RenderGameOverlayEvent
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import net.minecraftforge.fml.common.gameevent.TickEvent
+import java.util.regex.Pattern
+
+class MinionCraftHelper {
+
+ private var minionNamePattern = Pattern.compile("(.*) Minion (.*)")
+
+ var tick = 0
+ var display = mutableListOf<String>()
+
+ @SubscribeEvent
+ fun onTick(event: TickEvent.ClientTickEvent) {
+ if (event.phase != TickEvent.Phase.START) return
+ if (!LorenzUtils.inSkyBlock) return
+ if (!SkyHanniMod.feature.minions.minionCraftHelperEnabled) return
+
+ tick++
+ if (tick % 5 != 0) return
+
+ val mainInventory = Minecraft.getMinecraft()?.thePlayer?.inventory?.mainInventory ?: return
+
+ val minions = mutableMapOf<String, String>()
+ val otherItems = mutableMapOf<String, Int>()
+
+ for (item in mainInventory) {
+ val name = item?.name?.removeColor() ?: continue
+ if (name.contains(" Minion ")) {
+ val minionId = NotEnoughUpdates.INSTANCE.manager.createItemResolutionQuery()
+ .withItemStack(item)
+ .resolveInternalName() ?: continue
+ minions[name] = minionId
+ } else {
+ val (itemName, multiplier) = getMultiplier(name)
+ val old = otherItems.getOrDefault(itemName, 0)
+ otherItems[itemName] = old + item.stackSize * multiplier
+ }
+ }
+
+ display.clear()
+ for ((minionName, minionId) in minions) {
+ val matcher = minionNamePattern.matcher(minionName)
+ if (!matcher.matches()) return
+ val cleanName = matcher.group(1).removeColor()
+ val number = matcher.group(2).romanToDecimal()
+ addMinion(cleanName, number, minionId, otherItems)
+ }
+ }
+
+ 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,
+ minionId: String,
+ otherItems: MutableMap<String, Int>
+ ) {
+ val nextNumber = minionNumber + 1
+ display.add("$minionName Minion $minionNumber -> $nextNumber")
+ val recipes: List<NeuRecipe> = NotEnoughUpdates.INSTANCE.manager.getAvailableUsagesFor(minionId)
+ for (recipe in recipes) {
+ if (recipe !is CraftingRecipe) continue
+ val output = recipe.output
+ val internalItemId = output.internalItemId
+ if (!internalItemId.contains("_GENERATOR_")) continue
+ val map = mutableMapOf<String, Int>()
+ 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
+ }
+ }
+ for ((name, need) in map) {
+ val (itemName, multiplier) = getMultiplier(name)
+ val needAmount = need * multiplier
+ val have = otherItems.getOrDefault(itemName, 0)
+ val percentage = have.toDouble() / needAmount
+ if (percentage >= 1) {
+ display.add(" $itemName§8: §aDONE")
+ display.add(" ")
+ otherItems[itemName] = have - needAmount
+ addMinion(minionName, minionNumber + 1, minionId.addOneToId(), otherItems)
+ } else {
+ val format = LorenzUtils.formatPercentage(percentage)
+ val haveFormat = LorenzUtils.formatInteger(have)
+ val needFormat = LorenzUtils.formatInteger(needAmount)
+ display.add("$itemName§8: §e$format §8(§7$haveFormat§8/§7$needFormat§8)")
+ display.add(" ")
+ }
+ }
+ }
+ }
+
+ @SubscribeEvent
+ fun onRenderOverlay(event: RenderGameOverlayEvent.Post) {
+ if (event.type != RenderGameOverlayEvent.ElementType.ALL) return
+ if (!LorenzUtils.inSkyBlock) return
+ if (!SkyHanniMod.feature.minions.minionCraftHelperEnabled) return
+
+ SkyHanniMod.feature.minions.minionCraftHelperPos.renderStrings(display, center = true)
+ }
+}
+
+private fun String.addOneToId(): String {
+ val split = split("_")
+ val lastText = split.last()
+ val next = lastText.toInt() + 1
+ val result = replace(lastText, "" + next)
+ return result
+}