diff --git a/src/main/java/de/bixilon/minosoft/data/entities/wawla/EntityWawlaInformation.kt b/src/main/java/de/bixilon/minosoft/data/entities/wawla/EntityWawlaInformation.kt new file mode 100644 index 000000000..3c6dc6576 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/entities/wawla/EntityWawlaInformation.kt @@ -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 . + * + * 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 diff --git a/src/main/java/de/bixilon/minosoft/data/entities/wawla/EntityWawlaProvider.kt b/src/main/java/de/bixilon/minosoft/data/entities/wawla/EntityWawlaProvider.kt new file mode 100644 index 000000000..89f66d1c8 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/entities/wawla/EntityWawlaProvider.kt @@ -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 . + * + * 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 +} diff --git a/src/main/java/de/bixilon/minosoft/data/registries/blocks/wawla/BlockWawlaInformation.kt b/src/main/java/de/bixilon/minosoft/data/registries/blocks/wawla/BlockWawlaInformation.kt new file mode 100644 index 000000000..36371ba3d --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/registries/blocks/wawla/BlockWawlaInformation.kt @@ -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 . + * + * 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 diff --git a/src/main/java/de/bixilon/minosoft/data/registries/blocks/wawla/BlockWawlaProvider.kt b/src/main/java/de/bixilon/minosoft/data/registries/blocks/wawla/BlockWawlaProvider.kt new file mode 100644 index 000000000..e3f102908 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/registries/blocks/wawla/BlockWawlaProvider.kt @@ -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 . + * + * 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 +} diff --git a/src/main/java/de/bixilon/minosoft/data/registries/wawla/WawlaInformation.kt b/src/main/java/de/bixilon/minosoft/data/registries/wawla/WawlaInformation.kt new file mode 100644 index 000000000..f3932a53c --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/registries/wawla/WawlaInformation.kt @@ -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 . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.data.registries.wawla + +interface WawlaInformation diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/camera/target/TargetHandler.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/camera/target/TargetHandler.kt index b88846e63..f8d8399d4 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/camera/target/TargetHandler.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/camera/target/TargetHandler.kt @@ -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 diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/camera/target/targets/BlockTarget.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/camera/target/targets/BlockTarget.kt index 3203d5656..0211d4715 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/camera/target/targets/BlockTarget.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/camera/target/targets/BlockTarget.kt @@ -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 diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/HUDManager.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/HUDManager.kt index 27004f68c..b142173b3 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/HUDManager.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/HUDManager.kt @@ -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, ) } } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/WawlaElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/WawlaElement.kt new file mode 100644 index 000000000..b8b19b138 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/WawlaElement.kt @@ -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 . + * + * 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) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/WawlaHUDElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/WawlaHUDElement.kt new file mode 100644 index 000000000..88e48f0c2 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/WawlaHUDElement.kt @@ -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 . + * + * 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> { + private const val BACKGROUND_SIZE = 5 + override val identifier: ResourceLocation = "minosoft:wawla".toResourceLocation() + + override fun build(guiRenderer: GUIRenderer): LayoutedGUIElement { + return LayoutedGUIElement(WawlaHUDElement(guiRenderer)) + } + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/block/BlockWawlaElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/block/BlockWawlaElement.kt new file mode 100644 index 000000000..02cbef3ab --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/block/BlockWawlaElement.kt @@ -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 . + * + * 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) + } +}