wawla: break block indicator

This commit is contained in:
Bixilon 2023-01-18 15:39:16 +01:00
parent 4308d1b0d4
commit ae4da3d0b3
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
5 changed files with 113 additions and 6 deletions

View File

@ -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.WawlaElement
import de.bixilon.minosoft.gui.rendering.gui.hud.elements.wawla.WawlaHUDElement 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<Element?> = listOf( override val elements: List<Element?> = listOf(
createName(), createName(),
createAdditionalInformation(), createAdditionalInformation(),
createIdentifierElement(target.blockState.block), createIdentifierElement(target.blockState.block),
createMod(), createMod(),
WawlaBreakProgressElement(this),
) )
init { init {
parent = wawla
forceSilentApply() forceSilentApply()
} }

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.gui.rendering.gui.hud.elements.wawla.block
import de.bixilon.kotlinglm.vec2.Vec2i
import de.bixilon.minosoft.data.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)
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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,
;
}

View File

@ -48,8 +48,8 @@ class BreakInteractionHandler(
private var breakBlockState: BlockState? = null private var breakBlockState: BlockState? = null
var breakProgress = Double.NEGATIVE_INFINITY var breakProgress = Double.NEGATIVE_INFINITY
private set private set
val breakingBlock: Boolean var status: BlockBreakStatus? = null
get() = breakPosition != null private set
private var breakSelectedSlot: Int = -1 private var breakSelectedSlot: Int = -1
@ -63,6 +63,7 @@ class BreakInteractionHandler(
breakPosition = null breakPosition = null
breakBlockState = null breakBlockState = null
breakProgress = Double.NEGATIVE_INFINITY breakProgress = Double.NEGATIVE_INFINITY
status = null
breakSelectedSlot = -1 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) { if (breakProgress >= 1.0f) {
finishDigging() finishDigging()
} }

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * 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. * 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 package de.bixilon.minosoft.gui.rendering.input.interaction
import de.bixilon.kotlinglm.vec3.Vec3 import de.bixilon.kotlinglm.vec3.Vec3
import de.bixilon.kutil.time.TimeUtil
import de.bixilon.kutil.time.TimeUtil.millis import de.bixilon.kutil.time.TimeUtil.millis
import de.bixilon.minosoft.config.key.KeyActions import de.bixilon.minosoft.config.key.KeyActions
import de.bixilon.minosoft.config.key.KeyBinding import de.bixilon.minosoft.config.key.KeyBinding
@ -167,7 +166,7 @@ class InteractInteractionHandler(
} }
fun useItem() { fun useItem() {
if (interactionManager.`break`.breakingBlock) { if (interactionManager.`break`.status != null) {
return return
} }