hotbar polling, fix half hart display

This commit is contained in:
Bixilon 2021-10-16 17:42:06 +02:00
parent bdcb0fc26d
commit 72f11d51e6
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
5 changed files with 26 additions and 12 deletions

View File

@ -56,8 +56,6 @@ class HotbarElement(hudRenderer: HUDRenderer) : Element(hudRenderer) {
}
override fun forceRender(offset: Vec2i, z: Int, consumer: GUIVertexConsumer): Int {
// ToDo: Do not apply every frame
forceSilentApply()
var maxZ = 0
val topMaxSize = topLeft.size.max(topRight.size)
@ -78,7 +76,17 @@ class HotbarElement(hudRenderer: HUDRenderer) : Element(hudRenderer) {
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() {

View File

@ -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.HUDElement
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.util.KUtil.toResourceLocation
import glm_.vec2.Vec2i
@ -39,10 +38,6 @@ class HotbarHUDElement(hudRenderer: HUDRenderer) : HUDElement<HotbarElement>(hud
layout = HotbarElement(hudRenderer)
layout.prefMaxSize = Vec2i(-1, -1)
connection.registerEvent(CallbackEventInvoker.of<UpdateHealthEvent> {
layout.health.apply()
layout.hunger.apply()
})
connection.registerEvent(CallbackEventInvoker.of<ExperienceChangeEvent> {
layout.experience.apply()
})

View File

@ -161,7 +161,7 @@ class HotbarHealthElement(hudRenderer: HUDRenderer) : Element(hudRenderer) {
var healthLeft = totalHealth
var heart = 0
while (healthLeft > 0.5f) {
while (healthLeft >= 0.5f) {
val row = 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 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 maxHealth = player.getAttributeValue(DefaultStatusEffectAttributeNames.GENERIC_MAX_HEALTH).toFloat()
@ -254,6 +257,10 @@ class HotbarHealthElement(hudRenderer: HUDRenderer) : Element(hudRenderer) {
return true
}
override fun tick() {
apply()
}
companion object {
private const val HP_PER_ROW = 20
private const val HEARTS_PER_ROW = HP_PER_ROW / 2

View File

@ -131,11 +131,11 @@ class HotbarHungerElement(hudRenderer: HUDRenderer) : Element(hudRenderer) {
}
override fun tick() {
super.tick()
val healthCondition = hudRenderer.connection.player.healthCondition
animate = healthCondition.saturation <= 0.0f && ticks++ % (healthCondition.hunger * 3 + 1) == 0
apply()
}
override fun silentApply(): Boolean {

View File

@ -79,6 +79,10 @@ class HotbarProtectionElement(hudRenderer: HUDRenderer) : Element(hudRenderer) {
cacheUpToDate = false
}
override fun tick() {
apply()
}
companion object {
private val ARMOR_SIZE = Vec2i(8, 9)
private val SIZE = Vec2i(10 * ARMOR_SIZE.x, ARMOR_SIZE.y)