player model: load proper skin, player: set default player properties to null

This commit is contained in:
Bixilon 2022-06-06 18:06:52 +02:00
parent 5379ce921b
commit c82ceaf9a9
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
8 changed files with 20 additions and 15 deletions

View File

@ -46,7 +46,7 @@ abstract class PlayerEntity(
position: Vec3d = Vec3d.EMPTY,
rotation: EntityRotation = EntityRotation(0.0, 0.0),
name: String = "TBA",
properties: PlayerProperties = PlayerProperties(),
properties: PlayerProperties? = null,
var tabListItem: TabListItem = TabListItem(name = name, gamemode = Gamemodes.SURVIVAL, properties = properties),
) : LivingEntity(connection, entityType, data, position, rotation) {
override val dimensions: Vec2

View File

@ -32,7 +32,7 @@ class RemotePlayerEntity(
position: Vec3d = Vec3d.EMPTY,
rotation: EntityRotation = EntityRotation(0.0, 0.0),
name: String = "TBA",
properties: PlayerProperties = PlayerProperties(),
properties: PlayerProperties? = null,
tabListItem: TabListItem = TabListItem(name = name, gamemode = Gamemodes.SURVIVAL, properties = properties),
) : PlayerEntity(connection, entityType, data, position, rotation, name, properties, tabListItem) {

View File

@ -76,7 +76,7 @@ import kotlin.math.pow
class LocalPlayerEntity(
account: Account,
connection: PlayConnection,
) : PlayerEntity(connection, connection.registries.entityTypeRegistry[RemotePlayerEntity.RESOURCE_LOCATION]!!, EntityData(connection), Vec3d.EMPTY, EntityRotation(0.0, 0.0), account.username) {
) : PlayerEntity(connection, connection.registries.entityTypeRegistry[RemotePlayerEntity.RESOURCE_LOCATION]!!, EntityData(connection), Vec3d.EMPTY, EntityRotation(0.0, 0.0), account.username, account.properties) {
val healthCondition = PlayerHealthCondition()
val experienceCondition = PlayerExperienceCondition()
var spawnPosition: Vec3i = Vec3i.EMPTY

View File

@ -25,7 +25,7 @@ data class TabListItem(
var ping: Int = -1,
var gamemode: Gamemodes = Gamemodes.SURVIVAL,
var displayName: ChatComponent = ChatComponent.of(name),
var properties: PlayerProperties = PlayerProperties(),
var properties: PlayerProperties? = null,
var team: Team? = null,
var publicKey: PlayerPublicKey? = null,
) : Comparable<TabListItem> {

View File

@ -15,11 +15,9 @@ package de.bixilon.minosoft.gui.rendering.entity.models
import de.bixilon.minosoft.data.entities.entities.Entity
import de.bixilon.minosoft.gui.rendering.RenderWindow
import de.bixilon.minosoft.gui.rendering.skeletal.baked.BakedSkeletalModel
import de.bixilon.minosoft.gui.rendering.skeletal.instance.SkeletalInstance
abstract class SkeletalEntityModel<E : Entity>(renderWindow: RenderWindow, entity: E) : EntityModel<E>(renderWindow, entity) {
abstract val model: BakedSkeletalModel
abstract val instance: SkeletalInstance

View File

@ -18,21 +18,23 @@ import de.bixilon.minosoft.data.entities.entities.player.PlayerEntity
import de.bixilon.minosoft.gui.rendering.RenderWindow
import de.bixilon.minosoft.gui.rendering.entity.models.SkeletalEntityModel
import de.bixilon.minosoft.gui.rendering.models.ModelLoader.Companion.bbModel
import de.bixilon.minosoft.gui.rendering.skeletal.baked.BakedSkeletalModel
import de.bixilon.minosoft.gui.rendering.skeletal.instance.SkeletalInstance
import de.bixilon.minosoft.util.KUtil.toResourceLocation
class PlayerModel(renderWindow: RenderWindow, player: PlayerEntity) : SkeletalEntityModel<PlayerEntity>(renderWindow, player) {
override val model: BakedSkeletalModel = renderWindow.modelLoader.entities.loadModel(
"minecraft:entities/player/steve".toResourceLocation(),
"minecraft:entities/player/steve".toResourceLocation().bbModel(),
mutableMapOf(0 to renderWindow.textureManager.steveTexture),
)
override val instance = createModel()
init {
private fun createModel(): SkeletalInstance {
val unbaked = renderWindow.modelLoader.entities.loadUnbakedModel(BB_MODEL)
val texture = renderWindow.textureManager.getSkin(entity)
val model = unbaked.bake(renderWindow, mutableMapOf(0 to texture))
model.loadMesh(renderWindow)
return SkeletalInstance(renderWindow, Vec3i(), model)
}
override val instance: SkeletalInstance = SkeletalInstance(renderWindow, Vec3i(), model)
companion object {
private val BB_MODEL = "minecraft:entities/player/steve".toResourceLocation().bbModel()
}
}

View File

@ -16,6 +16,7 @@ package de.bixilon.minosoft.gui.rendering.system.base.texture
import de.bixilon.kotlinglm.vec2.Vec2
import de.bixilon.kotlinglm.vec2.Vec2i
import de.bixilon.minosoft.config.profile.profiles.account.AccountProfileManager
import de.bixilon.minosoft.data.entities.entities.player.PlayerEntity
import de.bixilon.minosoft.data.player.properties.PlayerProperties
import de.bixilon.minosoft.data.player.properties.textures.PlayerTexture.Companion.isSteve
import de.bixilon.minosoft.data.registries.ResourceLocation
@ -83,4 +84,8 @@ abstract class TextureManager {
}
return alexTexture
}
fun getSkin(player: PlayerEntity): DynamicTexture {
return getSkin(true, player.uuid ?: return steveTexture, player.tabListItem.properties)
}
}

View File

@ -40,7 +40,7 @@ class EntityPlayerS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
entityId = buffer.readVarInt()
var name = "TBA"
var properties = PlayerProperties()
var properties: PlayerProperties? = null
if (buffer.versionId < ProtocolVersions.V_14W21A) {
name = buffer.readString()
entityUUID = buffer.readUUIDString()