mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 08:58:02 -04:00
scoreboard score feature: performance, render distance, config, name offset
This commit is contained in:
parent
199b8a7587
commit
92b37112cf
@ -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.EntityProfile
|
||||||
import de.bixilon.minosoft.config.profile.profiles.entity.features.hitbox.HitboxC
|
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.name.NameC
|
||||||
|
import de.bixilon.minosoft.config.profile.profiles.entity.features.score.ScoreC
|
||||||
|
|
||||||
class FeaturesC(profile: EntityProfile) {
|
class FeaturesC(profile: EntityProfile) {
|
||||||
val hitbox = HitboxC(profile)
|
val hitbox = HitboxC(profile)
|
||||||
val name = NameC(profile)
|
val name = NameC(profile)
|
||||||
|
val score = ScoreC(profile)
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
|
}
|
@ -25,14 +25,29 @@ class EntityScoreboardFeature(renderer: PlayerRenderer<*>) : BillboardTextFeatur
|
|||||||
|
|
||||||
override fun update(millis: Long, delta: Float) {
|
override fun update(millis: Long, delta: Float) {
|
||||||
updateScore()
|
updateScore()
|
||||||
|
renderer.name.offset = if (this.text != null) NAME_OFFSET else DEFAULT_OFFSET
|
||||||
super.update(millis, delta)
|
super.update(millis, delta)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateScore() {
|
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()
|
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? {
|
private fun getScore(): ChatComponent? {
|
||||||
val objective = renderer.renderer.connection.scoreboard.positions[ScoreboardPositions.BELOW_NAME] ?: return null
|
val objective = renderer.renderer.connection.scoreboard.positions[ScoreboardPositions.BELOW_NAME] ?: return null
|
||||||
val score = objective.scores[renderer.entity.unsafeCast<PlayerEntity>().additional.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
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val RENDER_DISTANCE = 10
|
||||||
|
val NAME_OFFSET = DEFAULT_OFFSET + PROPERTIES.lineHeight * BillboardTextMesh.SCALE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user