[enhancement] Add an option to count elytras in Armor HUD (#1832)

* [enhancement] Add an option to count elytras in Armor HUD

This adds a new setting, CountElytras, under the Armor HUD.
If you have an elytra in your chestplate slot, the armor count will display the number of elytras in your inventory rather than the number of diamond chestplates.
This commit is contained in:
DifferentPerson 2021-01-09 17:14:53 -08:00 committed by GitHub
parent bf4c97c2f6
commit 6bfdecb1f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 4 deletions

View File

@ -26,6 +26,7 @@ object Armor : HudElement(
private val classic = setting("Classic", false)
private val armorCount = setting("ArmorCount", true)
private val countElytras = setting("CountElytras", false, { armorCount.value })
override val hudWidth: Float
get() = if (classic.value) {
@ -43,7 +44,6 @@ object Armor : HudElement(
private var stringWidth = 120.0f
private val armorItems = arrayOf(Items.DIAMOND_HELMET, Items.DIAMOND_CHESTPLATE, Items.DIAMOND_LEGGINGS, Items.DIAMOND_BOOTS)
private val armorCounts = IntArray(4)
private val duraColorGradient = ColorGradient(
0f to ColorHolder(180, 20, 20),
@ -55,9 +55,13 @@ object Armor : HudElement(
safeAsyncListener<TickEvent.ClientTickEvent> { event ->
if (event.phase != TickEvent.Phase.END) return@safeAsyncListener
for ((index, item) in armorItems.withIndex()) {
armorCounts[index] = InventoryUtils.countItemAll(item)
}
armorCounts[0] = InventoryUtils.countItemAll(Items.DIAMOND_HELMET)
armorCounts[1] = InventoryUtils.countItemAll(
if (countElytras.value && player.inventory.getStackInSlot(38).item == Items.ELYTRA) Items.ELYTRA
else Items.DIAMOND_CHESTPLATE
)
armorCounts[2] = InventoryUtils.countItemAll(Items.DIAMOND_LEGGINGS)
armorCounts[3] = InventoryUtils.countItemAll(Items.DIAMOND_BOOTS)
}
}