wawla: wip block information #103

This commit is contained in:
Bixilon 2023-01-18 12:23:45 +01:00
parent c222d48f8e
commit 72ea6fe675
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
11 changed files with 267 additions and 2 deletions

View File

@ -0,0 +1,18 @@
/*
* 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.data.entities.wawla
import de.bixilon.minosoft.data.registries.wawla.WawlaInformation
interface EntityWawlaInformation : WawlaInformation

View File

@ -0,0 +1,22 @@
/*
* 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.data.entities.wawla
import de.bixilon.minosoft.gui.rendering.camera.target.targets.EntityTarget
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
interface EntityWawlaProvider {
fun getWawlaInformation(connection: PlayConnection, target: EntityTarget): EntityWawlaInformation
}

View File

@ -0,0 +1,18 @@
/*
* 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.data.registries.blocks.wawla
import de.bixilon.minosoft.data.registries.wawla.WawlaInformation
interface BlockWawlaInformation : WawlaInformation

View File

@ -0,0 +1,22 @@
/*
* 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.data.registries.blocks.wawla
import de.bixilon.minosoft.gui.rendering.camera.target.targets.BlockTarget
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
interface BlockWawlaProvider {
fun getWawlaInformation(connection: PlayConnection, target: BlockTarget): BlockWawlaInformation
}

View File

@ -0,0 +1,16 @@
/*
* 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.data.registries.wawla
interface WawlaInformation

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
* 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.
*
@ -50,7 +50,6 @@ class TargetHandler(
private set
fun raycast() {
val eyePosition = camera.matrixHandler.entity.eyePosition.toVec3d
val cameraFront = camera.matrixHandler.entity.rotation.front.toVec3d
@ -134,14 +133,19 @@ class TargetHandler(
break
}
if (!blocks) {
continue
}
val entity = currentChunk?.getBlockEntity(blockPosition.inChunkPosition)
target = BlockTarget(
currentPosition,
distance,
voxelShapeRaycastResult.direction,
blockState,
entity,
blockPosition,
)
break

View File

@ -16,6 +16,7 @@ package de.bixilon.minosoft.gui.rendering.camera.target.targets
import de.bixilon.kotlinglm.vec3.Vec3d
import de.bixilon.kotlinglm.vec3.Vec3i
import de.bixilon.minosoft.data.direction.Directions
import de.bixilon.minosoft.data.entities.block.BlockEntity
import de.bixilon.minosoft.data.registries.blocks.BlockState
import de.bixilon.minosoft.data.text.BaseComponent
import de.bixilon.minosoft.data.text.ChatComponent
@ -27,6 +28,7 @@ open class BlockTarget(
distance: Double,
direction: Directions,
val blockState: BlockState,
val entity: BlockEntity?,
val blockPosition: Vec3i,
) : GenericTarget(position, distance, direction), TextFormattable {
val hitPosition = position - blockPosition

View File

@ -37,6 +37,7 @@ import de.bixilon.minosoft.gui.rendering.gui.hud.elements.other.PerformanceHUDEl
import de.bixilon.minosoft.gui.rendering.gui.hud.elements.scoreboard.ScoreboardSideElement
import de.bixilon.minosoft.gui.rendering.gui.hud.elements.tab.TabListElement
import de.bixilon.minosoft.gui.rendering.gui.hud.elements.title.TitleElement
import de.bixilon.minosoft.gui.rendering.gui.hud.elements.wawla.WawlaHUDElement
import de.bixilon.minosoft.gui.rendering.renderer.drawable.AsyncDrawable
import de.bixilon.minosoft.gui.rendering.renderer.drawable.Drawable
import de.bixilon.minosoft.util.KUtil.toResourceLocation
@ -138,6 +139,7 @@ class HUDManager(
PerformanceHUDElement,
TitleElement,
ScoreboardSideElement,
WawlaHUDElement,
)
}
}

View File

@ -0,0 +1,18 @@
/*
* 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
import de.bixilon.minosoft.gui.rendering.gui.elements.Element
abstract class WawlaElement(protected val wawla: WawlaHUDElement) : Element(wawla.guiRenderer)

View File

@ -0,0 +1,77 @@
/*
* 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
import de.bixilon.kotlinglm.vec2.Vec2i
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
import de.bixilon.minosoft.data.text.formatting.color.RGBColor.Companion.asRGBAColor
import de.bixilon.minosoft.data.text.formatting.color.RGBColor.Companion.asRGBColor
import de.bixilon.minosoft.gui.rendering.camera.target.targets.BlockTarget
import de.bixilon.minosoft.gui.rendering.camera.target.targets.EntityTarget
import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer
import de.bixilon.minosoft.gui.rendering.gui.elements.Element
import de.bixilon.minosoft.gui.rendering.gui.elements.LayoutedElement
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.mesh.GUIVertexConsumer
import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions
import de.bixilon.minosoft.gui.rendering.renderer.drawable.AsyncDrawable
import de.bixilon.minosoft.util.KUtil.toResourceLocation
class WawlaHUDElement(guiRenderer: GUIRenderer) : Element(guiRenderer), LayoutedElement, AsyncDrawable {
private var element: WawlaElement? = null
override val layoutOffset: Vec2i
get() = Vec2i((guiRenderer.scaledSize.x - ((element?.size?.x ?: 0) + BACKGROUND_SIZE)) / 2, BACKGROUND_SIZE)
override fun drawAsync() {
val target = context.camera.targetHandler.target
val element: WawlaElement? = when (target) {
is BlockTarget -> BlockWawlaElement(this, target)
is EntityTarget -> null
else -> null
}
this.element = element
forceSilentApply()
}
override fun forceRender(offset: Vec2i, consumer: GUIVertexConsumer, options: GUIVertexOptions?) {
val element = this.element ?: return
val size = element.size
ColorElement(guiRenderer, size + BACKGROUND_SIZE * 2, 0x3c05aa.asRGBColor()).render(offset, consumer, options)
ColorElement(guiRenderer, size + (BACKGROUND_SIZE - 2) * 2, 0x160611A0.asRGBAColor()).render(offset + (BACKGROUND_SIZE - (BACKGROUND_SIZE - 2)), consumer, options)
element.forceRender(offset + BACKGROUND_SIZE, consumer, options)
}
override fun onChildChange(child: Element) {
forceSilentApply()
super.onChildChange(this)
}
override fun forceSilentApply() {
cacheUpToDate = false
}
companion object : HUDBuilder<LayoutedGUIElement<WawlaHUDElement>> {
private const val BACKGROUND_SIZE = 5
override val identifier: ResourceLocation = "minosoft:wawla".toResourceLocation()
override fun build(guiRenderer: GUIRenderer): LayoutedGUIElement<WawlaHUDElement> {
return LayoutedGUIElement(WawlaHUDElement(guiRenderer))
}
}
}

View File

@ -0,0 +1,66 @@
/*
* 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.block
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.BlockTarget
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 BlockWawlaElement(wawla: WawlaHUDElement, private val target: BlockTarget) : WawlaElement(wawla) {
private val name = createName()
private val mod = createMod()
init {
forceSilentApply()
}
override fun forceRender(offset: Vec2i, consumer: GUIVertexConsumer, options: GUIVertexOptions?) {
// TODO: render block
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 {
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)
}
private fun createMod(): TextElement? {
val namespace = target.blockState.block.identifier.namespace
if (namespace == Namespaces.DEFAULT) {
return null
}
return TextElement(guiRenderer, TextComponent(namespace).color(ChatColors.BLUE), background = false)
}
}