Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend: Cleanup Forge Gfs #2434

Merged
merged 3 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 9 additions & 20 deletions src/main/java/at/hannibal2/skyhanni/features/mining/ForgeGfs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
Loading