diff options
| author | Brady <thatgravyboat@gmail.com> | 2024-04-25 07:29:05 -0230 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-25 11:59:05 +0200 |
| commit | 44b86cc6b1ecde84632f9cf4f06f5c35aa4d8b6d (patch) | |
| tree | 668d43de7b7329eebd83fdafeba5389d15de0d0d /src/main/java/at/hannibal2/skyhanni/features | |
| parent | 0eed4b0d2121a206d4eba81aa4a1888125acbe3e (diff) | |
| download | SkyHanni-44b86cc6b1ecde84632f9cf4f06f5c35aa4d8b6d.tar.gz SkyHanni-44b86cc6b1ecde84632f9cf4f06f5c35aa4d8b6d.tar.bz2 SkyHanni-44b86cc6b1ecde84632f9cf4f06f5c35aa4d8b6d.zip | |
Backend: Improves performance of item backgrounds and borders (#1497)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Co-authored-by: Cal <cwolfson58@gmail.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
4 files changed, 57 insertions, 38 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorRewardWarning.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorRewardWarning.kt index 41e1b59b7..2336ce65a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorRewardWarning.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/VisitorRewardWarning.kt @@ -1,7 +1,5 @@ package at.hannibal2.skyhanni.features.garden.visitor -import at.hannibal2.skyhanni.data.ItemRenderBackground.Companion.background -import at.hannibal2.skyhanni.data.ItemRenderBackground.Companion.borderLine import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.features.garden.visitor.VisitorAPI.ACCEPT_SLOT @@ -13,8 +11,10 @@ import at.hannibal2.skyhanni.utils.KeyboardManager import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.NumberUtil +import at.hannibal2.skyhanni.utils.RenderUtils.drawBorder +import at.hannibal2.skyhanni.utils.RenderUtils.highlight import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import net.minecraft.item.ItemStack +import net.minecraft.inventory.Slot import net.minecraftforge.event.entity.player.ItemTooltipEvent import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -23,26 +23,29 @@ class VisitorRewardWarning { private val config get() = VisitorAPI.config.rewardWarning @SubscribeEvent - fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { + fun onBackgroundDrawn(event: GuiContainerEvent.ForegroundDrawnEvent) { if (!VisitorAPI.inInventory) return if (!config.preventRefusing && !config.preventRefusingCopper && !config.preventAcceptingCopper) return val visitor = VisitorAPI.getVisitor(lastClickedNpc) ?: return - val refuseOfferStack = event.gui.inventorySlots.getSlot(REFUSE_SLOT).stack - val acceptOfferStack = event.gui.inventorySlots.getSlot(ACCEPT_SLOT).stack + val refuseOfferSlot = event.gui.inventorySlots.getSlot(REFUSE_SLOT) + val acceptOfferSlot = event.gui.inventorySlots.getSlot(ACCEPT_SLOT) val blockReason = visitor.blockReason ?: return if (blockReason.blockRefusing) { - renderColor(refuseOfferStack, acceptOfferStack, LorenzColor.GREEN) + renderColor(refuseOfferSlot, acceptOfferSlot, LorenzColor.GREEN) } else { - renderColor(acceptOfferStack, refuseOfferStack, LorenzColor.RED) + renderColor(acceptOfferSlot, refuseOfferSlot, LorenzColor.RED) } } - private fun renderColor(backgroundStack: ItemStack?, outlineStack: ItemStack?, outlineColor: LorenzColor) { - if (!config.bypassKey.isKeyHeld()) backgroundStack?.background = - LorenzColor.DARK_GRAY.addOpacity(config.opacity).rgb - if (config.optionOutline) outlineStack?.borderLine = outlineColor.addOpacity(200).rgb + private fun renderColor(backgroundSlot: Slot?, outlineSlot: Slot?, outlineColor: LorenzColor) { + if (!config.bypassKey.isKeyHeld() && backgroundSlot != null) { + backgroundSlot highlight LorenzColor.DARK_GRAY.addOpacity(config.opacity) + } + if (config.optionOutline && outlineSlot != null) { + outlineSlot drawBorder outlineColor.addOpacity(200) + } } @SubscribeEvent(priority = EventPriority.HIGH) diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt index b67c03ad3..60ce618c8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt @@ -2,8 +2,6 @@ package at.hannibal2.skyhanni.features.inventory import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator -import at.hannibal2.skyhanni.data.ItemRenderBackground.Companion.background -import at.hannibal2.skyhanni.data.ItemRenderBackground.Companion.borderLine import at.hannibal2.skyhanni.data.jsonobjects.repo.HideNotClickableItemsJson import at.hannibal2.skyhanni.data.jsonobjects.repo.HideNotClickableItemsJson.SalvageFilter import at.hannibal2.skyhanni.events.GuiContainerEvent @@ -33,6 +31,8 @@ import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.MultiFilter import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName +import at.hannibal2.skyhanni.utils.RenderUtils.drawBorder +import at.hannibal2.skyhanni.utils.RenderUtils.highlight import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.isMuseumDonated import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.isRiftExportable import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.isRiftTransferable @@ -93,7 +93,7 @@ class HideNotClickableItems { } @SubscribeEvent - fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { + fun onBackgroundDrawn(event: GuiContainerEvent.ForegroundDrawnEvent) { if (!LorenzUtils.inSkyBlock) return if (isDisabled()) return if (bypasssActive()) return @@ -102,14 +102,11 @@ class HideNotClickableItems { val chest = guiChest.inventorySlots as ContainerChest val chestName = chest.getInventoryName() - for ((_, stack) in chest.getLowerItems()) { + for ((slot, stack) in chest.getLowerItems()) { if (hide(chestName, stack)) { - val opacity = config.opacity - val color = LorenzColor.DARK_GRAY.addOpacity(opacity) - stack.background = color.rgb + slot highlight LorenzColor.DARK_GRAY.addOpacity(config.opacity) } else if (showGreenLine && config.itemsGreenLine) { - val color = LorenzColor.GREEN.addOpacity(200) - stack.borderLine = color.rgb + slot drawBorder LorenzColor.GREEN.addOpacity(200) } } } @@ -386,7 +383,6 @@ class HideNotClickableItems { if (!chestName.startsWith("Sack of Sacks")) return false if (ItemUtils.isSkyBlockMenuItem(stack)) return false - val name = stack.cleanName() showGreenLine = true if (ItemUtils.isSack(stack)) return false diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt index 1a88f1185..78ed735ec 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt @@ -1,7 +1,6 @@ package at.hannibal2.skyhanni.features.inventory import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.data.ItemRenderBackground.Companion.background import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.LorenzToolTipEvent import at.hannibal2.skyhanni.events.RepositoryReloadEvent @@ -11,6 +10,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.KeyboardManager import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.RenderUtils.highlight import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.inventory.ContainerChest @@ -56,7 +56,7 @@ class QuickCraftFeatures { } @SubscribeEvent - fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { + fun onBackgroundDrawn(event: GuiContainerEvent.ForegroundDrawnEvent) { val inventoryType = getInventoryType() ?: return if (KeyboardManager.isModifierKeyDown()) return if (event.gui !is GuiChest) return @@ -66,8 +66,7 @@ class QuickCraftFeatures { if (inventoryType.ignoreSlot(slot.slotNumber)) continue if (stack.name == "§cQuick Crafting Slot") continue if (needsQuickCraftConfirmation(stack)) { - val color = LorenzColor.DARK_GRAY.addOpacity(180) - stack.background = color.rgb + slot highlight LorenzColor.DARK_GRAY.addOpacity(180) } } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt index 998e25e35..c48a28eff 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt @@ -2,18 +2,19 @@ package at.hannibal2.skyhanni.features.itemabilities.abilitycooldown import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator -import at.hannibal2.skyhanni.data.ItemRenderBackground.Companion.background import at.hannibal2.skyhanni.events.ActionBarUpdateEvent import at.hannibal2.skyhanni.events.ItemClickEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.events.PlaySoundEvent +import at.hannibal2.skyhanni.events.RenderGuiItemOverlayEvent import at.hannibal2.skyhanni.events.RenderItemTipEvent import at.hannibal2.skyhanni.events.RenderObject import at.hannibal2.skyhanni.features.itemabilities.abilitycooldown.ItemAbility.Companion.getMultiplier import at.hannibal2.skyhanni.features.nether.ashfang.AshfangFreezeCooldown import at.hannibal2.skyhanni.utils.CollectionUtils.equalsOneOf +import at.hannibal2.skyhanni.utils.CollectionUtils.mapKeysNotNull import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils import at.hannibal2.skyhanni.utils.ItemUtils.cleanName @@ -23,6 +24,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.between import at.hannibal2.skyhanni.utils.LorenzUtils.round import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName +import at.hannibal2.skyhanni.utils.RenderUtils.highlight import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getAbilityScrolls import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getItemId import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getItemUuid @@ -48,7 +50,7 @@ class ItemAbilityCooldown { ) private var lastAbility = "" - private var items = mapOf<ItemStack, List<ItemText>>() + private var items = mapOf<String, List<ItemText>>() private var abilityItems = mapOf<ItemStack, MutableList<ItemAbility>>() private val WEIRD_TUBA = "WEIRD_TUBA".asInternalName() private val WEIRDER_TUBA = "WEIRDER_TUBA".asInternalName() @@ -254,7 +256,12 @@ class ItemAbilityCooldown { abilityItems = ItemUtils.getItemsInInventory(true).associateWith { hasAbility(it) } } - items = abilityItems.mapValues { kp -> kp.value.map { createItemText(it) } } + items = abilityItems.entries.associateByTo( + mutableMapOf(), + { it.key.getIdentifier() }, + { kp -> kp.value.map { createItemText(it) } } + ).mapKeysNotNull { it.key } + } private fun createItemText(ability: ItemAbility): ItemText { @@ -291,8 +298,7 @@ class ItemAbilityCooldown { val guiOpen = Minecraft.getMinecraft().currentScreen != null val uuid = stack.getIdentifier() ?: return - val list = items.filter { (it.key.getIdentifier()) == uuid } - .firstNotNullOfOrNull { it.value } ?: return + val list = items[uuid] ?: return for (itemText in list) { if (guiOpen && !itemText.onCooldown) continue @@ -303,16 +309,31 @@ class ItemAbilityCooldown { renderObject.offsetY = -10 } event.renderObjects.add(renderObject) + } + } + + @SubscribeEvent + fun onRenderItem(event: RenderGuiItemOverlayEvent) { + if (!isEnabled()) return + if (!config.itemAbilityCooldownBackground) return + + val guiOpen = Minecraft.getMinecraft().currentScreen != null + val stack = event.stack + + val uuid = stack?.getIdentifier() ?: return + val list = items[uuid] ?: return + + for (itemText in list) { + if (guiOpen && !itemText.onCooldown) continue + val color = itemText.color // fix multiple problems when having multiple abilities - if (config.itemAbilityCooldownBackground) { - var opacity = 130 - if (color == LorenzColor.GREEN) { - opacity = 80 - if (!config.itemAbilityShowWhenReady) return - } - stack.background = color.addOpacity(opacity).rgb + var opacity = 130 + if (color == LorenzColor.GREEN) { + opacity = 80 + if (!config.itemAbilityShowWhenReady) return } + event highlight color.addOpacity(opacity) } } |
