Skip to content

Commit

Permalink
Create countItems, remove isDerpy, fix translator
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatGravyBoat committed May 14, 2024
1 parent 104eff0 commit d4a0311
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/api/EntityAttributeAPI.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package at.hannibal2.skyhanni.api

import at.hannibal2.skyhanni.data.Perk
import at.hannibal2.skyhanni.events.EntityMaxHealthUpdateEvent
import at.hannibal2.skyhanni.events.entity.EntityAttributeUpdateEvent
import at.hannibal2.skyhanni.utils.LorenzUtils
import net.minecraft.entity.EntityLivingBase
import net.minecraft.entity.SharedMonsterAttributes
import net.minecraft.entity.item.EntityArmorStand
Expand Down Expand Up @@ -31,7 +31,7 @@ object EntityAttributeAPI {
// TODO Check for runic and corrupted mobs
private fun normalizeHealth(maxHealth: Double): Int {
return when {
LorenzUtils.isDerpy -> maxHealth / 2.0
Perk.DOUBLE_MOBS_HP.isActive -> maxHealth / 2.0
else -> maxHealth
}.toInt()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package at.hannibal2.skyhanni.features.dungeon
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.storage.ProfileSpecificStorage.DungeonStorage.DungeonRunInfo
import at.hannibal2.skyhanni.data.ProfileStorageData
import at.hannibal2.skyhanni.data.SackAPI.getAmountInSacks
import at.hannibal2.skyhanni.data.item.SkyhanniItems
import at.hannibal2.skyhanni.events.DungeonCompleteEvent
import at.hannibal2.skyhanni.events.GuiContainerEvent
Expand All @@ -15,7 +14,6 @@ import at.hannibal2.skyhanni.features.dungeon.DungeonAPI.DungeonChest
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.InventoryUtils.getAmountInInventory
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzColor
Expand All @@ -25,6 +23,7 @@ import at.hannibal2.skyhanni.utils.RenderUtils.highlight
import at.hannibal2.skyhanni.utils.StringUtils.anyMatches
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.matches
import at.hannibal2.skyhanni.utils.mc.McPlayer
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.init.Items
import net.minecraft.item.ItemStack
Expand Down Expand Up @@ -114,7 +113,7 @@ class CroesusChestTracker {
private fun kismetDungeonChestSetup(event: InventoryFullyOpenedEvent) {
chestInventory = DungeonChest.getByInventoryName(event.inventoryName) ?: return
if (config.kismetStackSize) {
kismetAmountCache = getKismetAmount()
kismetAmountCache = McPlayer.countItems(SkyhanniItems.KISMET_FEATHER(), true)
}
if (config.showUsedKismets) {
val kismetItem = event.inventoryItems[kismetSlotId] ?: return
Expand Down Expand Up @@ -240,9 +239,6 @@ class CroesusChestTracker {

private fun getKismetUsed(runIndex: Int) = getRun0(runIndex)?.kismetUsed ?: false

private fun getKismetAmount() =
SkyhanniItems.KISMET_FEATHER().getAmountInSacks() + SkyhanniItems.KISMET_FEATHER().getAmountInInventory()

private fun croesusSlotMapToRun(slotId: Int) = when (slotId) {
in 10..16 -> slotId - 10 // 0 - 6
in 19..25 -> slotId - 12 // 7 - 13
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ object DianaAPI {

fun hasGriffinPet() = PetAPI.isCurrentPet("Griffin")

fun isDoingDiana() = IslandType.HUB.isInIsland() && isRitualActive() && hasSpadeInInventory()
fun isDoingDiana() = IslandType.HUB.isInIsland() && isRitualActive() && McPlayer.has(spade, true)

val ItemStack.isDianaSpade get() = getInternalName() == spade

private fun hasSpadeInInventory() = McPlayer.has(spade)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.CollectionUtils.sortedDesc
import at.hannibal2.skyhanni.utils.ConfigUtils
import at.hannibal2.skyhanni.utils.HypixelCommands
import at.hannibal2.skyhanni.utils.InventoryUtils.getAmountInInventory
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.KeyboardManager
import at.hannibal2.skyhanni.utils.LorenzUtils
Expand All @@ -45,6 +44,7 @@ import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.datetime.TimeUtils.format
import at.hannibal2.skyhanni.utils.mc.McPlayer
import at.hannibal2.skyhanni.utils.mc.McSound
import at.hannibal2.skyhanni.utils.mc.McSound.play
import at.hannibal2.skyhanni.utils.renderables.Renderable
Expand Down Expand Up @@ -484,7 +484,7 @@ object ComposterOverlay {
BazaarApi.searchForBazaarItem(itemName, itemsNeeded)
return
}
val havingInInventory = internalName.getAmountInInventory()
val havingInInventory = McPlayer.countItems(internalName)
if (havingInInventory >= itemsNeeded) {
ChatUtils.chat("$itemName §8x${itemsNeeded} §ealready found in inventory!")
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package at.hannibal2.skyhanni.features.garden.visitor
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.config.features.garden.visitor.VisitorConfig.HighlightMode
import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.data.SackAPI.getAmountInSacks
import at.hannibal2.skyhanni.data.SackAPI.getAmountInSacksOrNull
import at.hannibal2.skyhanni.data.item.SkyhanniItems
import at.hannibal2.skyhanni.events.DebugDataCollectEvent
Expand All @@ -29,7 +28,6 @@ import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.ConfigUtils
import at.hannibal2.skyhanni.utils.InventoryUtils.getAmountInInventory
import at.hannibal2.skyhanni.utils.ItemBlink
import at.hannibal2.skyhanni.utils.ItemUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
Expand All @@ -54,6 +52,7 @@ import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.datetime.TimeUtils.format
import at.hannibal2.skyhanni.utils.getLorenzVec
import at.hannibal2.skyhanni.utils.mc.McPlayer
import at.hannibal2.skyhanni.utils.mc.McWorld
import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
Expand Down Expand Up @@ -541,8 +540,7 @@ object GardenVisitorFeatures {
private fun hasItems(visitor: VisitorAPI.Visitor): Boolean {
var ready = true
for ((internalName, required) in visitor.shoppingList) {
val having = internalName.getAmountInInventory() + internalName.getAmountInSacks()
if (having < required) {
if (McPlayer.countItems(internalName, true) < required) {
ready = false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import at.hannibal2.skyhanni.events.GuiContainerEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.features.inventory.bazaar.BazaarApi.Companion.getBazaarDataOrError
import at.hannibal2.skyhanni.utils.InventoryUtils.getAmountInInventory
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.itemName
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NumberUtil
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
import at.hannibal2.skyhanni.utils.mc.McPlayer
import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
Expand Down Expand Up @@ -48,7 +48,7 @@ class BazaarBestSellMethod {
if (internalName == null) {
return "§cUnknown Bazaar item!"
}
var having = internalName.getAmountInInventory()
var having = McPlayer.countItems(internalName)
lastClickedItem?.let {
if (it.getInternalName() == internalName) {
having += it.stackSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ object VerminTracker {
@SubscribeEvent
fun onSecondPassed(event: SecondPassedEvent) {
if (!RiftAPI.inRift()) return
hasVacuum = McPlayer.has(SkyhanniItems.TURBOMAX_VACUUM())
hasVacuum = McPlayer.has(SkyhanniItems.TURBOMAX_VACUUM(), true)
}

@SubscribeEvent
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/utils/EntityUtils.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.utils

import at.hannibal2.skyhanni.data.Perk
import at.hannibal2.skyhanni.data.mob.MobFilter.isRealPlayer
import at.hannibal2.skyhanni.events.SkyHanniRenderEntityEvent
import at.hannibal2.skyhanni.features.dungeon.DungeonAPI
Expand Down Expand Up @@ -86,7 +87,7 @@ object EntityUtils {

// TODO remove baseMaxHealth
fun EntityLivingBase.hasMaxHealth(health: Int, boss: Boolean = false, maxHealth: Int = baseMaxHealth): Boolean {
val derpyMultiplier = if (LorenzUtils.isDerpy) 2 else 1
val derpyMultiplier = if (Perk.DOUBLE_MOBS_HP.isActive) 2 else 1
if (maxHealth == health * derpyMultiplier) return true

if (!boss && !DungeonAPI.inDungeon()) {
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package at.hannibal2.skyhanni.utils

import at.hannibal2.skyhanni.data.item.SkyhanniItems
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull
import at.hannibal2.skyhanni.utils.mc.McPlayer
import io.github.moulberry.notenoughupdates.NotEnoughUpdates
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.inventory.GuiChest
Expand Down Expand Up @@ -89,7 +87,4 @@ object InventoryUtils {
fun getItemAtSlotIndex(slotIndex: Int): ItemStack? {
return getItemsInOpenChest().find { it.slotIndex == slotIndex }?.stack
}

// TODO add a method that also can include the amounts in your sacks
fun NEUInternalName.getAmountInInventory(): Int = McPlayer.countItems { it.getInternalNameOrNull() == this }
}
9 changes: 2 additions & 7 deletions src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,9 @@ object LorenzUtils {
}
}

private val recalculateDerpy =
RecalculatingValue(1.seconds) { Perk.DOUBLE_MOBS_HP.isActive }
fun Int.derpy() = if (Perk.DOUBLE_MOBS_HP.isActive) this / 2 else this

val isDerpy get() = recalculateDerpy.getValue()

fun Int.derpy() = if (isDerpy) this / 2 else this

fun Int.ignoreDerpy() = if (isDerpy) this * 2 else this
fun Int.ignoreDerpy() = if (Perk.DOUBLE_MOBS_HP.isActive) this * 2 else this

fun runDelayed(duration: Duration, runnable: () -> Unit) {
Timer().schedule(object : TimerTask() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ object GoogleTranslator {
private const val URL = "https://translate.google.com/translate_a/single"
private val GSON = Gson()

data class Sentence(val text: String, val from: String, val to: String)
data class Sentence(val trans: String, val orig: String)
data class Translation(val sentences: List<Sentence>, val src: String) {

val text: String get() = sentences.joinToString(" ") { it.text }
val text: String get() = sentences.joinToString(" ") { it.trans }
}

open class Error(val error: String, val message: String) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/utils/mc/McPlayer.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.utils.mc

import at.hannibal2.skyhanni.data.SackAPI.getAmountInSacks
import at.hannibal2.skyhanni.utils.ItemCategory
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull
import at.hannibal2.skyhanni.utils.ItemUtils.getItemCategoryOrNull
Expand Down Expand Up @@ -49,6 +50,8 @@ object McPlayer {
val boots: ItemStack? get() = armor[0]

fun countItems(predicate: (ItemStack) -> Boolean) = inventory.filter(predicate).sumOf { it.stackSize }
fun countItems(item: NEUInternalName, checkSacks: Boolean = false) =
countItems { it.getInternalNameOrNull() == item } + if (checkSacks) item.getAmountInSacks() else 0

fun has(item: NEUInternalName, onlyHotBar: Boolean = false) =
(if (onlyHotBar) hotbar else inventory).any { it.getInternalNameOrNull() == item }
Expand Down

0 comments on commit d4a0311

Please sign in to comment.