From bc7564f82a9aef11e4ee140f7bd828dc45d45b61 Mon Sep 17 00:00:00 2001 From: davchoo <4722249+davchoo@users.noreply.github.com> Date: Thu, 22 Dec 2022 21:11:22 -0500 Subject: [PATCH] Un-revert Crop and reorder skull textures to eliminate unused space Should reduce memory & storage usage for Bedrock clients Bug with top face flipping + per-face uv's was fixed in 1.19.40+ https://bugs.mojang.com/browse/MCPE-160073 Geometry is still offset by 0.5 to prevent lighting bugs --- .../geyser/pack/SkullResourcePackManager.java | 33 ++++++++++--------- .../models/blocks/player_skull.geo.json | 33 ++++++++++++++++--- .../models/blocks/player_skull_floor.geo.json | 31 ++++++++++++++--- .../models/blocks/player_skull_hand.geo.json | 31 ++++++++++++++--- .../models/blocks/player_skull_wall.geo.json | 31 ++++++++++++++--- 5 files changed, 127 insertions(+), 32 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/pack/SkullResourcePackManager.java b/core/src/main/java/org/geysermc/geyser/pack/SkullResourcePackManager.java index c8fc20bf8..199cd64f0 100644 --- a/core/src/main/java/org/geysermc/geyser/pack/SkullResourcePackManager.java +++ b/core/src/main/java/org/geysermc/geyser/pack/SkullResourcePackManager.java @@ -54,7 +54,7 @@ import java.util.zip.ZipOutputStream; public class SkullResourcePackManager { - private static final long RESOURCE_PACK_VERSION = 6; + private static final long RESOURCE_PACK_VERSION = 8; private static final Path SKULL_SKIN_CACHE_PATH = GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("cache").resolve("player_skulls"); @@ -113,21 +113,24 @@ public class SkullResourcePackManager { } BufferedImage image = SkinProvider.requestImage(skinUrl, null); - if (image.getHeight() != 64) { - // We have to resize legacy skins to 64x64 for them to be displayed properly - BufferedImage modernSkin = new BufferedImage(64, 64, image.getType()); + // Resize skins to 48x16 to save on space and memory + BufferedImage skullTexture = new BufferedImage(48, 16, image.getType()); + // Reorder skin parts to fit into the space + // Right, Front, Left, Back, Top, Bottom - head + // Right, Front, Left, Back, Top, Bottom - hat + Graphics g = skullTexture.createGraphics(); + // Right, Front, Left, Back of the head + g.drawImage(image, 0, 0, 32, 8, 0, 8, 32, 16, null); + // Right, Front, Left, Back of the hat + g.drawImage(image, 0, 8, 32, 16, 32, 8, 64, 16, null); + // Top and bottom of the head + g.drawImage(image, 32, 0, 48, 8, 8, 0, 24, 8, null); + // Top and bottom of the hat + g.drawImage(image, 32, 8, 48, 16, 40, 0, 56, 8, null); + g.dispose(); + image.flush(); - Graphics g = modernSkin.createGraphics(); - g.drawImage(image, 0, 0, null); - g.setColor(new Color(0, 0, 0, 0)); - g.fillRect(0, 32, 64, 32); - g.dispose(); - - image.flush(); - image = modernSkin; - } - - ImageIO.write(image, "png", skinPath.toFile()); + ImageIO.write(skullTexture, "png", skinPath.toFile()); SKULL_SKINS.put(skinHash, skinPath); GeyserImpl.getInstance().getLogger().debug("Cached player skull to " + skinPath + " for " + skinHash); } diff --git a/core/src/main/resources/bedrock/skull_resource_pack/models/blocks/player_skull.geo.json b/core/src/main/resources/bedrock/skull_resource_pack/models/blocks/player_skull.geo.json index 2681b406f..18bd5ea12 100644 --- a/core/src/main/resources/bedrock/skull_resource_pack/models/blocks/player_skull.geo.json +++ b/core/src/main/resources/bedrock/skull_resource_pack/models/blocks/player_skull.geo.json @@ -4,8 +4,8 @@ { "description": { "identifier": "geometry.geyser.player_skull", - "texture_width": 64, - "texture_height": 64 + "texture_width": 48, + "texture_height": 16 }, "bones": [ { @@ -33,7 +33,18 @@ "parent": "root_z", "pivot": [0, 24, 0], "cubes": [ - {"origin": [-4, 8, -4], "size": [8, 8, 8], "uv": [0, 0]} + { + "origin": [-4, 8, -4], + "size": [8, 8, 8], + "uv": { + "north": {"uv": [8, 0], "uv_size": [8, 8]}, + "east": {"uv": [0, 0], "uv_size": [8, 8]}, + "south": {"uv": [24, 0], "uv_size": [8, 8]}, + "west": {"uv": [16, 0], "uv_size": [8, 8]}, + "up": {"uv": [32, 0], "uv_size": [8, 8]}, + "down": {"uv": [40, 8], "uv_size": [8, -8]} + } + } ] }, { @@ -41,10 +52,22 @@ "parent": "player_skull", "pivot": [0, 24, 0], "cubes": [ - {"origin": [-4, 8, -4], "size": [8, 8, 8], "uv": [32, 0], "inflate": 0.25} + { + "origin": [-4, 8, -4], + "size": [8, 8, 8], + "inflate": 0.25, + "uv": { + "north": {"uv": [8, 8], "uv_size": [8, 8]}, + "east": {"uv": [0, 8], "uv_size": [8, 8]}, + "south": {"uv": [24, 8], "uv_size": [8, 8]}, + "west": {"uv": [16, 8], "uv_size": [8, 8]}, + "up": {"uv": [32, 8], "uv_size": [8, 8]}, + "down": {"uv": [40, 16], "uv_size": [8, -8]} + } + } ] } ] } ] -} +} \ No newline at end of file diff --git a/core/src/main/resources/bedrock/skull_resource_pack/models/blocks/player_skull_floor.geo.json b/core/src/main/resources/bedrock/skull_resource_pack/models/blocks/player_skull_floor.geo.json index 992ab4aab..da35cb4de 100644 --- a/core/src/main/resources/bedrock/skull_resource_pack/models/blocks/player_skull_floor.geo.json +++ b/core/src/main/resources/bedrock/skull_resource_pack/models/blocks/player_skull_floor.geo.json @@ -4,8 +4,8 @@ { "description": { "identifier": "geometry.geyser.player_skull_floor_${quadrant}", - "texture_width": 64, - "texture_height": 64 + "texture_width": 48, + "texture_height": 16 }, "bones": [ { @@ -13,7 +13,18 @@ "pivot": [0, 24, 0], "rotation": [0, ${y_rotation}, 0], "cubes": [ - {"origin": [-4, 0.5, -4], "size": [8, 8, 8], "uv": [0, 0]} + { + "origin": [-4, 0.5, -4], + "size": [8, 8, 8], + "uv": { + "north": {"uv": [8, 0], "uv_size": [8, 8]}, + "east": {"uv": [0, 0], "uv_size": [8, 8]}, + "south": {"uv": [24, 0], "uv_size": [8, 8]}, + "west": {"uv": [16, 0], "uv_size": [8, 8]}, + "up": {"uv": [32, 0], "uv_size": [8, 8]}, + "down": {"uv": [40, 8], "uv_size": [8, -8]} + } + } ] }, { @@ -21,7 +32,19 @@ "parent": "head", "pivot": [0, 24, 0], "cubes": [ - {"origin": [-4, 0.5, -4], "size": [8, 8, 8], "uv": [32, 0], "inflate": 0.5} + { + "origin": [-4, 0.5, -4], + "size": [8, 8, 8], + "inflate": 0.5, + "uv": { + "north": {"uv": [8, 8], "uv_size": [8, 8]}, + "east": {"uv": [0, 8], "uv_size": [8, 8]}, + "south": {"uv": [24, 8], "uv_size": [8, 8]}, + "west": {"uv": [16, 8], "uv_size": [8, 8]}, + "up": {"uv": [32, 8], "uv_size": [8, 8]}, + "down": {"uv": [40, 16], "uv_size": [8, -8]} + } + } ] } ] diff --git a/core/src/main/resources/bedrock/skull_resource_pack/models/blocks/player_skull_hand.geo.json b/core/src/main/resources/bedrock/skull_resource_pack/models/blocks/player_skull_hand.geo.json index 6ad5bea1b..5bd9e95a8 100644 --- a/core/src/main/resources/bedrock/skull_resource_pack/models/blocks/player_skull_hand.geo.json +++ b/core/src/main/resources/bedrock/skull_resource_pack/models/blocks/player_skull_hand.geo.json @@ -4,15 +4,26 @@ { "description": { "identifier": "geometry.geyser.player_skull_hand", - "texture_width": 64, - "texture_height": 64 + "texture_width": 48, + "texture_height": 16 }, "bones": [ { "name": "head", "pivot": [0, 24, 0], "cubes": [ - {"origin": [-4, 4, -4], "size": [8, 8, 8], "uv": [0, 0]} + { + "origin": [-4, 4, -4], + "size": [8, 8, 8], + "uv": { + "north": {"uv": [8, 0], "uv_size": [8, 8]}, + "east": {"uv": [0, 0], "uv_size": [8, 8]}, + "south": {"uv": [24, 0], "uv_size": [8, 8]}, + "west": {"uv": [16, 0], "uv_size": [8, 8]}, + "up": {"uv": [32, 0], "uv_size": [8, 8]}, + "down": {"uv": [40, 8], "uv_size": [8, -8]} + } + } ] }, { @@ -20,7 +31,19 @@ "parent": "head", "pivot": [0, 24, 0], "cubes": [ - {"origin": [-4, 4, -4], "size": [8, 8, 8], "uv": [32, 0], "inflate": 0.5} + { + "origin": [-4, 4, -4], + "size": [8, 8, 8], + "inflate": 0.5, + "uv": { + "north": {"uv": [8, 8], "uv_size": [8, 8]}, + "east": {"uv": [0, 8], "uv_size": [8, 8]}, + "south": {"uv": [24, 8], "uv_size": [8, 8]}, + "west": {"uv": [16, 8], "uv_size": [8, 8]}, + "up": {"uv": [32, 8], "uv_size": [8, 8]}, + "down": {"uv": [40, 16], "uv_size": [8, -8]} + } + } ] } ] diff --git a/core/src/main/resources/bedrock/skull_resource_pack/models/blocks/player_skull_wall.geo.json b/core/src/main/resources/bedrock/skull_resource_pack/models/blocks/player_skull_wall.geo.json index 5c39733dd..676a6e7f1 100644 --- a/core/src/main/resources/bedrock/skull_resource_pack/models/blocks/player_skull_wall.geo.json +++ b/core/src/main/resources/bedrock/skull_resource_pack/models/blocks/player_skull_wall.geo.json @@ -4,15 +4,26 @@ { "description": { "identifier": "geometry.geyser.player_skull_wall", - "texture_width": 64, - "texture_height": 64 + "texture_width": 48, + "texture_height": 16 }, "bones": [ { "name": "head", "pivot": [0, 24, 0], "cubes": [ - {"origin": [-4, 4, -0.5], "size": [8, 8, 8], "uv": [0, 0]} + { + "origin": [-4, 4, -0.5], + "size": [8, 8, 8], + "uv": { + "north": {"uv": [8, 0], "uv_size": [8, 8]}, + "east": {"uv": [0, 0], "uv_size": [8, 8]}, + "south": {"uv": [24, 0], "uv_size": [8, 8]}, + "west": {"uv": [16, 0], "uv_size": [8, 8]}, + "up": {"uv": [32, 0], "uv_size": [8, 8]}, + "down": {"uv": [40, 8], "uv_size": [8, -8]} + } + } ] }, { @@ -20,7 +31,19 @@ "parent": "head", "pivot": [0, 24, 0], "cubes": [ - {"origin": [-4, 4, -0.5], "size": [8, 8, 8], "uv": [32, 0], "inflate": 0.5} + { + "origin": [-4, 4, -0.5], + "size": [8, 8, 8], + "inflate": 0.5, + "uv": { + "north": {"uv": [8, 8], "uv_size": [8, 8]}, + "east": {"uv": [0, 8], "uv_size": [8, 8]}, + "south": {"uv": [24, 8], "uv_size": [8, 8]}, + "west": {"uv": [16, 8], "uv_size": [8, 8]}, + "up": {"uv": [32, 8], "uv_size": [8, 8]}, + "down": {"uv": [40, 16], "uv_size": [8, -8]} + } + } ] } ]