Skip to content

Commit

Permalink
Filter texture property from gameProfile in setSkullPlayer
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobkmar committed Jun 10, 2022
1 parent 3eb1577 commit 3f59990
Showing 1 changed file with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import net.axay.fabrik.core.text.LiteralTextBuilder
import net.axay.fabrik.core.text.literalText
import net.minecraft.nbt.CompoundTag
import net.minecraft.nbt.ListTag
import net.minecraft.nbt.NbtUtils
import net.minecraft.nbt.StringTag
import net.minecraft.network.chat.Component
import net.minecraft.server.level.ServerPlayer
Expand Down Expand Up @@ -90,13 +89,17 @@ fun ItemStack.setSkullTexture(
) {
orCreateTag.put("SkullOwner", CompoundTag().apply {
putUUID("Id", uuid)
getCompound("Properties").apply {
put("textures", ListTag().apply {
add(CompoundTag().apply {
putString("Value", texture)
})

val propsCompound = if (this.contains("Properties"))
this.getCompound("Properties")
else
CompoundTag().also { put("Properties", it) }

propsCompound.put("textures", ListTag().apply {
add(CompoundTag().apply {
putString("Value", texture)
})
}
})
})
}

Expand All @@ -110,8 +113,7 @@ fun ItemStack.setSkullTexture(
* ```
*/
fun ItemStack.setSkullPlayer(player: ServerPlayer) {
val gameProfile = player.gameProfile
orCreateTag.put("SkullOwner", CompoundTag().apply {
NbtUtils.writeGameProfile(this, gameProfile)
})
player.gameProfile.properties.get("textures")
.map { it.value }
.forEach(::setSkullTexture)
}

0 comments on commit 3f59990

Please sign in to comment.