From 72e03947031b49135dc6a4cc97ef6b79c05def76 Mon Sep 17 00:00:00 2001 From: Obsidian <108832807+Obsidianninja11@users.noreply.github.com> Date: Wed, 11 Oct 2023 01:07:24 -0800 Subject: Feature: Composter Getfromsacks (#475) composter allows bz + sacks #475 --- .../skyhanni/config/features/GardenConfig.java | 6 ++ .../features/garden/composter/ComposterOverlay.kt | 68 +++++++++++++++++++--- .../java/at/hannibal2/skyhanni/utils/SoundUtils.kt | 5 ++ 3 files changed, 72 insertions(+), 7 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni') diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/GardenConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/GardenConfig.java index aed826e3c..2bb959f44 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/GardenConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/GardenConfig.java @@ -1118,6 +1118,12 @@ public class GardenConfig { @ConfigAccordionId(id = 17) public int composterOverlayPriceType = 0; + @Expose + @ConfigOption(name = "Retrieve From", desc = "Change where to retrieve the materials from in the composter overlay: The Bazaar or Sacks.") + @ConfigEditorDropdown(values = {"Bazaar", "Sacks"}) + @ConfigAccordionId(id = 17) + public int composterOverlayRetrieveFrom = 0; + @Expose public Position composterOverlayOrganicMatterPos = new Position(140, 152, false, true); diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt index f8abc9270..5aa63b660 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.features.garden.composter import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.SackAPI import at.hannibal2.skyhanni.data.model.ComposterUpgrade import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent @@ -11,17 +12,22 @@ import at.hannibal2.skyhanni.events.TabListUpdateEvent import at.hannibal2.skyhanni.features.bazaar.BazaarApi import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.features.garden.composter.ComposterAPI.getLevel +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.LorenzUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.LorenzUtils.addSelector import at.hannibal2.skyhanni.utils.LorenzUtils.round import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc +import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNeeded import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.SoundUtils import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.TimeUtils @@ -35,6 +41,7 @@ import java.util.Collections import kotlin.math.ceil import kotlin.math.floor import kotlin.time.Duration +import kotlin.time.Duration.Companion.milliseconds import kotlin.time.DurationUnit class ComposterOverlay { @@ -56,6 +63,7 @@ class ComposterOverlay { private var maxLevel = false private var lastHovered = 0L + private var lastAttemptTime = SimpleTimeMark.farPast() companion object { var currentOrganicMatterItem: String? @@ -351,7 +359,8 @@ class ComposterOverlay { val priceCompost = getPrice("COMPOST") val profit = ((priceCompost * multiDropFactor) - (fuelPricePer + organicMatterPricePer)) * timeMultiplier - val profitPreview = ((priceCompost * multiDropFactorPreview) - (fuelPricePerPreview + organicMatterPricePerPreview)) * timeMultiplierPreview + val profitPreview = + ((priceCompost * multiDropFactorPreview) - (fuelPricePerPreview + organicMatterPricePerPreview)) * timeMultiplierPreview val profitFormatPreview = if (profit != profitPreview) " §c➜ §6" + NumberUtil.format(profitPreview) else "" val profitFormat = " §7Profit per $timeText: §6${NumberUtil.format(profit)}$profitFormatPreview" @@ -407,15 +416,14 @@ class ComposterOverlay { } list.add(item) val format = NumberUtil.format(totalPrice) - val selected = - if (internalName == currentOrganicMatterItem || internalName == currentFuelItem) "§n" else "" + val selected = if (internalName == currentOrganicMatterItem || internalName == currentFuelItem) "§n" else "" val rawItemName = itemName.removeColor() val name = itemName.substring(0, 2) + selected + rawItemName - list.add(Renderable.link("$name§r §8x${itemsNeeded.addSeparators()} §7(§6$format§7)") { + list.add(Renderable.link("$name §8x${itemsNeeded.addSeparators()} §7(§6$format§7)") { onClick(internalName) - if (LorenzUtils.isControlKeyDown()) { - inInventory = false - BazaarApi.searchForBazaarItem(itemName, itemsNeeded.toInt()) + if (LorenzUtils.isControlKeyDown() && lastAttemptTime.passedSince() > 500.milliseconds) { + lastAttemptTime = SimpleTimeMark.now() + retrieveMaterials(internalName, itemName, itemsNeeded.toInt()) } }) bigList.add(list) @@ -433,6 +441,52 @@ class ComposterOverlay { return first ?: error("First is empty!") } + private fun retrieveMaterials(internalName: String, itemName: String, itemsNeeded: Int) { + if (itemsNeeded == 0 || internalName == "BIOFUEL") return + if (config.composterOverlayRetrieveFrom == 0 && !LorenzUtils.noTradeMode) { + BazaarApi.searchForBazaarItem(itemName, itemsNeeded) + return + } + val having = InventoryUtils.countItemsInLowerInventory { it.getInternalName() == internalName.asInternalName() } + if (having >= itemsNeeded) { + LorenzUtils.chat("§e[SkyHanni] $itemName §8x${itemsNeeded} §ealready found in inventory!") + return + } + + val (amountInSacks, _, sacksLoaded) = SackAPI.fetchSackItem(internalName.asInternalName()) + + if (sacksLoaded == -1 || sacksLoaded == 2) { + if (sacksLoaded == 2) LorenzUtils.sendCommandToServer("gfs $internalName ${itemsNeeded - having}") + val sackType = if (internalName == "VOLTA" || internalName == "OIL_BARREL") "Mining" else "Enchanted Agronomy" // TODO Add sack type repo data + LorenzUtils.clickableChat( + "§e[SkyHanni] Sacks could not be loaded. Click here and open your §9$sackType Sack §eto update the data!", + "sax" + ) + return + } else if (amountInSacks == 0L) { + SoundUtils.playErrorSound() + if (LorenzUtils.noTradeMode) { + LorenzUtils.chat("§e[SkyHanni] No $itemName §efound in sacks.") + } else { + LorenzUtils.chat("§e[SkyHanni] No $itemName §efound in sacks. Opening Bazaar.") + BazaarApi.searchForBazaarItem(itemName, itemsNeeded) + } + return + } + + LorenzUtils.sendCommandToServer("gfs $internalName ${itemsNeeded - having}") + if (amountInSacks <= itemsNeeded - having) { + if (LorenzUtils.noTradeMode) { + LorenzUtils.chat("§e[SkyHanni] You're out of $itemName §ein your sacks!") + } else { + LorenzUtils.clickableChat( + "§e[SkyHanni] You're out of $itemName §ein your sacks! Click here to buy more on the Bazaar!", + "bz ${itemName.removeColor()}" + ) + } + } + } + private fun getPrice(internalName: String): Double { val useSellPrice = config.composterOverlayPriceType == 1 val price = NEUItems.getPrice(internalName, useSellPrice) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt index 64f10d514..5e0e50d3f 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt @@ -9,6 +9,7 @@ import net.minecraft.util.ResourceLocation object SoundUtils { private val beepSound by lazy { createSound("random.orb", 1f) } private val clickSound by lazy { createSound("gui.button.press", 1f) } + private val errorSound by lazy {createSound("mob.endermen.portal", 0f)} val centuryActiveTimerAlert by lazy { createSound("skyhanni:centurytimer.active", 1f) } fun ISound.playSound() { @@ -54,4 +55,8 @@ object SoundUtils { fun playClickSound() { clickSound.playSound() } + + fun playErrorSound() { + errorSound.playSound() + } } \ No newline at end of file -- cgit