From 192f1e876c3f432d4dbfb69c618d5e247c5f437e Mon Sep 17 00:00:00 2001 From: Moritz Zwerger Date: Mon, 6 Nov 2023 20:06:02 +0100 Subject: [PATCH] fix old skins (1.7) Yes, they are still widely used on modded servers. They are not flipped yet. so the test will fail --- .../base/texture/skin/SkinManagerTest.kt | 47 ++++++++++++++++++ ...2e4568ffdda762ec8d808895cc329a93d606e0.png | Bin 0 -> 779 bytes ...ffdda762ec8d808895cc329a93d606e0_fixed.png | Bin 0 -> 1643 bytes .../gui/atlas/textures/AtlasTexture.kt | 14 +----- .../system/base/texture/skin/SkinManager.kt | 23 ++++++++- .../gui/rendering/textures/TextureUtil.kt | 14 ++++++ 6 files changed, 85 insertions(+), 13 deletions(-) create mode 100644 src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/system/base/texture/skin/SkinManagerTest.kt create mode 100644 src/integration-test/resources/skins/7af7c07d1ded61b1d3312685b32e4568ffdda762ec8d808895cc329a93d606e0.png create mode 100644 src/integration-test/resources/skins/7af7c07d1ded61b1d3312685b32e4568ffdda762ec8d808895cc329a93d606e0_fixed.png diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/system/base/texture/skin/SkinManagerTest.kt b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/system/base/texture/skin/SkinManagerTest.kt new file mode 100644 index 000000000..e81e2f330 --- /dev/null +++ b/src/integration-test/kotlin/de/bixilon/minosoft/gui/rendering/system/base/texture/skin/SkinManagerTest.kt @@ -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 . + * + * 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) + } + +} diff --git a/src/integration-test/resources/skins/7af7c07d1ded61b1d3312685b32e4568ffdda762ec8d808895cc329a93d606e0.png b/src/integration-test/resources/skins/7af7c07d1ded61b1d3312685b32e4568ffdda762ec8d808895cc329a93d606e0.png new file mode 100644 index 0000000000000000000000000000000000000000..cdff90f7a6d1d08e4f8f3675792f0daad8a45e68 GIT binary patch literal 779 zcmV+m1N8ifP)UN4S^Vf2gxO;Kp^Dg(U%bM6kn~g z|G>Z2mepM|>nJnsz|Zb>^~_X#Ro&IvYB|@x-zOoatFw>6v$vXlS%Km=h2MV<*GxSb z09No441&$FtWQrGfCe!X0Cd?86@bgL55rvnR_2Fp6V!oA04aOpH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