entity renderer: invisible feature

Normal entity render features are now hidden when the entity is invisible
This commit is contained in:
Moritz Zwerger 2023-11-13 15:18:19 +01:00
parent cc92897293
commit 65e62441a8
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
8 changed files with 46 additions and 5 deletions

View File

@ -26,6 +26,7 @@ import de.bixilon.minosoft.gui.rendering.entities.EntityRendererTestUtil.create
import de.bixilon.minosoft.gui.rendering.entities.feature.text.BillbaordTextTestUtil.assertEmpty
import de.bixilon.minosoft.gui.rendering.entities.feature.text.BillbaordTextTestUtil.assertText
import de.bixilon.minosoft.gui.rendering.entities.feature.text.BillboardTextFeature
import de.bixilon.minosoft.gui.rendering.entities.feature.text.score.EntityScoreFeature
import de.bixilon.minosoft.gui.rendering.entities.renderer.living.player.PlayerRenderer
import org.testng.Assert.assertEquals
import org.testng.annotations.Test

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.gui.rendering.entities.feature
import de.bixilon.minosoft.gui.rendering.entities.feature.properties.InvisibleFeature.Companion.isInvisible
import de.bixilon.minosoft.gui.rendering.entities.renderer.EntityRenderer
class FeatureManager(val renderer: EntityRenderer<*>) : Iterable<EntityRenderFeature> {
@ -31,6 +32,7 @@ class FeatureManager(val renderer: EntityRenderer<*>) : Iterable<EntityRenderFea
fun update(millis: Long, delta: Float) {
for (feature in features) {
if (feature.isInvisible()) continue
feature.update(millis, delta)
}
}

View File

@ -0,0 +1,31 @@
/*
* 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.entities.feature.properties
import de.bixilon.minosoft.gui.rendering.entities.feature.EntityRenderFeature
interface InvisibleFeature {
val renderInvisible: Boolean
companion object {
fun EntityRenderFeature.isInvisible(): Boolean {
if (!renderer.isInvisible) return false
if (renderer !is InvisibleFeature) return true
if (!renderer.renderInvisible) return true
return false
}
}
}

View File

@ -27,11 +27,13 @@ import de.bixilon.minosoft.data.entities.entities.player.PlayerEntity
import de.bixilon.minosoft.data.entities.entities.player.local.LocalPlayerEntity
import de.bixilon.minosoft.data.scoreboard.NameTagVisibilities
import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.gui.rendering.entities.feature.properties.InvisibleFeature
import de.bixilon.minosoft.gui.rendering.entities.feature.text.BillboardTextFeature
import de.bixilon.minosoft.gui.rendering.entities.renderer.EntityRenderer
class EntityNameFeature(renderer: EntityRenderer<*>) : BillboardTextFeature(renderer, null) {
class EntityNameFeature(renderer: EntityRenderer<*>) : BillboardTextFeature(renderer, null), InvisibleFeature {
private var delta = 0.0f
override val renderInvisible get() = true
init {
renderer.entity.data.observe<ChatComponent?>(Entity.CUSTOM_NAME_DATA) { delta = 0.0f }

View File

@ -11,20 +11,22 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.gui.rendering.entities.feature.text.name
package de.bixilon.minosoft.gui.rendering.entities.feature.text.score
import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.minosoft.data.entities.entities.player.PlayerEntity
import de.bixilon.minosoft.data.text.BaseComponent
import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.data.text.TextComponent
import de.bixilon.minosoft.gui.rendering.entities.feature.properties.InvisibleFeature
import de.bixilon.minosoft.gui.rendering.entities.feature.text.BillboardTextFeature
import de.bixilon.minosoft.gui.rendering.entities.feature.text.BillboardTextMesh
import de.bixilon.minosoft.gui.rendering.entities.renderer.living.player.PlayerRenderer
class EntityScoreFeature(renderer: PlayerRenderer<*>) : BillboardTextFeature(renderer, null) {
class EntityScoreFeature(renderer: PlayerRenderer<*>) : BillboardTextFeature(renderer, null), InvisibleFeature {
private var delta = 0.0f
private val manager = renderer.renderer.features.score
override val renderInvisible get() = true
override fun update(millis: Long, delta: Float) {

View File

@ -38,6 +38,7 @@ abstract class EntityRenderer<E : Entity>(
val features = FeatureManager(this)
val info = entity.renderInfo
var distance: Double = 0.0
var isInvisible: Boolean = false
val hitbox = HitboxFeature(this).register()
val name = EntityNameFeature(this).register()
@ -71,6 +72,7 @@ abstract class EntityRenderer<E : Entity>(
}
open fun update(millis: Long, delta: Float) {
this.isInvisible = entity.isInvisible(renderer.connection.camera.entity)
updateLight(delta)
updateRenderInfo(millis)
updateMatrix(delta)

View File

@ -22,7 +22,7 @@ import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft
import de.bixilon.minosoft.gui.rendering.RenderContext
import de.bixilon.minosoft.gui.rendering.entities.EntitiesRenderer
import de.bixilon.minosoft.gui.rendering.entities.factory.RegisteredEntityModelFactory
import de.bixilon.minosoft.gui.rendering.entities.feature.text.name.EntityScoreFeature
import de.bixilon.minosoft.gui.rendering.entities.feature.text.score.EntityScoreFeature
import de.bixilon.minosoft.gui.rendering.entities.model.human.PlayerModel
import de.bixilon.minosoft.gui.rendering.entities.renderer.living.LivingEntityRenderer
import de.bixilon.minosoft.gui.rendering.models.loader.ModelLoader

View File

@ -18,6 +18,7 @@ import de.bixilon.kutil.observer.DataObserver.Companion.observe
import de.bixilon.minosoft.data.world.view.ViewDistanceChangeEvent
import de.bixilon.minosoft.gui.rendering.entities.EntitiesRenderer
import de.bixilon.minosoft.gui.rendering.entities.feature.EntityRenderFeature
import de.bixilon.minosoft.gui.rendering.entities.feature.properties.InvisibleFeature.Companion.isInvisible
import de.bixilon.minosoft.gui.rendering.entities.renderer.EntityRenderer
import de.bixilon.minosoft.gui.rendering.events.VisibilityGraphChangeEvent
import de.bixilon.minosoft.modding.event.listener.CallbackEventListener.Companion.listen
@ -81,7 +82,7 @@ class VisibilityManager(val renderer: EntitiesRenderer) {
lock.lock()
size++
for (feature in renderer.features) {
if (!feature.enabled || !feature.visible) continue
if (!feature.enabled || !feature.visible || feature.isInvisible()) continue
feature.collect(this)
}
lock.unlock()