From 72ea6fe67541e5811d6fc96c718ece7c7b010eec Mon Sep 17 00:00:00 2001 From: Bixilon Date: Wed, 18 Jan 2023 12:23:45 +0100 Subject: [PATCH 1/9] wawla: wip block information #103 --- .../entities/wawla/EntityWawlaInformation.kt | 18 +++++ .../entities/wawla/EntityWawlaProvider.kt | 22 ++++++ .../blocks/wawla/BlockWawlaInformation.kt | 18 +++++ .../blocks/wawla/BlockWawlaProvider.kt | 22 ++++++ .../data/registries/wawla/WawlaInformation.kt | 16 ++++ .../rendering/camera/target/TargetHandler.kt | 8 +- .../camera/target/targets/BlockTarget.kt | 2 + .../gui/rendering/gui/hud/HUDManager.kt | 2 + .../gui/hud/elements/wawla/WawlaElement.kt | 18 +++++ .../gui/hud/elements/wawla/WawlaHUDElement.kt | 77 +++++++++++++++++++ .../elements/wawla/block/BlockWawlaElement.kt | 66 ++++++++++++++++ 11 files changed, 267 insertions(+), 2 deletions(-) create mode 100644 src/main/java/de/bixilon/minosoft/data/entities/wawla/EntityWawlaInformation.kt create mode 100644 src/main/java/de/bixilon/minosoft/data/entities/wawla/EntityWawlaProvider.kt create mode 100644 src/main/java/de/bixilon/minosoft/data/registries/blocks/wawla/BlockWawlaInformation.kt create mode 100644 src/main/java/de/bixilon/minosoft/data/registries/blocks/wawla/BlockWawlaProvider.kt create mode 100644 src/main/java/de/bixilon/minosoft/data/registries/wawla/WawlaInformation.kt create mode 100644 src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/WawlaElement.kt create mode 100644 src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/WawlaHUDElement.kt create mode 100644 src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/block/BlockWawlaElement.kt 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) + } +} From 696dbf64999b6d150deb582cba86cd82ec95672d Mon Sep 17 00:00:00 2001 From: Bixilon Date: Wed, 18 Jan 2023 12:44:17 +0100 Subject: [PATCH 2/9] assets util: warn if asset is corrupted --- src/main/java/de/bixilon/minosoft/assets/util/FileAssetsUtil.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/de/bixilon/minosoft/assets/util/FileAssetsUtil.kt b/src/main/java/de/bixilon/minosoft/assets/util/FileAssetsUtil.kt index 48b1f0858..363dcefab 100644 --- a/src/main/java/de/bixilon/minosoft/assets/util/FileAssetsUtil.kt +++ b/src/main/java/de/bixilon/minosoft/assets/util/FileAssetsUtil.kt @@ -129,6 +129,7 @@ object FileAssetsUtil { val result = digest.digest().toHex() if (result != hash) { + Log.log(LogMessageType.ASSETS, LogLevels.WARN) { "Asset stored corrupted: (type=$type, hash=$hash)" } file.delete() return null } From 3590bf828a1d7ec3bd83d1052c1c40db871262eb Mon Sep 17 00:00:00 2001 From: Bixilon Date: Wed, 18 Jan 2023 12:44:33 +0100 Subject: [PATCH 3/9] entity wawla element --- .../gui/hud/elements/wawla/WawlaElement.kt | 12 +++- .../gui/hud/elements/wawla/WawlaHUDElement.kt | 3 +- .../elements/wawla/block/BlockWawlaElement.kt | 4 +- .../wawla/entity/EntityWawlaElement.kt | 62 +++++++++++++++++++ 4 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/entity/EntityWawlaElement.kt 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 index b8b19b138..fa66cfd84 100644 --- 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 @@ -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) + } +} 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 index 88e48f0c2..796759a68 100644 --- 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 @@ -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 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 index 02cbef3ab..ef8503e79 100644 --- 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 @@ -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? { diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/entity/EntityWawlaElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/entity/EntityWawlaElement.kt new file mode 100644 index 000000000..899a9c83c --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/entity/EntityWawlaElement.kt @@ -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 . + * + * 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) + } +} From 14f2d3a094d7f9f8243cae0c9d768cbf221cd1fa Mon Sep 17 00:00:00 2001 From: Bixilon Date: Wed, 18 Jan 2023 12:50:29 +0100 Subject: [PATCH 4/9] fix wrongly detected asset corruption if not verifying assets --- .../java/de/bixilon/minosoft/assets/util/FileAssetsUtil.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/assets/util/FileAssetsUtil.kt b/src/main/java/de/bixilon/minosoft/assets/util/FileAssetsUtil.kt index 363dcefab..c3c83ecc9 100644 --- a/src/main/java/de/bixilon/minosoft/assets/util/FileAssetsUtil.kt +++ b/src/main/java/de/bixilon/minosoft/assets/util/FileAssetsUtil.kt @@ -107,7 +107,7 @@ object FileAssetsUtil { stream.close() val result = digest.digest().toHex() - if (result != hash) { + if (verify && result != hash) { file.delete() throw IOException("Hash does not match (type=$type, expected=$hash, hash=$hash)") } @@ -127,8 +127,7 @@ object FileAssetsUtil { stream.close() - val result = digest.digest().toHex() - if (result != hash) { + if (verify && digest.digest().toHex() != hash) { Log.log(LogMessageType.ASSETS, LogLevels.WARN) { "Asset stored corrupted: (type=$type, hash=$hash)" } file.delete() return null From 799d34203f7590de4edf2cc910c8556c4bfbfa1e Mon Sep 17 00:00:00 2001 From: Bixilon Date: Wed, 18 Jan 2023 13:10:40 +0100 Subject: [PATCH 5/9] wawla: additional information --- .../data/registries/wawla/WawlaInformation.kt | 6 +++- .../elements/wawla/block/BlockWawlaElement.kt | 31 +++++++++++++++++-- .../wawla/entity/EntityWawlaElement.kt | 18 +++++++++-- 3 files changed, 50 insertions(+), 5 deletions(-) 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 index f3932a53c..b684d0cbf 100644 --- a/src/main/java/de/bixilon/minosoft/data/registries/wawla/WawlaInformation.kt +++ b/src/main/java/de/bixilon/minosoft/data/registries/wawla/WawlaInformation.kt @@ -13,4 +13,8 @@ package de.bixilon.minosoft.data.registries.wawla -interface WawlaInformation +import de.bixilon.minosoft.data.text.ChatComponent + +interface WawlaInformation { + val text: ChatComponent +} 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 index ef8503e79..7e79cb3d1 100644 --- 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 @@ -14,7 +14,9 @@ package de.bixilon.minosoft.gui.rendering.gui.hud.elements.wawla.block import de.bixilon.kotlinglm.vec2.Vec2i +import de.bixilon.minosoft.data.registries.blocks.wawla.BlockWawlaProvider import de.bixilon.minosoft.data.registries.identified.Namespaces +import de.bixilon.minosoft.data.text.BaseComponent 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 @@ -26,6 +28,7 @@ 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 additional = createAdditionalInformation() private val mod = createMod() init { @@ -38,13 +41,15 @@ class BlockWawlaElement(wawla: WawlaHUDElement, private val target: BlockTarget) name.render(offset, consumer, options) offset.y += name.size.y + additional?.let { it.render(offset, consumer, options); offset.y += it.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), + x = maxOf(name.size.x, mod?.size?.x ?: 0, additional?.size?.x ?: 0), + y = name.size.y + (mod?.size?.y ?: 0) + (additional?.size?.y ?: 0), ) this.size = size @@ -61,4 +66,26 @@ class BlockWawlaElement(wawla: WawlaHUDElement, private val target: BlockTarget) } return TextElement(guiRenderer, TextComponent(namespace).color(ChatColors.BLUE), background = false) } + + private fun createAdditionalInformation(): TextElement? { + val component = BaseComponent() + + if (target.blockState.block is BlockWawlaProvider) { + component += target.blockState.block.getWawlaInformation(context.connection, target).text + component += "\n" + } + if (target.entity is BlockWawlaProvider) { + component += target.entity.getWawlaInformation(context.connection, target).text + component += "\n" + } + + if (component.parts.isEmpty()) return null + + if (component.parts.last().toString() == "\n") { + component.parts.removeLast() + } + component.setFallbackColor(ChatColors.GRAY) + + return TextElement(guiRenderer, component, background = false) + } } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/entity/EntityWawlaElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/entity/EntityWawlaElement.kt index 899a9c83c..7a93196c2 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/entity/EntityWawlaElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/entity/EntityWawlaElement.kt @@ -14,6 +14,7 @@ package de.bixilon.minosoft.gui.rendering.gui.hud.elements.wawla.entity import de.bixilon.kotlinglm.vec2.Vec2i +import de.bixilon.minosoft.data.entities.wawla.EntityWawlaProvider import de.bixilon.minosoft.data.registries.identified.Namespaces import de.bixilon.minosoft.data.text.TextComponent import de.bixilon.minosoft.data.text.formatting.color.ChatColors @@ -26,6 +27,7 @@ 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 additional = createAdditionalInformation() private val mod = createMod() init { @@ -36,13 +38,15 @@ class EntityWawlaElement(wawla: WawlaHUDElement, private val target: EntityTarge name.render(offset, consumer, options) offset.y += name.size.y + additional?.let { it.render(offset, consumer, options); offset.y += it.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), + x = maxOf(name.size.x, mod?.size?.x ?: 0, additional?.size?.x ?: 0), + y = name.size.y + (mod?.size?.y ?: 0) + (additional?.size?.y ?: 0), ) this.size = size @@ -59,4 +63,14 @@ class EntityWawlaElement(wawla: WawlaHUDElement, private val target: EntityTarge } return TextElement(guiRenderer, TextComponent(namespace).color(ChatColors.BLUE), background = false) } + + private fun createAdditionalInformation(): TextElement? { + if (target.entity !is EntityWawlaProvider) return null + + val text = target.entity.getWawlaInformation(context.connection, target).text + + text.setFallbackColor(ChatColors.GRAY) + + return TextElement(guiRenderer, text, background = false) + } } From ae5e45f454e2783534d80c8465853be50a01d483 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Wed, 18 Jan 2023 14:39:21 +0100 Subject: [PATCH 6/9] wawla: config, more entity information --- .../config/profile/profiles/gui/hud/HudC.kt | 4 ++- .../profile/profiles/gui/hud/wawla/WawlaC.kt | 27 +++++++++++++++++ .../profiles/gui/hud/wawla/block/BlockC.kt} | 9 ++++-- .../profiles/gui/hud/wawla/entity/EntityC.kt} | 12 ++++++-- .../data/entities/entities/LivingEntity.kt | 3 +- .../entities/entities/decoration/ItemFrame.kt | 12 ++++++-- .../entities/wawla/EntityWawlaProvider.kt | 3 +- .../blocks/wawla/BlockWawlaProvider.kt | 3 +- .../gui/hud/elements/wawla/WawlaHUDElement.kt | 19 ++++++++++-- .../elements/wawla/block/BlockWawlaElement.kt | 4 +-- .../wawla/entity/EntityWawlaElement.kt | 30 ++++++++++++++++++- 11 files changed, 108 insertions(+), 18 deletions(-) create mode 100644 src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/wawla/WawlaC.kt rename src/main/java/de/bixilon/minosoft/{data/entities/wawla/EntityWawlaInformation.kt => config/profile/profiles/gui/hud/wawla/block/BlockC.kt} (72%) rename src/main/java/de/bixilon/minosoft/{data/registries/blocks/wawla/BlockWawlaInformation.kt => config/profile/profiles/gui/hud/wawla/entity/EntityC.kt} (66%) diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/HudC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/HudC.kt index 41f191677..a06df32dd 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/HudC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/HudC.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. * @@ -16,8 +16,10 @@ package de.bixilon.minosoft.config.profile.profiles.gui.hud import de.bixilon.minosoft.config.profile.profiles.gui.GUIProfile import de.bixilon.minosoft.config.profile.profiles.gui.hud.crosshair.CrosshairC import de.bixilon.minosoft.config.profile.profiles.gui.hud.hotbar.HotbarC +import de.bixilon.minosoft.config.profile.profiles.gui.hud.wawla.WawlaC class HudC(profile: GUIProfile) { val crosshair = CrosshairC(profile) val hotbar = HotbarC(profile) + val wawla = WawlaC(profile) } diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/wawla/WawlaC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/wawla/WawlaC.kt new file mode 100644 index 000000000..d7b6668d8 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/wawla/WawlaC.kt @@ -0,0 +1,27 @@ +/* + * 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.config.profile.profiles.gui.hud.wawla + +import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate +import de.bixilon.minosoft.config.profile.profiles.gui.GUIProfile +import de.bixilon.minosoft.config.profile.profiles.gui.hud.wawla.block.BlockC +import de.bixilon.minosoft.config.profile.profiles.gui.hud.wawla.entity.EntityC + +class WawlaC(profile: GUIProfile) { + var enabled by BooleanDelegate(profile, true) + var limitReach by BooleanDelegate(profile, true) + + val block = BlockC(profile) + val entity = EntityC(profile) +} diff --git a/src/main/java/de/bixilon/minosoft/data/entities/wawla/EntityWawlaInformation.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/wawla/block/BlockC.kt similarity index 72% rename from src/main/java/de/bixilon/minosoft/data/entities/wawla/EntityWawlaInformation.kt rename to src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/wawla/block/BlockC.kt index 3c6dc6576..832158d5a 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/wawla/EntityWawlaInformation.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/wawla/block/BlockC.kt @@ -11,8 +11,11 @@ * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ -package de.bixilon.minosoft.data.entities.wawla +package de.bixilon.minosoft.config.profile.profiles.gui.hud.wawla.block -import de.bixilon.minosoft.data.registries.wawla.WawlaInformation +import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate +import de.bixilon.minosoft.config.profile.profiles.gui.GUIProfile -interface EntityWawlaInformation : WawlaInformation +class BlockC(profile: GUIProfile) { + var enabled by BooleanDelegate(profile, true) +} diff --git a/src/main/java/de/bixilon/minosoft/data/registries/blocks/wawla/BlockWawlaInformation.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/wawla/entity/EntityC.kt similarity index 66% rename from src/main/java/de/bixilon/minosoft/data/registries/blocks/wawla/BlockWawlaInformation.kt rename to src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/wawla/entity/EntityC.kt index 36371ba3d..2e48475b5 100644 --- a/src/main/java/de/bixilon/minosoft/data/registries/blocks/wawla/BlockWawlaInformation.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/wawla/entity/EntityC.kt @@ -11,8 +11,14 @@ * This software is not affiliated with Mojang AB, the original developer of Minecraft. */ -package de.bixilon.minosoft.data.registries.blocks.wawla +package de.bixilon.minosoft.config.profile.profiles.gui.hud.wawla.entity -import de.bixilon.minosoft.data.registries.wawla.WawlaInformation +import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate +import de.bixilon.minosoft.config.profile.profiles.gui.GUIProfile -interface BlockWawlaInformation : WawlaInformation +class EntityC(profile: GUIProfile) { + var enabled by BooleanDelegate(profile, true) + var health by BooleanDelegate(profile, true) + + var hand by BooleanDelegate(profile, true) +} diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/LivingEntity.kt b/src/main/java/de/bixilon/minosoft/data/entities/entities/LivingEntity.kt index 776f47900..7208ce77d 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/LivingEntity.kt +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/LivingEntity.kt @@ -20,6 +20,7 @@ import de.bixilon.minosoft.data.entities.Poses import de.bixilon.minosoft.data.entities.data.EntityData import de.bixilon.minosoft.data.entities.data.EntityDataField import de.bixilon.minosoft.data.entities.entities.player.Hands +import de.bixilon.minosoft.data.entities.wawla.EntityWawlaProvider import de.bixilon.minosoft.data.registries.effects.attributes.DefaultStatusEffectAttributeNames import de.bixilon.minosoft.data.registries.entities.EntityType import de.bixilon.minosoft.data.text.formatting.color.ChatColors @@ -30,7 +31,7 @@ import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.sp import de.bixilon.minosoft.gui.rendering.util.VecUtil.horizontal import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection -abstract class LivingEntity(connection: PlayConnection, entityType: EntityType, data: EntityData, position: Vec3d, rotation: EntityRotation) : Entity(connection, entityType, data, position, rotation) { +abstract class LivingEntity(connection: PlayConnection, entityType: EntityType, data: EntityData, position: Vec3d, rotation: EntityRotation) : Entity(connection, entityType, data, position, rotation), EntityWawlaProvider { private val entityEffectParticle = connection.registries.particleType[EntityEffectParticle] private val ambientEntityEffectParticle = connection.registries.particleType[AmbientEntityEffectParticle] diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/decoration/ItemFrame.kt b/src/main/java/de/bixilon/minosoft/data/entities/entities/decoration/ItemFrame.kt index 37c62ba75..3f57ddf00 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/decoration/ItemFrame.kt +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/decoration/ItemFrame.kt @@ -19,14 +19,17 @@ import de.bixilon.minosoft.data.entities.EntityRotation import de.bixilon.minosoft.data.entities.data.EntityData import de.bixilon.minosoft.data.entities.data.EntityDataField import de.bixilon.minosoft.data.entities.entities.SynchronizedEntityData +import de.bixilon.minosoft.data.entities.wawla.EntityWawlaProvider import de.bixilon.minosoft.data.registries.entities.EntityFactory import de.bixilon.minosoft.data.registries.entities.EntityType import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft import de.bixilon.minosoft.data.registries.identified.ResourceLocation +import de.bixilon.minosoft.data.text.ChatComponent +import de.bixilon.minosoft.data.text.TextComponent +import de.bixilon.minosoft.gui.rendering.camera.target.targets.EntityTarget import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection -import de.bixilon.minosoft.util.KUtil -open class ItemFrame(connection: PlayConnection, entityType: EntityType, data: EntityData, position: Vec3d, rotation: EntityRotation) : HangingEntity(connection, entityType, data, position, rotation) { +open class ItemFrame(connection: PlayConnection, entityType: EntityType, data: EntityData, position: Vec3d, rotation: EntityRotation) : HangingEntity(connection, entityType, data, position, rotation), EntityWawlaProvider { @get:SynchronizedEntityData val item: ItemStack? @@ -39,10 +42,15 @@ open class ItemFrame(connection: PlayConnection, entityType: EntityType, data: E @get:SynchronizedEntityData var facing: Directions = Directions.NORTH + override fun setObjectData(data: Int) { facing = Directions[data] } + override fun getWawlaInformation(connection: PlayConnection, target: EntityTarget): ChatComponent { + return TextComponent("Item: $item") + } + companion object : EntityFactory { override val identifier: ResourceLocation = minecraft("item_frame") private val ITEM_DATA = EntityDataField("ITEM_FRAME_ITEM") 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 index 89f66d1c8..7f098caaf 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/wawla/EntityWawlaProvider.kt +++ b/src/main/java/de/bixilon/minosoft/data/entities/wawla/EntityWawlaProvider.kt @@ -13,10 +13,11 @@ package de.bixilon.minosoft.data.entities.wawla +import de.bixilon.minosoft.data.text.ChatComponent 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 + fun getWawlaInformation(connection: PlayConnection, target: EntityTarget): ChatComponent } 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 index e3f102908..c6ad6c39d 100644 --- 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 @@ -13,10 +13,11 @@ package de.bixilon.minosoft.data.registries.blocks.wawla +import de.bixilon.minosoft.data.text.ChatComponent 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 + fun getWawlaInformation(connection: PlayConnection, target: BlockTarget): ChatComponent } 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 index 796759a68..da6a36fb5 100644 --- 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 @@ -35,15 +35,28 @@ import de.bixilon.minosoft.util.KUtil.toResourceLocation class WawlaHUDElement(guiRenderer: GUIRenderer) : Element(guiRenderer), LayoutedElement, AsyncDrawable { private var element: WawlaElement? = null + val profile = guiRenderer.connection.profiles.gui.hud.wawla + override val layoutOffset: Vec2i get() = Vec2i((guiRenderer.scaledSize.x - ((element?.size?.x ?: 0) + BACKGROUND_SIZE)) / 2, BACKGROUND_SIZE) + override val skipDraw: Boolean + get() = !profile.enabled override fun drawAsync() { val target = context.camera.targetHandler.target - val element: WawlaElement? = when (target) { - is BlockTarget -> BlockWawlaElement(this, target) - is EntityTarget -> EntityWawlaElement(this, target) + + if (target == null) { + this.element = null + forceSilentApply() + return + } + val distance = target.distance + + + val element: WawlaElement? = when { + target is BlockTarget && profile.block.enabled && (!profile.limitReach || distance <= context.connection.player.reachDistance) -> BlockWawlaElement(this, target) + target is EntityTarget && profile.entity.enabled && (!profile.limitReach || distance <= 3.0) -> EntityWawlaElement(this, target) // TODO: use constant for distance else -> null } this.element = element 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 index 7e79cb3d1..d457f3e33 100644 --- 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 @@ -71,11 +71,11 @@ class BlockWawlaElement(wawla: WawlaHUDElement, private val target: BlockTarget) val component = BaseComponent() if (target.blockState.block is BlockWawlaProvider) { - component += target.blockState.block.getWawlaInformation(context.connection, target).text + component += target.blockState.block.getWawlaInformation(context.connection, target) component += "\n" } if (target.entity is BlockWawlaProvider) { - component += target.entity.getWawlaInformation(context.connection, target).text + component += target.entity.getWawlaInformation(context.connection, target) component += "\n" } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/entity/EntityWawlaElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/entity/EntityWawlaElement.kt index 7a93196c2..74679c640 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/entity/EntityWawlaElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/entity/EntityWawlaElement.kt @@ -14,8 +14,13 @@ package de.bixilon.minosoft.gui.rendering.gui.hud.elements.wawla.entity import de.bixilon.kotlinglm.vec2.Vec2i +import de.bixilon.kutil.math.simple.DoubleMath.rounded10 +import de.bixilon.minosoft.data.container.EquipmentSlots +import de.bixilon.minosoft.data.entities.entities.LivingEntity import de.bixilon.minosoft.data.entities.wawla.EntityWawlaProvider +import de.bixilon.minosoft.data.registries.effects.attributes.DefaultStatusEffectAttributeNames import de.bixilon.minosoft.data.registries.identified.Namespaces +import de.bixilon.minosoft.data.text.BaseComponent 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 @@ -27,6 +32,7 @@ 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 base = createBaseInformation() private val additional = createAdditionalInformation() private val mod = createMod() @@ -64,10 +70,32 @@ class EntityWawlaElement(wawla: WawlaHUDElement, private val target: EntityTarge return TextElement(guiRenderer, TextComponent(namespace).color(ChatColors.BLUE), background = false) } + private fun createBaseInformation(): TextElement? { + val entity = target.entity + val component = BaseComponent() + if (entity is LivingEntity && wawla.profile.entity.health) { + component += TextComponent("Health: ${entity.health.rounded10}/${java.lang.Float.max(0.0f, entity.getAttributeValue(DefaultStatusEffectAttributeNames.GENERIC_MAX_HEALTH).toFloat() + entity.absorptionHearts)}") + component += "\n" + } + val hand = entity.equipment[EquipmentSlots.MAIN_HAND] + if (wawla.profile.entity.hand && hand != null) { + component += TextComponent("Hand: ${hand.item.count}x ${hand.item.item}") + component += "\n" + } + + if (component.length == 0) return null + + component.setFallbackColor(ChatColors.GRAY) + + return TextElement(guiRenderer, component, background = false) + } + private fun createAdditionalInformation(): TextElement? { if (target.entity !is EntityWawlaProvider) return null - val text = target.entity.getWawlaInformation(context.connection, target).text + val text = target.entity.getWawlaInformation(context.connection, target) + + if (text.length == 0) return null // isEmpty text.setFallbackColor(ChatColors.GRAY) From 4308d1b0d4ac2c3b7b74f606598e233ac91a2cfa Mon Sep 17 00:00:00 2001 From: Bixilon Date: Wed, 18 Jan 2023 15:03:04 +0100 Subject: [PATCH 7/9] wawla: improvements --- .../profile/profiles/gui/hud/wawla/WawlaC.kt | 2 + .../profiles/gui/hud/wawla/entity/EntityC.kt | 2 +- .../data/entities/entities/LivingEntity.kt | 3 +- .../blocks/types/plant/CropBlock.kt | 25 ++++++++++- .../minosoft/data/text/ChatComponentUtil.kt | 43 +++++++++++++++++++ .../gui/hud/elements/wawla/WawlaElement.kt | 38 ++++++++++++++++ .../elements/wawla/block/BlockWawlaElement.kt | 39 +++++------------ .../wawla/entity/EntityWawlaElement.kt | 35 +++++---------- 8 files changed, 130 insertions(+), 57 deletions(-) create mode 100644 src/main/java/de/bixilon/minosoft/data/text/ChatComponentUtil.kt diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/wawla/WawlaC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/wawla/WawlaC.kt index d7b6668d8..7423aca4e 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/wawla/WawlaC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/wawla/WawlaC.kt @@ -22,6 +22,8 @@ class WawlaC(profile: GUIProfile) { var enabled by BooleanDelegate(profile, true) var limitReach by BooleanDelegate(profile, true) + var identifier by BooleanDelegate(profile, false) + val block = BlockC(profile) val entity = EntityC(profile) } diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/wawla/entity/EntityC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/wawla/entity/EntityC.kt index 2e48475b5..4bc58c527 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/wawla/entity/EntityC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/gui/hud/wawla/entity/EntityC.kt @@ -20,5 +20,5 @@ class EntityC(profile: GUIProfile) { var enabled by BooleanDelegate(profile, true) var health by BooleanDelegate(profile, true) - var hand by BooleanDelegate(profile, true) + var hand by BooleanDelegate(profile, false) } diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/LivingEntity.kt b/src/main/java/de/bixilon/minosoft/data/entities/entities/LivingEntity.kt index 7208ce77d..776f47900 100644 --- a/src/main/java/de/bixilon/minosoft/data/entities/entities/LivingEntity.kt +++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/LivingEntity.kt @@ -20,7 +20,6 @@ import de.bixilon.minosoft.data.entities.Poses import de.bixilon.minosoft.data.entities.data.EntityData import de.bixilon.minosoft.data.entities.data.EntityDataField import de.bixilon.minosoft.data.entities.entities.player.Hands -import de.bixilon.minosoft.data.entities.wawla.EntityWawlaProvider import de.bixilon.minosoft.data.registries.effects.attributes.DefaultStatusEffectAttributeNames import de.bixilon.minosoft.data.registries.entities.EntityType import de.bixilon.minosoft.data.text.formatting.color.ChatColors @@ -31,7 +30,7 @@ import de.bixilon.minosoft.gui.rendering.particle.types.render.texture.simple.sp import de.bixilon.minosoft.gui.rendering.util.VecUtil.horizontal import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection -abstract class LivingEntity(connection: PlayConnection, entityType: EntityType, data: EntityData, position: Vec3d, rotation: EntityRotation) : Entity(connection, entityType, data, position, rotation), EntityWawlaProvider { +abstract class LivingEntity(connection: PlayConnection, entityType: EntityType, data: EntityData, position: Vec3d, rotation: EntityRotation) : Entity(connection, entityType, data, position, rotation) { private val entityEffectParticle = connection.registries.particleType[EntityEffectParticle] private val ambientEntityEffectParticle = connection.registries.particleType[AmbientEntityEffectParticle] diff --git a/src/main/java/de/bixilon/minosoft/data/registries/blocks/types/plant/CropBlock.kt b/src/main/java/de/bixilon/minosoft/data/registries/blocks/types/plant/CropBlock.kt index 0df56df52..a4ca82085 100644 --- a/src/main/java/de/bixilon/minosoft/data/registries/blocks/types/plant/CropBlock.kt +++ b/src/main/java/de/bixilon/minosoft/data/registries/blocks/types/plant/CropBlock.kt @@ -16,16 +16,39 @@ package de.bixilon.minosoft.data.registries.blocks.types.plant import de.bixilon.minosoft.data.registries.blocks.BlockFactory import de.bixilon.minosoft.data.registries.blocks.BlockState import de.bixilon.minosoft.data.registries.blocks.MinecraftBlocks +import de.bixilon.minosoft.data.registries.blocks.wawla.BlockWawlaProvider import de.bixilon.minosoft.data.registries.identified.ResourceLocation import de.bixilon.minosoft.data.registries.registries.Registries +import de.bixilon.minosoft.data.text.BaseComponent +import de.bixilon.minosoft.data.text.ChatComponent +import de.bixilon.minosoft.data.world.chunk.light.SectionLight.Companion.BLOCK_LIGHT_MASK +import de.bixilon.minosoft.data.world.chunk.light.SectionLight.Companion.SKY_LIGHT_MASK +import de.bixilon.minosoft.gui.rendering.camera.target.targets.BlockTarget +import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection -open class CropBlock(resourceLocation: ResourceLocation, registries: Registries, data: Map) : PlantBlock(resourceLocation, registries, data) { +open class CropBlock(resourceLocation: ResourceLocation, registries: Registries, data: Map) : PlantBlock(resourceLocation, registries, data), BlockWawlaProvider { override fun canPlaceOn(blockState: BlockState): Boolean { return blockState.block.identifier == MinecraftBlocks.FARMLAND } + override fun getWawlaInformation(connection: PlayConnection, target: BlockTarget): ChatComponent { + val light = connection.world.getLight(target.blockPosition) + + val blockLight = light and BLOCK_LIGHT_MASK + val skyLight = (light and SKY_LIGHT_MASK) shr 4 + + val component = BaseComponent("Light: ") + + component += if (blockLight < MIN_LIGHT_LEVEL) "§4$blockLight§r" else "§a$blockLight§r" + + component += "($skyLight)" + + return component + } + companion object : BlockFactory { + const val MIN_LIGHT_LEVEL = 7 override fun build(resourceLocation: ResourceLocation, registries: Registries, data: Map): CropBlock { return CropBlock(resourceLocation, registries, data) diff --git a/src/main/java/de/bixilon/minosoft/data/text/ChatComponentUtil.kt b/src/main/java/de/bixilon/minosoft/data/text/ChatComponentUtil.kt new file mode 100644 index 000000000..8de97a661 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/text/ChatComponentUtil.kt @@ -0,0 +1,43 @@ +/* + * 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.text + +object ChatComponentUtil { + + fun BaseComponent.removeTrailingNewlines() { + val iterator = this.parts.iterator() + + for (part in iterator) { + val message = part.message + if (message.isEmptyOrNewline()) { + iterator.remove() + continue + } + break + } + + for (index in parts.size - 1 downTo 0) { + val message = parts[index].message + if (message.isEmptyOrNewline()) { + parts.removeAt(index) + continue + } + break + } + } + + private fun String.isEmptyOrNewline(): Boolean { + return isEmpty() || this == "\n" || this == "\r" || this == "\n\r" || this == "\r\n" + } +} 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 index fa66cfd84..de56a2a99 100644 --- 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 @@ -13,16 +13,54 @@ package de.bixilon.minosoft.gui.rendering.gui.hud.elements.wawla +import de.bixilon.kotlinglm.vec2.Vec2i +import de.bixilon.minosoft.data.registries.identified.Identified 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 +import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer +import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions +import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY +import de.bixilon.minosoft.util.KUtil.format abstract class WawlaElement(protected val wawla: WawlaHUDElement) : Element(wawla.guiRenderer) { + abstract val elements: List + + + override fun forceRender(offset: Vec2i, consumer: GUIVertexConsumer, options: GUIVertexOptions?) { + for (element in elements) { + if (element == null) continue + + element.render(offset, consumer, options) + offset.y += element.size.y + } + } + + override fun forceSilentApply() { + val size = Vec2i.EMPTY + + for (element in elements) { + if (element == null) continue + + val elementSize = element.size + size.x = maxOf(size.x, elementSize.x) + size.y += elementSize.y + } + + this.size = size + } 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) } + + protected fun createIdentifierElement(item: Identified): TextElement? { + if (!wawla.profile.identifier) { + return null + } + return TextElement(guiRenderer, item.identifier.format(), background = false, scale = 0.8f) + } } 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 index d457f3e33..2f8a8876f 100644 --- 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 @@ -13,48 +13,30 @@ package de.bixilon.minosoft.gui.rendering.gui.hud.elements.wawla.block -import de.bixilon.kotlinglm.vec2.Vec2i import de.bixilon.minosoft.data.registries.blocks.wawla.BlockWawlaProvider import de.bixilon.minosoft.data.registries.identified.Namespaces import de.bixilon.minosoft.data.text.BaseComponent +import de.bixilon.minosoft.data.text.ChatComponentUtil.removeTrailingNewlines 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.Element 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 additional = createAdditionalInformation() - private val mod = createMod() + override val elements: List = listOf( + createName(), + createAdditionalInformation(), + createIdentifierElement(target.blockState.block), + 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 - - additional?.let { it.render(offset, consumer, options); offset.y += it.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, additional?.size?.x ?: 0), - y = name.size.y + (mod?.size?.y ?: 0) + (additional?.size?.y ?: 0), - ) - - this.size = size - } - private fun createName(): TextElement { return createNameElement(target.blockState.block.item.translationKey) // TODO: use key of block and not item } @@ -79,11 +61,10 @@ class BlockWawlaElement(wawla: WawlaHUDElement, private val target: BlockTarget) component += "\n" } + component.removeTrailingNewlines() + if (component.parts.isEmpty()) return null - if (component.parts.last().toString() == "\n") { - component.parts.removeLast() - } component.setFallbackColor(ChatColors.GRAY) return TextElement(guiRenderer, component, background = false) diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/entity/EntityWawlaElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/entity/EntityWawlaElement.kt index 74679c640..e4e0e818a 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/entity/EntityWawlaElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/entity/EntityWawlaElement.kt @@ -13,7 +13,6 @@ package de.bixilon.minosoft.gui.rendering.gui.hud.elements.wawla.entity -import de.bixilon.kotlinglm.vec2.Vec2i import de.bixilon.kutil.math.simple.DoubleMath.rounded10 import de.bixilon.minosoft.data.container.EquipmentSlots import de.bixilon.minosoft.data.entities.entities.LivingEntity @@ -21,42 +20,28 @@ import de.bixilon.minosoft.data.entities.wawla.EntityWawlaProvider import de.bixilon.minosoft.data.registries.effects.attributes.DefaultStatusEffectAttributeNames import de.bixilon.minosoft.data.registries.identified.Namespaces import de.bixilon.minosoft.data.text.BaseComponent +import de.bixilon.minosoft.data.text.ChatComponentUtil.removeTrailingNewlines 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.Element 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 base = createBaseInformation() - private val additional = createAdditionalInformation() - private val mod = createMod() + override val elements: List = listOf( + createName(), + createBaseInformation(), + createAdditionalInformation(), + createIdentifierElement(target.entity.type), + createMod(), + ) init { forceSilentApply() } - override fun forceRender(offset: Vec2i, consumer: GUIVertexConsumer, options: GUIVertexOptions?) { - name.render(offset, consumer, options) - offset.y += name.size.y - - additional?.let { it.render(offset, consumer, options); offset.y += it.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, additional?.size?.x ?: 0), - y = name.size.y + (mod?.size?.y ?: 0) + (additional?.size?.y ?: 0), - ) - - this.size = size - } private fun createName(): TextElement { return createNameElement(target.entity.type.translationKey) @@ -83,6 +68,7 @@ class EntityWawlaElement(wawla: WawlaHUDElement, private val target: EntityTarge component += "\n" } + component.removeTrailingNewlines() if (component.length == 0) return null component.setFallbackColor(ChatColors.GRAY) @@ -95,6 +81,7 @@ class EntityWawlaElement(wawla: WawlaHUDElement, private val target: EntityTarge val text = target.entity.getWawlaInformation(context.connection, target) + if (text is BaseComponent) text.removeTrailingNewlines() if (text.length == 0) return null // isEmpty text.setFallbackColor(ChatColors.GRAY) From ae4da3d0b39a3a57b2f40f0555af054e62609f52 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Wed, 18 Jan 2023 15:39:16 +0100 Subject: [PATCH 8/9] wawla: break block indicator --- .../elements/wawla/block/BlockWawlaElement.kt | 4 +- .../wawla/block/WawlaBreakProgressElement.kt | 58 +++++++++++++++++++ .../input/interaction/BlockBreakStatus.kt | 38 ++++++++++++ .../interaction/BreakInteractionHandler.kt | 14 ++++- .../interaction/InteractInteractionHandler.kt | 5 +- 5 files changed, 113 insertions(+), 6 deletions(-) create mode 100644 src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/block/WawlaBreakProgressElement.kt create mode 100644 src/main/java/de/bixilon/minosoft/gui/rendering/input/interaction/BlockBreakStatus.kt 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 index 2f8a8876f..e2975c607 100644 --- 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 @@ -25,15 +25,17 @@ 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 -class BlockWawlaElement(wawla: WawlaHUDElement, private val target: BlockTarget) : WawlaElement(wawla) { +class BlockWawlaElement(wawla: WawlaHUDElement, val target: BlockTarget) : WawlaElement(wawla) { override val elements: List = listOf( createName(), createAdditionalInformation(), createIdentifierElement(target.blockState.block), createMod(), + WawlaBreakProgressElement(this), ) init { + parent = wawla forceSilentApply() } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/block/WawlaBreakProgressElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/block/WawlaBreakProgressElement.kt new file mode 100644 index 000000000..d01fc5c1e --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/wawla/block/WawlaBreakProgressElement.kt @@ -0,0 +1,58 @@ +/* + * 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.text.formatting.color.ChatColors +import de.bixilon.minosoft.gui.rendering.gui.elements.Element +import de.bixilon.minosoft.gui.rendering.gui.elements.primitive.ColorElement +import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer +import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions +import de.bixilon.minosoft.gui.rendering.input.interaction.BlockBreakStatus +import de.bixilon.minosoft.gui.rendering.util.vec.vec2.Vec2iUtil.EMPTY + +class WawlaBreakProgressElement(block: BlockWawlaElement) : Element(block.guiRenderer) { + private val `break` = context.inputHandler.interactionManager.`break` + private val status = `break`.status + private val progress = if (status != null) `break`.breakProgress else null + + init { + parent = block + forceSilentApply() + } + + override fun forceRender(offset: Vec2i, consumer: GUIVertexConsumer, options: GUIVertexOptions?) { + if (progress == null) { + return + } + val maxWidth = parent?.size?.x ?: 0 + if (status == BlockBreakStatus.USELESS) { + ColorElement(guiRenderer, Vec2i(maxWidth, size.y), color = ChatColors.RED).forceRender(offset, consumer, options) + return + } + val width = (progress * (maxWidth - 1)).toInt() + 1 // bar is always 1 pixel wide + + val color = when (status) { + BlockBreakStatus.INEFFECTIVE -> ChatColors.RED + BlockBreakStatus.SLOW -> ChatColors.YELLOW + else -> ChatColors.GREEN + } + + ColorElement(guiRenderer, Vec2i(width, size.y), color).render(offset, consumer, options) + } + + override fun forceSilentApply() { + this.size = if (progress == null) Vec2i.EMPTY else Vec2i(-1, 3) + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/input/interaction/BlockBreakStatus.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/input/interaction/BlockBreakStatus.kt new file mode 100644 index 000000000..04857c227 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/input/interaction/BlockBreakStatus.kt @@ -0,0 +1,38 @@ +/* + * 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.input.interaction + +enum class BlockBreakStatus { + /** + * Block can not be broken + */ + USELESS, + + /** + * Block can only be broken with tool + */ + INEFFECTIVE, + + /** + * Breaking can be faster with the correct tool + */ + SLOW, + + /** + * Current tool is effective + */ + EFFECTIVE, + ; + +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/input/interaction/BreakInteractionHandler.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/input/interaction/BreakInteractionHandler.kt index 3482d7bb1..984234a53 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/input/interaction/BreakInteractionHandler.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/input/interaction/BreakInteractionHandler.kt @@ -48,8 +48,8 @@ class BreakInteractionHandler( private var breakBlockState: BlockState? = null var breakProgress = Double.NEGATIVE_INFINITY private set - val breakingBlock: Boolean - get() = breakPosition != null + var status: BlockBreakStatus? = null + private set private var breakSelectedSlot: Int = -1 @@ -63,6 +63,7 @@ class BreakInteractionHandler( breakPosition = null breakBlockState = null breakProgress = Double.NEGATIVE_INFINITY + status = null breakSelectedSlot = -1 } @@ -238,6 +239,15 @@ class BreakInteractionHandler( } } + // TODO: properly set slow status if block drops without tool + this.status = when { + damage <= 0.0f -> BlockBreakStatus.USELESS + speedMultiplier <= 1.0f -> BlockBreakStatus.SLOW + isBestTool -> BlockBreakStatus.EFFECTIVE + target.blockState.requiresTool -> BlockBreakStatus.INEFFECTIVE + else -> BlockBreakStatus.SLOW + } + if (breakProgress >= 1.0f) { finishDigging() } diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/input/interaction/InteractInteractionHandler.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/input/interaction/InteractInteractionHandler.kt index e8f96c723..0318aebb3 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/input/interaction/InteractInteractionHandler.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/input/interaction/InteractInteractionHandler.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. * @@ -14,7 +14,6 @@ package de.bixilon.minosoft.gui.rendering.input.interaction import de.bixilon.kotlinglm.vec3.Vec3 -import de.bixilon.kutil.time.TimeUtil import de.bixilon.kutil.time.TimeUtil.millis import de.bixilon.minosoft.config.key.KeyActions import de.bixilon.minosoft.config.key.KeyBinding @@ -167,7 +166,7 @@ class InteractInteractionHandler( } fun useItem() { - if (interactionManager.`break`.breakingBlock) { + if (interactionManager.`break`.status != null) { return } From 96d3b9b6479ec73f7b61faab40bb99efc64b93ac Mon Sep 17 00:00:00 2001 From: Bixilon Date: Wed, 18 Jan 2023 15:46:06 +0100 Subject: [PATCH 9/9] wawla: add missing space to CropBlock --- .../minosoft/data/registries/blocks/types/plant/CropBlock.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/bixilon/minosoft/data/registries/blocks/types/plant/CropBlock.kt b/src/main/java/de/bixilon/minosoft/data/registries/blocks/types/plant/CropBlock.kt index a4ca82085..1ead2cca2 100644 --- a/src/main/java/de/bixilon/minosoft/data/registries/blocks/types/plant/CropBlock.kt +++ b/src/main/java/de/bixilon/minosoft/data/registries/blocks/types/plant/CropBlock.kt @@ -42,7 +42,7 @@ open class CropBlock(resourceLocation: ResourceLocation, registries: Registries, component += if (blockLight < MIN_LIGHT_LEVEL) "§4$blockLight§r" else "§a$blockLight§r" - component += "($skyLight)" + component += " ($skyLight)" return component }