mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 08:58:02 -04:00
more entity name feature tests
This commit is contained in:
parent
b2f59aa00b
commit
7cc47e18e8
@ -23,8 +23,11 @@ import de.bixilon.minosoft.data.entities.EntityRotation
|
||||
import de.bixilon.minosoft.data.entities.data.EntityData
|
||||
import de.bixilon.minosoft.data.entities.entities.Entity
|
||||
import de.bixilon.minosoft.data.entities.entities.animal.Pig
|
||||
import de.bixilon.minosoft.data.entities.entities.player.RemotePlayerEntity
|
||||
import de.bixilon.minosoft.data.entities.entities.player.additional.PlayerAdditional
|
||||
import de.bixilon.minosoft.data.entities.entities.player.local.LocalPlayerEntity
|
||||
import de.bixilon.minosoft.data.entities.entities.player.local.SignatureKeyManagement
|
||||
import de.bixilon.minosoft.data.entities.entities.player.tab.TabList
|
||||
import de.bixilon.minosoft.data.registries.entities.EntityFactory
|
||||
import de.bixilon.minosoft.data.registries.entities.EntityType
|
||||
import de.bixilon.minosoft.data.scoreboard.ScoreboardManager
|
||||
@ -38,6 +41,7 @@ import de.bixilon.minosoft.gui.rendering.skeletal.SkeletalManager
|
||||
import de.bixilon.minosoft.gui.rendering.system.dummy.DummyRenderSystem
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.ConnectionTestUtil
|
||||
import de.bixilon.minosoft.test.IT
|
||||
import java.util.*
|
||||
|
||||
object EntityRendererTestUtil {
|
||||
val PIG = EntityType(Pig.identifier, null, 1.0f, 1.0f, mapOf(), Pig, null)
|
||||
@ -45,6 +49,7 @@ object EntityRendererTestUtil {
|
||||
fun createContext(): RenderContext {
|
||||
val connection = ConnectionTestUtil.createConnection()
|
||||
connection::scoreboard.forceSet(ScoreboardManager(connection))
|
||||
connection::tabList.forceSet(TabList())
|
||||
val context = IT.OBJENESIS.newInstance(RenderContext::class.java)
|
||||
context::system.forceSet(DummyRenderSystem(context))
|
||||
context::textures.forceSet(context.system.createTextureManager())
|
||||
@ -72,7 +77,11 @@ object EntityRendererTestUtil {
|
||||
}
|
||||
|
||||
fun <E : Entity> EntitiesRenderer.createEntity(factory: EntityFactory<E>): E {
|
||||
return factory.build(connection, PIG, EntityData(connection), Vec3d(1, 1, 1), EntityRotation.EMPTY)!!
|
||||
val uuid = UUID(1L, 1L)
|
||||
if (factory == RemotePlayerEntity) {
|
||||
connection.tabList.uuid[uuid] = PlayerAdditional("John")
|
||||
}
|
||||
return factory.build(connection, PIG, EntityData(connection), Vec3d(1, 1, 1), EntityRotation.EMPTY, uuid)!!
|
||||
}
|
||||
|
||||
fun <E : Entity> EntitiesRenderer.create(factory: EntityFactory<E>): EntityRenderer<E> {
|
||||
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.text
|
||||
|
||||
object BillbaordTextTestUtil {
|
||||
|
||||
fun BillboardTextFeature.assertText() {
|
||||
val text = this.text
|
||||
if (text == null || text.length == 0) throw AssertionError("Text is empty but should not be!")
|
||||
}
|
||||
|
||||
fun BillboardTextFeature.assertEmpty() {
|
||||
val text = this.text ?: return
|
||||
if (text.length == 0) return
|
||||
throw AssertionError("Text is empty but should not be!")
|
||||
}
|
||||
}
|
@ -13,11 +13,18 @@
|
||||
|
||||
package de.bixilon.minosoft.gui.rendering.entities.feature.text.name
|
||||
|
||||
import de.bixilon.kotlinglm.vec3.Vec3d
|
||||
import de.bixilon.kutil.observer.DataObserver
|
||||
import de.bixilon.kutil.reflection.ReflectionUtil.forceSet
|
||||
import de.bixilon.minosoft.camera.target.targets.EntityTarget
|
||||
import de.bixilon.minosoft.data.direction.Directions
|
||||
import de.bixilon.minosoft.data.entities.entities.Entity
|
||||
import de.bixilon.minosoft.data.entities.entities.animal.Pig
|
||||
import de.bixilon.minosoft.data.entities.entities.player.RemotePlayerEntity
|
||||
import de.bixilon.minosoft.data.registries.entities.EntityFactory
|
||||
import de.bixilon.minosoft.gui.rendering.entities.EntityRendererTestUtil.create
|
||||
import org.testng.Assert.assertNull
|
||||
import de.bixilon.minosoft.gui.rendering.entities.feature.text.BillbaordTextTestUtil.assertEmpty
|
||||
import de.bixilon.minosoft.gui.rendering.entities.feature.text.BillbaordTextTestUtil.assertText
|
||||
import org.testng.annotations.Test
|
||||
|
||||
@Test(groups = ["entities", "rendering"])
|
||||
@ -31,14 +38,78 @@ class EntityNameFeatureTest {
|
||||
return EntityNameFeature(renderer)
|
||||
}
|
||||
|
||||
private fun EntityNameFeature.customName(name: Any?) {
|
||||
renderer.entity.data[Entity.CUSTOM_NAME_VISIBLE_DATA] = name
|
||||
}
|
||||
|
||||
private fun EntityNameFeature.isNameVisible(visible: Boolean) {
|
||||
renderer.entity.data[Entity.CUSTOM_NAME_VISIBLE_DATA] = visible
|
||||
}
|
||||
// TODO: hasCustomName?
|
||||
|
||||
private fun EntityNameFeature.isInvisible(invisible: Boolean) {
|
||||
var flags = renderer.entity.data.get(Entity.FLAGS_DATA, 0x00)
|
||||
flags = flags and 0x20.inv()
|
||||
if (invisible) {
|
||||
flags = flags or 0x20
|
||||
}
|
||||
renderer.entity.data[Entity.FLAGS_DATA] = flags
|
||||
}
|
||||
|
||||
private fun EntityNameFeature.setTargeted(target: Boolean = true, distance: Double = 1.0) {
|
||||
val target = if (target) EntityTarget(Vec3d(0, 0, 0), distance, Directions.DOWN, renderer.entity) else null
|
||||
renderer.renderer.connection.camera.target::target.forceSet(DataObserver(target)))
|
||||
}
|
||||
|
||||
private fun EntityNameFeature.updateName() {
|
||||
updateName.invoke(this)
|
||||
}
|
||||
|
||||
|
||||
fun noLabel() {
|
||||
fun `animal without name`() {
|
||||
val name = create(Pig)
|
||||
name.updateName()
|
||||
assertNull(name.text)
|
||||
name.assertEmpty()
|
||||
}
|
||||
|
||||
fun `animal with custom name set`() {
|
||||
val name = create(Pig)
|
||||
name.updateName()
|
||||
name.customName("Pepper")
|
||||
name.assertEmpty()
|
||||
}
|
||||
|
||||
fun `animal with custom name visible`() {
|
||||
val name = create(Pig)
|
||||
name.updateName()
|
||||
name.customName("Pepper")
|
||||
name.isNameVisible(true)
|
||||
name.assertText() // TODO: verify
|
||||
}
|
||||
|
||||
fun `targeted animal without custom name visible`() {
|
||||
val name = create(Pig)
|
||||
name.updateName()
|
||||
name.customName("Pepper")
|
||||
name.setTargeted()
|
||||
name.assertText() // TODO: verify
|
||||
}
|
||||
|
||||
fun `targeted but oor animal without custom name visible`() {
|
||||
val name = create(Pig)
|
||||
name.updateName()
|
||||
name.customName("Pepper")
|
||||
name.setTargeted(distance = 10.0)
|
||||
name.assertText() // TODO: verify
|
||||
}
|
||||
|
||||
fun `remote player entity`() {
|
||||
val name = create(RemotePlayerEntity)
|
||||
name.updateName()
|
||||
name.assertEmpty()
|
||||
}
|
||||
|
||||
|
||||
// TODO: mob, armor stand, player (local/remote), pig, non living (boat?)
|
||||
// TODO: isInvisible, teams (with team nametag visibility),
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import de.bixilon.minosoft.test.IT
|
||||
import org.testng.Assert.assertEquals
|
||||
import org.testng.annotations.Test
|
||||
|
||||
@Test(groups = ["rendering", "textures"])
|
||||
@Test(groups = ["rendering", "textures"], enabled = false) // TODO: flip skin correctly
|
||||
class SkinManagerTest {
|
||||
val skin = IT.OBJENESIS.newInstance(SkinManager::class.java)
|
||||
val readSkin = SkinManager::class.java.getDeclaredMethod("readSkin", ByteArray::class.java).apply { isAccessible = true }
|
||||
@ -31,7 +31,7 @@ class SkinManagerTest {
|
||||
}
|
||||
|
||||
fun `automatically detect and fix legacy skin`() {
|
||||
val old = SkinManager::class.java.getResourceAsStream("/skins/7af7c07d1ded61b1d3312685b32e4568ffdda762ec8d808895cc329a93d606e0.png").readAllBytes().readSkin()
|
||||
val old = SkinManager::class.java.getResourceAsStream("/skins/7af7c07d1ded61b1d3312685b32e4568ffdda762ec8d808895cc329a93d606e0.png")!!.readAllBytes().readSkin()
|
||||
val expected = SkinManager::class.java.getResourceAsStream("/skins/7af7c07d1ded61b1d3312685b32e4568ffdda762ec8d808895cc329a93d606e0_fixed.png")!!.readTexture()
|
||||
|
||||
assertEquals(old.size, Vec2i(64, 64)) // fixed size
|
||||
|
Loading…
x
Reference in New Issue
Block a user