From 2ca368019c5a10199ca49ec426cc545a14681555 Mon Sep 17 00:00:00 2001 From: davchoo Date: Thu, 28 Jul 2022 19:43:03 -0400 Subject: [PATCH] Use identifier from CustomBlockData in SkullResourcePackManager --- .../geyser/pack/SkullResourcePackManager.java | 19 ++++++++++--------- .../org/geysermc/geyser/util/FileUtils.java | 8 ++++++++ 2 files changed, 18 insertions(+), 9 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 e61b9190d..c8fc20bf8 100644 --- a/core/src/main/java/org/geysermc/geyser/pack/SkullResourcePackManager.java +++ b/core/src/main/java/org/geysermc/geyser/pack/SkullResourcePackManager.java @@ -29,6 +29,7 @@ import it.unimi.dsi.fastutil.Pair; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.registry.BlockRegistries; +import org.geysermc.geyser.registry.type.CustomSkull; import org.geysermc.geyser.skin.SkinProvider; import org.geysermc.geyser.util.FileUtils; @@ -180,7 +181,7 @@ public class SkullResourcePackManager { } private static void addFloorGeometries(ZipOutputStream zipOS) throws IOException { - String template = new String(FileUtils.readAllBytes("bedrock/skull_resource_pack/models/blocks/player_skull_floor.geo.json"), StandardCharsets.UTF_8); + String template = FileUtils.readToString("bedrock/skull_resource_pack/models/blocks/player_skull_floor.geo.json"); String[] quadrants = {"a", "b", "c", "d"}; for (int i = 0; i < quadrants.length; i++) { String quadrant = quadrants[i]; @@ -197,11 +198,11 @@ public class SkullResourcePackManager { } private static void addAttachables(ZipOutputStream zipOS) throws IOException { - String template = new String(FileUtils.readAllBytes("bedrock/skull_resource_pack/attachables/template_attachable.json"), StandardCharsets.UTF_8); - for (String skinHash : SKULL_SKINS.keySet()) { - ZipEntry entry = new ZipEntry("skull_resource_pack/attachables/" + skinHash + ".json"); + String template = FileUtils.readToString("bedrock/skull_resource_pack/attachables/template_attachable.json"); + for (CustomSkull skull : BlockRegistries.CUSTOM_SKULLS.get().values()) { + ZipEntry entry = new ZipEntry("skull_resource_pack/attachables/" + skull.getSkinHash() + ".json"); zipOS.putNextEntry(entry); - zipOS.write(fillAttachableJson(template, skinHash).getBytes(StandardCharsets.UTF_8)); + zipOS.write(fillAttachableJson(template, skull).getBytes(StandardCharsets.UTF_8)); zipOS.closeEntry(); } } @@ -218,14 +219,14 @@ public class SkullResourcePackManager { } private static void fillTemplate(ZipOutputStream zipOS, String path, UnaryOperator filler) throws IOException { - String template = new String(FileUtils.readAllBytes(path), StandardCharsets.UTF_8); + String template = FileUtils.readToString(path); String result = filler.apply(template); zipOS.write(result.getBytes(StandardCharsets.UTF_8)); } - private static String fillAttachableJson(String template, String skinHash) { - return template.replace("${identifier}", "geyser:player_skull_" + skinHash) // TOOD use CustomSkull for this - .replace("${texture}", skinHash); + private static String fillAttachableJson(String template, CustomSkull skull) { + return template.replace("${identifier}", skull.getCustomBlockData().identifier()) + .replace("${texture}", skull.getSkinHash()); } private static String fillManifestJson(String template) { diff --git a/core/src/main/java/org/geysermc/geyser/util/FileUtils.java b/core/src/main/java/org/geysermc/geyser/util/FileUtils.java index 6df9c2177..e6c7b41fa 100644 --- a/core/src/main/java/org/geysermc/geyser/util/FileUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/FileUtils.java @@ -188,6 +188,14 @@ public class FileUtils { } } + /** + * @param resource the internal resource to read off from + * @return the contents decoded as a UTF-8 String + */ + public static String readToString(String resource) { + return new String(readAllBytes(resource), StandardCharsets.UTF_8); + } + /** * Read the lines of a file and return it as a stream *