mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 10:55:01 -04:00
fix old skins (1.7)
Yes, they are still widely used on modded servers. They are not flipped yet. so the test will fail
This commit is contained in:
parent
2d30078126
commit
192f1e876c
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* 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.system.base.texture.skin
|
||||||
|
|
||||||
|
import de.bixilon.kotlinglm.vec2.Vec2i
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.texture.data.TextureData
|
||||||
|
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.readTexture
|
||||||
|
import de.bixilon.minosoft.test.IT
|
||||||
|
import org.testng.Assert.assertEquals
|
||||||
|
import org.testng.annotations.Test
|
||||||
|
|
||||||
|
@Test(groups = ["rendering", "textures"])
|
||||||
|
class SkinManagerTest {
|
||||||
|
val skin = IT.OBJENESIS.newInstance(SkinManager::class.java)
|
||||||
|
val readSkin = SkinManager::class.java.getDeclaredMethod("readSkin", ByteArray::class.java).apply { isAccessible = true }
|
||||||
|
|
||||||
|
|
||||||
|
private fun ByteArray.readSkin(): TextureData {
|
||||||
|
return readSkin.invoke(skin, this) as TextureData
|
||||||
|
}
|
||||||
|
|
||||||
|
fun `automatically detect and fix legacy skin`() {
|
||||||
|
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
|
||||||
|
assertEquals(expected.size, Vec2i(64, 64))
|
||||||
|
|
||||||
|
old.buffer.rewind()
|
||||||
|
expected.buffer.rewind()
|
||||||
|
|
||||||
|
// TextureUtil.dump(File("/home/moritz/test.png"), old.size, old.buffer, true, false)
|
||||||
|
assertEquals(old.buffer, expected.buffer)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 779 B |
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
@ -22,6 +22,7 @@ import de.bixilon.minosoft.gui.rendering.system.base.texture.array.TextureArrayP
|
|||||||
import de.bixilon.minosoft.gui.rendering.system.base.texture.data.TextureData
|
import de.bixilon.minosoft.gui.rendering.system.base.texture.data.TextureData
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.Texture
|
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.Texture
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.TextureRenderData
|
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.TextureRenderData
|
||||||
|
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil
|
||||||
import de.bixilon.minosoft.gui.rendering.textures.properties.ImageProperties
|
import de.bixilon.minosoft.gui.rendering.textures.properties.ImageProperties
|
||||||
|
|
||||||
class AtlasTexture(
|
class AtlasTexture(
|
||||||
@ -42,18 +43,7 @@ class AtlasTexture(
|
|||||||
fun request(size: Vec2i): Vec2i? = null
|
fun request(size: Vec2i): Vec2i? = null
|
||||||
|
|
||||||
fun put(offset: Vec2i, source: TextureData, start: Vec2i, size: Vec2i): CodeTexturePart {
|
fun put(offset: Vec2i, source: TextureData, start: Vec2i, size: Vec2i): CodeTexturePart {
|
||||||
for (y in 0 until size.y) {
|
TextureUtil.copy(start, source, offset, this.data, size)
|
||||||
for (x in 0 until size.x) {
|
|
||||||
val sourceOffset = ((start.y + y) * source.size.x + (start.x + x)) * 4
|
|
||||||
val destinationOffset = ((offset.y + y) * this.size.x + (offset.x + x)) * 4
|
|
||||||
|
|
||||||
data.buffer.put(destinationOffset + 0, source.buffer.get(sourceOffset + 0))
|
|
||||||
data.buffer.put(destinationOffset + 1, source.buffer.get(sourceOffset + 1))
|
|
||||||
data.buffer.put(destinationOffset + 2, source.buffer.get(sourceOffset + 2))
|
|
||||||
data.buffer.put(destinationOffset + 3, source.buffer.get(sourceOffset + 3))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return CodeTexturePart(this, pixel * offset, pixel * (offset + size), size)
|
return CodeTexturePart(this, pixel * offset, pixel * (offset + size), size)
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.gui.rendering.system.base.texture.skin
|
package de.bixilon.minosoft.gui.rendering.system.base.texture.skin
|
||||||
|
|
||||||
|
import de.bixilon.kotlinglm.vec2.Vec2i
|
||||||
import de.bixilon.kutil.exception.ExceptionUtil.catchAll
|
import de.bixilon.kutil.exception.ExceptionUtil.catchAll
|
||||||
import de.bixilon.minosoft.assets.AssetsManager
|
import de.bixilon.minosoft.assets.AssetsManager
|
||||||
import de.bixilon.minosoft.config.profile.profiles.account.AccountProfileManager
|
import de.bixilon.minosoft.config.profile.profiles.account.AccountProfileManager
|
||||||
@ -21,7 +22,11 @@ import de.bixilon.minosoft.data.entities.entities.player.PlayerEntity
|
|||||||
import de.bixilon.minosoft.data.entities.entities.player.local.LocalPlayerEntity
|
import de.bixilon.minosoft.data.entities.entities.player.local.LocalPlayerEntity
|
||||||
import de.bixilon.minosoft.data.entities.entities.player.properties.PlayerProperties
|
import de.bixilon.minosoft.data.entities.entities.player.properties.PlayerProperties
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureManager
|
import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureManager
|
||||||
|
import de.bixilon.minosoft.gui.rendering.system.base.texture.data.TextureData
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.texture.skin.vanilla.DefaultSkinProvider
|
import de.bixilon.minosoft.gui.rendering.system.base.texture.skin.vanilla.DefaultSkinProvider
|
||||||
|
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil
|
||||||
|
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.readTexture
|
||||||
|
import java.io.ByteArrayInputStream
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class SkinManager(private val textureManager: TextureManager) {
|
class SkinManager(private val textureManager: TextureManager) {
|
||||||
@ -51,7 +56,7 @@ class SkinManager(private val textureManager: TextureManager) {
|
|||||||
|
|
||||||
private fun getSkin(uuid: UUID, properties: PlayerProperties?, async: Boolean = true): PlayerSkin? {
|
private fun getSkin(uuid: UUID, properties: PlayerProperties?, async: Boolean = true): PlayerSkin? {
|
||||||
val texture = properties?.textures?.skin ?: return default[uuid]
|
val texture = properties?.textures?.skin ?: return default[uuid]
|
||||||
return PlayerSkin(textureManager.dynamicTextures.pushRaw(texture.getHash(), async) { texture.read() }, default[uuid]?.texture, texture.metadata.model)
|
return PlayerSkin(textureManager.dynamicTextures.push(texture.getHash(), async) { texture.read().readSkin() }, default[uuid]?.texture, texture.metadata.model)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getSkin(player: PlayerEntity, properties: PlayerProperties? = null, fetch: Boolean = true, async: Boolean = true): PlayerSkin? {
|
fun getSkin(player: PlayerEntity, properties: PlayerProperties? = null, fetch: Boolean = true, async: Boolean = true): PlayerSkin? {
|
||||||
@ -67,4 +72,20 @@ class SkinManager(private val textureManager: TextureManager) {
|
|||||||
|
|
||||||
return getSkin(uuid, properties ?: if (fetch) catchAll { PlayerProperties.fetch(uuid) } else null, async)
|
return getSkin(uuid, properties ?: if (fetch) catchAll { PlayerProperties.fetch(uuid) } else null, async)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun ByteArray.readSkin(): TextureData {
|
||||||
|
val data = ByteArrayInputStream(this).readTexture()
|
||||||
|
if (data.size.y != 32) return data
|
||||||
|
|
||||||
|
val next = TextureData(Vec2i(64))
|
||||||
|
data.buffer.rewind()
|
||||||
|
next.buffer.put(data.buffer)
|
||||||
|
|
||||||
|
TextureUtil.copy(Vec2i(0, 16), next, Vec2i(16, 48), next, Vec2i(16, 16)) // leg [0, 16][16,16] to left leg [16, 48]
|
||||||
|
TextureUtil.copy(Vec2i(40, 16), next, Vec2i(32, 48), next, Vec2i(16, 16)) // arm [40, 16] to left arm [32, 48]
|
||||||
|
|
||||||
|
// TODO: flip
|
||||||
|
|
||||||
|
return next
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,4 +123,18 @@ object TextureUtil {
|
|||||||
|
|
||||||
ImageIO.write(bufferedImage, "png", file)
|
ImageIO.write(bufferedImage, "png", file)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun copy(sourceOffset: Vec2i, source: TextureData, targetOffset: Vec2i, target: TextureData, size: Vec2i) {
|
||||||
|
for (y in 0 until size.y) {
|
||||||
|
for (x in 0 until size.x) {
|
||||||
|
val sofs = ((sourceOffset.y + y) * source.size.x + (sourceOffset.x + x)) * 4
|
||||||
|
val dofs = ((targetOffset.y + y) * target.size.x + (targetOffset.x + x)) * 4
|
||||||
|
|
||||||
|
target.buffer.put(dofs + 0, source.buffer.get(sofs + 0))
|
||||||
|
target.buffer.put(dofs + 1, source.buffer.get(sofs + 1))
|
||||||
|
target.buffer.put(dofs + 2, source.buffer.get(sofs + 2))
|
||||||
|
target.buffer.put(dofs + 3, source.buffer.get(sofs + 3))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user