aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThunderblade73 <85900443+Thunderblade73@users.noreply.github.com>2024-09-07 21:32:20 +0200
committerGitHub <noreply@github.com>2024-09-07 21:32:20 +0200
commit321188e2828284484718a78ecaf9e7a98905d658 (patch)
tree6f22a6ad68977d6e20c53cc7f559f501dadb76cc /src
parente657a74d8ef21bfc05873b5a2dcd73b6c1b8503f (diff)
downloadskyhanni-321188e2828284484718a78ecaf9e7a98905d658.tar.gz
skyhanni-321188e2828284484718a78ecaf9e7a98905d658.tar.bz2
skyhanni-321188e2828284484718a78ecaf9e7a98905d658.zip
Backend: Cleanup Forge Gfs (#2434)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/mining/ForgeGfs.kt29
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/PrimitiveItemStack.kt4
4 files changed, 18 insertions, 23 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/ForgeGfs.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/ForgeGfs.kt
index 28f117832..995198674 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/mining/ForgeGfs.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/mining/ForgeGfs.kt
@@ -8,12 +8,13 @@ import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.InventoryUpdatedEvent
import at.hannibal2.skyhanni.events.render.gui.ReplaceItemEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
-import at.hannibal2.skyhanni.utils.ChatUtils
+import at.hannibal2.skyhanni.utils.CollectionUtils
+import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut
import at.hannibal2.skyhanni.utils.ItemUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull
-import at.hannibal2.skyhanni.utils.ItemUtils.itemNameWithoutColor
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUInternalName
+import at.hannibal2.skyhanni.utils.PrimitiveItemStack.Companion.makePrimitiveStack
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.client.player.inventory.ContainerLocalMenu
@@ -78,27 +79,15 @@ object ForgeGfs {
// Search for the first 4 columns only
// Normally would be 3, but the gemstone mixture is the only one that overflows to 4
- for (i in 0..53) {
- if (i % 9 <= 3) {
- val currentItem = event.container.getSlot(i).stack
- val amount = currentItem.stackSize
- val currItemInternalName = currentItem.getInternalNameOrNull() ?: continue
- if (SackAPI.sackListInternalNames.contains(currItemInternalName.asString())) {
- itemMap.addAndFold(currItemInternalName, amount)
- }
+ for (i in CollectionUtils.takeColumn(0, 53, 0, 4)) {
+ val currentItem = event.container.getSlot(i).stack
+ val currItemInternalName = currentItem.getInternalNameOrNull() ?: continue
+ if (SackAPI.sackListInternalNames.contains(currItemInternalName.asString())) {
+ itemMap.addOrPut(currItemInternalName, currentItem.stackSize)
}
}
- for ((internalName, amount) in itemMap) {
- val getItYet = GetFromSackAPI.getFromSack(internalName, amount)
- if (!getItYet) {
- ChatUtils.chat("§cFailed to get $amount ${internalName.itemNameWithoutColor} from sacks.")
- }
- }
- }
-
- private fun MutableMap<NEUInternalName, Int>.addAndFold(key: NEUInternalName, value: Int) {
- this[key] = this.getOrDefault(key, 0) + value
+ GetFromSackAPI.getFromSack(itemMap.map { it.key.makePrimitiveStack(it.value) })
}
fun isEnabled() = LorenzUtils.inSkyBlock && config.forgeGfs
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt
index 9590ba5c1..56bdcfabd 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt
@@ -288,6 +288,10 @@ object CollectionUtils {
add(Renderable.itemStack(itemStack, scale = scale))
}
+ fun takeColumn(start: Int, end: Int, startColumn: Int, endColumn: Int, rowSize: Int = 9) =
+ generateSequence(start) { it + 1 }.map { (it / (endColumn - startColumn)) * rowSize + (it % (endColumn - startColumn)) + startColumn }
+ .takeWhile { it <= end }
+
fun MutableList<Renderable>.addItemStack(internalName: NEUInternalName) {
addItemStack(internalName.getItemStack())
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
index c271ef66c..81eb2968c 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
@@ -14,9 +14,9 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NumberUtil.isInt
import at.hannibal2.skyhanni.utils.PrimitiveItemStack.Companion.makePrimitiveStack
+import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getItemId
import at.hannibal2.skyhanni.utils.json.BaseGsonBuilder
import at.hannibal2.skyhanni.utils.json.fromJson
-import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getItemId
import at.hannibal2.skyhanni.utils.system.PlatformUtils
import com.google.gson.JsonObject
import com.google.gson.JsonPrimitive
@@ -343,7 +343,7 @@ object NEUItems {
val id = current.first
return if (current.second > 1) {
val child = getPrimitiveMultiplier(id, tryCount + 1)
- val result = child.multiply(current.second)
+ val result = child * current.second
multiplierCache[internalName] = result
result
} else {
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/PrimitiveItemStack.kt b/src/main/java/at/hannibal2/skyhanni/utils/PrimitiveItemStack.kt
index 2173fcc8f..52faaba30 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/PrimitiveItemStack.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/PrimitiveItemStack.kt
@@ -9,7 +9,9 @@ data class PrimitiveItemStack(val internalName: NEUInternalName, val amount: Int
fun createItem(): ItemStack = internalName.getItemStack().apply { stackSize = amount }
- fun multiply(multiplier: Int): PrimitiveItemStack = PrimitiveItemStack(internalName, amount * multiplier)
+ operator fun times(multiplier: Int): PrimitiveItemStack = PrimitiveItemStack(internalName, amount * multiplier)
+
+ operator fun plus(amount: Int): PrimitiveItemStack = PrimitiveItemStack(internalName, this.amount + amount)
val itemName by lazy { internalName.itemName }