mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 19:05:02 -04:00
hotbar polling, fix half hart display
This commit is contained in:
parent
bdcb0fc26d
commit
72f11d51e6
@ -56,8 +56,6 @@ class HotbarElement(hudRenderer: HUDRenderer) : Element(hudRenderer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun forceRender(offset: Vec2i, z: Int, consumer: GUIVertexConsumer): Int {
|
override fun forceRender(offset: Vec2i, z: Int, consumer: GUIVertexConsumer): Int {
|
||||||
// ToDo: Do not apply every frame
|
|
||||||
forceSilentApply()
|
|
||||||
var maxZ = 0
|
var maxZ = 0
|
||||||
|
|
||||||
val topMaxSize = topLeft.size.max(topRight.size)
|
val topMaxSize = topLeft.size.max(topRight.size)
|
||||||
@ -78,7 +76,17 @@ class HotbarElement(hudRenderer: HUDRenderer) : Element(hudRenderer) {
|
|||||||
element.silentApply()
|
element.silentApply()
|
||||||
}
|
}
|
||||||
|
|
||||||
size = base.size + Vec2i(0, max(topLeft.size.y, topRight.size.y)) + Vec2i(0, experience.size.y)
|
_size = base.size + Vec2i(0, max(topLeft.size.y, topRight.size.y)) + Vec2i(0, experience.size.y)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun silentApply(): Boolean {
|
||||||
|
forceSilentApply()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onChildChange(child: Element) {
|
||||||
|
silentApply() // ToDo: Check
|
||||||
|
parent?.onChildChange(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun tick() {
|
override fun tick() {
|
||||||
|
@ -18,7 +18,6 @@ import de.bixilon.minosoft.gui.rendering.gui.hud.HUDRenderer
|
|||||||
import de.bixilon.minosoft.gui.rendering.gui.hud.elements.HUDBuilder
|
import de.bixilon.minosoft.gui.rendering.gui.hud.elements.HUDBuilder
|
||||||
import de.bixilon.minosoft.gui.rendering.gui.hud.elements.HUDElement
|
import de.bixilon.minosoft.gui.rendering.gui.hud.elements.HUDElement
|
||||||
import de.bixilon.minosoft.modding.event.events.ExperienceChangeEvent
|
import de.bixilon.minosoft.modding.event.events.ExperienceChangeEvent
|
||||||
import de.bixilon.minosoft.modding.event.events.UpdateHealthEvent
|
|
||||||
import de.bixilon.minosoft.modding.event.invoker.CallbackEventInvoker
|
import de.bixilon.minosoft.modding.event.invoker.CallbackEventInvoker
|
||||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||||
import glm_.vec2.Vec2i
|
import glm_.vec2.Vec2i
|
||||||
@ -39,10 +38,6 @@ class HotbarHUDElement(hudRenderer: HUDRenderer) : HUDElement<HotbarElement>(hud
|
|||||||
layout = HotbarElement(hudRenderer)
|
layout = HotbarElement(hudRenderer)
|
||||||
layout.prefMaxSize = Vec2i(-1, -1)
|
layout.prefMaxSize = Vec2i(-1, -1)
|
||||||
|
|
||||||
connection.registerEvent(CallbackEventInvoker.of<UpdateHealthEvent> {
|
|
||||||
layout.health.apply()
|
|
||||||
layout.hunger.apply()
|
|
||||||
})
|
|
||||||
connection.registerEvent(CallbackEventInvoker.of<ExperienceChangeEvent> {
|
connection.registerEvent(CallbackEventInvoker.of<ExperienceChangeEvent> {
|
||||||
layout.experience.apply()
|
layout.experience.apply()
|
||||||
})
|
})
|
||||||
|
@ -161,7 +161,7 @@ class HotbarHealthElement(hudRenderer: HUDRenderer) : Element(hudRenderer) {
|
|||||||
var healthLeft = totalHealth
|
var healthLeft = totalHealth
|
||||||
var heart = 0
|
var heart = 0
|
||||||
|
|
||||||
while (healthLeft > 0.5f) {
|
while (healthLeft >= 0.5f) {
|
||||||
val row = heart / HEARTS_PER_ROW
|
val row = heart / HEARTS_PER_ROW
|
||||||
val column = heart % HEARTS_PER_ROW
|
val column = heart % HEARTS_PER_ROW
|
||||||
|
|
||||||
@ -232,7 +232,10 @@ class HotbarHealthElement(hudRenderer: HUDRenderer) : Element(hudRenderer) {
|
|||||||
val wither = witherStatusEffect?.let { player.activeStatusEffects[it] != null } ?: false
|
val wither = witherStatusEffect?.let { player.activeStatusEffects[it] != null } ?: false
|
||||||
val frozen = player.ticksFrozen > 0
|
val frozen = player.ticksFrozen > 0
|
||||||
|
|
||||||
val health = player.healthCondition.hp
|
var health = player.healthCondition.hp
|
||||||
|
if (health > 0.0f && health < 0.5f) {
|
||||||
|
health = 0.5f
|
||||||
|
}
|
||||||
val absorptionsAmount = player.playerAbsorptionHearts // ToDo: This is (probably) calculated as effect instance
|
val absorptionsAmount = player.playerAbsorptionHearts // ToDo: This is (probably) calculated as effect instance
|
||||||
|
|
||||||
val maxHealth = player.getAttributeValue(DefaultStatusEffectAttributeNames.GENERIC_MAX_HEALTH).toFloat()
|
val maxHealth = player.getAttributeValue(DefaultStatusEffectAttributeNames.GENERIC_MAX_HEALTH).toFloat()
|
||||||
@ -254,6 +257,10 @@ class HotbarHealthElement(hudRenderer: HUDRenderer) : Element(hudRenderer) {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun tick() {
|
||||||
|
apply()
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val HP_PER_ROW = 20
|
private const val HP_PER_ROW = 20
|
||||||
private const val HEARTS_PER_ROW = HP_PER_ROW / 2
|
private const val HEARTS_PER_ROW = HP_PER_ROW / 2
|
||||||
|
@ -131,11 +131,11 @@ class HotbarHungerElement(hudRenderer: HUDRenderer) : Element(hudRenderer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun tick() {
|
override fun tick() {
|
||||||
super.tick()
|
|
||||||
|
|
||||||
val healthCondition = hudRenderer.connection.player.healthCondition
|
val healthCondition = hudRenderer.connection.player.healthCondition
|
||||||
|
|
||||||
animate = healthCondition.saturation <= 0.0f && ticks++ % (healthCondition.hunger * 3 + 1) == 0
|
animate = healthCondition.saturation <= 0.0f && ticks++ % (healthCondition.hunger * 3 + 1) == 0
|
||||||
|
|
||||||
|
apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun silentApply(): Boolean {
|
override fun silentApply(): Boolean {
|
||||||
|
@ -79,6 +79,10 @@ class HotbarProtectionElement(hudRenderer: HUDRenderer) : Element(hudRenderer) {
|
|||||||
cacheUpToDate = false
|
cacheUpToDate = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun tick() {
|
||||||
|
apply()
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val ARMOR_SIZE = Vec2i(8, 9)
|
private val ARMOR_SIZE = Vec2i(8, 9)
|
||||||
private val SIZE = Vec2i(10 * ARMOR_SIZE.x, ARMOR_SIZE.y)
|
private val SIZE = Vec2i(10 * ARMOR_SIZE.x, ARMOR_SIZE.y)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user