diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/entity/features/FeaturesC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/entity/features/FeaturesC.kt index efcc6edcc..3feedd5b6 100644 --- a/src/main/java/de/bixilon/minosoft/config/profile/profiles/entity/features/FeaturesC.kt +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/entity/features/FeaturesC.kt @@ -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) } diff --git a/src/main/java/de/bixilon/minosoft/config/profile/profiles/entity/features/score/ScoreC.kt b/src/main/java/de/bixilon/minosoft/config/profile/profiles/entity/features/score/ScoreC.kt new file mode 100644 index 000000000..f71ebf6dc --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/config/profile/profiles/entity/features/score/ScoreC.kt @@ -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 . + * + * 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) +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/text/EntityScoreboardFeature.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/text/EntityScoreboardFeature.kt index eb2fd6812..e4f3b9a4d 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/text/EntityScoreboardFeature.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/entities/feature/text/EntityScoreboardFeature.kt @@ -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().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 + } }