entity wawla element

This commit is contained in:
Bixilon 2023-01-18 12:44:33 +01:00
parent 696dbf6499
commit 3590bf828a
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 76 additions and 5 deletions

View File

@ -13,6 +13,16 @@
package de.bixilon.minosoft.gui.rendering.gui.hud.elements.wawla
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.data.text.formatting.color.ChatColors
import de.bixilon.minosoft.gui.rendering.gui.elements.Element
import de.bixilon.minosoft.gui.rendering.gui.elements.text.TextElement
abstract class WawlaElement(protected val wawla: WawlaHUDElement) : Element(wawla.guiRenderer)
abstract class WawlaElement(protected val wawla: WawlaHUDElement) : Element(wawla.guiRenderer) {
protected fun createNameElement(translationKey: ResourceLocation?): TextElement {
val name = wawla.context.connection.language.translate(translationKey)
name.setFallbackColor(ChatColors.WHITE)
return TextElement(guiRenderer, name, background = false, scale = 1.2f)
}
}

View File

@ -26,6 +26,7 @@ import de.bixilon.minosoft.gui.rendering.gui.elements.primitive.ColorElement
import de.bixilon.minosoft.gui.rendering.gui.gui.LayoutedGUIElement
import de.bixilon.minosoft.gui.rendering.gui.hud.elements.HUDBuilder
import de.bixilon.minosoft.gui.rendering.gui.hud.elements.wawla.block.BlockWawlaElement
import de.bixilon.minosoft.gui.rendering.gui.hud.elements.wawla.entity.EntityWawlaElement
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions
import de.bixilon.minosoft.gui.rendering.renderer.drawable.AsyncDrawable
@ -42,7 +43,7 @@ class WawlaHUDElement(guiRenderer: GUIRenderer) : Element(guiRenderer), Layouted
val target = context.camera.targetHandler.target
val element: WawlaElement? = when (target) {
is BlockTarget -> BlockWawlaElement(this, target)
is EntityTarget -> null
is EntityTarget -> EntityWawlaElement(this, target)
else -> null
}
this.element = element

View File

@ -51,9 +51,7 @@ class BlockWawlaElement(wawla: WawlaHUDElement, private val target: BlockTarget)
}
private fun createName(): TextElement {
val name = wawla.context.connection.language.translate(target.blockState.block.item.translationKey) // TODO: use key of block and not item
name.setFallbackColor(ChatColors.WHITE)
return TextElement(guiRenderer, name, background = false)
return createNameElement(target.blockState.block.item.translationKey) // TODO: use key of block and not item
}
private fun createMod(): TextElement? {

View File

@ -0,0 +1,62 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.gui.rendering.gui.hud.elements.wawla.entity
import de.bixilon.kotlinglm.vec2.Vec2i
import de.bixilon.minosoft.data.registries.identified.Namespaces
import de.bixilon.minosoft.data.text.TextComponent
import de.bixilon.minosoft.data.text.formatting.color.ChatColors
import de.bixilon.minosoft.gui.rendering.camera.target.targets.EntityTarget
import de.bixilon.minosoft.gui.rendering.gui.elements.text.TextElement
import de.bixilon.minosoft.gui.rendering.gui.hud.elements.wawla.WawlaElement
import de.bixilon.minosoft.gui.rendering.gui.hud.elements.wawla.WawlaHUDElement
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions
class EntityWawlaElement(wawla: WawlaHUDElement, private val target: EntityTarget) : WawlaElement(wawla) {
private val name = createName()
private val mod = createMod()
init {
forceSilentApply()
}
override fun forceRender(offset: Vec2i, consumer: GUIVertexConsumer, options: GUIVertexOptions?) {
name.render(offset, consumer, options)
offset.y += name.size.y
mod?.let { it.render(offset, consumer, options); offset.y += it.size.y }
}
override fun forceSilentApply() {
val size = Vec2i(
x = maxOf(name.size.x, mod?.size?.x ?: 0),
y = name.size.y + (mod?.size?.y ?: 0),
)
this.size = size
}
private fun createName(): TextElement {
return createNameElement(target.entity.type.translationKey)
}
private fun createMod(): TextElement? {
val namespace = target.entity.type.identifier.namespace
if (namespace == Namespaces.DEFAULT) {
return null
}
return TextElement(guiRenderer, TextComponent(namespace).color(ChatColors.BLUE), background = false)
}
}