scoreboard score feature: performance, render distance, config, name offset

This commit is contained in:
Moritz Zwerger 2023-11-06 15:55:00 +01:00
parent 199b8a7587
commit 92b37112cf
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 52 additions and 1 deletions

View File

@ -16,8 +16,10 @@ package de.bixilon.minosoft.config.profile.profiles.entity.features
import de.bixilon.minosoft.config.profile.profiles.entity.EntityProfile
import de.bixilon.minosoft.config.profile.profiles.entity.features.hitbox.HitboxC
import de.bixilon.minosoft.config.profile.profiles.entity.features.name.NameC
import de.bixilon.minosoft.config.profile.profiles.entity.features.score.ScoreC
class FeaturesC(profile: EntityProfile) {
val hitbox = HitboxC(profile)
val name = NameC(profile)
val score = ScoreC(profile)
}

View File

@ -0,0 +1,29 @@
/*
* 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.config.profile.profiles.entity.features.score
import de.bixilon.minosoft.config.profile.delegate.primitive.BooleanDelegate
import de.bixilon.minosoft.config.profile.profiles.entity.EntityProfile
class ScoreC(profile: EntityProfile) {
/**
* Shows scores of entities
*/
var enabled by BooleanDelegate(profile, true)
/**
* Shows your local score
*/
var local by BooleanDelegate(profile, false)
}

View File

@ -25,14 +25,29 @@ class EntityScoreboardFeature(renderer: PlayerRenderer<*>) : BillboardTextFeatur
override fun update(millis: Long, delta: Float) {
updateScore()
renderer.name.offset = if (this.text != null) NAME_OFFSET else DEFAULT_OFFSET
super.update(millis, delta)
}
private fun updateScore() {
// TODO: self, offset name, render distance (10), performance
if (!renderScore()) {
this.text = null
return
}
// TODO: cache score (just update every x time, listen for events, ...)
this.text = getScore()
}
private fun renderScore(): Boolean {
if (renderer.distance > RENDER_DISTANCE * RENDER_DISTANCE) return false
val renderer = renderer.renderer
val profile = renderer.profile.features.score
if (!profile.enabled) return false
if (this.renderer.entity === renderer.connection.camera.entity && (!renderer.context.camera.view.view.renderSelf || !profile.local)) return false
return true
}
private fun getScore(): ChatComponent? {
val objective = renderer.renderer.connection.scoreboard.positions[ScoreboardPositions.BELOW_NAME] ?: return null
val score = objective.scores[renderer.entity.unsafeCast<PlayerEntity>().additional.name] ?: return null
@ -43,4 +58,9 @@ class EntityScoreboardFeature(renderer: PlayerRenderer<*>) : BillboardTextFeatur
return text
}
companion object {
const val RENDER_DISTANCE = 10
val NAME_OFFSET = DEFAULT_OFFSET + PROPERTIES.lineHeight * BillboardTextMesh.SCALE
}
}