diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-05-03 17:36:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-03 17:36:17 +0200 |
commit | 9cb0e36272953669c69057bb33c5dabbe1116f70 (patch) | |
tree | a7ac4c074282a4ef0b3bc7acaa7d7fe3856e7547 | |
parent | 04f23d3a8136cf7b49269160f046fef82e86810f (diff) | |
download | skyhanni-9cb0e36272953669c69057bb33c5dabbe1116f70.tar.gz skyhanni-9cb0e36272953669c69057bb33c5dabbe1116f70.tar.bz2 skyhanni-9cb0e36272953669c69057bb33c5dabbe1116f70.zip |
Backend: Renderable in GardenCropMilestoneDisplay (#1534)
Co-authored-by: HiZe <superhize@hotmail.com>
Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com>
Co-authored-by: alexia <me@alexia.lol>
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
4 files changed, 79 insertions, 48 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt index 107959f95..2ec370dee 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt @@ -28,6 +28,7 @@ import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactor import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateShopPrice import at.hannibal2.skyhanni.utils.BlockUtils.isBabyCrop import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.CollectionUtils.addItemStack import at.hannibal2.skyhanni.utils.DelayedRun import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName @@ -41,6 +42,7 @@ import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.RenderUtils.addItemIcon import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getCultivatingCounter import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getHoeCounter +import at.hannibal2.skyhanni.utils.renderables.Renderable import net.minecraft.client.Minecraft import net.minecraft.item.ItemStack import net.minecraft.network.play.client.C09PacketHeldItemChange @@ -169,6 +171,15 @@ object GardenAPI { ) = addItemIcon(crop.icon.copy(), highlight, scale = scale) + // TODO rename to addCropIcon + fun MutableList<Renderable>.addCropIconRenderable( + crop: CropType, + scale: Double = NEUItems.itemFontSize, + highlight: Boolean = false, + ) { + addItemStack(crop.icon.copy(), highlight = highlight, scale = scale) + } + fun hideExtraGuis() = ComposterOverlay.inInventory || AnitaMedalProfit.inInventory || SkyMartCopperPrice.inInventory || FarmingContestAPI.inInventory || VisitorAPI.inInventory || FFGuideGUI.isInGui() || ChocolateShopPrice.inInventory || ChocolateFactoryAPI.inChocolateFactory || diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt index 9e10a8941..7a91b8765 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt @@ -17,29 +17,30 @@ import at.hannibal2.skyhanni.events.ProfileJoinEvent import at.hannibal2.skyhanni.features.garden.CropType import at.hannibal2.skyhanni.features.garden.FarmingFortuneDisplay import at.hannibal2.skyhanni.features.garden.GardenAPI -import at.hannibal2.skyhanni.features.garden.GardenAPI.addCropIcon +import at.hannibal2.skyhanni.features.garden.GardenAPI.addCropIconRenderable import at.hannibal2.skyhanni.features.garden.GardenAPI.getCropType import at.hannibal2.skyhanni.features.garden.farming.GardenCropSpeed.setSpeed import at.hannibal2.skyhanni.test.command.ErrorManager -import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList +import at.hannibal2.skyhanni.utils.CollectionUtils.addString import at.hannibal2.skyhanni.utils.ConditionalUtils import at.hannibal2.skyhanni.utils.ConfigUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.round import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.SoundUtils import at.hannibal2.skyhanni.utils.TimeUnit import at.hannibal2.skyhanni.utils.TimeUtils +import at.hannibal2.skyhanni.utils.renderables.Renderable import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import java.util.Collections import kotlin.time.Duration.Companion.seconds object GardenCropMilestoneDisplay { - private var progressDisplay = emptyList<List<Any>>() - private var mushroomCowPerkDisplay = emptyList<List<Any>>() + private var progressDisplay = emptyList<Renderable>() + private var mushroomCowPerkDisplay = emptyList<Renderable>() private val cultivatingData = mutableMapOf<CropType, Long>() private val config get() = GardenAPI.config.cropMilestones private val overflowConfig get() = config.overflow @@ -71,12 +72,12 @@ object GardenCropMilestoneDisplay { if (!isEnabled()) return if (GardenAPI.hideExtraGuis()) return - config.progressDisplayPos.renderStringsAndItems( + config.progressDisplayPos.renderRenderables( progressDisplay, posLabel = "Crop Milestone Progress" ) if (config.mushroomPetPerk.enabled) { - config.mushroomPetPerk.pos.renderStringsAndItems( + config.mushroomPetPerk.pos.renderRenderables( mushroomCowPerkDisplay, posLabel = "Mushroom Cow Perk" ) } @@ -144,10 +145,10 @@ object GardenCropMilestoneDisplay { } } - private fun drawProgressDisplay(crop: CropType): MutableList<List<Any>> { + private fun drawProgressDisplay(crop: CropType): List<Renderable> { val counter = crop.getCounter() - val lineMap = HashMap<Int, List<Any>>() - lineMap[0] = Collections.singletonList("§6Crop Milestones") + val lineMap = mutableMapOf<Int, Renderable>() + lineMap[0] = Renderable.string("§6Crop Milestones") val customTargetLevel = storage?.get(crop) ?: 0 val overflowDisplay = overflowConfig.cropMilestoneDisplay @@ -158,14 +159,14 @@ object GardenCropMilestoneDisplay { val useCustomGoal = customTargetLevel != 0 && customTargetLevel > currentTier nextTier = if (useCustomGoal) customTargetLevel else nextTier - val list = mutableListOf<Any>() - list.addCropIcon(crop) - if (crop.isMaxed(overflowDisplay)) { - list.add("§7" + crop.cropName + " §eMAXED") - } else { - list.add("§7" + crop.cropName + " §8$currentTier➜§3$nextTier") - } - lineMap[1] = list + lineMap[1] = Renderable.horizontalContainer(buildList { + addCropIconRenderable(crop) + if (crop.isMaxed(overflowDisplay) && !overflowDisplay) { + addString("§7" + crop.cropName + " §eMAXED") + } else { + addString("§7" + crop.cropName + " §8$currentTier➜§3$nextTier") + } + }) val allowOverflowOrCustom = overflowDisplay || useCustomGoal val cropsForNextTier = GardenCropMilestones.getCropsForTier(nextTier, crop, allowOverflowOrCustom) @@ -178,13 +179,13 @@ object GardenCropMilestoneDisplay { Pair(have, need) } - lineMap[2] = if (crop.isMaxed(overflowDisplay)) { + lineMap[2] = if (crop.isMaxed(overflowDisplay) && !overflowDisplay) { val haveFormat = counter.addSeparators() - Collections.singletonList("§7Counter: §e$haveFormat") + Renderable.string("§7Counter: §e$haveFormat") } else { val haveFormat = have.addSeparators() val needFormat = need.addSeparators() - Collections.singletonList("§e$haveFormat§8/§e$needFormat") + Renderable.string("§e$haveFormat§8/§e$needFormat") } val farmingFortune = FarmingFortuneDisplay.getCurrentFarmingFortune() @@ -193,7 +194,7 @@ object GardenCropMilestoneDisplay { if (farmingFortuneSpeed > 0) { crop.setSpeed(farmingFortuneSpeed) - if (!crop.isMaxed(overflowDisplay)) { + if (!crop.isMaxed(overflowDisplay) || overflowDisplay) { val missing = need - have val missingTimeSeconds = missing / farmingFortuneSpeed val millis = missingTimeSeconds * 1000 @@ -204,30 +205,38 @@ object GardenCropMilestoneDisplay { tryWarn(millis, "§b${crop.cropName} $nextTier in $duration") val speedText = "§7In §b$duration" - lineMap[3] = Collections.singletonList(speedText) + lineMap[3] = Renderable.string(speedText) GardenAPI.itemInHand?.let { if (GardenAPI.readCounter(it) == -1L) { - lineMap[3] = listOf(speedText, " §7Inaccurate!") + lineMap[3] = Renderable.string("$speedText §7Inaccurate!") } } } val format = (farmingFortuneSpeed * 60).addSeparators() - lineMap[4] = Collections.singletonList("§7Crops/Minute§8: §e$format") + lineMap[4] = Renderable.string("§7Crops/Minute§8: §e$format") val formatBps = speed.round(config.blocksBrokenPrecision).addSeparators() - lineMap[5] = Collections.singletonList("§7Blocks/Second§8: §e$formatBps") + lineMap[5] = Renderable.string("§7Blocks/Second§8: §e$formatBps") } val percentageFormat = LorenzUtils.formatPercentage(have.toDouble() / need.toDouble()) - lineMap[6] = if (crop.isMaxed(overflowDisplay)) { - Collections.singletonList("§7Percentage: §e100%") + lineMap[6] = if (crop.isMaxed(overflowDisplay) && !overflowDisplay) { + Renderable.string("§7Percentage: §e100%") } else { - Collections.singletonList("§7Percentage: §e$percentageFormat") + Renderable.string("§7Percentage: §e$percentageFormat") } + if (overflowConfig.chat) { + if (currentTier >= 46 && currentTier == previousNext && + nextRealTier == currentTier + 1 && lastWarnedLevel != currentTier) { + GardenCropMilestones.onOverflowLevelUp(crop, currentTier - 1, nextRealTier - 1) + lastWarnedLevel = currentTier + } + } if (overflowConfig.chat) { - if (currentTier >= 46 && currentTier == previousNext && nextRealTier == currentTier + 1 && lastWarnedLevel != currentTier) { + if (currentTier >= 46 && currentTier == previousNext && + nextRealTier == currentTier + 1 && lastWarnedLevel != currentTier) { GardenCropMilestones.onOverflowLevelUp(crop, currentTier - 1, nextRealTier - 1) lastWarnedLevel = currentTier } @@ -256,8 +265,8 @@ object GardenCropMilestoneDisplay { } } - private fun formatDisplay(lineMap: HashMap<Int, List<Any>>): MutableList<List<Any>> { - val newList = mutableListOf<List<Any>>() + private fun formatDisplay(lineMap: MutableMap<Int, Renderable>): List<Renderable> { + val newList = mutableListOf<Renderable>() for (index in config.text) { // TODO, change functionality to use enum rather than ordinals lineMap[index.ordinal]?.let { @@ -266,7 +275,7 @@ object GardenCropMilestoneDisplay { } if (needsInventory) { - newList.addAsSingletonList("§cOpen §e/cropmilestones §cto update!") + newList.addString("§cOpen §e/cropmilestones §cto update!") } return newList @@ -277,13 +286,13 @@ object GardenCropMilestoneDisplay { val allowOverflow = overflowConfig.cropMilestoneDisplay if (mushroom.isMaxed(allowOverflow)) { mushroomCowPerkDisplay = listOf( - listOf("§6Mooshroom Cow Perk"), - listOf("§eMushroom crop is maxed!"), + Renderable.string("§6Mooshroom Cow Perk"), + Renderable.string("§eMushroom crop is maxed!"), ) return } - val lineMap = HashMap<Int, List<Any>>() + val lineMap = HashMap<Int, Renderable>() val counter = mushroom.getCounter() val currentTier = GardenCropMilestones.getTierForCropCount(counter, mushroom, allowOverflow) @@ -300,14 +309,15 @@ object GardenCropMilestoneDisplay { val missing = need - have - lineMap[0] = Collections.singletonList("§6Mooshroom Cow Perk") - - val list = mutableListOf<Any>() - list.addCropIcon(mushroom) - list.add("§7Mushroom Tier $nextTier") - lineMap[1] = list + lineMap[0] = Renderable.string("§6Mooshroom Cow Perk") + lineMap[1] = Renderable.horizontalContainer( + buildList { + addCropIconRenderable(mushroom) + addString("§7Mushroom Tier $nextTier") + } + ) - lineMap[2] = Collections.singletonList("§e$haveFormat§8/§e$needFormat") + lineMap[2] = Renderable.string("§e$haveFormat§8/§e$needFormat") val speed = GardenCropSpeed.averageBlocksPerSecond if (speed != 0.0) { @@ -318,18 +328,18 @@ object GardenCropMilestoneDisplay { // TODO, change functionality to use enum rather than ordinals val biggestUnit = TimeUnit.entries[config.highestTimeFormat.get().ordinal] val duration = TimeUtils.formatDuration(millis.toLong(), biggestUnit) - lineMap[3] = Collections.singletonList("§7In §b$duration") + lineMap[3] = Renderable.string("§7In §b$duration") } val percentageFormat = LorenzUtils.formatPercentage(have.toDouble() / need.toDouble()) - lineMap[4] = Collections.singletonList("§7Percentage: §e$percentageFormat") + lineMap[4] = Renderable.string("§7Percentage: §e$percentageFormat") if (currentTier >= 46 && currentTier == previousMushNext && nextTier == currentTier + 1 && lastMushWarnedLevel != currentTier) { GardenCropMilestones.onOverflowLevelUp(mushroom, currentTier - 1, nextTier - 1) lastMushWarnedLevel = currentTier } - val newList = mutableListOf<List<Any>>() + val newList = mutableListOf<Renderable>() for (index in config.mushroomPetPerk.text) { // TODO, change functionality to use enum rather than ordinals lineMap[index.ordinal]?.let { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt index df4f15e47..2da2fbda2 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/CollectionUtils.kt @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.utils import at.hannibal2.skyhanni.utils.NEUItems.getItemStack import at.hannibal2.skyhanni.utils.renderables.Renderable +import net.minecraft.enchantment.Enchantment import net.minecraft.item.ItemStack import java.util.Collections import java.util.Queue @@ -202,8 +203,16 @@ object CollectionUtils { } // TODO add internal name support, and caching - fun MutableList<Renderable>.addItemStack(itemStack: ItemStack) { - add(Renderable.itemStack(itemStack)) + fun MutableList<Renderable>.addItemStack( + itemStack: ItemStack, + highlight: Boolean = false, + scale: Double = NEUItems.itemFontSize, + ) { + if (highlight) { + // Hack to add enchant glint, like Hypixel does it + itemStack.addEnchantment(Enchantment.protection, 0) + } + add(Renderable.itemStack(itemStack, scale = scale)) } fun MutableList<Renderable>.addItemStack(internalName: NEUInternalName) { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt index 2f512cb87..d17831fb5 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt @@ -637,6 +637,7 @@ object RenderUtils { return offsetX } + @Deprecated("use renderable item list", ReplaceWith("")) fun MutableList<Any>.addItemIcon( item: ItemStack, highlight: Boolean = false, |