Skip to content

Commit

Permalink
extract duplicate code into ItemUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
hannibal002 committed May 16, 2024
1 parent 8d4a3f5 commit 4cde1ae
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import at.hannibal2.skyhanni.utils.DisplayTableEntry
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.itemName
import at.hannibal2.skyhanni.utils.ItemUtils.loreCosts
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.round
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUItems.getPrice
import at.hannibal2.skyhanni.utils.NEUItems.getPriceOrNull
import at.hannibal2.skyhanni.utils.NumberUtil
Expand All @@ -22,7 +22,6 @@ import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import com.google.gson.JsonPrimitive
import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

class SkyMartCopperPrice {
Expand All @@ -40,25 +39,6 @@ class SkyMartCopperPrice {
var inInventory = false
}

private fun ItemStack.loreCosts(): MutableList<NEUInternalName> {
var found = false
val list = mutableListOf<NEUInternalName>()
for (lines in getLore()) {
if (lines == "§7Cost") {
found = true
continue
}

if (!found) continue
if (lines.isEmpty()) return list

NEUInternalName.fromItemNameOrNull(lines)?.let {
list.add(it)
}
}
return list
}

@SubscribeEvent
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
if (!isEnabled()) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import at.hannibal2.skyhanni.utils.DisplayTableEntry
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.itemName
import at.hannibal2.skyhanni.utils.ItemUtils.loreCosts
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUItems.getPrice
import at.hannibal2.skyhanni.utils.NEUItems.getPriceOrNull
import at.hannibal2.skyhanni.utils.NumberUtil
Expand Down Expand Up @@ -50,25 +50,6 @@ object ChocolateShopPrice {
update()
}

private fun ItemStack.loreCosts(): MutableList<NEUInternalName> {
var found = false
val list = mutableListOf<NEUInternalName>()
for (lines in getLore()) {
if (lines == "§7Cost") {
found = true
continue
}

if (!found) continue
if (lines.isEmpty()) return list

NEUInternalName.fromItemNameOrNull(lines)?.let {
list.add(it)
}
}
return list
}

private fun update() {
val multiplier = 1.million
// TODO merge core with SkyMartCopperPrice into a utils
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -386,4 +386,23 @@ object ItemUtils {
}
return name
}

fun ItemStack.loreCosts(): MutableList<NEUInternalName> {
var found = false
val list = mutableListOf<NEUInternalName>()
for (lines in getLore()) {
if (lines == "§7Cost") {
found = true
continue
}

if (!found) continue
if (lines.isEmpty()) return list

NEUInternalName.fromItemNameOrNull(lines)?.let {
list.add(it)
}
}
return list
}
}

0 comments on commit 4cde1ae

Please sign in to comment.