aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/gui
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-11-15 23:13:50 +0100
committerLinnea Gräf <nea@nea.moe>2025-11-15 23:13:50 +0100
commit4d8399ff4d769def62e6a8241327c4f2dac47e71 (patch)
tree703f8651cb680d2583d82c2b1b4aee0911ccb490 /src/main/kotlin/gui
parent215178c650d38a4a77fdef6dc8815c07bef29c25 (diff)
downloadFirmament-4d8399ff4d769def62e6a8241327c4f2dac47e71.tar.gz
Firmament-4d8399ff4d769def62e6a8241327c4f2dac47e71.tar.bz2
Firmament-4d8399ff4d769def62e6a8241327c4f2dac47e71.zip
snapshot: main source set compile
Diffstat (limited to 'src/main/kotlin/gui')
-rw-r--r--src/main/kotlin/gui/entity/GuiPlayer.kt44
-rw-r--r--src/main/kotlin/gui/entity/ModifyPlayerSkin.kt76
-rw-r--r--src/main/kotlin/gui/entity/ModifyRiding.kt2
3 files changed, 52 insertions, 70 deletions
diff --git a/src/main/kotlin/gui/entity/GuiPlayer.kt b/src/main/kotlin/gui/entity/GuiPlayer.kt
index e7f2e45..2598de6 100644
--- a/src/main/kotlin/gui/entity/GuiPlayer.kt
+++ b/src/main/kotlin/gui/entity/GuiPlayer.kt
@@ -1,56 +1,28 @@
package moe.nea.firmament.gui.entity
-import com.mojang.authlib.GameProfile
-import java.util.UUID
-import net.minecraft.client.network.AbstractClientPlayerEntity
+import net.minecraft.client.network.ClientMannequinEntity
import net.minecraft.client.util.DefaultSkinHelper
-import net.minecraft.client.util.SkinTextures
-import net.minecraft.client.util.SkinTextures.Model
import net.minecraft.client.world.ClientWorld
-import net.minecraft.util.Identifier
-import net.minecraft.util.math.Vec3d
+import net.minecraft.entity.player.SkinTextures
import net.minecraft.world.World
+import moe.nea.firmament.util.MC
-/**
- * @see moe.nea.firmament.init.EarlyRiser
- */
fun makeGuiPlayer(world: World): GuiPlayer {
- val constructor = GuiPlayer::class.java.getDeclaredConstructor(ClientWorld::class.java, GameProfile::class.java)
- val player = constructor.newInstance(world, GameProfile(UUID.randomUUID(), "Linnea"))
- player.postInit()
+ val player = GuiPlayer(MC.instance.world!!)
return player
}
-class GuiPlayer(world: ClientWorld?, profile: GameProfile?) : AbstractClientPlayerEntity(world, profile) {
+class GuiPlayer(world: ClientWorld?) : ClientMannequinEntity(world, MC.instance.playerSkinCache) {
override fun isSpectator(): Boolean {
return false
}
- fun postInit() {
- skinTexture = DefaultSkinHelper.getSkinTextures(this.getUuid()).texture
- lastVelocity = Vec3d.ZERO
- model = Model.WIDE
- }
-
- override fun isCreative(): Boolean {
- return false
- }
-
override fun shouldRenderName(): Boolean {
return false
}
- lateinit var skinTexture: Identifier
- var capeTexture: Identifier? = null
- var model: Model = Model.WIDE
- override fun getSkinTextures(): SkinTextures {
- return SkinTextures(
- skinTexture,
- null,
- capeTexture,
- null,
- model,
- true
- )
+ var skinTextures: SkinTextures = DefaultSkinHelper.getSkinTextures(this.getUuid()) // TODO: 1.21.10
+ override fun getSkin(): SkinTextures {
+ return skinTextures
}
}
diff --git a/src/main/kotlin/gui/entity/ModifyPlayerSkin.kt b/src/main/kotlin/gui/entity/ModifyPlayerSkin.kt
index 28f0070..48cd855 100644
--- a/src/main/kotlin/gui/entity/ModifyPlayerSkin.kt
+++ b/src/main/kotlin/gui/entity/ModifyPlayerSkin.kt
@@ -1,47 +1,57 @@
-
package moe.nea.firmament.gui.entity
import com.google.gson.JsonObject
import com.google.gson.JsonPrimitive
import kotlin.experimental.and
import kotlin.experimental.or
-import net.minecraft.client.util.SkinTextures
+import net.minecraft.client.network.ClientPlayerLikeEntity
import net.minecraft.entity.LivingEntity
+import net.minecraft.entity.PlayerLikeEntity
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.entity.player.PlayerModelPart
+import net.minecraft.entity.player.PlayerSkinType
+import net.minecraft.entity.player.SkinTextures
+import net.minecraft.util.AssetInfo
import net.minecraft.util.Identifier
object ModifyPlayerSkin : EntityModifier {
- val playerModelPartIndex = PlayerModelPart.entries.associateBy { it.getName() }
- override fun apply(entity: LivingEntity, info: JsonObject): LivingEntity {
- require(entity is GuiPlayer)
- info["cape"]?.let {
- entity.capeTexture = Identifier.of(it.asString)
- }
- info["skin"]?.let {
- entity.skinTexture = Identifier.of(it.asString)
- }
- info["slim"]?.let {
- entity.model = if (it.asBoolean) SkinTextures.Model.SLIM else SkinTextures.Model.WIDE
- }
- info["parts"]?.let {
- var trackedData = entity.dataTracker.get(PlayerEntity.PLAYER_MODEL_PARTS)
- if (it is JsonPrimitive && it.isBoolean) {
- trackedData = (if (it.asBoolean) -1 else 0).toByte()
- } else {
- val obj = it.asJsonObject
- for ((k, v) in obj.entrySet()) {
- val part = playerModelPartIndex[k]!!
- trackedData = if (v.asBoolean) {
- trackedData and (part.bitFlag.inv().toByte())
- } else {
- trackedData or (part.bitFlag.toByte())
- }
- }
- }
- entity.dataTracker.set(PlayerEntity.PLAYER_MODEL_PARTS, trackedData)
- }
- return entity
- }
+ val playerModelPartIndex = PlayerModelPart.entries.associateBy { it.getName() }
+ override fun apply(entity: LivingEntity, info: JsonObject): LivingEntity {
+ require(entity is GuiPlayer)
+ var capeTexture = entity.skinTextures.cape
+ var model = entity.skinTextures.model
+ var bodyTexture = entity.skinTextures.body
+ fun mkTexAsset(id: Identifier) = AssetInfo.TextureAssetInfo(id, id)
+ info["cape"]?.let {
+ capeTexture = mkTexAsset(Identifier.of(it.asString))
+ }
+ info["skin"]?.let {
+ bodyTexture = mkTexAsset(Identifier.of(it.asString))
+ }
+ info["slim"]?.let {
+ model = if (it.asBoolean) PlayerSkinType.SLIM else PlayerSkinType.WIDE
+ }
+ info["parts"]?.let {
+ var trackedData = entity.dataTracker.get(PlayerLikeEntity.PLAYER_MODE_CUSTOMIZATION_ID)
+ if (it is JsonPrimitive && it.isBoolean) {
+ trackedData = (if (it.asBoolean) -1 else 0).toByte()
+ } else {
+ val obj = it.asJsonObject
+ for ((k, v) in obj.entrySet()) {
+ val part = playerModelPartIndex[k]!!
+ trackedData = if (v.asBoolean) {
+ trackedData and (part.bitFlag.inv().toByte())
+ } else {
+ trackedData or (part.bitFlag.toByte())
+ }
+ }
+ }
+ entity.dataTracker.set(PlayerEntity.PLAYER_MODE_CUSTOMIZATION_ID, trackedData)
+ }
+ entity.skinTextures = SkinTextures(
+ bodyTexture, capeTexture, null, model, true
+ )
+ return entity
+ }
}
diff --git a/src/main/kotlin/gui/entity/ModifyRiding.kt b/src/main/kotlin/gui/entity/ModifyRiding.kt
index 5c4c78d..d482b37 100644
--- a/src/main/kotlin/gui/entity/ModifyRiding.kt
+++ b/src/main/kotlin/gui/entity/ModifyRiding.kt
@@ -8,7 +8,7 @@ object ModifyRiding : EntityModifier {
override fun apply(entity: LivingEntity, info: JsonObject): LivingEntity {
val newEntity = EntityRenderer.constructEntity(info)
require(newEntity != null)
- newEntity.startRiding(entity, true)
+ newEntity.startRiding(entity, true, false)
return entity
}