diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java | 4 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt | 13 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/OtherInventoryData.kt (renamed from src/main/java/at/hannibal2/skyhanni/data/InventoryData.kt) | 2 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt | 121 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/events/InventoryCloseEvent.kt | 10 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/events/InventoryOpenEvent.kt | 8 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt | 1 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/minion/MinionCollectLogic.kt | 66 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt | 19 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt | 33 |
10 files changed, 194 insertions, 83 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index 7c06076de..be749d95a 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -28,6 +28,7 @@ import at.hannibal2.skyhanni.features.garden.*; 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.MinionCollectLogic; import at.hannibal2.skyhanni.features.minion.MinionFeatures; import at.hannibal2.skyhanni.features.misc.*; import at.hannibal2.skyhanni.features.misc.tiarelay.TiaRelayHelper; @@ -116,7 +117,7 @@ public class SkyHanniMod { loadModule(new ItemTipHelper()); loadModule(new RenderLivingEntityHelper()); loadModule(new SkillExperience()); - loadModule(new InventoryData()); + loadModule(new OtherInventoryData()); loadModule(new TabListData()); loadModule(new RenderGuiData()); loadModule(new GardenCropMilestones()); @@ -238,6 +239,7 @@ public class SkyHanniMod { loadModule(new AnitaMedalProfit()); loadModule(new ComposterDisplay()); loadModule(new GardenComposterInventoryFeatures()); + loadModule(new MinionCollectLogic()); Commands.INSTANCE.init(); diff --git a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt index d8c5f35de..733e8709f 100644 --- a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt @@ -8,6 +8,7 @@ import at.hannibal2.skyhanni.features.bazaar.BazaarApi import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.regex.Pattern @@ -27,7 +28,7 @@ class CollectionAPI { @SubscribeEvent fun onProfileDataLoad(event: ProfileApiDataLoadedEvent) { val profileData = event.profileData - val jsonElement = profileData["collection"]?: return + val jsonElement = profileData["collection"] ?: return val asJsonObject = jsonElement.asJsonObject ?: return for ((rawName, rawCounter) in asJsonObject.entrySet()) { val counter = rawCounter.asLong @@ -116,5 +117,15 @@ class CollectionAPI { } return null } + + // TODO add support for replenish (higher collection than actual items in inv) + fun addFromInventory(internalName: String, amount: Int) { + val name = NEUItems.getItemStack(internalName).name?.removeColor() ?: return + + val oldValue = collectionValue[name] ?: return + + val newValue = oldValue + amount + collectionValue[name] = newValue + } } }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/data/InventoryData.kt b/src/main/java/at/hannibal2/skyhanni/data/OtherInventoryData.kt index d3630c159..580383e0c 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/InventoryData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/OtherInventoryData.kt @@ -7,7 +7,7 @@ import net.minecraft.network.play.server.S2FPacketSetSlot import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent -class InventoryData { +class OtherInventoryData { private var currentInventory: Inventory? = null private var acceptItems = false private var lateEvent: LateInventoryOpenEvent? = null diff --git a/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt b/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt index 1572468d8..dd6a37bcd 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt @@ -1,16 +1,23 @@ package at.hannibal2.skyhanni.data +import at.hannibal2.skyhanni.api.CollectionAPI +import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.OwnInventorItemUpdateEvent import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.features.bazaar.BazaarApi +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName +import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.NEUItems +import net.minecraft.item.ItemStack import net.minecraft.network.play.server.S2FPacketSetSlot +import net.minecraftforge.event.world.WorldEvent import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class OwnInventoryData { -// private var itemNames = mutableMapOf<Int, String>() -// private var itemAmount = mutableMapOf<Int, Int>() -// private var counter = mutableMapOf<String, Int>() + private var itemNames = mutableMapOf<Int, String>() + private var itemAmount = mutableMapOf<Int, Int>() @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true) fun onChatPacket(event: PacketEvent.ReceiveEvent) { @@ -22,57 +29,63 @@ class OwnInventoryData { OwnInventorItemUpdateEvent(item).postAndCatch() } } -// if (packet is S2FPacketSetSlot) { -//// println("S2FPacketSetSlot") -// val windowId = packet.func_149175_c() -// val item = packet.func_149174_e() -// val slot = packet.func_149173_d() -// if (windowId != 0) return -// -// val name = item?.name ?: "null" -// -// val oldItem = itemNames.getOrDefault(slot, "null") -// val oldAmount = itemAmount.getOrDefault(slot, 0) -// -//// println(" ") -//// println("windowId: $windowId") -// val amount = item?.stackSize ?: 0 -// if (name == oldItem) { -// if (amount > oldAmount) { -// val diff = amount - oldAmount -//// println("added $diff $name") -// add(name, diff) -// } -// } else { -// if (name != "null") { -//// println("added new $amount $name") -// add(name, amount) -// } -// } -//// println("$slot $oldItem x$oldAmount -> $name x$amount") -// itemNames[slot] = name -// itemAmount[slot] = amount -// } + if (packet is S2FPacketSetSlot) { + val windowId = packet.func_149175_c() + val item = packet.func_149174_e() + val slot = packet.func_149173_d() + if (windowId != 0) return + val name = item?.name ?: "null" + + val oldItem = itemNames.getOrDefault(slot, "null") + val oldAmount = itemAmount.getOrDefault(slot, 0) + + val amount = item?.stackSize ?: 0 + if (name == oldItem) { + val diff = amount - oldAmount + if (amount > oldAmount) { + add(item, diff) + } + } else { + if (name != "null") { + add(item, amount) + } + } + itemNames[slot] = name + itemAmount[slot] = amount + } + } + + @SubscribeEvent + fun onInventoryClose(event: InventoryCloseEvent) { + BazaarApi.inBazaarInventory = false + lastClose = System.currentTimeMillis() + } + + @SubscribeEvent + fun onWorldLoad(event: WorldEvent.Load) { + lastWorldSwitch = System.currentTimeMillis() } -// private fun add(name: String, add: Int) { -// if (name == "§fHay Bale") return -// if (name == "§fSeeds") return -// if (name.contains("Hoe")) return -// -// // TODO remove later -// if (name.contains("Mushroom")) return -// -//// println("added $add $name") -// val old = counter.getOrDefault(name, 0) -//// if (name == "§fWheat") { -//// if (old == 1502) { -//// old = 2504173 -//// } -//// } -// val new = old + add -// val format = LorenzUtils.formatInteger(new) -// println("have $name $format") -// counter[name] = new -// } + private var lastClose = 0L + private var lastWorldSwitch = 0L + + private fun add(item: ItemStack?, add: Int) { + if (item == null) return + + val diffClose = System.currentTimeMillis() - lastClose + if (diffClose < 500) return + + val diffWorld = System.currentTimeMillis() - lastWorldSwitch + if (diffWorld < 3_000) return + + val internalName = item.getInternalName() + val (_, amount) = NEUItems.getMultiplier(internalName) + if (amount > 1) return + + addMultiplier(internalName, add) + } + + private fun addMultiplier(internalName: String, amount: Int) { + CollectionAPI.addFromInventory(internalName, amount) + } }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/events/InventoryCloseEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/InventoryCloseEvent.kt index 8ff1f481b..2aa1ec65a 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/InventoryCloseEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/InventoryCloseEvent.kt @@ -1,5 +1,11 @@ package at.hannibal2.skyhanni.events -import at.hannibal2.skyhanni.data.InventoryData +import at.hannibal2.skyhanni.data.OtherInventoryData +import net.minecraft.item.ItemStack -class InventoryCloseEvent(val inventory: InventoryData.Inventory): LorenzEvent()
\ No newline at end of file +class InventoryCloseEvent(val inventory: OtherInventoryData.Inventory): LorenzEvent() { + val inventoryId: Int by lazy { inventory.windowId } + val inventoryName: String by lazy {inventory.title } + val inventorySize: Int by lazy {inventory.slotCount } + val inventoryItems: MutableMap<Int, ItemStack> by lazy {inventory.items } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/events/InventoryOpenEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/InventoryOpenEvent.kt index aec3e6542..3c95e4507 100644 --- a/src/main/java/at/hannibal2/skyhanni/events/InventoryOpenEvent.kt +++ b/src/main/java/at/hannibal2/skyhanni/events/InventoryOpenEvent.kt @@ -1,16 +1,16 @@ package at.hannibal2.skyhanni.events -import at.hannibal2.skyhanni.data.InventoryData +import at.hannibal2.skyhanni.data.OtherInventoryData import net.minecraft.item.ItemStack -open class BaseInventoryOpenEvent(inventory: InventoryData.Inventory): LorenzEvent() { +open class BaseInventoryOpenEvent(inventory: OtherInventoryData.Inventory): LorenzEvent() { val inventoryId: Int by lazy { inventory.windowId } val inventoryName: String by lazy {inventory.title } val inventorySize: Int by lazy {inventory.slotCount } val inventoryItems: MutableMap<Int, ItemStack> by lazy {inventory.items } } -class InventoryOpenEvent(inventory: InventoryData.Inventory): BaseInventoryOpenEvent(inventory) +class InventoryOpenEvent(inventory: OtherInventoryData.Inventory): BaseInventoryOpenEvent(inventory) // Firing with items that are added later -class LateInventoryOpenEvent(inventory: InventoryData.Inventory): BaseInventoryOpenEvent(inventory)
\ No newline at end of file +class LateInventoryOpenEvent(inventory: OtherInventoryData.Inventory): BaseInventoryOpenEvent(inventory)
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt index a1c632725..de36c15a8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt @@ -39,7 +39,6 @@ class GardenOptimalSpeed { } } - @SubscribeEvent fun onGuiOpen(event: GuiOpenEvent) { rancherOverlayList = CropType.values().map { crop -> diff --git a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionCollectLogic.kt b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionCollectLogic.kt new file mode 100644 index 000000000..d6f971ec3 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionCollectLogic.kt @@ -0,0 +1,66 @@ +package at.hannibal2.skyhanni.features.minion + +import at.hannibal2.skyhanni.api.CollectionAPI +import at.hannibal2.skyhanni.data.IslandType +import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.events.InventoryOpenEvent +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName +import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NEUItems +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class MinionCollectLogic { + private var oldMap = mapOf<String, Int>() + + @SubscribeEvent + fun onInventoryOpen(event: InventoryOpenEvent) { + if (!LorenzUtils.inSkyBlock) return + if (LorenzUtils.skyBlockIsland != IslandType.PRIVATE_ISLAND) return + if (!event.inventoryName.contains(" Minion ")) return + + event.inventoryItems[48]?.let { + if ("§aCollect All" == it.name) { + openMinion() + } + } + } + + private fun openMinion() { + if (oldMap.isNotEmpty()) return + oldMap = count() + } + + private fun count(): MutableMap<String, Int> { + val map = mutableMapOf<String, Int>() + for (stack in InventoryUtils.getItemsInOwnInventory()) { + val internalName = stack.getInternalName() + val (newId, amount) = NEUItems.getMultiplier(internalName) + val old = map[newId] ?: 0 + map[newId] = old + amount * stack.stackSize + } + return map + } + + // hypixel opens a new inventory after clicking on an item in minion inventory, InventoryCloseEvent is not usable here + @SubscribeEvent + fun onCloseWindow(event: GuiContainerEvent.CloseWindowEvent) { + closeMinion() + } + + private fun closeMinion() { + if (oldMap.isEmpty()) return + + for ((internalId, amount) in count()) { + val old = oldMap[internalId] ?: 0 + val diff = amount - old + + if (diff > 0) { + CollectionAPI.addFromInventory(internalId, diff) + } + } + + oldMap = emptyMap() + } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt index 53e39e575..7ef3ff968 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt @@ -40,9 +40,7 @@ object InventoryUtils { val chestName = if (guiChest is GuiChest) { val chest = guiChest.inventorySlots as ContainerChest chest.getInventoryName() - } else { - "" - } + } else "" return chestName } @@ -50,10 +48,19 @@ object InventoryUtils { return this.lowerChestInventory.displayName.unformattedText.trim() } + fun getItemsInOwnInventory(): MutableList<ItemStack> { + val list = mutableListOf<ItemStack>() + for (itemStack in Minecraft.getMinecraft().thePlayer.inventory.mainInventory) { + itemStack?.let { + list.add(it) + } + } + + return list + } + fun countItemsInLowerInventory(predicate: (ItemStack) -> Boolean) = - Minecraft.getMinecraft().thePlayer.inventory.mainInventory - .filter { it != null && predicate(it) } - .sumOf { it.stackSize } + getItemsInOwnInventory().filter { predicate(it) }.sumOf { it.stackSize } fun getArmor(): Array<ItemStack?> = Minecraft.getMinecraft().thePlayer.inventory.armorInventory diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt index 85dc8816c..cf2515ac1 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -126,17 +126,17 @@ object NEUItems { GlStateManager.popMatrix() } - fun getMultiplier(rawId: String, tryCount: Int = 0): Pair<String, Int> { - if (multiplierCache.contains(rawId)) { - return multiplierCache[rawId]!! + fun getMultiplier(internalName: String, tryCount: Int = 0): Pair<String, Int> { + if (multiplierCache.contains(internalName)) { + return multiplierCache[internalName]!! } if (tryCount == 10) { - val message = "Error reading getMultiplier for item '$rawId'" + val message = "Error reading getMultiplier for item '$internalName'" Error(message).printStackTrace() LorenzUtils.error(message) - return Pair(rawId, 1) + return Pair(internalName, 1) } - for (recipe in getRecipes(rawId)) { + for (recipe in getRecipes(internalName)) { if (recipe !is CraftingRecipe) continue val map = mutableMapOf<String, Int>() @@ -144,26 +144,33 @@ object NEUItems { val count = ingredient.count.toInt() var internalItemId = ingredient.internalItemId // ignore cactus green - if (rawId == "ENCHANTED_CACTUS_GREEN") { + if (internalName == "ENCHANTED_CACTUS_GREEN") { if (internalItemId == "INK_SACK-2") { internalItemId = "CACTUS" } } // ignore wheat in enchanted cookie - if (rawId == "ENCHANTED_COOKIE") { + if (internalName == "ENCHANTED_COOKIE") { if (internalItemId == "WHEAT") { continue } } // ignore golden carrot in enchanted golden carrot - if (rawId == "ENCHANTED_GOLDEN_CARROT") { + if (internalName == "ENCHANTED_GOLDEN_CARROT") { if (internalItemId == "GOLDEN_CARROT") { continue } } + // ignore rabbit hide in leather + if (internalName == "LEATHER") { + if (internalItemId == "RABBIT_HIDE") { + continue + } + } + // println("") // println("rawId: $rawId") // println("internalItemId: $internalItemId") @@ -177,15 +184,15 @@ object NEUItems { return if (current.second > 1) { val child = getMultiplier(id, tryCount + 1) val result = Pair(child.first, child.second * current.second) - multiplierCache[rawId] = result + multiplierCache[internalName] = result result } else { - Pair(rawId, 1) + Pair(internalName, 1) } } - val result = Pair(rawId, 1) - multiplierCache[rawId] = result + val result = Pair(internalName, 1) + multiplierCache[internalName] = result return result } |