blob: 0b393bb047987dbca6e278e876a5a92721e7f906 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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.entity.ClientAvatarEntity
import net.minecraft.world.entity.LivingEntity
import net.minecraft.world.entity.Avatar
import net.minecraft.world.entity.player.Player
import net.minecraft.world.entity.player.PlayerModelPart
import net.minecraft.world.entity.player.PlayerModelType
import net.minecraft.world.entity.player.PlayerSkin
import net.minecraft.core.ClientAsset
import net.minecraft.resources.ResourceLocation
object ModifyPlayerSkin : EntityModifier {
val playerModelPartIndex = PlayerModelPart.entries.associateBy { it.id }
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: ResourceLocation) = ClientAsset.ResourceTexture(id, id)
info["cape"]?.let {
capeTexture = mkTexAsset(ResourceLocation.parse(it.asString))
}
info["skin"]?.let {
bodyTexture = mkTexAsset(ResourceLocation.parse(it.asString))
}
info["slim"]?.let {
model = if (it.asBoolean) PlayerModelType.SLIM else PlayerModelType.WIDE
}
info["parts"]?.let {
var trackedData = entity.entityData.get(Avatar.DATA_PLAYER_MODE_CUSTOMISATION)
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.mask.inv().toByte())
} else {
trackedData or (part.mask.toByte())
}
}
}
entity.entityData.set(Player.DATA_PLAYER_MODE_CUSTOMISATION, trackedData)
}
entity.skinTextures = PlayerSkin(
bodyTexture, capeTexture, null, model, true
)
return entity
}
}
|