From ebb027382c0f97a25d3dcfbe3ad4e8028b29353c Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Fri, 21 Jun 2024 18:11:48 -0400 Subject: [PATCH 01/54] Add Map Icon Slicing for 1.20.5+ --- .../forwards/ForwardsPackConverter.java | 4 + .../impl/textures/MapIconSlicerConverter.java | 44 +++ .../main/resources/forwards/map_icons.json | 347 ++++++++++++++++++ .../resourcepack/library/utilities/Util.java | 4 +- library/src/main/resources/protocol.json | 5 +- 5 files changed, 401 insertions(+), 3 deletions(-) create mode 100644 conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconSlicerConverter.java create mode 100644 conversions/Forwards/src/main/resources/forwards/map_icons.json diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java index 45b4d7a3..d8696044 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java @@ -108,6 +108,10 @@ private void converterRunner(String from, String to, String light) { if (protocolFrom <= Util.getVersionProtocol(gson, "1.20.1") && protocolTo >= Util.getVersionProtocol(gson, "1.20.2")) this.registerConverter(new SlicerConverter(this, protocolFrom)); + + if (protocolFrom < Util.getVersionProtocol(gson, "1.20.5") + && protocolTo >= Util.getVersionProtocol(gson, "1.20.5")) + this.registerConverter(new MapIconSlicerConverter(this, protocolFrom)); } public void runPack(Pack pack) { diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconSlicerConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconSlicerConverter.java new file mode 100644 index 00000000..e0f568fa --- /dev/null +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconSlicerConverter.java @@ -0,0 +1,44 @@ +package com.agentdid127.resourcepack.forwards.impl.textures; + +import com.agentdid127.resourcepack.forwards.impl.textures.slicing.Slice; +import com.agentdid127.resourcepack.forwards.impl.textures.slicing.Slicer; +import com.agentdid127.resourcepack.library.Converter; +import com.agentdid127.resourcepack.library.PackConverter; +import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.JsonUtil; +import com.google.gson.Gson; +import com.google.gson.JsonObject; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; + +public class MapIconSlicerConverter extends Converter { + private final int protocolFrom; + + public MapIconSlicerConverter(PackConverter packConverter, int protocolFrom) { + super(packConverter); + this.protocolFrom = protocolFrom; + } + + /** + * Converts maps + * + * @param pack + * @throws IOException + */ + @Override + public void convert(Pack pack) throws IOException { + Path texturesPath = pack.getWorkingPath().resolve("assets/minecraft/textures".replace("/", File.separator)); + if (!texturesPath.toFile().exists()) + return; + Path mapIconsPath = texturesPath.resolve("map/".replace("/", File.separator)); + if (!mapIconsPath.toFile().exists()) + return; + Gson gson = packConverter.getGson(); + JsonObject mapIconsJson = JsonUtil.readJsonResource(gson, "/forwards/map_icons.json", JsonObject.class); + assert mapIconsJson != null; + Slice slice = Slice.parse(mapIconsJson); + Slicer.runSlicer(gson, slice, mapIconsPath, SlicerConverter.PredicateRunnable.class, protocolFrom, false); + } +} diff --git a/conversions/Forwards/src/main/resources/forwards/map_icons.json b/conversions/Forwards/src/main/resources/forwards/map_icons.json new file mode 100644 index 00000000..b37875f4 --- /dev/null +++ b/conversions/Forwards/src/main/resources/forwards/map_icons.json @@ -0,0 +1,347 @@ +{ + "path": "map_icons.png", + "width": 128, + "height": 128, + "delete": true, + "textures": [ + { + "path": "decorations/player.png", + "box": { + "x": 0, + "y": 0, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/frame.png", + "box": { + "x": 8, + "y": 0, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/red_marker.png", + "box": { + "x": 16, + "y": 0, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/target_x.png", + "box": { + "x": 24, + "y": 0, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/target_point.png", + "box": { + "x": 32, + "y": 0, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/player_off_map.png", + "box": { + "x": 40, + "y": 0, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/player_off_limits.png", + "box": { + "x": 48, + "y": 0, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/woodland_mansion.png", + "box": { + "x": 56, + "y": 0, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/ocean_monument.png", + "box": { + "x": 64, + "y": 0, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/white_banner.png", + "box": { + "x": 72, + "y": 0, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/orange_banner.png", + "box": { + "x": 80, + "y": 0, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/magenta_banner.png", + "box": { + "x": 88, + "y": 0, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/light_blue_banner.png", + "box": { + "x": 96, + "y": 0, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/yellow_banner.png", + "box": { + "x": 104, + "y": 0, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/lime_banner.png", + "box": { + "x": 112, + "y": 0, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/pink_banner.png", + "box": { + "x": 0, + "y": 8, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/gray_banner.png", + "box": { + "x": 8, + "y": 8, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/light_gray_banner.png", + "box": { + "x": 16, + "y": 8, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/cyan_banner.png", + "box": { + "x": 24, + "y": 8, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/purple_banner.png", + "box": { + "x": 32, + "y": 8, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/blue_banner.png", + "box": { + "x": 40, + "y": 8, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/brown_banner.png", + "box": { + "x": 48, + "y": 8, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/green_banner.png", + "box": { + "x": 56, + "y": 8, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/red_banner.png", + "box": { + "x": 64, + "y": 8, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/black_banner.png", + "box": { + "x": 72, + "y": 8, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/red_x.png", + "box": { + "x": 80, + "y": 8, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/desert_village.png", + "predicate": { + "protocol": { + "min_inclusive": 764, + "max_inclusive": null + } + }, + "box": { + "x": 88, + "y": 8, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/plains_village.png", + "predicate": { + "protocol": { + "min_inclusive": 764, + "max_inclusive": null + } + }, + "box": { + "x": 96, + "y": 8, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/savanna_village.png", + "predicate": { + "protocol": { + "min_inclusive": 764, + "max_inclusive": null + } + }, + "box": { + "x": 104, + "y": 8, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/snowy_village.png", + "predicate": { + "protocol": { + "min_inclusive": 764, + "max_inclusive": null + } + }, + "box": { + "x": 112, + "y": 8, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/taiga_village.png", + "predicate": { + "protocol": { + "min_inclusive": 764, + "max_inclusive": null + } + }, + "box": { + "x": 120, + "y": 8, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/jungle_temple.png", + "predicate": { + "protocol": { + "min_inclusive": 764, + "max_inclusive": null + } + }, + "box": { + "x": 0, + "y": 16, + "width": 8, + "height": 8 + } + }, + { + "path": "decorations/swamp_hut.png", + "predicate": { + "protocol": { + "min_inclusive": 764, + "max_inclusive": null + } + }, + "box": { + "x": 8, + "y": 16, + "width": 8, + "height": 8 + } + } + ] +} \ No newline at end of file diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Util.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Util.java index 38f5baf5..2225117b 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Util.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Util.java @@ -48,7 +48,7 @@ public static int getVersionProtocol(Gson gson, String version) { } public static int getLatestProtocol(Gson gson) { - return getVersionProtocol(gson, "1.20.4"); + return getVersionProtocol(gson, "1.21"); } /** @@ -63,7 +63,7 @@ public static String getVersionFromProtocol(Gson gson, int protocol) { JsonObject protocols = JsonUtil.readJsonResource(gson, "/protocol.json"); if (protocols == null) return null; - Collection keys = protocols.entrySet().stream().map(i -> i.getKey()) + Collection keys = protocols.entrySet().stream().map(Map.Entry::getKey) .collect(Collectors.toCollection(ArrayList::new)); keys.forEach(key -> { if (Integer.parseInt(protocols.get(key).getAsString()) == protocol) diff --git a/library/src/main/resources/protocol.json b/library/src/main/resources/protocol.json index 81238833..40c964c7 100644 --- a/library/src/main/resources/protocol.json +++ b/library/src/main/resources/protocol.json @@ -76,5 +76,8 @@ "1.20.1": "763", "1.20.2": "764", "1.20.3": "765", - "1.20.4": "765" + "1.20.4": "765", + "1.20.5": "766", + "1.20.6": "766", + "1.21": "767" } \ No newline at end of file From 1c8a63e3fd636a72f45cf8d4226d2a5a045f6dca Mon Sep 17 00:00:00 2001 From: CoryBorek Date: Fri, 21 Jun 2024 18:23:58 -0400 Subject: [PATCH 02/54] let mcmeta support 1.20.5+ --- .../resourcepack/backwards/impl/PackMetaConverter.java | 8 +++++++- .../resourcepack/forwards/impl/PackMetaConverter.java | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/PackMetaConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/PackMetaConverter.java index eeda5567..835be486 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/PackMetaConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/PackMetaConverter.java @@ -31,7 +31,13 @@ public void convert(Pack pack) throws IOException { if (!file.toFile().exists()) return; // Possible TODO: Make this JSON? Possibly use protocol.json, but update it. - if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.20.3")) + if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.21")) + versionInt = 34; + else if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.20.5") + && version < Util.getVersionProtocol(packConverter.getGson(), "1.21")) + versionInt = 32; + else if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.20.3") + && version < Util.getVersionProtocol(packConverter.getGson(), "1.20.5")) versionInt = 22; else if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.20.2") && version < Util.getVersionProtocol(packConverter.getGson(), "1.20.3")) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java index 9d32d198..28afb558 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java @@ -36,7 +36,13 @@ public void convert(Pack pack) throws IOException { int versionInt = 4; // Possible TODO: Make this JSON? Possibly use protocol.json, but update it. - if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.20.3")) + if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.21")) + versionInt = 34; + else if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.20.5") + && to < Util.getVersionProtocol(packConverter.getGson(), "1.21")) + versionInt = 32; + else if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.20.3") + && to < Util.getVersionProtocol(packConverter.getGson(), "1.20.5")) versionInt = 22; else if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.20.2") && to < Util.getVersionProtocol(packConverter.getGson(), "1.20.3")) From 19a7b95133e1864c89e2bc3ff0d1dbc8d9a18ca9 Mon Sep 17 00:00:00 2001 From: CoryBorek Date: Fri, 21 Jun 2024 21:14:31 -0400 Subject: [PATCH 03/54] update README, license, and notice of original upstream --- LICENSE | 2 +- README.MD | 14 +++++++------- licenses/hypixel | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 licenses/hypixel diff --git a/LICENSE b/LICENSE index a0f0e2ac..577621d8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 Hypixel Inc. +Copyright (c) 2024 agentdid127. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.MD b/README.MD index 86ee49e5..5c84fadc 100644 --- a/README.MD +++ b/README.MD @@ -1,12 +1,9 @@ # Resource Pack Converter [![](https://jitpack.io/v/agentdid127/ResourcePackConverter.svg)](https://jitpack.io/#agentdid127/ResourcePackConverter) +This is a program that converts most issues with resource packs between any version from 1.7.2 all the way to 1.20.3. -This is my fork of Hypixel's Resource Pack Converter. It updates to any newer version from 1.8.x - 1.20.x - -We know that many use resource packs in nonstandard and quirky ways - but giving this a shot *may* reduce quite a bit of your pain and workload for the 1.13 conversion. - -This should convert most things, but if it doesn't please let me know what didn't work so I can fix it. +This should convert most things, but if you notice anything that does not work correctly, or should be added, create an issue on Github. Also if any other developers would like to open any PRs with fixes and additions please feel free. @@ -31,9 +28,12 @@ To update to any other version than 1.12-1.13, you can use these parameters. We hope this helps out! -# Not On the list to add -- Horse and Zombified Piglin Conversion (the models were changed, which may make that much more difficult to convert) +## Not On the list to add +- Horse, Zombified Piglin, and Bat Conversion (the models were changed, which may make that much more difficult to convert) ## In-Development Versions Before a version of the converter is ready for release, it will be automatically built on a Jenkins server, where you can get non-production builds. Note: that there is no guaruntee that these versions are stable, however, feel free to post issue reports on the issues page. [Jenkins Server](https://jenkins.dc1.agentdid127.com/job/agentdid127/job/ResourcePackConverter/job/master/) + +### Upstream +This program was originally derived from Hypixel's Resource Pack Converter, though has been essentially reworked over the span of 5 years. Very few, if any bits of the original software remain, but in case that does exist, their original license is included in the licenses' directory. diff --git a/licenses/hypixel b/licenses/hypixel new file mode 100644 index 00000000..a0f0e2ac --- /dev/null +++ b/licenses/hypixel @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Hypixel Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 58ba5f2523ce79df9a0c74237cf1f91fcad4902c Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Sat, 22 Jun 2024 13:38:32 -0400 Subject: [PATCH 04/54] Fix Particle Texture Size for Conversion --- .../textures/ParticleTextureConverter.java | 24 ++++++++++++++++--- .../forwards/impl/textures/slicing/Slice.java | 20 ++++++++++++---- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java index 65e2db17..86debe66 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java @@ -6,7 +6,9 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.FileUtil; +import com.agentdid127.resourcepack.library.utilities.ImageConverter; import com.agentdid127.resourcepack.library.utilities.JsonUtil; +import com.agentdid127.resourcepack.library.utilities.Util; import com.google.gson.Gson; import com.google.gson.JsonObject; @@ -25,7 +27,7 @@ public ParticleTextureConverter(PackConverter packConverter, int from, int to) { /** * Slice particles.png into multiple for 1.14+ - * + * * @param pack * @throws IOException */ @@ -38,10 +40,26 @@ public void convert(Pack pack) throws IOException { if (!particlePath.toFile().exists()) return; Gson gson = packConverter.getGson(); - JsonObject particlesJson = JsonUtil.readJsonResource(gson, "/forwards/particles.json", - JsonObject.class); + + JsonObject particlesJson = JsonUtil.readJsonResource(gson, "/forwards/particles.json", JsonObject.class); + assert particlesJson != null; + Slice slice = Slice.parse(particlesJson); + if (from <= Util.getVersionProtocol(gson, "1.12.2") && + to >= Util.getVersionProtocol(gson, "1.13")) { + Path particlesPath = particlePath.resolve(slice.getPath()); + if (particlesPath.toFile().exists()) { + ImageConverter converter = new ImageConverter(slice.getWidth(), slice.getHeight(), particlesPath); + converter.newImage(256, 256); + converter.subImage(0, 0, 128, 128, 0, 0); + converter.store(); + slice.setWidth(256); + slice.setHeight(256); + } + } + Slicer.runSlicer(gson, slice, particlePath, SlicerConverter.PredicateRunnable.class, from, false); + Path entityPath = texturesPath.resolve("entity"); FileUtil.moveIfExists(particlePath.resolve("fishing_hook.png"), entityPath.resolve("fishing_hook.png")); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicing/Slice.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicing/Slice.java index c8269fe3..f99f5946 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicing/Slice.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicing/Slice.java @@ -1,13 +1,13 @@ package com.agentdid127.resourcepack.forwards.impl.textures.slicing; -import java.io.File; -import java.util.LinkedList; -import java.util.List; - import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import java.io.File; +import java.util.LinkedList; +import java.util.List; + public class Slice { private String path; private String name; @@ -33,6 +33,18 @@ public int getHeight() { return height; } + public void setWidth(int width) { + if (this.width == width) + return; + this.width = width; + } + + public void setHeight(int height) { + if (this.height == height) + return; + this.height = height; + } + public JsonObject getPredicate() { return predicate; } From 41f3c996cdb54af352f6725289634642965ad9fb Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Sat, 22 Jun 2024 13:56:19 -0400 Subject: [PATCH 05/54] Fix slicing for versions & New log message --- .../textures/ParticleTextureConverter.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java index 86debe66..b3059453 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java @@ -5,10 +5,7 @@ import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; -import com.agentdid127.resourcepack.library.utilities.FileUtil; -import com.agentdid127.resourcepack.library.utilities.ImageConverter; -import com.agentdid127.resourcepack.library.utilities.JsonUtil; -import com.agentdid127.resourcepack.library.utilities.Util; +import com.agentdid127.resourcepack.library.utilities.*; import com.google.gson.Gson; import com.google.gson.JsonObject; @@ -17,7 +14,8 @@ import java.nio.file.Path; public class ParticleTextureConverter extends Converter { - int from, to; + private final int from; + private final int to; public ParticleTextureConverter(PackConverter packConverter, int from, int to) { super(packConverter); @@ -36,9 +34,11 @@ public void convert(Pack pack) throws IOException { Path texturesPath = pack.getWorkingPath().resolve("assets/minecraft/textures".replace("/", File.separator)); if (!texturesPath.toFile().exists()) return; + Path particlePath = texturesPath.resolve("particle"); if (!particlePath.toFile().exists()) return; + Gson gson = packConverter.getGson(); JsonObject particlesJson = JsonUtil.readJsonResource(gson, "/forwards/particles.json", JsonObject.class); @@ -47,6 +47,7 @@ public void convert(Pack pack) throws IOException { Slice slice = Slice.parse(particlesJson); if (from <= Util.getVersionProtocol(gson, "1.12.2") && to >= Util.getVersionProtocol(gson, "1.13")) { + Logger.log("Detected 'particles.png' from versions before 1.13, converting to newer size.."); Path particlesPath = particlePath.resolve(slice.getPath()); if (particlesPath.toFile().exists()) { ImageConverter converter = new ImageConverter(slice.getWidth(), slice.getHeight(), particlesPath); @@ -58,9 +59,11 @@ public void convert(Pack pack) throws IOException { } } - Slicer.runSlicer(gson, slice, particlePath, SlicerConverter.PredicateRunnable.class, from, false); - - Path entityPath = texturesPath.resolve("entity"); - FileUtil.moveIfExists(particlePath.resolve("fishing_hook.png"), entityPath.resolve("fishing_hook.png")); + if (from <= Util.getVersionProtocol(gson, "1.13.2") && + to >= Util.getVersionProtocol(gson, "1.14")) { + Slicer.runSlicer(gson, slice, particlePath, SlicerConverter.PredicateRunnable.class, from, false); + Path entityPath = texturesPath.resolve("entity"); + FileUtil.moveIfExists(particlePath.resolve("fishing_hook.png"), entityPath.resolve("fishing_hook.png")); + } } } \ No newline at end of file From 887f9a57267241bd56c63af2ee55a68ae05344b8 Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Sat, 22 Jun 2024 13:57:27 -0400 Subject: [PATCH 06/54] Move new log message into the if block --- .../forwards/impl/textures/ParticleTextureConverter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java index b3059453..ab8b30d0 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java @@ -47,9 +47,9 @@ public void convert(Pack pack) throws IOException { Slice slice = Slice.parse(particlesJson); if (from <= Util.getVersionProtocol(gson, "1.12.2") && to >= Util.getVersionProtocol(gson, "1.13")) { - Logger.log("Detected 'particles.png' from versions before 1.13, converting to newer size.."); Path particlesPath = particlePath.resolve(slice.getPath()); if (particlesPath.toFile().exists()) { + Logger.log("Detected 'particles.png' from versions before 1.13, converting to newer size.."); ImageConverter converter = new ImageConverter(slice.getWidth(), slice.getHeight(), particlesPath); converter.newImage(256, 256); converter.subImage(0, 0, 128, 128, 0, 0); From ca8aaf5ade52185058e8f4d71a416ddb9e16a5a2 Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Sat, 22 Jun 2024 16:05:52 -0400 Subject: [PATCH 07/54] Fix my hiccup in particles default size --- .../forwards/ForwardsPackConverter.java | 2 +- .../textures/ParticleTextureConverter.java | 4 ++-- .../src/main/resources/forwards/particles.json | 4 ++-- .../library/utilities/JsonUtil.java | 18 +++++++++--------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java index 5ff1e8d4..5d5271d9 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java @@ -1,12 +1,12 @@ package com.agentdid127.resourcepack.forwards; +import com.agentdid127.resourcepack.forwards.impl.*; import com.agentdid127.resourcepack.forwards.impl.textures.*; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.Logger; import com.agentdid127.resourcepack.library.utilities.Util; -import com.agentdid127.resourcepack.forwards.impl.*; import com.google.gson.GsonBuilder; import java.io.IOException; diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java index ab8b30d0..0e35ce18 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java @@ -54,9 +54,9 @@ public void convert(Pack pack) throws IOException { converter.newImage(256, 256); converter.subImage(0, 0, 128, 128, 0, 0); converter.store(); - slice.setWidth(256); - slice.setHeight(256); } + slice.setWidth(256); + slice.setHeight(256); } if (from <= Util.getVersionProtocol(gson, "1.13.2") && diff --git a/conversions/Forwards/src/main/resources/forwards/particles.json b/conversions/Forwards/src/main/resources/forwards/particles.json index 20a495ba..1dacc8e5 100644 --- a/conversions/Forwards/src/main/resources/forwards/particles.json +++ b/conversions/Forwards/src/main/resources/forwards/particles.json @@ -1,7 +1,7 @@ { "path": "particles.png", - "width": 256, - "height": 256, + "width": 128, + "height": 128, "delete": true, "textures": [ { diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/JsonUtil.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/JsonUtil.java index 7a1a1b0f..14e0fb0b 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/JsonUtil.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/JsonUtil.java @@ -1,21 +1,21 @@ package com.agentdid127.resourcepack.library.utilities; +import com.agentdid127.resourcepack.library.PackConverter; +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.stream.JsonReader; + import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.StringReader; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.Collections; -import com.agentdid127.resourcepack.library.PackConverter; -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.stream.JsonReader; - public class JsonUtil { public static JsonArray add(JsonArray lhs, JsonArray rhs) { return add(lhs, rhs, (byte) 1); @@ -63,7 +63,7 @@ public static JsonArray asArray(Gson gson, String raw) { } public static void writeJson(Gson gson, Path out, JsonElement json) throws IOException { - Files.write(out, Collections.singleton(gson.toJson(json)), Charset.forName("UTF-8")); + Files.write(out, Collections.singleton(gson.toJson(json)), StandardCharsets.UTF_8); } public static boolean isJson(Gson gson, String Json) { From 29fcee7ec9cfd4f5c6129432006f35e2a118594d Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Sat, 22 Jun 2024 16:10:55 -0400 Subject: [PATCH 08/54] Another hiccup, fixed. --- .../textures/ParticleTextureConverter.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java index 0e35ce18..8f109837 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java @@ -45,16 +45,18 @@ public void convert(Pack pack) throws IOException { assert particlesJson != null; Slice slice = Slice.parse(particlesJson); - if (from <= Util.getVersionProtocol(gson, "1.12.2") && - to >= Util.getVersionProtocol(gson, "1.13")) { - Path particlesPath = particlePath.resolve(slice.getPath()); - if (particlesPath.toFile().exists()) { - Logger.log("Detected 'particles.png' from versions before 1.13, converting to newer size.."); - ImageConverter converter = new ImageConverter(slice.getWidth(), slice.getHeight(), particlesPath); - converter.newImage(256, 256); - converter.subImage(0, 0, 128, 128, 0, 0); - converter.store(); + if (to >= Util.getVersionProtocol(gson, "1.13")) { + if (from <= Util.getVersionProtocol(gson, "1.12.2")) { + Path particlesPath = particlePath.resolve(slice.getPath()); + if (particlesPath.toFile().exists()) { + Logger.log("Detected 'particles.png' from versions before 1.13, converting to newer size.."); + ImageConverter converter = new ImageConverter(slice.getWidth(), slice.getHeight(), particlesPath); + converter.newImage(256, 256); + converter.subImage(0, 0, 128, 128, 0, 0); + converter.store(); + } } + slice.setWidth(256); slice.setHeight(256); } From af673cc271436ba8edae2b51c9baf9c949308df0 Mon Sep 17 00:00:00 2001 From: CoryBorek Date: Sat, 29 Jun 2024 21:50:29 -0400 Subject: [PATCH 09/54] version bump --- Applications/Console/pom.xml | 2 +- Applications/Gui/pom.xml | 2 +- Applications/pom.xml | 6 +++--- conversions/Backwards/pom.xml | 2 +- conversions/Forwards/pom.xml | 2 +- conversions/pom.xml | 4 ++-- library/pom.xml | 2 +- pom.xml | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Applications/Console/pom.xml b/Applications/Console/pom.xml index 43239265..659243c6 100644 --- a/Applications/Console/pom.xml +++ b/Applications/Console/pom.xml @@ -5,7 +5,7 @@ Applications com.agentdid127.resourcepack - 2.2.4 + 2.2.5 4.0.0 diff --git a/Applications/Gui/pom.xml b/Applications/Gui/pom.xml index e7d77534..6f44e016 100644 --- a/Applications/Gui/pom.xml +++ b/Applications/Gui/pom.xml @@ -5,7 +5,7 @@ Applications com.agentdid127.resourcepack - 2.2.4 + 2.2.5 4.0.0 diff --git a/Applications/pom.xml b/Applications/pom.xml index 1360e1a8..9ed8e767 100644 --- a/Applications/pom.xml +++ b/Applications/pom.xml @@ -5,7 +5,7 @@ ResourcePackConverter com.agentdid127 - 2.2.4 + 2.2.5 4.0.0 @@ -33,12 +33,12 @@ com.agentdid127.resourcepack Forwards - 2.2.4 + 2.2.5 com.agentdid127.resourcepack Backwards - 2.2.4 + 2.2.5 diff --git a/conversions/Backwards/pom.xml b/conversions/Backwards/pom.xml index f9628855..5d49c732 100644 --- a/conversions/Backwards/pom.xml +++ b/conversions/Backwards/pom.xml @@ -5,7 +5,7 @@ conversions com.agentdid127.resourcepack - 2.2.4 + 2.2.5 4.0.0 diff --git a/conversions/Forwards/pom.xml b/conversions/Forwards/pom.xml index 7f3f1ce9..61f01879 100644 --- a/conversions/Forwards/pom.xml +++ b/conversions/Forwards/pom.xml @@ -5,7 +5,7 @@ conversions com.agentdid127.resourcepack - 2.2.4 + 2.2.5 4.0.0 diff --git a/conversions/pom.xml b/conversions/pom.xml index 6fde6fb2..de11e72a 100644 --- a/conversions/pom.xml +++ b/conversions/pom.xml @@ -5,7 +5,7 @@ ResourcePackConverter com.agentdid127 - 2.2.4 + 2.2.5 4.0.0 @@ -32,7 +32,7 @@ com.agentdid127.resourcepack Library - 2.2.4 + 2.2.5 diff --git a/library/pom.xml b/library/pom.xml index bf0cfb9c..d49628c7 100644 --- a/library/pom.xml +++ b/library/pom.xml @@ -10,7 +10,7 @@ com.agentdid127 ResourcePackConverter - 2.2.4 + 2.2.5 ../pom.xml \ No newline at end of file diff --git a/pom.xml b/pom.xml index a6a5a34f..8327da3c 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.agentdid127 ResourcePackConverter - 2.2.4 + 2.2.5 pom ResourcePackConverter From 248f4ffc8895763dc30b3f9e429013c88570f459 Mon Sep 17 00:00:00 2001 From: SBDeveloper Date: Sun, 4 Aug 2024 15:38:53 +0200 Subject: [PATCH 10/54] Add check if textures folder exists, closes #220 --- .../forwards/impl/ImageFormatConverter.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ImageFormatConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ImageFormatConverter.java index b28b4912..64cd36e2 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ImageFormatConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ImageFormatConverter.java @@ -9,6 +9,7 @@ import java.io.File; import java.io.IOException; import java.nio.file.Path; +import java.nio.file.Paths; /** * Converts Images to only use PNG formats. @@ -34,7 +35,7 @@ public ImageFormatConverter(PackConverter packConverter) { @Override public void convert(Pack pack) throws IOException { // All textures in the game - Path texturesPath = pack.getWorkingPath().resolve("assets/minecraft/textures".replace("/", File.separator)); + Path texturesPath = pack.getWorkingPath().resolve(Paths.get("assets", "minecraft", "textures")); // check for invalid images for all of these types. for (String type : types) { @@ -50,8 +51,18 @@ public void convert(Pack pack) throws IOException { * @throws IOException If the images are not found, or the remapping fails. */ protected void findImage(Path path, String type) throws IOException { + // Find all files in the directory File directory = path.toFile(); - for (File file : directory.listFiles()) { + if (!directory.exists() || !directory.isDirectory()) { + return; + } + File[] files = directory.listFiles(); + if (files == null) { + return; + } + + // Check each file + for (File file : files) { if (file.isDirectory()) findImage(file.toPath(), type); else { From 20c6331dfbb4a1d5d059d207c1c3a0e77d1356cf Mon Sep 17 00:00:00 2001 From: Cory Borek Date: Sun, 4 Aug 2024 21:34:48 -0400 Subject: [PATCH 11/54] Update conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ImageFormatConverter.java --- .../resourcepack/forwards/impl/ImageFormatConverter.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ImageFormatConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ImageFormatConverter.java index 64cd36e2..57983fd8 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ImageFormatConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ImageFormatConverter.java @@ -56,13 +56,9 @@ protected void findImage(Path path, String type) throws IOException { if (!directory.exists() || !directory.isDirectory()) { return; } - File[] files = directory.listFiles(); - if (files == null) { - return; - } // Check each file - for (File file : files) { + for (File file : directory.listFiles()) { if (file.isDirectory()) findImage(file.toPath(), type); else { From 37c6fbe7d9b45fcd07f12075645f6a7e89062e3d Mon Sep 17 00:00:00 2001 From: Cory Borek Date: Sat, 12 Oct 2024 23:22:45 -0400 Subject: [PATCH 12/54] fix bad read of pack.mcmeta --- .../resourcepack/forwards/ForwardsPackConverter.java | 2 +- .../resourcepack/forwards/impl/PackMetaConverter.java | 5 +++++ .../agentdid127/resourcepack/library/utilities/JsonUtil.java | 1 + pom.xml | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java index 7b731af8..6d225bb0 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java @@ -20,7 +20,7 @@ public class ForwardsPackConverter extends PackConverter { public ForwardsPackConverter(String from, String to, String light, boolean minify, Path input, boolean debug, PrintStream out) { - GsonBuilder gsonBuilder = new GsonBuilder().disableHtmlEscaping().setLenient(); + GsonBuilder gsonBuilder = new GsonBuilder().setLenient(); if (!minify) gsonBuilder.setPrettyPrinting(); gson = gsonBuilder.create(); diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java index 28afb558..687222fc 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java @@ -87,6 +87,11 @@ else if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.7.2") versionInt = 0; JsonObject json = JsonUtil.readJson(packConverter.getGson(), file); + + if (json == null) { + json = new JsonObject(); + } + { JsonObject meta = json.getAsJsonObject("meta"); if (meta == null) diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/JsonUtil.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/JsonUtil.java index 14e0fb0b..fa38bb0d 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/JsonUtil.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/JsonUtil.java @@ -71,6 +71,7 @@ public static boolean isJson(Gson gson, String Json) { gson.fromJson(Json, Object.class); return true; } catch (com.google.gson.JsonSyntaxException ex) { + ex.printStackTrace(); return false; } } diff --git a/pom.xml b/pom.xml index 8327da3c..e8852f25 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ com.google.code.gson gson - 2.8.9 + 2.11.0 net.sf.jopt-simple From 443b03120b09e916d21b2d2f3819b9a877dc9280 Mon Sep 17 00:00:00 2001 From: Cory Borek Date: Sat, 9 Nov 2024 19:54:44 -0500 Subject: [PATCH 13/54] Rework Debug Logs, Check for some invalid json objects, fix squid.png Debug Logs now do not check for the global variable, only their own internal debug session. Tabs are not manually added anymore. Check for null and invalid json objects. Squid.png only moved if it didn't exist. Now fixed. --- .../com/agentdid127/resourcepack/Options.java | 2 +- .../com/agentdid127/resourcepack/GUI.java | 8 +-- .../backwards/BackwardsPackConverter.java | 15 ++-- .../backwards/impl/BlockStateConverter.java | 3 +- .../backwards/impl/LangConverter.java | 4 +- .../backwards/impl/MCPatcherConverter.java | 3 +- .../backwards/impl/ModelConverter.java | 15 ++-- .../backwards/impl/NameConverter.java | 34 ++++----- .../impl/textures/MapIconConverter.java | 2 +- .../forwards/ForwardsPackConverter.java | 15 ++-- .../forwards/impl/AnimationConverter.java | 30 ++++---- .../forwards/impl/BlockStateConverter.java | 70 ++++++++++--------- .../forwards/impl/LangConverter.java | 4 +- .../forwards/impl/MCPatcherConverter.java | 3 +- .../forwards/impl/ModelConverter.java | 34 +++++---- .../forwards/impl/NameConverter.java | 34 ++++----- .../forwards/impl/SoundsConverter.java | 3 +- .../forwards/impl/SpacesConverter.java | 6 +- .../impl/textures/MapIconConverter.java | 2 +- .../textures/ParticleTextureConverter.java | 2 +- .../impl/textures/slicing/Slicer.java | 4 +- .../resourcepack/library/PackConverter.java | 1 - .../resourcepack/library/pack/Pack.java | 6 +- .../resourcepack/library/pack/ZipPack.java | 8 +-- .../library/utilities/FileUtil.java | 6 +- .../library/utilities/ImageConverter.java | 4 +- .../library/utilities/Logger.java | 42 ++++++++++- 27 files changed, 193 insertions(+), 167 deletions(-) diff --git a/Applications/Console/src/main/java/com/agentdid127/resourcepack/Options.java b/Applications/Console/src/main/java/com/agentdid127/resourcepack/Options.java index 3362bfff..15f81b4f 100644 --- a/Applications/Console/src/main/java/com/agentdid127/resourcepack/Options.java +++ b/Applications/Console/src/main/java/com/agentdid127/resourcepack/Options.java @@ -16,7 +16,7 @@ public class Options { public static final OptionSpec INPUT_DIR = PARSER.acceptsAll(Arrays.asList("i", "input", "input-dir"), "Input directory for the packs").withRequiredArg().withValuesConvertedBy(new PathConverter()).defaultsTo(Paths.get("./")); - public static final OptionSpec DEBUG = PARSER.accepts("debug", "Displays other output").withRequiredArg().ofType(Boolean.class).defaultsTo(true); + public static final OptionSpec DEBUG = PARSER.accepts("debug", "Displays other output").withRequiredArg().ofType(Boolean.class).defaultsTo(false); public static final OptionSpec TO = PARSER.accepts("to", "Updates to version").withRequiredArg().ofType(String.class).defaultsTo("1.13"); diff --git a/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java b/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java index b8cf1a77..684fd9d7 100644 --- a/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java +++ b/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java @@ -50,11 +50,11 @@ public GUI() { convertButton.setVisible(false); try { if (Util.getVersionProtocol(gson, from) > Util.getVersionProtocol(gson, to)) - new BackwardsPackConverter(from, to, light, minify, Paths.get("./"), true, out).runDir(); + new BackwardsPackConverter(from, to, light, minify, Paths.get("./"), false, out).runDir(); else - new ForwardsPackConverter(from, to, light, minify, Paths.get("./"), true, out).runDir(); - } catch (IOException ioException) { - out.println(Arrays.toString(ioException.getStackTrace())); + new ForwardsPackConverter(from, to, light, minify, Paths.get("./"), false, out).runDir(); + } catch (Exception exception) { + out.println(Arrays.toString(exception.getStackTrace())); } convertButton.setVisible(true); return; diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/BackwardsPackConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/BackwardsPackConverter.java index 565909fe..67abc86e 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/BackwardsPackConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/BackwardsPackConverter.java @@ -24,10 +24,9 @@ public BackwardsPackConverter(String from, String to, String light, boolean mini if (!minify) gsonBuilder.setPrettyPrinting(); gson = gsonBuilder.create(); - DEBUG = debug; + Logger.setDebug(debug); Logger.setStream(out); - Logger.log(from); - Logger.log(to); + Logger.log("Converting packs from: " + from + " to " + to); this.INPUT_DIR = input; converterRunner(from, to, light); } @@ -88,15 +87,19 @@ private void converterRunner(String from, String to, String light) { public void runPack(Pack pack) { try { Logger.log("Converting " + pack); + Logger.addTab(); pack.getHandler().setup(); - Logger.log(" Running Converters"); + Logger.log("Running Converters"); for (Converter converter : converters.values()) { - if (DEBUG) - Logger.log(" Running " + converter.getClass().getSimpleName()); + Logger.addTab(); + Logger.log("Running " + converter.getClass().getSimpleName()); converter.convert(pack); + Logger.subTab(); } pack.getHandler().finish(); + Logger.subTab(); } catch (Throwable t) { + Logger.resetTab(); Logger.log("Failed to convert!"); Util.propagate(t); } diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/BlockStateConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/BlockStateConverter.java index 02b5f407..e39d45f3 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/BlockStateConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/BlockStateConverter.java @@ -89,8 +89,7 @@ public void convert(Pack pack) throws IOException { } if (anyChanges) { JsonUtil.writeJson(packConverter.getGson(), file, json); - if (PackConverter.DEBUG) - Logger.log(" Converted " + file.getFileName()); + Logger.debug("Converted " + file.getFileName()); } } catch (IOException e) { Util.propagate(e); diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/LangConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/LangConverter.java index 88427e5a..f86fb5ee 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/LangConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/LangConverter.java @@ -86,7 +86,7 @@ public void convert(Pack pack) throws IOException { try { int modelNoJson = model.getFileName().toString().indexOf(".json"); String file2 = model.getFileName().toString().substring(0, modelNoJson); - Logger.log("Saving: " + file2 + ".lang"); + Logger.debug("Saving: " + file2 + ".lang"); out.store( new FileOutputStream( pack.getWorkingPath() @@ -103,7 +103,7 @@ public void convert(Pack pack) throws IOException { for (int i = 0; i < models.size(); i++) { Path langFilePath = pack.getWorkingPath() .resolve(("assets/minecraft/lang/" + models.get(i)).replace("/", File.separator)); - Logger.log("Deleting: " + langFilePath); + Logger.debug("Deleting: " + langFilePath); Files.delete(langFilePath); } } diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/MCPatcherConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/MCPatcherConverter.java index a9af3ca2..53aecfcd 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/MCPatcherConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/MCPatcherConverter.java @@ -64,8 +64,7 @@ protected void remapProperties(Path path) throws IOException { .filter(path1 -> path1.toString().endsWith(".properties")) .forEach(model -> { try (InputStream input = new FileInputStream(model.toString())) { - if (PackConverter.DEBUG) - Logger.log("Updating:" + model.getFileName()); + Logger.debug("Updating:" + model.getFileName()); PropertiesEx prop = new PropertiesEx(); prop.load(input); diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/ModelConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/ModelConverter.java index 9465902b..732f1d3e 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/ModelConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/ModelConverter.java @@ -80,13 +80,13 @@ protected void remapModelJson(Path models) throws IOException { && JsonUtil.readJson(packConverter.getGson(), model).isJsonObject()) jsonObject = JsonUtil.readJson(packConverter.getGson(), model); else { - if (PackConverter.DEBUG) { - Logger.log("Could not convert model: " + model.getFileName()); + Logger.debug("Could not convert model: " + model.getFileName()); + Logger.addTab(); if (JsonUtil.readJson(packConverter.getGson(), model) == null) - Logger.log("Check for Syntax Errors in file."); + Logger.debug("Check for Syntax Errors in file."); else - Logger.log("File is not JSON Object."); - } + Logger.debug("File is not JSON Object."); + Logger.subTab(); return; } @@ -223,8 +223,7 @@ else if (value.startsWith("item/")) } if (!JsonUtil.readJson(packConverter.getGson(), model).equals(jsonObject)) { - if (PackConverter.DEBUG) - Logger.log("Updating Model: " + model.getFileName()); + Logger.debug("Updating Model: " + model.getFileName()); JsonUtil.writeJson(packConverter.getGson(), model, jsonObject); } } catch (IOException e) { @@ -354,7 +353,7 @@ protected String setParent(String prefix, String path, String parent, String ite String parent2 = parent.replace(prefix, ""); JsonObject file = JsonUtil.readJsonResource(packConverter.getGson(), path).getAsJsonObject(item); if (file == null) { - Logger.log("Prefix Failed on: " + parent); + Logger.debug("Prefix Failed on: " + parent); return ""; } return file.has(parent2) ? prefix + file.get(parent2).getAsString() : parent; diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/NameConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/NameConverter.java index 46525417..553c808e 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/NameConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/NameConverter.java @@ -68,11 +68,9 @@ public void convert(Pack pack) throws IOException { && from > Util.getVersionProtocol(packConverter.getGson(), "1.13")) { // OptiFine conversion if (minecraftPath.resolve("mcpatcher").toFile().exists()) { - if (PackConverter.DEBUG) - Logger.log("MCPatcher exists, switching to optifine"); + Logger.debug("MCPatcher exists, switching to optifine"); if (minecraftPath.resolve("optifine").toFile().exists()) { - if (PackConverter.DEBUG) - Logger.log("OptiFine exists, merging directories"); + Logger.debug("OptiFine exists, merging directories"); FileUtil.mergeDirectories(minecraftPath.resolve("optifine").toFile(), minecraftPath.resolve("mcpatcher").toFile()); } else @@ -182,8 +180,7 @@ public void convert(Pack pack) throws IOException { // Less than 1.12 if (from > Util.getVersionProtocol(packConverter.getGson(), "1.13") && to < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { - if (PackConverter.DEBUG) - Logger.log("Finding files that are greater than 1.12"); + Logger.debug("Finding files that are greater than 1.12"); findFiles(texturesPath); } } @@ -220,14 +217,12 @@ protected void findFiles(Path path) throws IOException { for (File file : directory.listFiles()) { if (file.isDirectory()) { if (file.getName().equals("item")) { - if (PackConverter.DEBUG) - Logger.log("Found Items folder, renaming"); + Logger.debug("Found Items folder, renaming"); FileUtil.renameFile(path.resolve(file.getName()), file.getName().replaceAll("item", "items")); } if (file.getName().equals("block")) { - if (PackConverter.DEBUG) - Logger.log("Found blocks folder, renaming"); + Logger.debug("Found blocks folder, renaming"); FileUtil.renameFile(path.resolve(file.getName()), file.getName().replaceAll("block", "blocks")); } @@ -238,8 +233,7 @@ protected void findFiles(Path path) throws IOException { FileUtil.renameFile(path.resolve(file.getName()), file.getName().replaceAll("[()]", "")); if (!file.getName().equals(file.getName().toLowerCase())) - if (PackConverter.DEBUG) - Logger.log("Renamed: " + file.getName() + "->" + file.getName().toLowerCase()); + Logger.debug("Renamed: " + file.getName() + "->" + file.getName().toLowerCase()); FileUtil.renameFile(path.resolve(file.getName()), file.getName().toLowerCase()); } @@ -266,8 +260,8 @@ protected void renameAll(Mapping mapping, String extension, Path path) throws IO newName + extension); if (ret == null) return; - if (ret && PackConverter.DEBUG) - Logger.log(" Renamed: " + name + extension + "->" + newName + extension); + if (ret) + Logger.debug("Renamed: " + name + extension + "->" + newName + extension); else if (!ret) System.err.println(" Failed to rename: " + name + extension + "->" + newName + extension); }); @@ -282,11 +276,10 @@ else if (!ret) newName + extension); if (ret == null) return; - if (ret && PackConverter.DEBUG) - Logger.log(" Renamed: " + name + extension + "->" + newName + extension); + if (ret) + Logger.debug("Renamed: " + name + extension + "->" + newName + extension); else if (!ret) - System.err.println( - " Failed to rename: " + name + extension + "->" + newName + extension); + Logger.log("Failed to rename: " + name + extension + "->" + newName + extension); } }); } @@ -307,9 +300,8 @@ else if (!ret) Boolean ret = FileUtil.renameFile(path1, newName + extension); if (ret == null) return; - if (ret && PackConverter.DEBUG) - Logger.log( - " Renamed: " + path1.getFileName().toString() + "->" + newName + extension); + if (ret) + Logger.debug("Renamed: " + path1.getFileName().toString() + "->" + newName + extension); else if (!ret) System.err.println(" Failed to rename: " + path1.getFileName().toString() + "->" + newName + extension); diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/MapIconConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/MapIconConverter.java index 3cc23ba6..dc107284 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/MapIconConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/MapIconConverter.java @@ -61,7 +61,7 @@ public void convert(Pack pack) throws IOException { int newX = (int) (mapped >> 32); int newY = (int) (long) mapped; - Logger.log(" Mapping " + x + "," + y + " to " + newX + "," + newY); + Logger.log("Mapping " + x + "," + y + " to " + newX + "," + newY); g2d.drawImage(image.getSubimage(x * scale, y * scale, 8 * scale, 8 * scale), newX * scale, newY * scale, null); diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java index 6d225bb0..595a9f5b 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java @@ -24,10 +24,9 @@ public ForwardsPackConverter(String from, String to, String light, boolean minif if (!minify) gsonBuilder.setPrettyPrinting(); gson = gsonBuilder.create(); - DEBUG = debug; + Logger.setDebug(debug); Logger.setStream(out); - Logger.log(from); - Logger.log(to); + Logger.log("Converting packs from: " + from + " to " + to); this.INPUT_DIR = input; converterRunner(from, to, light); } @@ -122,14 +121,18 @@ public void runPack(Pack pack) { try { Logger.log("Converting " + pack); pack.getHandler().setup(); - Logger.log(" Running Converters"); + Logger.addTab(); + Logger.log("Running Converters"); for (Converter converter : converters.values()) { - if (DEBUG) - Logger.log(" Running " + converter.getClass().getSimpleName()); + Logger.addTab(); + Logger.log("Running " + converter.getClass().getSimpleName()); converter.convert(pack); + Logger.subTab(); } + Logger.subTab(); pack.getHandler().finish(); } catch (Throwable t) { + Logger.resetTab(); Logger.log("Failed to convert!"); Util.propagate(t); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/AnimationConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/AnimationConverter.java index eecc5e59..1df3f78f 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/AnimationConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/AnimationConverter.java @@ -42,24 +42,28 @@ protected void fixAnimations(Path animations) throws IOException { try { JsonObject json = JsonUtil.readJson(packConverter.getGson(), file); - boolean anyChanges = false; - JsonElement animationElement = json.get("animation"); - if (animationElement instanceof JsonObject) { - JsonObject animationObject = (JsonObject) animationElement; + if (json != null) { + boolean anyChanges = false; + JsonElement animationElement = json.get("animation"); + if (animationElement instanceof JsonObject) { + JsonObject animationObject = (JsonObject) animationElement; - // TODO: Confirm this doesn't break any packs - animationObject.remove("width"); - animationObject.remove("height"); + // TODO: Confirm this doesn't break any packs + animationObject.remove("width"); + animationObject.remove("height"); - anyChanges = true; - } + anyChanges = true; + } - if (anyChanges) { - JsonUtil.writeJson(packConverter.getGson(), file, json); - if (PackConverter.DEBUG) - Logger.log(" Converted " + file.getFileName()); + if (anyChanges) { + JsonUtil.writeJson(packConverter.getGson(), file, json); + Logger.debug("Converted " + file.getFileName()); + } + } else { + Logger.log("File: " + file.getFileName() + " is not a valid JSON file."); } } catch (IOException e) { + Logger.log("Failed to convert file: " + file.getFileName()); Util.propagate(e); } }); diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.java index 8fe1965c..624f74de 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.java @@ -43,47 +43,49 @@ public void convert(Pack pack) throws IOException { .forEach(file -> { try { JsonObject json = JsonUtil.readJson(packConverter.getGson(), file); - - // process multipart - if (json.has("multipart")) { - JsonElement multipart = json.get("multipart"); - if (multipart.isJsonArray()) { - JsonArray multipartArray = multipart.getAsJsonArray(); - for (JsonElement element : multipartArray) { - JsonObject multipartObject = element.getAsJsonObject(); - for (Map.Entry entry : multipartObject.entrySet()) - updateModelPath(entry); + if (json != null) { + // process multipart + if (json.has("multipart")) { + JsonElement multipart = json.get("multipart"); + if (multipart.isJsonArray()) { + JsonArray multipartArray = multipart.getAsJsonArray(); + for (JsonElement element : multipartArray) { + JsonObject multipartObject = element.getAsJsonObject(); + for (Map.Entry entry : multipartObject.entrySet()) + updateModelPath(entry); + } } } - } - // process variants - if (json.has("variants")) { - JsonElement variants = json.get("variants"); - if (variants.isJsonObject()) { - JsonObject variantsObject = variants.getAsJsonObject(); - // change "normal" key to "" - if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.12.2") - && to >= Util.getVersionProtocol(packConverter.getGson(), "1.13") - && variantsObject.has("normal")) { - JsonElement normal = variantsObject.get("normal"); - if (normal instanceof JsonObject || normal instanceof JsonArray) { - variantsObject.add("", normal); - variantsObject.remove("normal"); - anyChanges = true; + // process variants + if (json.has("variants")) { + JsonElement variants = json.get("variants"); + if (variants.isJsonObject()) { + JsonObject variantsObject = variants.getAsJsonObject(); + // change "normal" key to "" + if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.12.2") + && to >= Util.getVersionProtocol(packConverter.getGson(), "1.13") + && variantsObject.has("normal")) { + JsonElement normal = variantsObject.get("normal"); + if (normal instanceof JsonObject || normal instanceof JsonArray) { + variantsObject.add("", normal); + variantsObject.remove("normal"); + anyChanges = true; + } } - } - // update model paths to prepend block - for (Map.Entry entry : variantsObject.entrySet()) - updateModelPath(entry); + // update model paths to prepend block + for (Map.Entry entry : variantsObject.entrySet()) + updateModelPath(entry); + } } - } - if (anyChanges) { - JsonUtil.writeJson(packConverter.getGson(), file, json); - if (PackConverter.DEBUG) - Logger.log(" Converted " + file.getFileName()); + if (anyChanges) { + JsonUtil.writeJson(packConverter.getGson(), file, json); + Logger.debug("Converted " + file.getFileName()); + } + } else { + Logger.log("Failed to convert: " + file.getFileName() + " as JSON is invalid."); } } catch (IOException e) { Util.propagate(e); diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/LangConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/LangConverter.java index 76fd7de7..5e2cb3dd 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/LangConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/LangConverter.java @@ -97,7 +97,7 @@ public void convert(Pack pack) throws IOException { try { int modelNoLang = model.getFileName().toString().indexOf(".lang"); String file2 = model.getFileName().toString().substring(0, modelNoLang); - Logger.log("Saving: " + file2 + ".json"); + Logger.debug("Saving: " + file2 + ".json"); Path outLangPath = pack.getWorkingPath() .resolve(("assets/minecraft/lang/" + file2 + ".json").replace("/", File.separator)); JsonUtil.writeJson(packConverter.getGson(), outLangPath, out); @@ -112,7 +112,7 @@ public void convert(Pack pack) throws IOException { for (int i = 0; i < models.size(); i++) { Path langFilePath = pack.getWorkingPath() .resolve(("assets/minecraft/lang/" + models.get(i)).replace("/", File.separator)); - Logger.log("Deleting: " + langFilePath); + Logger.debug("Deleting: " + langFilePath); Files.delete(langFilePath); } } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java index e91a1e88..a99c0bec 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java @@ -63,8 +63,7 @@ protected void remapProperties(Path path) throws IOException { Files.list(path).filter(path1 -> path1.toString().endsWith(".properties")).forEach(model -> { try (InputStream input = new FileInputStream(model.toString())) { - if (PackConverter.DEBUG) - Logger.log("Updating:" + model.getFileName()); + Logger.debug("Updating:" + model.getFileName()); PropertiesEx prop = new PropertiesEx(); prop.load(input); diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java index 85df5b7e..7fb468ad 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java @@ -78,13 +78,12 @@ protected void remapModelJson(Path path) throws IOException { && JsonUtil.readJson(packConverter.getGson(), model).isJsonObject()) jsonObject = JsonUtil.readJson(packConverter.getGson(), model); else { - if (PackConverter.DEBUG) { - Logger.log("Could not convert model: " + model.getFileName()); - if (JsonUtil.readJson(packConverter.getGson(), model) == null) - Logger.log("Check for Syntax Errors in file."); - else - Logger.log("File is not JSON Object."); - } + Logger.debug("Could not convert model: " + model.getFileName()); + Logger.addTab(); + if (JsonUtil.readJson(packConverter.getGson(), model) == null) + Logger.debug("Check for Syntax Errors in file."); + else Logger.debug("File is not JSON Object."); + Logger.subTab(); return; } @@ -102,7 +101,7 @@ protected void remapModelJson(Path path) throws IOException { // handle the remapping of textures, for models that use default texture names jsonObject = packConverter.getGson().fromJson(content, JsonObject.class); if (jsonObject.keySet().isEmpty() || jsonObject.entrySet().isEmpty()) { - Logger.log("Model '" + model.getFileName() + "' was empty, skipping..."); + Logger.debug("Model '" + model.getFileName() + "' was empty, skipping..."); return; } @@ -129,13 +128,13 @@ protected void remapModelJson(Path path) throws IOException { value = "block/" + nameConverter.getBlockMapping() .remap(value.substring("block/".length())).toLowerCase() .replaceAll("[()]", ""); - if (PackConverter.DEBUG) { - Logger.log(value.substring("block/".length()).toLowerCase() - .replaceAll("[()]", "")); - Logger.log(nameConverter.getBlockMapping() - .remap(value.substring("block/".length())).toLowerCase() - .replaceAll("[()]", "")); - } + + Logger.debug(value.substring("block/".length()).toLowerCase() + .replaceAll("[()]", "")); + Logger.debug(nameConverter.getBlockMapping() + .remap(value.substring("block/".length())).toLowerCase() + .replaceAll("[()]", "")); + } else if (value.startsWith("item/")) { value = "item/" + nameConverter.getItemMapping() .remap(value.substring("item/".length())).toLowerCase() @@ -278,8 +277,7 @@ else if (parent.startsWith("item/")) } if (!JsonUtil.readJson(packConverter.getGson(), model).equals(jsonObject)) { - if (PackConverter.DEBUG) - Logger.log("Updating Model: " + model.getFileName()); + Logger.debug("Updating Model: " + model.getFileName()); JsonUtil.writeJson(packConverter.getGson(), model, jsonObject); } } catch (IOException e) { @@ -300,7 +298,7 @@ protected String setParent(String prefix, String path, String parent, String ite String parent2 = parent.replace(prefix, ""); JsonObject file = JsonUtil.readJsonResource(packConverter.getGson(), path).getAsJsonObject(item); if (file == null) { - Logger.log("Prefix Failed on: " + parent); + Logger.debug("Prefix Failed on: " + parent); return ""; } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java index ea75a0f7..5cbd76f3 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java @@ -65,8 +65,7 @@ public void convert(Pack pack) throws IOException { // Less than 1.12 if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.12.2") && to > Util.getVersionProtocol(packConverter.getGson(), "1.13")) { - if (PackConverter.DEBUG) - Logger.log("Finding files that are less than 1.12"); + Logger.debug("Finding files that are less than 1.12"); findFiles(minecraftPath); } @@ -74,11 +73,9 @@ public void convert(Pack pack) throws IOException { if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.13")) { // OptiFine conversion if (minecraftPath.resolve("mcpatcher").toFile().exists()) { - if (PackConverter.DEBUG) - Logger.log("MCPatcher exists, switching to optifine"); + Logger.debug("MCPatcher exists, switching to optifine"); if (minecraftPath.resolve("optifine").toFile().exists()) { - if (PackConverter.DEBUG) - Logger.log("OptiFine exists, merging directories"); + Logger.debug("OptiFine exists, merging directories"); FileUtil.mergeDirectories(minecraftPath.resolve("optifine").toFile(), minecraftPath.resolve("mcpatcher").toFile()); } else @@ -212,7 +209,7 @@ public void convert(Pack pack) throws IOException { renameAll(itemMapping17, ".png", modelsPath.resolve("item")); if (!entityPath.resolve("squid").toFile().exists()) entityPath.resolve("squid").toFile().mkdir(); - if (entityPath.resolve("squid.png").toFile().exists()) + if (!entityPath.resolve("squid.png").toFile().exists()) Files.move(entityPath.resolve("squid.png"), entityPath.resolve("squid/squid.png")); } @@ -261,14 +258,12 @@ protected void findFiles(Path path) throws IOException { for (File file : directory.listFiles()) { if (file.isDirectory()) { if (file.getName().equals("items")) { - if (PackConverter.DEBUG) - Logger.log("Found Items folder, renaming"); + Logger.debug("Found Items folder, renaming"); FileUtil.renameFile(path.resolve(file.getName()), file.getName().replaceAll("items", "item")); } if (file.getName().equals("blocks")) { - if (PackConverter.DEBUG) - Logger.log("Found blocks folder, renaming"); + Logger.debug("Found blocks folder, renaming"); FileUtil.renameFile(path.resolve(file.getName()), file.getName().replaceAll("blocks", "block")); } @@ -279,8 +274,7 @@ protected void findFiles(Path path) throws IOException { FileUtil.renameFile(path.resolve(file.getName()), file.getName().replaceAll("[()]", "")); if (!file.getName().equals(file.getName().toLowerCase())) - if (PackConverter.DEBUG) - Logger.log("Renamed: " + file.getName() + "->" + file.getName().toLowerCase()); + Logger.debug("Renamed: " + file.getName() + "->" + file.getName().toLowerCase()); FileUtil.renameFile(path.resolve(file.getName()), file.getName().toLowerCase()); } @@ -308,11 +302,10 @@ protected void renameAll(Mapping mapping, String extension, Path path) throws IO newName + extension); if (ret == null) return; - if (ret && PackConverter.DEBUG) { - Logger.log(" Renamed: " + name + extension + "->" + newName + extension); + if (ret) { + Logger.debug("Renamed: " + name + extension + "->" + newName + extension); } else if (!ret) { - System.err.println( - " Failed to rename: " + name + extension + "->" + newName + extension); + Logger.log("Failed to rename: " + name + extension + "->" + newName + extension); } }); } @@ -342,11 +335,10 @@ protected void renameAll(Mapping mapping, String extension, Path path) throws IO Boolean ret = FileUtil.renameFile(path1, newName + extension); if (ret == null) return; - if (ret && PackConverter.DEBUG) { - Logger.log( - " Renamed: " + path1.getFileName().toString() + "->" + newName + extension); + if (ret) { + Logger.debug("Renamed: " + path1.getFileName().toString() + "->" + newName + extension); } else if (!ret) { - System.err.println(" Failed to rename: " + path1.getFileName().toString() + "->" + newName + Logger.log("Failed to rename: " + path1.getFileName().toString() + "->" + newName + extension); } } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/SoundsConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/SoundsConverter.java index 855d9d14..caea50ee 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/SoundsConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/SoundsConverter.java @@ -62,8 +62,7 @@ else if (jsonElement instanceof JsonPrimitive) String rewrite = path.toFile().getCanonicalPath().substring( baseSoundsPath.toString().length() + 1, path.toFile().getCanonicalPath().length() - 4); - if (PackConverter.DEBUG) - Logger.log(" Rewriting Sound: '" + sound + "' -> '" + rewrite + "'"); + Logger.debug("Rewriting Sound: '" + sound + "' -> '" + rewrite + "'"); sound = rewrite; } else { sound = jsonElement.getAsString(); diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/SpacesConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/SpacesConverter.java index 1a36301a..59ab3ccb 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/SpacesConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/SpacesConverter.java @@ -64,11 +64,11 @@ protected String fixSpaces(Path path) throws IOException { if (ret == null) return "null"; - if (ret && PackConverter.DEBUG) { - Logger.log(" Renamed: " + path.getFileName().toString() + "->" + noSpaces); + if (ret) { + Logger.debug("Renamed: " + path.getFileName().toString() + "->" + noSpaces); return path.getParent() + File.separator + noSpaces; } else if (!ret) { - System.err.println(" Failed to rename: " + path.getFileName().toString() + "->" + noSpaces); + Logger.log("Failed to rename: " + path.getFileName().toString() + "->" + noSpaces); return path.getParent() + File.separator + noSpaces; } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter.java index e35aba8f..7382f3cc 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter.java @@ -62,7 +62,7 @@ public void convert(Pack pack) throws IOException { int newX = (int) (mapped >> 32); int newY = (int) (long) mapped; - Logger.log(" Mapping " + x + "," + y + " to " + newX + "," + newY); + Logger.debug("Mapping " + x + "," + y + " to " + newX + "," + newY); g2d.drawImage(image.getSubimage(x * scale, y * scale, 8 * scale, 8 * scale), newX * scale, newY * scale, null); diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java index 8f109837..d0044972 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java @@ -49,7 +49,7 @@ public void convert(Pack pack) throws IOException { if (from <= Util.getVersionProtocol(gson, "1.12.2")) { Path particlesPath = particlePath.resolve(slice.getPath()); if (particlesPath.toFile().exists()) { - Logger.log("Detected 'particles.png' from versions before 1.13, converting to newer size.."); + Logger.debug("Detected 'particles.png' from versions before 1.13, converting to newer size.."); ImageConverter converter = new ImageConverter(slice.getWidth(), slice.getHeight(), particlesPath); converter.newImage(256, 256); converter.subImage(0, 0, 128, 128, 0, 0); diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicing/Slicer.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicing/Slicer.java index a9505de0..c3a1b11e 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicing/Slicer.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicing/Slicer.java @@ -21,7 +21,7 @@ public static void runSlicer(Gson gson, Slice slice, Path root, Class pre Path path = root.resolve(slice.getPath()); if (!path.toFile().exists()) { - Logger.log("Texture '" + slice.getPath() + "' doesn't exist, ignoring..."); + Logger.debug("Texture '" + slice.getPath() + "' doesn't exist, ignoring..."); return; } @@ -79,7 +79,7 @@ public static void runSlicer(Gson gson, Slice slice, Path root, Class pre } if (!path.toFile().delete()) - Logger.log("Failed to remove '" + path.getFileName() + "' whilst slicing."); + Logger.debug("Failed to remove '" + path.getFileName() + "' whilst slicing."); if (!slice.shouldDelete()) converter.store(imagePath); diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/PackConverter.java b/library/src/main/java/com/agentdid127/resourcepack/library/PackConverter.java index 7bcebc1e..b392d2e6 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/PackConverter.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/PackConverter.java @@ -8,7 +8,6 @@ public abstract class PackConverter { protected final Map, Converter> converters = new LinkedHashMap<>(); protected Gson gson; - public static boolean DEBUG = true; /** * Registers Converter. diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/pack/Pack.java b/library/src/main/java/com/agentdid127/resourcepack/library/pack/Pack.java index 8dde31fa..f3aa2a3e 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/pack/Pack.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/pack/Pack.java @@ -74,11 +74,11 @@ public Handler(Pack pack) { */ public void setup() throws IOException { if (pack.getWorkingPath().toFile().exists()) { - Logger.log(" Deleting existing conversion"); + Logger.log("Deleting existing conversion"); FileUtil.deleteDirectoryAndContents(pack.getWorkingPath()); } - Logger.log(" Copying existing pack"); + Logger.log("Copying existing pack"); FileUtil.copyDirectory(pack.getOriginalPath(), pack.getWorkingPath()); bomRemover(pack.getWorkingPath()); @@ -90,7 +90,7 @@ static void bomRemover(Path workingPath) throws IOException { ".txt", ".json", ".mcmeta", ".properties", ".lang"); int count = bom.findBOMs().size(); if (count > 0) - Logger.log("Removing BOMs from " + count + " files."); + Logger.debug("Removing BOMs from " + count + " files."); bom.removeBOMs(); } diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/pack/ZipPack.java b/library/src/main/java/com/agentdid127/resourcepack/library/pack/ZipPack.java index d07036d7..673ad0cc 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/pack/ZipPack.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/pack/ZipPack.java @@ -44,13 +44,13 @@ public Path getConvertedZipPath() { @Override public void setup() throws IOException { if (pack.getWorkingPath().toFile().exists()) { - Logger.log(" Deleting existing conversion"); + Logger.log("Deleting existing conversion"); FileUtil.deleteDirectoryAndContents(pack.getWorkingPath()); } Path convertedZipPath = getConvertedZipPath(); if (convertedZipPath.toFile().exists()) { - Logger.log(" Deleting existing conversion zip"); + Logger.log("Deleting existing conversion zip"); convertedZipPath.toFile().delete(); } @@ -75,7 +75,7 @@ public void setup() throws IOException { @Override public void finish() throws IOException { try { - Logger.log(" Zipping working directory"); + Logger.log("Zipping working directory"); ZipFile zipFile = new ZipFile(getConvertedZipPath().toFile()); ZipParameters parameters = new ZipParameters(); parameters.setIncludeRootFolder(false); @@ -85,7 +85,7 @@ public void finish() throws IOException { Util.propagate(e); } - Logger.log(" Deleting working directory"); + Logger.log("Deleting working directory"); FileUtil.deleteDirectoryAndContents(pack.getWorkingPath()); } diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/FileUtil.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/FileUtil.java index 3853ced1..6a431f46 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/FileUtil.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/FileUtil.java @@ -102,13 +102,13 @@ public static Boolean mergeDirectories(File dir1, File dir2) throws IOException File[] files = dir2.listFiles(); for (File file : files) { if (file.isDirectory()) { - Logger.log(targetDirPath + File.separator + file.getName()); + Logger.debug(targetDirPath + File.separator + file.getName()); File file3 = new File(targetDirPath + File.separator + file.getName()); file3.mkdirs(); - Logger.log("Created" + file3.getName()); + Logger.debug("Created" + file3.getName()); mergeDirectories(file3, file); } else { - Logger.log(targetDirPath + File.separator + file.getName()); + Logger.debug(targetDirPath + File.separator + file.getName()); file.renameTo(new File(targetDirPath + File.separator + file.getName())); } } diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/ImageConverter.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/ImageConverter.java index 1c4d6041..777c7daa 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/ImageConverter.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/ImageConverter.java @@ -39,7 +39,7 @@ public ImageConverter(Integer defaultWIn, Integer defaultHIn, Path locationIn) t } if (!fileIsPowerOfTwo()) { - Logger.log("Image (" + image.getWidth() + "x" + image.getHeight() + ") '" + locationIn.getFileName() + Logger.debug("Image (" + image.getWidth() + "x" + image.getHeight() + ") '" + locationIn.getFileName() + "' resolution size is not a power of 2. Converting to be so."); int fixed_width = (int) Math.ceil(Math.log(image.getWidth()) / Math.log(2)); @@ -105,7 +105,7 @@ public void fillEmpty(int x, int y, int width, int height) { */ public void setImage(int defaultWIn, int defaultHIn) throws IOException { if (!imageIsPowerOfTwo(newImage)) { - Logger.log("Image '" + location.getFileName() + "' is not a power of 2"); + Logger.debug("Image '" + location.getFileName() + "' is not a power of 2"); return; } image = newImage; diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Logger.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Logger.java index d6b28220..2334f9f8 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Logger.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Logger.java @@ -4,16 +4,54 @@ public class Logger { private static PrintStream stream; + private static boolean debug; + + private static int tabs = 0; + + public static void addTab() { + tabs++; + } + + public static void subTab() { + tabs--; + if (tabs < 0) tabs = 0; + } + + public static void resetTab() { + tabs = 0; + } + + private static String getTabs() { + String out = ""; + + for (int i = 0; i < tabs; i++) { + out += " "; + } + return out; + } public static void setStream(PrintStream stream) { Logger.stream = stream; } + public static void setDebug(boolean debug) { + Logger.debug = debug; + } + + public static void debug(String message) { + if (debug) log(message); + } + public static void log(String message) { - stream.println(message); + stream.println(getTabs() + message); + } + + private static void debug(Object thing) { + if (debug) log(thing); } public static void log(Object thing) { - stream.println(String.valueOf(thing)); + String tabs = getTabs(); + stream.println(tabs + String.valueOf(thing).replaceAll("\n", "\n" + tabs)); } } From 29a0eb383a6e1ad4233d58a55bcebb15eb87a426 Mon Sep 17 00:00:00 2001 From: Cory Borek Date: Sat, 9 Nov 2024 19:55:28 -0500 Subject: [PATCH 14/54] Don't throw an error with invalid json objects We are checking for a valid json object here. It is suppsed to throw an error if it isn't here. --- .../com/agentdid127/resourcepack/library/utilities/JsonUtil.java | 1 - 1 file changed, 1 deletion(-) diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/JsonUtil.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/JsonUtil.java index fa38bb0d..14e0fb0b 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/JsonUtil.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/JsonUtil.java @@ -71,7 +71,6 @@ public static boolean isJson(Gson gson, String Json) { gson.fromJson(Json, Object.class); return true; } catch (com.google.gson.JsonSyntaxException ex) { - ex.printStackTrace(); return false; } } From 1576a1357ee5aff11ab0566c8872151ebd56e86f Mon Sep 17 00:00:00 2001 From: SBDeveloper Date: Sun, 1 Dec 2024 19:37:11 +0100 Subject: [PATCH 15/54] Added 1.21.2-1.21.3 to version lists --- .../resourcepack/backwards/impl/PackMetaConverter.java | 5 ++++- .../resourcepack/forwards/impl/PackMetaConverter.java | 5 ++++- .../com/agentdid127/resourcepack/library/utilities/Util.java | 2 +- library/src/main/resources/protocol.json | 5 ++++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/PackMetaConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/PackMetaConverter.java index 835be486..fb43643d 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/PackMetaConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/PackMetaConverter.java @@ -31,7 +31,10 @@ public void convert(Pack pack) throws IOException { if (!file.toFile().exists()) return; // Possible TODO: Make this JSON? Possibly use protocol.json, but update it. - if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.21")) + if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.21.2")) + versionInt = 42; + else if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.21") + && version < Util.getVersionProtocol(packConverter.getGson(), "1.21.2")) versionInt = 34; else if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.20.5") && version < Util.getVersionProtocol(packConverter.getGson(), "1.21")) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java index 687222fc..4bf962e0 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java @@ -36,7 +36,10 @@ public void convert(Pack pack) throws IOException { int versionInt = 4; // Possible TODO: Make this JSON? Possibly use protocol.json, but update it. - if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.21")) + if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.21.2")) + versionInt = 42; + else if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.21") + && to < Util.getVersionProtocol(packConverter.getGson(), "1.21.2")) versionInt = 34; else if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.20.5") && to < Util.getVersionProtocol(packConverter.getGson(), "1.21")) diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Util.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Util.java index 2225117b..81013b18 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Util.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Util.java @@ -48,7 +48,7 @@ public static int getVersionProtocol(Gson gson, String version) { } public static int getLatestProtocol(Gson gson) { - return getVersionProtocol(gson, "1.21"); + return getVersionProtocol(gson, "1.21.3"); } /** diff --git a/library/src/main/resources/protocol.json b/library/src/main/resources/protocol.json index 40c964c7..17c98e5b 100644 --- a/library/src/main/resources/protocol.json +++ b/library/src/main/resources/protocol.json @@ -79,5 +79,8 @@ "1.20.4": "765", "1.20.5": "766", "1.20.6": "766", - "1.21": "767" + "1.21": "767", + "1.21.1": "767", + "1.21.2": "768", + "1.21.3": "768" } \ No newline at end of file From e94528d366b90305774a35ce207477d76e73c198 Mon Sep 17 00:00:00 2001 From: SBDeveloper Date: Sun, 1 Dec 2024 20:08:37 +0100 Subject: [PATCH 16/54] Implemented pack format from protocol functionality --- .../backwards/impl/PackMetaConverter.java | 60 +-- .../forwards/impl/PackMetaConverter.java | 69 +-- .../resourcepack/library/utilities/Util.java | 93 ++-- library/src/main/resources/protocol.json | 420 ++++++++++++++---- 4 files changed, 415 insertions(+), 227 deletions(-) diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/PackMetaConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/PackMetaConverter.java index fb43643d..1a09457b 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/PackMetaConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/PackMetaConverter.java @@ -21,7 +21,7 @@ public PackMetaConverter(PackConverter packConverter, int versionIn) { /** * Converts MCMeta to newer version - * + * * @param pack * @throws IOException */ @@ -30,59 +30,11 @@ public void convert(Pack pack) throws IOException { Path file = pack.getWorkingPath().resolve("pack.mcmeta"); if (!file.toFile().exists()) return; - // Possible TODO: Make this JSON? Possibly use protocol.json, but update it. - if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.21.2")) - versionInt = 42; - else if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.21") - && version < Util.getVersionProtocol(packConverter.getGson(), "1.21.2")) - versionInt = 34; - else if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.20.5") - && version < Util.getVersionProtocol(packConverter.getGson(), "1.21")) - versionInt = 32; - else if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.20.3") - && version < Util.getVersionProtocol(packConverter.getGson(), "1.20.5")) - versionInt = 22; - else if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.20.2") - && version < Util.getVersionProtocol(packConverter.getGson(), "1.20.3")) - versionInt = 18; - else if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.20") - && version < Util.getVersionProtocol(packConverter.getGson(), "1.20.2")) - versionInt = 15; - else if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.19.4") - && version < Util.getVersionProtocol(packConverter.getGson(), "1.20")) - versionInt = 13; - else if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.19.3") - && version < Util.getVersionProtocol(packConverter.getGson(), "1.19.4")) - versionInt = 12; - else if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.19") - && version < Util.getVersionProtocol(packConverter.getGson(), "1.19.3")) - versionInt = 9; - else if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.18") - && version < Util.getVersionProtocol(packConverter.getGson(), "1.19")) - versionInt = 8; - else if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.17") - && version < Util.getVersionProtocol(packConverter.getGson(), "1.18")) - versionInt = 7; - else if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.16.2") - && version < Util.getVersionProtocol(packConverter.getGson(), "1.17")) - versionInt = 6; - else if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.15") - && version < Util.getVersionProtocol(packConverter.getGson(), "1.16.2")) - versionInt = 5; - else if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.13") - && version < Util.getVersionProtocol(packConverter.getGson(), "1.15")) - versionInt = 4; - else if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.11") - && version < Util.getVersionProtocol(packConverter.getGson(), "1.13")) - versionInt = 3; - else if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.9") - && version < Util.getVersionProtocol(packConverter.getGson(), "1.11")) - versionInt = 2; - else if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.7.2") - && version < Util.getVersionProtocol(packConverter.getGson(), "1.9")) - versionInt = 1; - else - versionInt = 0; + + JsonObject versionObj = Util.getVersionObjectByProtocol(packConverter.getGson(), version); + if (versionObj != null) { + versionInt = Integer.parseInt(versionObj.get("pack_format").getAsString()); + } JsonObject json = JsonUtil.readJson(packConverter.getGson(), file); { diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java index 4bf962e0..deb10ac4 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java @@ -23,7 +23,7 @@ public PackMetaConverter(PackConverter packConverter, int from, int to) { /** * Converts MCMeta to newer version - * + * * @param pack * @throws IOException */ @@ -34,67 +34,17 @@ public void convert(Pack pack) throws IOException { return; int versionInt = 4; - - // Possible TODO: Make this JSON? Possibly use protocol.json, but update it. - if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.21.2")) - versionInt = 42; - else if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.21") - && to < Util.getVersionProtocol(packConverter.getGson(), "1.21.2")) - versionInt = 34; - else if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.20.5") - && to < Util.getVersionProtocol(packConverter.getGson(), "1.21")) - versionInt = 32; - else if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.20.3") - && to < Util.getVersionProtocol(packConverter.getGson(), "1.20.5")) - versionInt = 22; - else if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.20.2") - && to < Util.getVersionProtocol(packConverter.getGson(), "1.20.3")) - versionInt = 18; - else if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.20") - && to < Util.getVersionProtocol(packConverter.getGson(), "1.20.2")) - versionInt = 15; - else if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.19.4") - && to < Util.getVersionProtocol(packConverter.getGson(), "1.20")) - versionInt = 13; - else if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.19.3") - && to < Util.getVersionProtocol(packConverter.getGson(), "1.19.4")) - versionInt = 12; - else if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.19") - && to < Util.getVersionProtocol(packConverter.getGson(), "1.19.3")) - versionInt = 9; - else if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.18") - && to < Util.getVersionProtocol(packConverter.getGson(), "1.19")) - versionInt = 8; - else if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.17") - && to < Util.getVersionProtocol(packConverter.getGson(), "1.18")) - versionInt = 7; - else if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.16.2") - && to < Util.getVersionProtocol(packConverter.getGson(), "1.17")) - versionInt = 6; - else if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.15") - && to < Util.getVersionProtocol(packConverter.getGson(), "1.16.2")) - versionInt = 5; - else if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.13") - && to < Util.getVersionProtocol(packConverter.getGson(), "1.15")) - versionInt = 4; - else if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.11") - && to < Util.getVersionProtocol(packConverter.getGson(), "1.13")) - versionInt = 3; - else if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.9") - && to < Util.getVersionProtocol(packConverter.getGson(), "1.11")) - versionInt = 2; - else if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.7.2") - && to < Util.getVersionProtocol(packConverter.getGson(), "1.9")) - versionInt = 1; - else - versionInt = 0; + JsonObject versionObj = Util.getVersionObjectByProtocol(packConverter.getGson(), to); + if (versionObj != null) { + versionInt = Integer.parseInt(versionObj.get("pack_format").getAsString()); + } JsonObject json = JsonUtil.readJson(packConverter.getGson(), file); if (json == null) { json = new JsonObject(); } - + { JsonObject meta = json.getAsJsonObject("meta"); if (meta == null) @@ -111,9 +61,12 @@ else if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.7.2") if (from < Util.getVersionProtocol(packConverter.getGson(), "1.20.2") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.20.2")) { + JsonObject fromVersion = Util.getVersionObjectByProtocol(packConverter.getGson(), from); + JsonObject toVersion = Util.getVersionObjectByProtocol(packConverter.getGson(), to); + JsonObject supportedFormats = new JsonObject(); - supportedFormats.addProperty("min_inclusive", versionInt); - supportedFormats.addProperty("max_inclusive", versionInt); // TODO: A better way to do this + supportedFormats.addProperty("min_inclusive", fromVersion != null ? Integer.parseInt(fromVersion.get("pack_format").getAsString()) : versionInt); + supportedFormats.addProperty("max_inclusive", toVersion != null ? Integer.parseInt(toVersion.get("pack_format").getAsString()) : versionInt); packObject.add("supported_formats", supportedFormats); } diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Util.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Util.java index 81013b18..d289bc91 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Util.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Util.java @@ -2,17 +2,17 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.google.gson.Gson; +import com.google.gson.JsonElement; import com.google.gson.JsonObject; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; -import java.io.*; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Collection; import java.util.Map; -import java.util.concurrent.atomic.AtomicReference; -import java.util.stream.Collectors; public final class Util { private Util() { @@ -21,7 +21,7 @@ private Util() { /** * Reads Image as BufferedImage - * + * * @param path Path to file * @return Buffered Image */ @@ -36,45 +36,76 @@ public static BufferedImage readImageResource(String path) { } /** - * Gets version protocol number - * - * @param gson Gson object to use - * @param version Minecraft Version Number. - * @return Protocol Integer Number + * Gets Minecraft Version from Protocol number + * + * @param gson Gson object to use + * @param protocol Protocol version number + * @return Minecraft Version number */ - public static int getVersionProtocol(Gson gson, String version) { + public static String getVersionFromProtocol(Gson gson, int protocol) { JsonObject protocols = JsonUtil.readJsonResource(gson, "/protocol.json"); - return protocols == null ? 0 : Integer.parseInt(protocols.get(version).getAsString()); - } + if (protocols == null) return null; - public static int getLatestProtocol(Gson gson) { - return getVersionProtocol(gson, "1.21.3"); + for (Map.Entry entry : protocols.entrySet()) { + JsonObject versionObj = entry.getValue().getAsJsonObject(); + if (Integer.parseInt(versionObj.get("protocol_version").getAsString()) == protocol) { + return entry.getKey(); + } + } + return null; } /** - * Gets Minecraft Version from Protocol number - * + * Gets version object containing protocol_version and pack_format by protocol version + * * @param gson Gson object to use * @param protocol Protocol version number - * @return Minecraft Version number + * @return JsonObject containing version information */ - public static String getVersionFromProtocol(Gson gson, int protocol) { - AtomicReference version = new AtomicReference("ok boomer"); + public static JsonObject getVersionObjectByProtocol(Gson gson, int protocol) { JsonObject protocols = JsonUtil.readJsonResource(gson, "/protocol.json"); - if (protocols == null) - return null; - Collection keys = protocols.entrySet().stream().map(Map.Entry::getKey) - .collect(Collectors.toCollection(ArrayList::new)); - keys.forEach(key -> { - if (Integer.parseInt(protocols.get(key).getAsString()) == protocol) - version.set(key); - }); - return version.toString(); + if (protocols == null) return null; + + for (Map.Entry entry : protocols.entrySet()) { + JsonObject versionObj = entry.getValue().getAsJsonObject(); + if (Integer.parseInt(versionObj.get("protocol_version").getAsString()) == protocol) { + return versionObj; + } + } + return null; + } + + /** + * Gets version object containing protocol_version and pack_format + * + * @param gson Gson object to use + * @param version Minecraft Version Number. + * @return JsonObject containing version information + */ + public static JsonObject getVersionObject(Gson gson, String version) { + JsonObject protocols = JsonUtil.readJsonResource(gson, "/protocol.json"); + return protocols == null ? null : protocols.getAsJsonObject(version); + } + + /** + * Gets version protocol number + * + * @param gson Gson object to use + * @param version Minecraft Version Number. + * @return Protocol Integer Number + */ + public static int getVersionProtocol(Gson gson, String version) { + JsonObject versionObj = getVersionObject(gson, version); + return versionObj == null ? 0 : Integer.parseInt(versionObj.get("protocol_version").getAsString()); + } + + public static int getLatestProtocol(Gson gson) { + return getVersionProtocol(gson, "1.21.3"); } /** * Gets Supported versions of Resource Pack Converter - * + * * @param gson Gson object to use * @return String list of all minecraft versions */ diff --git a/library/src/main/resources/protocol.json b/library/src/main/resources/protocol.json index 17c98e5b..9eeb96da 100644 --- a/library/src/main/resources/protocol.json +++ b/library/src/main/resources/protocol.json @@ -1,86 +1,338 @@ { - "1.7.2": "4", - "1.7.3": "4", - "1.7.4": "4", - "1.7.5": "4", - "1.7.6": "5", - "1.7.7": "5", - "1.7.8": "5", - "1.7.9": "5", - "1.7.10": "5", - "1.8": "47", - "1.8.0": "47", - "1.8.1": "47", - "1.8.2": "47", - "1.8.3": "47", - "1.8.4": "47", - "1.8.5": "47", - "1.8.6": "47", - "1.8.7": "47", - "1.8.8": "47", - "1.8.9": "47", - "1.9": "107", - "1.9.0": "107", - "1.9.1": "108", - "1.9.2": "109", - "1.9.3": "110", - "1.9.4": "110", - "1.10": "210", - "1.10.0": "210", - "1.10.1": "210", - "1.10.2": "210", - "1.11": "315", - "1.11.0": "315", - "1.11.1": "316", - "1.11.2": "316", - "1.12": "335", - "1.12.0": "335", - "1.12.1": "338", - "1.12.2": "340", - "1.13": "393", - "1.13.0": "393", - "1.13.1": "401", - "1.13.2": "404", - "1.14": "477", - "1.14.0": "477", - "1.14.1": "480", - "1.14.2": "485", - "1.14.3": "490", - "1.14.4": "498", - "1.15": "573", - "1.15.0": "573", - "1.15.1": "575", - "1.15.2": "578", - "1.16": "735", - "1.16.0": "735", - "1.16.1": "736", - "1.16.2": "751", - "1.16.3": "753", - "1.16.4": "754", - "1.16.5": "754", - "1.17": "755", - "1.17.0": "755", - "1.17.1": "756", - "1.18": "757", - "1.18.0": "757", - "1.18.1": "758", - "1.18.2": "758", - "1.19": "759", - "1.19.0": "759", - "1.19.1": "760", - "1.19.2": "760", - "1.19.3": "761", - "1.19.4": "762", - "1.20": "763", - "1.20.0": "763", - "1.20.1": "763", - "1.20.2": "764", - "1.20.3": "765", - "1.20.4": "765", - "1.20.5": "766", - "1.20.6": "766", - "1.21": "767", - "1.21.1": "767", - "1.21.2": "768", - "1.21.3": "768" + "1.7.2": { + "protocol_version": "4", + "pack_format": "1" + }, + "1.7.3": { + "protocol_version": "4", + "pack_format": "1" + }, + "1.7.4": { + "protocol_version": "4", + "pack_format": "1" + }, + "1.7.5": { + "protocol_version": "4", + "pack_format": "1" + }, + "1.7.6": { + "protocol_version": "5", + "pack_format": "1" + }, + "1.7.7": { + "protocol_version": "5", + "pack_format": "1" + }, + "1.7.8": { + "protocol_version": "5", + "pack_format": "1" + }, + "1.7.9": { + "protocol_version": "5", + "pack_format": "1" + }, + "1.7.10": { + "protocol_version": "5", + "pack_format": "1" + }, + "1.8": { + "protocol_version": "47", + "pack_format": "1" + }, + "1.8.0": { + "protocol_version": "47", + "pack_format": "1" + }, + "1.8.1": { + "protocol_version": "47", + "pack_format": "1" + }, + "1.8.2": { + "protocol_version": "47", + "pack_format": "1" + }, + "1.8.3": { + "protocol_version": "47", + "pack_format": "1" + }, + "1.8.4": { + "protocol_version": "47", + "pack_format": "1" + }, + "1.8.5": { + "protocol_version": "47", + "pack_format": "1" + }, + "1.8.6": { + "protocol_version": "47", + "pack_format": "1" + }, + "1.8.7": { + "protocol_version": "47", + "pack_format": "1" + }, + "1.8.8": { + "protocol_version": "47", + "pack_format": "1" + }, + "1.8.9": { + "protocol_version": "47", + "pack_format": "1" + }, + "1.9": { + "protocol_version": "107", + "pack_format": "2" + }, + "1.9.0": { + "protocol_version": "107", + "pack_format": "2" + }, + "1.9.1": { + "protocol_version": "108", + "pack_format": "2" + }, + "1.9.2": { + "protocol_version": "109", + "pack_format": "2" + }, + "1.9.3": { + "protocol_version": "110", + "pack_format": "2" + }, + "1.9.4": { + "protocol_version": "110", + "pack_format": "2" + }, + "1.10": { + "protocol_version": "210", + "pack_format": "2" + }, + "1.10.0": { + "protocol_version": "210", + "pack_format": "2" + }, + "1.10.1": { + "protocol_version": "210", + "pack_format": "2" + }, + "1.10.2": { + "protocol_version": "210", + "pack_format": "2" + }, + "1.11": { + "protocol_version": "315", + "pack_format": "3" + }, + "1.11.0": { + "protocol_version": "315", + "pack_format": "3" + }, + "1.11.1": { + "protocol_version": "316", + "pack_format": "3" + }, + "1.11.2": { + "protocol_version": "316", + "pack_format": "3" + }, + "1.12": { + "protocol_version": "335", + "pack_format": "3" + }, + "1.12.0": { + "protocol_version": "335", + "pack_format": "3" + }, + "1.12.1": { + "protocol_version": "338", + "pack_format": "3" + }, + "1.12.2": { + "protocol_version": "340", + "pack_format": "3" + }, + "1.13": { + "protocol_version": "393", + "pack_format": "4" + }, + "1.13.0": { + "protocol_version": "393", + "pack_format": "4" + }, + "1.13.1": { + "protocol_version": "401", + "pack_format": "4" + }, + "1.13.2": { + "protocol_version": "404", + "pack_format": "4" + }, + "1.14": { + "protocol_version": "477", + "pack_format": "4" + }, + "1.14.0": { + "protocol_version": "477", + "pack_format": "4" + }, + "1.14.1": { + "protocol_version": "480", + "pack_format": "4" + }, + "1.14.2": { + "protocol_version": "485", + "pack_format": "4" + }, + "1.14.3": { + "protocol_version": "490", + "pack_format": "4" + }, + "1.14.4": { + "protocol_version": "498", + "pack_format": "4" + }, + "1.15": { + "protocol_version": "573", + "pack_format": "5" + }, + "1.15.0": { + "protocol_version": "573", + "pack_format": "5" + }, + "1.15.1": { + "protocol_version": "575", + "pack_format": "5" + }, + "1.15.2": { + "protocol_version": "578", + "pack_format": "5" + }, + "1.16": { + "protocol_version": "735", + "pack_format": "5" + }, + "1.16.0": { + "protocol_version": "735", + "pack_format": "5" + }, + "1.16.1": { + "protocol_version": "736", + "pack_format": "5" + }, + "1.16.2": { + "protocol_version": "751", + "pack_format": "6" + }, + "1.16.3": { + "protocol_version": "753", + "pack_format": "6" + }, + "1.16.4": { + "protocol_version": "754", + "pack_format": "6" + }, + "1.16.5": { + "protocol_version": "754", + "pack_format": "6" + }, + "1.17": { + "protocol_version": "755", + "pack_format": "7" + }, + "1.17.0": { + "protocol_version": "755", + "pack_format": "7" + }, + "1.17.1": { + "protocol_version": "756", + "pack_format": "7" + }, + "1.18": { + "protocol_version": "757", + "pack_format": "8" + }, + "1.18.0": { + "protocol_version": "757", + "pack_format": "8" + }, + "1.18.1": { + "protocol_version": "758", + "pack_format": "8" + }, + "1.18.2": { + "protocol_version": "758", + "pack_format": "8" + }, + "1.19": { + "protocol_version": "759", + "pack_format": "9" + }, + "1.19.0": { + "protocol_version": "759", + "pack_format": "9" + }, + "1.19.1": { + "protocol_version": "760", + "pack_format": "9" + }, + "1.19.2": { + "protocol_version": "760", + "pack_format": "9" + }, + "1.19.3": { + "protocol_version": "761", + "pack_format": "12" + }, + "1.19.4": { + "protocol_version": "762", + "pack_format": "13" + }, + "1.20": { + "protocol_version": "763", + "pack_format": "15" + }, + "1.20.0": { + "protocol_version": "763", + "pack_format": "15" + }, + "1.20.1": { + "protocol_version": "763", + "pack_format": "15" + }, + "1.20.2": { + "protocol_version": "764", + "pack_format": "18" + }, + "1.20.3": { + "protocol_version": "765", + "pack_format": "22" + }, + "1.20.4": { + "protocol_version": "765", + "pack_format": "22" + }, + "1.20.5": { + "protocol_version": "766", + "pack_format": "32" + }, + "1.20.6": { + "protocol_version": "766", + "pack_format": "32" + }, + "1.21": { + "protocol_version": "767", + "pack_format": "34" + }, + "1.21.1": { + "protocol_version": "767", + "pack_format": "34" + }, + "1.21.2": { + "protocol_version": "768", + "pack_format": "42" + }, + "1.21.3": { + "protocol_version": "768", + "pack_format": "42" + } } \ No newline at end of file From 43aab2ec00f5d21f3b43c2cf345aa60c69ae0985 Mon Sep 17 00:00:00 2001 From: SBDeveloper Date: Sun, 1 Dec 2024 20:10:46 +0100 Subject: [PATCH 17/54] Removed hardcoded version from getLatestProtocol --- .../resourcepack/library/utilities/Util.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Util.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Util.java index d289bc91..c5e4b70e 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Util.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Util.java @@ -100,7 +100,18 @@ public static int getVersionProtocol(Gson gson, String version) { } public static int getLatestProtocol(Gson gson) { - return getVersionProtocol(gson, "1.21.3"); + JsonObject protocols = JsonUtil.readJsonResource(gson, "/protocol.json"); + if (protocols == null) return 0; + + int latestProtocol = 0; + for (Map.Entry entry : protocols.entrySet()) { + JsonObject versionObj = entry.getValue().getAsJsonObject(); + int protocol = Integer.parseInt(versionObj.get("protocol_version").getAsString()); + if (protocol > latestProtocol) { + latestProtocol = protocol; + } + } + return latestProtocol; } /** From 50677aa125242e3140f7c5d01aed213ce4eb5bdf Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Thu, 19 Dec 2024 21:53:28 -0500 Subject: [PATCH 18/54] Should fix #235 and some other issues I had + Cleanup --- .../forwards/impl/NameConverter.java | 209 +++++++++++------- .../impl/textures/slicing/Slicer.java | 44 ++-- .../library/utilities/FileUtil.java | 72 +++--- 3 files changed, 198 insertions(+), 127 deletions(-) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java index 5cbd76f3..835bde71 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java @@ -16,10 +16,11 @@ import java.nio.file.Paths; import java.util.Arrays; import java.util.List; +import java.util.Objects; public class NameConverter extends Converter { - private int to; - private int from; + private final int to; + private final int from; private final Mapping blockMapping; private final Mapping newBlockMapping; @@ -55,7 +56,7 @@ public NameConverter(PackConverter packConverter, int from, int to) { /** * Fixes folder names and file names - * + * * @param pack Resource Pack * @throws IOException Error handler */ @@ -76,12 +77,14 @@ public void convert(Pack pack) throws IOException { Logger.debug("MCPatcher exists, switching to optifine"); if (minecraftPath.resolve("optifine").toFile().exists()) { Logger.debug("OptiFine exists, merging directories"); - FileUtil.mergeDirectories(minecraftPath.resolve("optifine").toFile(), - minecraftPath.resolve("mcpatcher").toFile()); - } else + FileUtil.mergeDirectories(minecraftPath.resolve("optifine").toFile(), minecraftPath.resolve("mcpatcher").toFile()); + } else { Files.move(minecraftPath.resolve("mcpatcher"), minecraftPath.resolve("optifine")); - if (minecraftPath.resolve("mcpatcher").toFile().exists()) + } + + if (minecraftPath.resolve("mcpatcher").toFile().exists()) { FileUtil.deleteDirectoryAndContents(minecraftPath.resolve("mcpatcher")); + } } // 1.13 Models @@ -89,16 +92,20 @@ public void convert(Pack pack) throws IOException { if (modelsPath.toFile().exists()) { // 1.13 block/item name change if (modelsPath.resolve("blocks").toFile().exists()) { - if (modelsPath.resolve("block").toFile().exists()) + if (modelsPath.resolve("block").toFile().exists()) { FileUtil.deleteDirectoryAndContents(modelsPath.resolve("block")); + } + Files.move(modelsPath.resolve("blocks"), modelsPath.resolve("block")); } // Update all blocks for 1.13 renameAll(blockMapping, ".json", modelsPath.resolve("block")); if (modelsPath.resolve("items").toFile().exists()) { - if (modelsPath.resolve("item").toFile().exists()) + if (modelsPath.resolve("item").toFile().exists()) { FileUtil.deleteDirectoryAndContents(modelsPath.resolve("item")); + } + Files.move(modelsPath.resolve("items"), modelsPath.resolve("item")); } @@ -110,25 +117,29 @@ public void convert(Pack pack) throws IOException { Path itemModelPath = modelsPath.resolve("iem"); renameAll(newItemMapping, ".json", itemModelPath); if (!itemModelPath.resolve("ink_sac.json").toFile().exists() - && itemModelPath.resolve("black_dye.json").toFile().exists()) - Files.copy(itemModelPath.resolve("black_dye.json"), - itemModelPath.resolve("ink_sac.json")); + && itemModelPath.resolve("black_dye.json").toFile().exists()) { + Files.copy(itemModelPath.resolve("black_dye.json"), itemModelPath.resolve("ink_sac.json")); + } + if (!itemModelPath.resolve("cocoa_beans.json").toFile().exists() - && itemModelPath.resolve("brown_dye.json").toFile().exists()) - Files.copy(itemModelPath.resolve("brown_dye.json"), - itemModelPath.resolve("cocoa_beans.json")); + && itemModelPath.resolve("brown_dye.json").toFile().exists()) { + Files.copy(itemModelPath.resolve("brown_dye.json"), itemModelPath.resolve("cocoa_beans.json")); + } + if (!itemModelPath.resolve("bone_meal.json").toFile().exists() - && itemModelPath.resolve("white_dye.json").toFile().exists()) - Files.copy(itemModelPath.resolve("white_dye.json"), - itemModelPath.resolve("bone_meal.json")); + && itemModelPath.resolve("white_dye.json").toFile().exists()) { + Files.copy(itemModelPath.resolve("white_dye.json"), itemModelPath.resolve("bone_meal.json")); + } + if (!itemModelPath.resolve("lapis_lazuli.json").toFile().exists() - && itemModelPath.resolve("blue_dye.json").toFile().exists()) - Files.copy(itemModelPath.resolve("blue_dye.json"), - itemModelPath.resolve("lapis_lazuli.json")); + && itemModelPath.resolve("blue_dye.json").toFile().exists()) { + Files.copy(itemModelPath.resolve("blue_dye.json"), itemModelPath.resolve("lapis_lazuli.json")); + } } - if (to > Util.getVersionProtocol(packConverter.getGson(), "1.19")) + if (to > Util.getVersionProtocol(packConverter.getGson(), "1.19")) { renameAll(blockMapping19, ".json", modelsPath.resolve("block")); + } if (to > Util.getVersionProtocol(packConverter.getGson(), "1.20.3")) { renameAll(itemMapping203, ".json", modelsPath.resolve("item")); @@ -137,10 +148,10 @@ public void convert(Pack pack) throws IOException { } // Update BlockStates - Path blockStates = pack.getWorkingPath() - .resolve("assets/minecraft/blockstates".replace("/", File.separator)); - if (blockStates.toFile().exists()) + Path blockStates = pack.getWorkingPath().resolve("assets/minecraft/blockstates".replace("/", File.separator)); + if (blockStates.toFile().exists()) { renameAll(blockMapping, ".json", blockStates); + } // Update textures Path texturesPath = pack.getWorkingPath().resolve("assets/minecraft/textures".replace("/", File.separator)); @@ -170,21 +181,24 @@ public void convert(Pack pack) throws IOException { renameAll(newItemMapping, ".png.mcmeta", itemPath); Path itemModelPath = modelsPath.resolve("item"); if (!itemModelPath.resolve("ink_sac.png").toFile().exists() - && itemModelPath.resolve("black_dye.png").toFile().exists()) - Files.copy(itemModelPath.resolve("black_dye.png"), - itemModelPath.resolve("ink_sac.png")); + && itemModelPath.resolve("black_dye.png").toFile().exists()) { + Files.copy(itemModelPath.resolve("black_dye.png"), itemModelPath.resolve("ink_sac.png")); + } + if (!itemModelPath.resolve("cocoa_beans.png").toFile().exists() - && itemModelPath.resolve("brown_dye.png").toFile().exists()) - Files.copy(itemModelPath.resolve("brown_dye.png"), - itemModelPath.resolve("cocoa_beans.png")); + && itemModelPath.resolve("brown_dye.png").toFile().exists()) { + Files.copy(itemModelPath.resolve("brown_dye.png"), itemModelPath.resolve("cocoa_beans.png")); + } + if (!itemModelPath.resolve("bone_meal.png").toFile().exists() - && itemModelPath.resolve("white_dye.png").toFile().exists()) - Files.copy(itemModelPath.resolve("white_dye.png"), - itemModelPath.resolve("bone_meal.png")); + && itemModelPath.resolve("white_dye.png").toFile().exists()) { + Files.copy(itemModelPath.resolve("white_dye.png"), itemModelPath.resolve("bone_meal.png")); + } + if (!itemModelPath.resolve("lapis_lazuli.png").toFile().exists() - && itemModelPath.resolve("blue_dye.png").toFile().exists()) - Files.copy(itemModelPath.resolve("blue_dye.png"), - itemModelPath.resolve("lapis_lazuli.png")); + && itemModelPath.resolve("blue_dye.png").toFile().exists()) { + Files.copy(itemModelPath.resolve("blue_dye.png"), itemModelPath.resolve("lapis_lazuli.png")); + } } // Entities @@ -193,11 +207,18 @@ public void convert(Pack pack) throws IOException { // 1.16 Iron golems if (from < Util.getVersionProtocol(packConverter.getGson(), "1.15") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.15")) { - if (!entityPath.resolve("iron_golem").toFile().exists()) + if (!entityPath.resolve("iron_golem").toFile().exists()) { entityPath.resolve("iron_golem").toFile().mkdir(); - if (entityPath.resolve("iron_golem.png").toFile().exists()) - Files.move(entityPath.resolve("iron_golem.png"), entityPath - .resolve("iron_golem/iron_golem.png")); + } + + if (entityPath.resolve("iron_golem.png").toFile().exists()) { + Path newIronGolemPath = entityPath.resolve("iron_golem/iron_golem.png"); + if (newIronGolemPath.toFile().exists()) { + newIronGolemPath.toFile().delete(); + } + + Files.move(entityPath.resolve("iron_golem.png"), newIronGolemPath); + } } // 1.17 Squid @@ -207,21 +228,38 @@ public void convert(Pack pack) throws IOException { renameAll(itemMapping17, ".png", texturesPath.resolve("item")); renameAll(blockMapping17, ".png", modelsPath.resolve("block")); renameAll(itemMapping17, ".png", modelsPath.resolve("item")); - if (!entityPath.resolve("squid").toFile().exists()) - entityPath.resolve("squid").toFile().mkdir(); - if (!entityPath.resolve("squid.png").toFile().exists()) - Files.move(entityPath.resolve("squid.png"), - entityPath.resolve("squid/squid.png")); + + Path squidFolderPath = entityPath.resolve("squid"); + if (!squidFolderPath.toFile().exists()) { + squidFolderPath.toFile().mkdir(); + } + + if (entityPath.resolve("squid.png").toFile().exists()) { + Path newSquidPath = squidFolderPath.resolve("squid.png"); + if (newSquidPath.toFile().exists()) { + newSquidPath.toFile().delete(); + } + + Files.move(entityPath.resolve("squid.png"), newSquidPath); + } } if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.19") - && from < Util.getVersionProtocol(packConverter.getGson(), "1.19")) + && from < Util.getVersionProtocol(packConverter.getGson(), "1.19")) { renameAll(blockMapping19, ".png", blockPath); + } // 1.13 End Crystals if (entityPath.resolve("endercrystal").toFile().exists() - && !entityPath.resolve("end_crystal").toFile().exists()) - Files.move(entityPath.resolve("endercrystal"), entityPath.resolve("end_crystal")); + && !entityPath.resolve("end_crystal").toFile().exists()) { + Path newEnderCrystalPath = entityPath.resolve("end_crystal"); + if (newEnderCrystalPath.toFile().exists()) { + newEnderCrystalPath.toFile().delete(); + } + + Files.move(entityPath.resolve("endercrystal"), newEnderCrystalPath); + } + findEntityFiles(entityPath); } } @@ -229,33 +267,33 @@ public void convert(Pack pack) throws IOException { /** * Finds files in entity folder - * + * * @param path * @throws IOException */ protected void findEntityFiles(Path path) throws IOException { - if (!path.toFile().exists()) - return; - File directory = path.toFile(); - for (File file : directory.listFiles()) { - if (!file.isDirectory()) - continue; - renameAll(entityMapping, ".png", file.toPath()); - renameAll(entityMapping, ".png.mcmeta", file.toPath()); - findEntityFiles(file.toPath()); + if (path.toFile().exists()) { + File directory = path.toFile(); + for (File file : Objects.requireNonNull(directory.listFiles())) { + if (file.isDirectory()) { + renameAll(entityMapping, ".png", file.toPath()); + renameAll(entityMapping, ".png.mcmeta", file.toPath()); + findEntityFiles(file.toPath()); + } + } } } /** * Finds files in folders called - * + * * @param path * @throws IOException */ - protected void findFiles(Path path) throws IOException { + protected void findFiles(Path path) { if (path.toFile().exists()) { File directory = path.toFile(); - for (File file : directory.listFiles()) { + for (File file : Objects.requireNonNull(directory.listFiles())) { if (file.isDirectory()) { if (file.getName().equals("items")) { Logger.debug("Found Items folder, renaming"); @@ -270,11 +308,13 @@ protected void findFiles(Path path) throws IOException { findFiles(file.toPath()); } - if (file.getName().contains("(")) + if (file.getName().contains("(")) { FileUtil.renameFile(path.resolve(file.getName()), file.getName().replaceAll("[()]", "")); + } - if (!file.getName().equals(file.getName().toLowerCase())) + if (!file.getName().equals(file.getName().toLowerCase())) { Logger.debug("Renamed: " + file.getName() + "->" + file.getName().toLowerCase()); + } FileUtil.renameFile(path.resolve(file.getName()), file.getName().toLowerCase()); } @@ -283,7 +323,7 @@ protected void findFiles(Path path) throws IOException { /** * Renames folder - * + * * @param mapping * @param extension * @param path @@ -296,7 +336,7 @@ protected void renameAll(Mapping mapping, String extension, Path path) throws IO List grasses = Arrays.asList("grass", "tall_grass", "double_grass"); if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.12.2")) { if ((path.endsWith("blockstates") || path.endsWith("textures/block"))) { - grasses.stream().forEach(name -> { + grasses.forEach(name -> { String newName = mapping.remap(name); Boolean ret = FileUtil.renameFile(Paths.get(path + File.separator + name + extension), newName + extension); @@ -314,35 +354,44 @@ protected void renameAll(Mapping mapping, String extension, Path path) throws IO // remap snow jsons, but not images. if (from < Util.getVersionProtocol(packConverter.getGson(), "1.13") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.13")) { - if (path.resolve("snow_layer.json").toFile().exists()) + if (path.resolve("snow_layer.json").toFile().exists()) { FileUtil.renameFile(path.resolve("snow_layer" + extension), "snow" + extension); + } } + Logger.addTab(); Files.list(path).forEach(path1 -> { if (!path1.toString().endsWith(extension)) return; - String baseName = path1.getFileName().toString().substring(0, - path1.getFileName().toString().length() - extension.length()); + String baseName = path1.getFileName().toString().substring(0, path1.getFileName().toString().length() - extension.length()); // skip the already renamed grass blocks - if (grasses.contains(baseName) - && (path.endsWith("blockstates") || path.endsWith("textures/block"))) + if (grasses.contains(baseName) && (path.endsWith("blockstates") || path.endsWith("textures/block"))) { return; + } + + String remappedName = mapping.remap(baseName); + if (remappedName != null && !remappedName.equals(baseName)) { + Path newPath = path1.getParent().resolve(remappedName + extension); + if (newPath.toFile().exists()) { + // Same note from Slicer.java line 38 + newPath.toFile().delete(); + } - String newName = mapping.remap(baseName); - if (newName != null && !newName.equals(baseName)) { - Boolean ret = FileUtil.renameFile(path1, newName + extension); - if (ret == null) + Boolean renameSuccess = FileUtil.renameFile(path1, newPath); + if (renameSuccess == null) { return; - if (ret) { - Logger.debug("Renamed: " + path1.getFileName().toString() + "->" + newName + extension); - } else if (!ret) { - Logger.log("Failed to rename: " + path1.getFileName().toString() + "->" + newName - + extension); + } + + if (renameSuccess) { + Logger.debug("Renamed: " + path1.getFileName().toString() + "->" + newPath.getFileName()); + } else if (!renameSuccess) { + Logger.log("Failed to rename: " + path1.getFileName().toString() + "->" + newPath.getFileName()); } } }); + Logger.subTab(); } } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicing/Slicer.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicing/Slicer.java index c3a1b11e..79bba225 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicing/Slicer.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicing/Slicer.java @@ -1,9 +1,5 @@ package com.agentdid127.resourcepack.forwards.impl.textures.slicing; -import java.io.IOException; -import java.lang.reflect.Method; -import java.nio.file.Path; - import com.agentdid127.resourcepack.forwards.impl.textures.SlicerConverter; import com.agentdid127.resourcepack.library.utilities.FileUtil; import com.agentdid127.resourcepack.library.utilities.ImageConverter; @@ -12,12 +8,16 @@ import com.google.gson.Gson; import com.google.gson.JsonObject; +import java.io.IOException; +import java.lang.reflect.Method; +import java.nio.file.Path; + public class Slicer { - public static void runSlicer(Gson gson, Slice slice, Path root, Class predicateClass, int from, - boolean texture_has_metadata) + public static void runSlicer(Gson gson, Slice slice, Path root, Class predicateClass, int from, boolean has_metadata) throws IOException { - if (!SlicerConverter.PredicateRunnable.run(gson, from, slice.getPredicate())) + if (!SlicerConverter.PredicateRunnable.run(gson, from, slice.getPredicate())) { return; + } Path path = root.resolve(slice.getPath()); if (!path.toFile().exists()) { @@ -28,11 +28,19 @@ public static void runSlicer(Gson gson, Slice slice, Path root, Class pre ImageConverter converter = new ImageConverter(slice.getWidth(), slice.getHeight(), path); Path imagePath = path; - if (slice.getPathName() != null) + if (slice.getPathName() != null) { imagePath = path.resolveSibling(slice.getPathName()); + } for (Texture texture : slice.getTextures()) { Path texturePath = root.resolve(texture.getPath()); + if (texturePath.toFile().exists()) { + // Sometimes packs include both newer and older textures but + // since we are upgrading to a newer version, we want what was shown in the original + // version so we delete the existing new one, so we can replace it with the + // version used in said version. + texturePath.toFile().delete(); + } FileUtil.ensureParentExists(texturePath); if (predicateClass != null) { @@ -48,7 +56,6 @@ public static void runSlicer(Gson gson, Slice slice, Path root, Class pre try { Box box = texture.getBox(); - converter.saveSlice( box.getX(), box.getY(), @@ -56,19 +63,20 @@ public static void runSlicer(Gson gson, Slice slice, Path root, Class pre box.getHeight(), texturePath); - if (texture.shouldRemove()) + if (texture.shouldRemove()) { converter.fillEmpty( box.getX(), box.getY(), box.getWidth(), box.getHeight()); + } - if (texture_has_metadata) { + if (has_metadata) { JsonObject metadata = texture.getMetadata(); - if (metadata.keySet().isEmpty() || metadata.entrySet().isEmpty()) - continue; - Path metadataPath = texturePath.resolveSibling(texturePath.getFileName() + ".mcmeta"); - JsonUtil.writeJson(gson, metadataPath, metadata); + if (!metadata.keySet().isEmpty() && !metadata.entrySet().isEmpty()) { + Path metadataPath = texturePath.resolveSibling(texturePath.getFileName() + ".mcmeta"); + JsonUtil.writeJson(gson, metadataPath, metadata); + } } } catch (Exception exception) { Logger.log("Failed to slice texture '" + texture.getPath() + "' (error='" @@ -78,10 +86,12 @@ public static void runSlicer(Gson gson, Slice slice, Path root, Class pre } } - if (!path.toFile().delete()) + if (!path.toFile().delete()) { Logger.debug("Failed to remove '" + path.getFileName() + "' whilst slicing."); + } - if (!slice.shouldDelete()) + if (!slice.shouldDelete()) { converter.store(imagePath); + } } } diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/FileUtil.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/FileUtil.java index 6a431f46..ff27e2b6 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/FileUtil.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/FileUtil.java @@ -5,31 +5,26 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Comparator; +import java.util.Objects; public final class FileUtil { public static void moveIfExists(Path in, Path out) throws IOException { - if (!in.toFile().exists()) - return; - ensureParentExists(out); - Files.move(in, out); - } - - public static void copyIfExists(Path in, Path out) throws IOException { - if (!in.toFile().exists()) - return; - ensureParentExists(out); - Files.copy(in, out); + if (in.toFile().exists()) { + ensureParentExists(out); + Files.move(in, out); + } } public static void ensureParentExists(Path path) { Path parentPath = path.getParent(); - if (!parentPath.toFile().exists()) + if (!parentPath.toFile().exists()) { parentPath.toFile().mkdirs(); + } } /** * Copies Directory - * + * * @param src directory Source * @param dest Directory Destination * @throws IOException @@ -48,23 +43,22 @@ public static void copyDirectory(Path src, Path dest) throws IOException { /** * Deletes full directory - * + * * @param dirPath Path of Directory to delete * @throws IOException */ public static void deleteDirectoryAndContents(Path dirPath) throws IOException { - if (!dirPath.toFile().exists()) - return; - - // noinspection ResultOfMethodCallIgnored - Files.walk(dirPath).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(file -> { - file.delete(); - }); + if (dirPath.toFile().exists()) { + // noinspection ResultOfMethodCallIgnored + Files.walk(dirPath).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(file -> { + file.delete(); + }); + } } /** * If file exists, return file with correct casing. - * + * * @param path * @return * @throws IOException @@ -73,13 +67,30 @@ public static boolean fileExistsCorrectCasing(Path path) throws IOException { return path.toFile().exists() && path.toString().equals(path.toFile().getCanonicalPath()); } + /** + * @return null if file doesn't exist, {@code true} if successfully renamed, + * {@code false} if failed + */ + public static Boolean renameFile(Path file, Path newFile) { + if (!file.toFile().exists()) { + return null; + } + try { + Files.move(file, newFile); + return true; + } catch (IOException e) { + return false; + } + } + /** * @return null if file doesn't exist, {@code true} if successfully renamed, * {@code false} if failed */ public static Boolean renameFile(Path file, String newName) { - if (!file.toFile().exists()) + if (!file.toFile().exists()) { return null; + } try { Files.move(file, file.getParent().resolve(newName)); return true; @@ -90,16 +101,18 @@ public static Boolean renameFile(Path file, String newName) { /** * Takes dir2 and merges it into dir1 - * + * * @param dir1 * @param dir2 */ - public static Boolean mergeDirectories(File dir1, File dir2) throws IOException { - if (!dir1.exists() && !dir2.exists()) - return null; + public static void mergeDirectories(File dir1, File dir2) throws IOException { + if (!dir1.exists() && !dir2.exists()) { + return; + } String targetDirPath = dir1.getAbsolutePath(); File[] files = dir2.listFiles(); + assert files != null; for (File file : files) { if (file.isDirectory()) { Logger.debug(targetDirPath + File.separator + file.getName()); @@ -113,9 +126,8 @@ public static Boolean mergeDirectories(File dir1, File dir2) throws IOException } } - if (dir2.list().length == 0) + if (Objects.requireNonNull(dir2.list()).length == 0) { Files.delete(dir2.toPath()); - - return true; + } } } \ No newline at end of file From 7d3f07fd1eb5ba1cb8291143abc63cf1851758aa Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Sun, 22 Dec 2024 14:40:05 -0500 Subject: [PATCH 19/54] Fix a few backwards-converter bugs in NameConverter & EnchantPathConverter --- .../backwards/impl/EnchantPathConverter.java | 41 ++- .../backwards/impl/NameConverter.java | 290 +++++++++++------- .../forwards/impl/NameConverter.java | 57 ++-- 3 files changed, 231 insertions(+), 157 deletions(-) diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/EnchantPathConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/EnchantPathConverter.java index 43f2ee9f..25333c85 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/EnchantPathConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/EnchantPathConverter.java @@ -17,18 +17,39 @@ public EnchantPathConverter(PackConverter packConverter) { @Override public void convert(Pack pack) throws IOException { Path miscPath = pack.getWorkingPath().resolve("assets/minecraft/textures/misc".replace("/", File.separator)); + if (miscPath.toFile().exists()) { + return; + } - if (miscPath.resolve("enchanted_glint_item.png").toFile().exists()) - Files.move(miscPath.resolve("enchanted_glint_item.png"), miscPath.resolve("enchanted_item_glint.png")); - else if (miscPath.resolve("enchanted_glint_entity.png").toFile().exists()) - Files.move(miscPath.resolve("enchanted_glint_entity.png"), miscPath.resolve("enchanted_item_glint.png")); + Path enchantGlintItemPath = miscPath.resolve("enchanted_glint_item.png"); + Path enchantGlintEntityPath = miscPath.resolve("enchanted_glint_entity.png"); + Path newEnchantGlintItemPath = miscPath.resolve("enchanted_item_glint.png"); + if (enchantGlintItemPath.toFile().exists()) { + if (newEnchantGlintItemPath.toFile().exists()) { + newEnchantGlintItemPath.toFile().delete(); + } + Files.move(enchantGlintItemPath, newEnchantGlintItemPath); + } else if (enchantGlintEntityPath.toFile().exists()) { + if (newEnchantGlintItemPath.toFile().exists()) { + newEnchantGlintItemPath.toFile().delete(); + } + Files.move(enchantGlintEntityPath, newEnchantGlintItemPath); + } - if (miscPath.resolve("enchanted_glint_item.png.mcmeta").toFile().exists()) - Files.move(miscPath.resolve("enchanted_glint_item.png.mcmeta"), - miscPath.resolve("enchanted_item_glint.png.mcmeta")); - else if (miscPath.resolve("enchanted_glint_entity.png.mcmeta").toFile().exists()) - Files.move(miscPath.resolve("enchanted_glint_entity.png.mcmeta"), - miscPath.resolve("enchanted_item_glint.png.mcmeta")); + Path enchantGlintItemMetaPath = miscPath.resolve("enchanted_glint_item.png.mcmeta"); + Path enchantGlintEntityMetaPath = miscPath.resolve("enchanted_glint_entity.png.mcmeta"); + Path newEnchantGlintItemMetaPath = miscPath.resolve("enchanted_item_glint.png.mcmeta"); + if (enchantGlintItemMetaPath.toFile().exists()) { + if (newEnchantGlintItemMetaPath.toFile().exists()) { + newEnchantGlintItemMetaPath.toFile().delete(); + } + Files.move(enchantGlintItemMetaPath, newEnchantGlintItemMetaPath); + } else if (enchantGlintEntityMetaPath.toFile().exists()) { + if (newEnchantGlintItemMetaPath.toFile().exists()) { + newEnchantGlintItemMetaPath.toFile().delete(); + } + Files.move(enchantGlintEntityMetaPath, newEnchantGlintItemMetaPath); + } Files.deleteIfExists(miscPath.resolve("enchanted_glint_entity.png.mcmeta")); Files.deleteIfExists(miscPath.resolve("enchanted_glint_item.png.mcmeta")); diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/NameConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/NameConverter.java index 553c808e..e8eecd14 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/NameConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/NameConverter.java @@ -13,9 +13,10 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Arrays; import java.util.List; +import java.util.Objects; +import java.util.stream.Stream; public class NameConverter extends Converter { private int to; @@ -71,48 +72,52 @@ public void convert(Pack pack) throws IOException { Logger.debug("MCPatcher exists, switching to optifine"); if (minecraftPath.resolve("optifine").toFile().exists()) { Logger.debug("OptiFine exists, merging directories"); - FileUtil.mergeDirectories(minecraftPath.resolve("optifine").toFile(), - minecraftPath.resolve("mcpatcher").toFile()); - } else + FileUtil.mergeDirectories(minecraftPath.resolve("optifine").toFile(), minecraftPath.resolve("mcpatcher").toFile()); + } else { Files.move(minecraftPath.resolve("mcpatcher"), minecraftPath.resolve("optifine")); - if (minecraftPath.resolve("mcpatcher").toFile().exists()) + } + + if (minecraftPath.resolve("mcpatcher").toFile().exists()) { FileUtil.deleteDirectoryAndContents(minecraftPath.resolve("mcpatcher")); + } } } Path modelsPath = minecraftPath.resolve("models"); - Path itemModelsPath = modelsPath.resolve("item"); Path blockModelsPath = modelsPath.resolve("block"); - if (modelsPath.toFile().exists()) { - // 1.20.3 Models - if (to < Util.getVersionProtocol(packConverter.getGson(), "1.20.3")) + if (to < Util.getVersionProtocol(packConverter.getGson(), "1.20.3")) { renameAll(blockMapping203, ".json", blockModelsPath); + } // 1.19 Models - if (to < Util.getVersionProtocol(packConverter.getGson(), "1.19")) + if (to < Util.getVersionProtocol(packConverter.getGson(), "1.19")) { renameAll(blockMapping19, ".json", blockModelsPath); + } // Update 1.14 items - if (to < Util.getVersionProtocol(packConverter.getGson(), "1.14")) + if (to < Util.getVersionProtocol(packConverter.getGson(), "1.14")) { renameAll(newItemMapping, ".json", itemModelsPath); + } // 1.13 Models if (to < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { renameAll(itemMapping, ".json", itemModelsPath); renameAll(blockMapping, ".json", blockModelsPath); Path bannerModelPath = itemModelsPath.resolve("banner.json"); - if (bannerModelPath.toFile().exists()) + if (bannerModelPath.toFile().exists()) { bannerModelPath.toFile().delete(); + } } } // Update BlockStates Path blockStates = minecraftPath.resolve("blockstates"); - if (blockStates.toFile().exists()) + if (blockStates.toFile().exists()) { renameAll(blockMapping, ".json", blockStates); + } // Update textures Path texturesPath = minecraftPath.resolve("textures"); @@ -122,58 +127,74 @@ public void convert(Pack pack) throws IOException { // 1.20.3 if (to < Util.getVersionProtocol(packConverter.getGson(), "1.20.3") - && from >= Util.getVersionProtocol(packConverter.getGson(), "1.20.3")) + && from >= Util.getVersionProtocol(packConverter.getGson(), "1.20.3")) { renameAll(blockMapping203, ".png", texturesBlockPath); + } // 1.19 if (to < Util.getVersionProtocol(packConverter.getGson(), "1.19") - && from >= Util.getVersionProtocol(packConverter.getGson(), "1.19")) + && from >= Util.getVersionProtocol(packConverter.getGson(), "1.19")) { renameAll(blockMapping19, ".png", texturesBlockPath); + } // Entities Path entityPath = texturesPath.resolve("entity"); + if (entityPath.toFile().exists()) { + // 1.17 Squid + if (to < Util.getVersionProtocol(packConverter.getGson(), "1.17") + && from >= Util.getVersionProtocol(packConverter.getGson(), "1.17")) { + renameAll(blockMapping17, ".png", texturesBlockPath); + renameAll(itemMapping17, ".png", texturesItemPath); + renameAll(blockMapping17, ".png", blockModelsPath); + renameAll(itemMapping17, ".png", itemModelsPath); + Path squidPath = entityPath.resolve("squid/squid.png"); + if (squidPath.toFile().exists()) { + Path newSquidPath = entityPath.resolve("squid.png"); + if (newSquidPath.toFile().exists()) { + newSquidPath.toFile().delete(); + } + Files.move(squidPath, newSquidPath); + } + } - // 1.17 Squid - if (to < Util.getVersionProtocol(packConverter.getGson(), "1.17") - && from >= Util.getVersionProtocol(packConverter.getGson(), "1.17")) { - renameAll(blockMapping17, ".png", texturesBlockPath); - renameAll(itemMapping17, ".png", texturesItemPath); - renameAll(blockMapping17, ".png", blockModelsPath); - renameAll(itemMapping17, ".png", itemModelsPath); - Path newSquidPath = entityPath.resolve("squid/squid.png"); - if (newSquidPath.toFile().exists()) - Files.move(newSquidPath, entityPath.resolve("squid.png")); - } - - // 1.16 Iron golems - if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.16") - && to < Util.getVersionProtocol(packConverter.getGson(), "1.16")) { - Path newIronGolemPath = entityPath - .resolve("iron_golem/iron_golem.png".replace("/", File.separator)); - if (newIronGolemPath.toFile().exists()) - Files.move(newIronGolemPath, entityPath.resolve("iron_golem.png")); - } - - if (to < Util.getVersionProtocol(packConverter.getGson(), "1.14")) { - renameAll(newBlockMapping, ".png", texturesBlockPath); - renameAll(newBlockMapping, ".png.mcmeta", texturesBlockPath); - renameAll(newItemMapping, ".png", texturesItemPath); - renameAll(newItemMapping, ".png.mcmeta", texturesItemPath); - } - - if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.13") - && to < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { - renameAll(blockMapping, ".png", texturesBlockPath); - renameAll(blockMapping, ".png.mcmeta", texturesBlockPath); + // 1.16 Iron golems + if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.16") + && to < Util.getVersionProtocol(packConverter.getGson(), "1.16")) { + Path ironGolemPath = entityPath.resolve("iron_golem/iron_golem.png".replace("/", File.separator)); + if (ironGolemPath.toFile().exists()) { + Path newIronGolemPath = entityPath.resolve("iron_golem.png"); + if (newIronGolemPath.toFile().exists()) { + newIronGolemPath.toFile().delete(); + } + Files.move(ironGolemPath, newIronGolemPath); + } + } - renameAll(itemMapping, ".png", texturesItemPath); - renameAll(itemMapping, ".png.mcmeta", texturesItemPath); + if (to < Util.getVersionProtocol(packConverter.getGson(), "1.14")) { + renameAll(newBlockMapping, ".png", texturesBlockPath); + renameAll(newBlockMapping, ".png.mcmeta", texturesBlockPath); + renameAll(newItemMapping, ".png", texturesItemPath); + renameAll(newItemMapping, ".png.mcmeta", texturesItemPath); + } - // 1.13 End Crystals - if (entityPath.resolve("end_crystal").toFile().exists()) - Files.move(entityPath.resolve("end_crystal"), entityPath.resolve("endercrystal")); + if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.13") + && to < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { + renameAll(blockMapping, ".png", texturesBlockPath); + renameAll(blockMapping, ".png.mcmeta", texturesBlockPath); + renameAll(itemMapping, ".png", texturesItemPath); + renameAll(itemMapping, ".png.mcmeta", texturesItemPath); + + // 1.13 End Crystals + if (entityPath.resolve("end_crystal").toFile().exists()) { + Path newEnderCrystalFolderPath = entityPath.resolve("endcrystal"); + if (newEnderCrystalFolderPath.toFile().exists()) { + newEnderCrystalFolderPath.toFile().delete(); + } + Files.move(entityPath.resolve("end_crystal"), newEnderCrystalFolderPath); + } - findEntityFiles(texturesPath.resolve("entity")); + findEntityFiles(texturesPath.resolve("entity")); + } } } @@ -187,26 +208,29 @@ public void convert(Pack pack) throws IOException { /** * Finds files in entity folder - * + * * @param path * @throws IOException */ protected void findEntityFiles(Path path) throws IOException { - if (!path.toFile().exists()) - return; File directory = path.toFile(); - for (File file : directory.listFiles()) { - if (file.isDirectory()) - continue; - renameAll(entityMapping, ".png", file.toPath()); - renameAll(entityMapping, ".png.mcmeta", file.toPath()); - findEntityFiles(file.toPath()); + if (!directory.exists()) + return; + File[] files = directory.listFiles(); + if (files == null) + return; // why is this happening?? + for (File file : files) { + if (file.isDirectory()) { + renameAll(entityMapping, ".png", file.toPath()); + renameAll(entityMapping, ".png.mcmeta", file.toPath()); + findEntityFiles(file.toPath()); + } } } /** * Finds files in folders called - * + * * @param path * @throws IOException */ @@ -214,7 +238,7 @@ protected void findFiles(Path path) throws IOException { if (!path.toFile().exists()) return; File directory = path.toFile(); - for (File file : directory.listFiles()) { + for (File file : Objects.requireNonNull(directory.listFiles())) { if (file.isDirectory()) { if (file.getName().equals("item")) { Logger.debug("Found Items folder, renaming"); @@ -229,11 +253,13 @@ protected void findFiles(Path path) throws IOException { findFiles(file.toPath()); } - if (file.getName().contains("(")) + if (file.getName().contains("(")) { FileUtil.renameFile(path.resolve(file.getName()), file.getName().replaceAll("[()]", "")); + } - if (!file.getName().equals(file.getName().toLowerCase())) + if (!file.getName().equals(file.getName().toLowerCase())) { Logger.debug("Renamed: " + file.getName() + "->" + file.getName().toLowerCase()); + } FileUtil.renameFile(path.resolve(file.getName()), file.getName().toLowerCase()); } @@ -241,73 +267,101 @@ protected void findFiles(Path path) throws IOException { /** * Renames folder - * + * * @param mapping * @param extension * @param path * @throws IOException */ protected void renameAll(Mapping mapping, String extension, Path path) throws IOException { - if (path.toFile().exists()) { - // remap grass blocks in order due to the cyclical way their names have changed, - // i.e grass -> grass_block, tall_grass -> grass, double_grass -> tall_grass - List grasses = Arrays.asList("tall_grass", "grass", "grass_block"); - if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.12.2") - && (path.endsWith("blockstates") || path.endsWith("textures/block"))) { - grasses.stream().forEach(name -> { - String newName = mapping.remap(name); - Boolean ret = FileUtil.renameFile(Paths.get(path + File.separator + name + extension), - newName + extension); - if (ret == null) - return; - if (ret) - Logger.debug("Renamed: " + name + extension + "->" + newName + extension); - else if (!ret) - System.err.println(" Failed to rename: " + name + extension + "->" + newName + extension); - }); - } + if (!path.toFile().exists()) { + return; + } - if (from > Util.getVersionProtocol(packConverter.getGson(), "1.12.2") && - to <= Util.getVersionProtocol(packConverter.getGson(), "1.12.2")) { - Arrays.asList("snow", "snow_block").stream().forEach(name -> { - String newName = mapping.remap(name); - if (!extension.equals(".png")) { - Boolean ret = FileUtil.renameFile(Paths.get(path + File.separator + name + extension), - newName + extension); - if (ret == null) - return; - if (ret) - Logger.debug("Renamed: " + name + extension + "->" + newName + extension); - else if (!ret) - Logger.log("Failed to rename: " + name + extension + "->" + newName + extension); - } - }); - } + // remap grass blocks in order due to the cyclical way their names have changed, + // i.e grass -> grass_block, tall_grass -> grass, double_grass -> tall_grass + List grasses = Arrays.asList("tall_grass", "grass", "grass_block"); + if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.12.2") + && (path.endsWith("blockstates") || path.endsWith("textures/block"))) { + grasses.forEach(name -> { + Path basePath = path.resolve(name + extension); + String remappedName = mapping.remap(name); + + Path newPath = path.resolve(remappedName + extension); + if (newPath.toFile().exists()) { + // Same note from Slicer.java line 38 + newPath.toFile().delete(); + } - Files.list(path).forEach(path1 -> { - if (!path1.toString().endsWith(extension)) + Boolean renameSuccess = FileUtil.renameFile(basePath, newPath); + if (renameSuccess == null) { return; + } - String baseName = path1.getFileName().toString().substring(0, - path1.getFileName().toString().length() - extension.length()); - // skip the already renamed grass blocks - if (grasses.contains(baseName) - && (path.endsWith("blockstates") || path.endsWith("textures/block"))) - return; + if (renameSuccess) { + Logger.debug("Renamed: " + name + extension + "->" + newPath.getFileName()); + } else if (!renameSuccess) { + System.err.println(" Failed to rename: " + name + extension + "->" + newPath.getFileName()); + } + }); + } + + if (from > Util.getVersionProtocol(packConverter.getGson(), "1.12.2") && + to <= Util.getVersionProtocol(packConverter.getGson(), "1.12.2")) { + Stream.of("snow", "snow_block").forEach(name -> { + Path basePath = path.resolve(name + extension); + String remappedName = mapping.remap(name); + + if (!extension.equals(".png")) { + Path newPath = path.resolve(remappedName + extension); + if (newPath.toFile().exists()) { + // Same note from Slicer.java line 38 + newPath.toFile().delete(); + } - String newName = mapping.remap(baseName); - if (newName != null && !newName.equals(baseName)) { - Boolean ret = FileUtil.renameFile(path1, newName + extension); - if (ret == null) + Boolean renameSuccess = FileUtil.renameFile(basePath, newPath); + if (renameSuccess == null) { return; - if (ret) - Logger.debug("Renamed: " + path1.getFileName().toString() + "->" + newName + extension); - else if (!ret) - System.err.println(" Failed to rename: " + path1.getFileName().toString() + "->" + newName - + extension); + } + + if (renameSuccess) { + Logger.debug("Renamed: " + name + extension + "->" + newPath.getFileName()); + } else if (!renameSuccess) { + Logger.log("Failed to rename: " + name + extension + "->" + newPath.getFileName()); + } } }); } + + Files.list(path) + .filter(path1 -> path.toString().endsWith(extension)) + .forEach(path1 -> { + String baseName = path1.getFileName().toString().substring(0, path1.getFileName().toString().length() - extension.length()); + // NOTE: skip the already renamed grass blocks + if (grasses.contains(baseName) && (path.endsWith("blockstates") || path.endsWith("textures/block"))) { + return; + } + + String remappedName = mapping.remap(baseName); + if (remappedName != null && !remappedName.equals(baseName)) { + Path newPath = path1.getParent().resolve(remappedName + extension); + if (newPath.toFile().exists()) { + // Same note from Slicer.java line 38 + newPath.toFile().delete(); + } + + Boolean renameSuccess = FileUtil.renameFile(path1, newPath); + if (renameSuccess == null) { + return; + } + + if (renameSuccess) { + Logger.debug("Renamed: " + path1.getFileName().toString() + "->" + newPath.getFileName()); + } else if (!renameSuccess) { + System.err.println(" Failed to rename: " + path1.getFileName().toString() + "->" + newPath.getFileName()); + } + } + }); } public Mapping getBlockMapping() { diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java index 835bde71..29f4234a 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java @@ -360,37 +360,36 @@ protected void renameAll(Mapping mapping, String extension, Path path) throws IO } Logger.addTab(); - Files.list(path).forEach(path1 -> { - if (!path1.toString().endsWith(extension)) - return; + Files.list(path) + .filter(path1 -> path.toString().endsWith(extension)) + .forEach(path1 -> { + String baseName = path1.getFileName().toString().substring(0, path1.getFileName().toString().length() - extension.length()); - String baseName = path1.getFileName().toString().substring(0, path1.getFileName().toString().length() - extension.length()); - - // skip the already renamed grass blocks - if (grasses.contains(baseName) && (path.endsWith("blockstates") || path.endsWith("textures/block"))) { - return; - } - - String remappedName = mapping.remap(baseName); - if (remappedName != null && !remappedName.equals(baseName)) { - Path newPath = path1.getParent().resolve(remappedName + extension); - if (newPath.toFile().exists()) { - // Same note from Slicer.java line 38 - newPath.toFile().delete(); - } - - Boolean renameSuccess = FileUtil.renameFile(path1, newPath); - if (renameSuccess == null) { - return; - } + // skip the already renamed grass blocks + if (grasses.contains(baseName) && (path.endsWith("blockstates") || path.endsWith("textures/block"))) { + return; + } - if (renameSuccess) { - Logger.debug("Renamed: " + path1.getFileName().toString() + "->" + newPath.getFileName()); - } else if (!renameSuccess) { - Logger.log("Failed to rename: " + path1.getFileName().toString() + "->" + newPath.getFileName()); - } - } - }); + String remappedName = mapping.remap(baseName); + if (remappedName != null && !remappedName.equals(baseName)) { + Path newPath = path1.getParent().resolve(remappedName + extension); + if (newPath.toFile().exists()) { + // Same note from Slicer.java line 38 + newPath.toFile().delete(); + } + + Boolean renameSuccess = FileUtil.renameFile(path1, newPath); + if (renameSuccess == null) { + return; + } + + if (renameSuccess) { + Logger.debug("Renamed: " + path1.getFileName().toString() + "->" + newPath.getFileName()); + } else if (!renameSuccess) { + Logger.log("Failed to rename: " + path1.getFileName().toString() + "->" + newPath.getFileName()); + } + } + }); Logger.subTab(); } } From ca0e28c6bc42ae12379df2298587e8c276e83d42 Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Sun, 22 Dec 2024 17:26:49 -0500 Subject: [PATCH 20/54] Use Logger.error --- .../backwards/impl/NameConverter.java | 4 ++-- .../library/utilities/Logger.java | 21 ++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/NameConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/NameConverter.java index e8eecd14..5c8097ac 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/NameConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/NameConverter.java @@ -301,7 +301,7 @@ protected void renameAll(Mapping mapping, String extension, Path path) throws IO if (renameSuccess) { Logger.debug("Renamed: " + name + extension + "->" + newPath.getFileName()); } else if (!renameSuccess) { - System.err.println(" Failed to rename: " + name + extension + "->" + newPath.getFileName()); + Logger.error(" Failed to rename: " + name + extension + "->" + newPath.getFileName()); } }); } @@ -358,7 +358,7 @@ protected void renameAll(Mapping mapping, String extension, Path path) throws IO if (renameSuccess) { Logger.debug("Renamed: " + path1.getFileName().toString() + "->" + newPath.getFileName()); } else if (!renameSuccess) { - System.err.println(" Failed to rename: " + path1.getFileName().toString() + "->" + newPath.getFileName()); + Logger.error(" Failed to rename: " + path1.getFileName().toString() + "->" + newPath.getFileName()); } } }); diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Logger.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Logger.java index 2334f9f8..9cc53ae5 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Logger.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Logger.java @@ -14,7 +14,9 @@ public static void addTab() { public static void subTab() { tabs--; - if (tabs < 0) tabs = 0; + if (tabs < 0) { + tabs = 0; + } } public static void resetTab() { @@ -22,12 +24,11 @@ public static void resetTab() { } private static String getTabs() { - String out = ""; - + StringBuilder out = new StringBuilder(); for (int i = 0; i < tabs; i++) { - out += " "; + out.append(" "); } - return out; + return out.toString(); } public static void setStream(PrintStream stream) { @@ -39,15 +40,21 @@ public static void setDebug(boolean debug) { } public static void debug(String message) { - if (debug) log(message); + if (debug) { + log(message); + } } public static void log(String message) { stream.println(getTabs() + message); } + public static void error(String message) { + log(message); + } + private static void debug(Object thing) { - if (debug) log(thing); + debug(thing.toString()); } public static void log(Object thing) { From ec24aae9fc51579200ac3b67c441941b401a1ab3 Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Thu, 9 Jan 2025 16:54:28 -0500 Subject: [PATCH 21/54] Add 1.21.4 & ArmorMoverConverter --- conversions/Forwards/pom.xml | 12 + .../forwards/ForwardsPackConverter.java | 39 +- .../impl/textures/ArmorMoverConverter.java | 97 +++ .../impl/textures/ChestConverter.java | 30 +- library/src/main/resources/protocol.json | 676 +++++++++--------- 5 files changed, 495 insertions(+), 359 deletions(-) create mode 100644 conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java diff --git a/conversions/Forwards/pom.xml b/conversions/Forwards/pom.xml index 61f01879..f4ddff0b 100644 --- a/conversions/Forwards/pom.xml +++ b/conversions/Forwards/pom.xml @@ -7,6 +7,18 @@ com.agentdid127.resourcepack 2.2.5 + + + + org.apache.maven.plugins + maven-compiler-plugin + + 11 + 11 + + + + 4.0.0 com.agentdid127.resourcepack diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java index 595a9f5b..2a7aaa5a 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java @@ -19,7 +19,7 @@ public class ForwardsPackConverter extends PackConverter { Path INPUT_DIR; public ForwardsPackConverter(String from, String to, String light, boolean minify, Path input, boolean debug, - PrintStream out) { + PrintStream out) { GsonBuilder gsonBuilder = new GsonBuilder().setLenient(); if (!minify) gsonBuilder.setPrettyPrinting(); @@ -47,8 +47,9 @@ private void converterRunner(String from, String to, String light) { } if (protocolFrom < Util.getVersionProtocol(gson, "1.11") - && protocolTo >= Util.getVersionProtocol(gson, "1.11")) + && protocolTo >= Util.getVersionProtocol(gson, "1.11")) { this.registerConverter(new SpacesConverter(this)); + } this.registerConverter(new ModelConverter(this, light, protocolTo, protocolFrom)); @@ -63,28 +64,34 @@ private void converterRunner(String from, String to, String light) { this.registerConverter(new BlockStateConverter(this, protocolFrom, protocolTo)); - if (protocolTo >= Util.getVersionProtocol(gson, "1.13")) + if (protocolTo >= Util.getVersionProtocol(gson, "1.13")) { this.registerConverter(new LangConverter(this, from, to)); + } this.registerConverter(new ParticleTextureConverter(this, protocolFrom, protocolTo)); - if (protocolFrom < Util.getVersionProtocol(gson, "1.15") && protocolTo >= Util.getVersionProtocol(gson, "1.15")) + if (protocolFrom < Util.getVersionProtocol(gson, "1.15") && protocolTo >= Util.getVersionProtocol(gson, "1.15")) { this.registerConverter(new ChestConverter(this)); + } if (protocolFrom <= Util.getVersionProtocol(gson, "1.13") - && protocolTo >= Util.getVersionProtocol(gson, "1.14.4")) + && protocolTo >= Util.getVersionProtocol(gson, "1.14.4")) { this.registerConverter(new PaintingConverter(this)); + } if (protocolFrom <= Util.getVersionProtocol(gson, "1.13.2") - && protocolTo >= Util.getVersionProtocol(gson, "1.14")) + && protocolTo >= Util.getVersionProtocol(gson, "1.14")) { this.registerConverter(new MobEffectAtlasConverter(this, protocolFrom)); + } if (protocolFrom < Util.getVersionProtocol(gson, "1.15") - && protocolTo >= Util.getVersionProtocol(gson, "1.15")) + && protocolTo >= Util.getVersionProtocol(gson, "1.15")) { this.registerConverter(new EnchantConverter(this)); + } if (protocolFrom < Util.getVersionProtocol(gson, "1.18") - && protocolTo >= Util.getVersionProtocol(gson, "1.18")) + && protocolTo >= Util.getVersionProtocol(gson, "1.18")) { this.registerConverter(new ParticleConverter(this)); + } this.registerConverter(new InventoryConverter(this)); @@ -101,20 +108,28 @@ private void converterRunner(String from, String to, String light) { } if (protocolFrom < Util.getVersionProtocol(gson, "1.20") - && protocolTo >= Util.getVersionProtocol(gson, "1.20")) + && protocolTo >= Util.getVersionProtocol(gson, "1.20")) { this.registerConverter(new TitleConverter(this)); + } if (protocolFrom < Util.getVersionProtocol(gson, "1.20.2") - && protocolTo >= Util.getVersionProtocol(gson, "1.20.2")) + && protocolTo >= Util.getVersionProtocol(gson, "1.20.2")) { this.registerConverter(new SlicerConverter(this, protocolFrom)); + } if (protocolFrom < Util.getVersionProtocol(gson, "1.20.3") - && protocolTo >= Util.getVersionProtocol(gson, "1.20.3")) + && protocolTo >= Util.getVersionProtocol(gson, "1.20.3")) { this.registerConverter(new ImageFormatConverter(this)); + } if (protocolFrom < Util.getVersionProtocol(gson, "1.20.5") - && protocolTo >= Util.getVersionProtocol(gson, "1.20.5")) + && protocolTo >= Util.getVersionProtocol(gson, "1.20.5")) { this.registerConverter(new MapIconSlicerConverter(this, protocolFrom)); + } + + if (protocolFrom < Util.getVersionProtocol(gson, "1.21.2") && protocolTo >= Util.getVersionProtocol(gson, "1.21.2")) { + this.registerConverter(new ArmorMoverConverter(this)); + } } public void runPack(Pack pack) { diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java new file mode 100644 index 00000000..7eb0c8ab --- /dev/null +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java @@ -0,0 +1,97 @@ +package com.agentdid127.resourcepack.forwards.impl.textures; + +import com.agentdid127.resourcepack.library.Converter; +import com.agentdid127.resourcepack.library.PackConverter; +import com.agentdid127.resourcepack.library.pack.Pack; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; + +public class ArmorMoverConverter extends Converter { + private final List MATERIALS = new ArrayList<>(); + + public ArmorMoverConverter(PackConverter packConverter) { + super(packConverter); + MATERIALS.add("chainmail"); + MATERIALS.add("diamond"); + MATERIALS.add("gold"); + MATERIALS.add("iron"); + MATERIALS.add("leather"); + MATERIALS.add("netherite"); + } + + @Override + public void convert(Pack pack) throws IOException { + Path texturesPath = pack.getWorkingPath().resolve("assets/minecraft/textures/".replace("/", File.separator)); + if (!texturesPath.toFile().exists()) { + return; + } + + Path modelsPath = texturesPath.resolve("models"); + if (!modelsPath.toFile().exists()) { + return; + } + + Path modelsArmorPath = modelsPath.resolve("armor"); + if (!modelsArmorPath.toFile().exists()) { + return; + } + + // Just incase a pack wants to be special and include both versions 💀 + Path equipmentFolderPath = texturesPath.resolve("entity/equipment".replace("/", File.separator)); + if (equipmentFolderPath.toFile().exists()) { + equipmentFolderPath.toFile().delete(); + } + equipmentFolderPath.toFile().mkdirs(); + + Path humanoidPath = equipmentFolderPath.resolve("humanoid"); + Path humanoidLeggingsPath = equipmentFolderPath.resolve("humanoid_leggings"); + + // TODO: Cleanup this messy for loop + for (String material : MATERIALS) { + Path layer1Path = modelsArmorPath.resolve(material + "_layer_1.png"); + if (layer1Path.toFile().exists() && !humanoidPath.toFile().exists()) { + humanoidPath.toFile().mkdirs(); + } + + Path layer2Path = modelsArmorPath.resolve(material + "_layer_2.png"); + if (layer2Path.toFile().exists() && !humanoidLeggingsPath.toFile().exists()) { + humanoidLeggingsPath.toFile().mkdirs(); + } + + if (layer1Path.toFile().exists()) { + Files.move(layer1Path, humanoidPath.resolve(material + ".png")); + } + + if (layer2Path.toFile().exists()) { + Files.move(layer2Path, humanoidLeggingsPath.resolve(material + ".png")); + } + + if (material.equals("leather")) { + Path overlayLayer1 = modelsPath.resolve("_layer_1_overlay.png"); + if (overlayLayer1.toFile().exists() && !humanoidPath.toFile().exists()) { + humanoidLeggingsPath.toFile().mkdirs(); + } + + Path overlayLayer2 = modelsPath.resolve("_layer_2_overlay.png"); + if (overlayLayer2.toFile().exists() && !humanoidLeggingsPath.toFile().exists()) { + humanoidPath.toFile().mkdirs(); + } + + if (overlayLayer1.toFile().exists()) { + Files.move(overlayLayer1, humanoidPath.resolve(material + "_overlay.png")); + } + + if (overlayLayer2.toFile().exists()) { + Files.move(overlayLayer2, humanoidLeggingsPath.resolve(material + "_overlay.png")); + } + } + } + + modelsPath.toFile().delete(); + } +} diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ChestConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ChestConverter.java index 467bd605..8dc5ac57 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ChestConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ChestConverter.java @@ -4,6 +4,7 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.ImageConverter; +import com.agentdid127.resourcepack.library.utilities.Logger; import java.io.File; import java.io.IOException; @@ -16,16 +17,16 @@ public ChestConverter(PackConverter packConverter) { /** * Fixes Chest Textures in 1.15 Remaps textures, and updates images - * + * * @param pack * @throws IOException */ @Override public void convert(Pack pack) throws IOException { - Path imagePath = pack.getWorkingPath() - .resolve("assets/minecraft/textures/entity/chest".replace("/", File.separator)); - if (!imagePath.toFile().exists()) + Path imagePath = pack.getWorkingPath().resolve("assets/minecraft/textures/entity/chest".replace("/", File.separator)); + if (!imagePath.toFile().exists()) { return; + } // Double chest doubleChest(imagePath, "normal"); @@ -41,19 +42,21 @@ public void convert(Pack pack) throws IOException { /** * Fixes Normal chests - * + * * @param imagePath * @param name * @throws IOException */ private void chest(Path imagePath, String name) throws IOException { - if (!imagePath.resolve(name + ".png").toFile().exists()) + if (!imagePath.resolve(name + ".png").toFile().exists()) { return; + } int defaultW = 64, defaultH = 64; ImageConverter normal = new ImageConverter(defaultW, defaultH, imagePath.resolve(name + ".png")); - if (!normal.fileIsPowerOfTwo()) + if (!normal.fileIsPowerOfTwo()) { return; + } // Create a new Image normal.newImage(defaultW, defaultH); @@ -85,18 +88,21 @@ private void chest(Path imagePath, String name) throws IOException { /** * Splits Double Chests into 2 images - * + * * @param imagePath * @param name * @throws IOException */ private void doubleChest(Path imagePath, String name) throws IOException { int defaultW = 128, defaultH = 64; - if (!imagePath.resolve(name + "_double.png").toFile().exists()) + if (!imagePath.resolve(name + "_double.png").toFile().exists()) { return; + } + ImageConverter normal = new ImageConverter(defaultW, defaultH, imagePath.resolve(name + "_double.png")); - if (!normal.fileIsPowerOfTwo()) + if (!normal.fileIsPowerOfTwo()) { return; + } // Left Side // Body @@ -142,6 +148,8 @@ private void doubleChest(Path imagePath, String name) throws IOException { normal.subImage(1, 1, 2, 5, 3, 1, true); normal.store(imagePath.resolve(name + "_right.png")); - imagePath.resolve(name + "_double.png").toFile().delete(); + if (!imagePath.resolve(name + "_double.png").toFile().delete()) { + Logger.log("Failed to remove chest \"_double.png\"."); + } } } diff --git a/library/src/main/resources/protocol.json b/library/src/main/resources/protocol.json index 9eeb96da..f472f36a 100644 --- a/library/src/main/resources/protocol.json +++ b/library/src/main/resources/protocol.json @@ -1,338 +1,342 @@ { - "1.7.2": { - "protocol_version": "4", - "pack_format": "1" - }, - "1.7.3": { - "protocol_version": "4", - "pack_format": "1" - }, - "1.7.4": { - "protocol_version": "4", - "pack_format": "1" - }, - "1.7.5": { - "protocol_version": "4", - "pack_format": "1" - }, - "1.7.6": { - "protocol_version": "5", - "pack_format": "1" - }, - "1.7.7": { - "protocol_version": "5", - "pack_format": "1" - }, - "1.7.8": { - "protocol_version": "5", - "pack_format": "1" - }, - "1.7.9": { - "protocol_version": "5", - "pack_format": "1" - }, - "1.7.10": { - "protocol_version": "5", - "pack_format": "1" - }, - "1.8": { - "protocol_version": "47", - "pack_format": "1" - }, - "1.8.0": { - "protocol_version": "47", - "pack_format": "1" - }, - "1.8.1": { - "protocol_version": "47", - "pack_format": "1" - }, - "1.8.2": { - "protocol_version": "47", - "pack_format": "1" - }, - "1.8.3": { - "protocol_version": "47", - "pack_format": "1" - }, - "1.8.4": { - "protocol_version": "47", - "pack_format": "1" - }, - "1.8.5": { - "protocol_version": "47", - "pack_format": "1" - }, - "1.8.6": { - "protocol_version": "47", - "pack_format": "1" - }, - "1.8.7": { - "protocol_version": "47", - "pack_format": "1" - }, - "1.8.8": { - "protocol_version": "47", - "pack_format": "1" - }, - "1.8.9": { - "protocol_version": "47", - "pack_format": "1" - }, - "1.9": { - "protocol_version": "107", - "pack_format": "2" - }, - "1.9.0": { - "protocol_version": "107", - "pack_format": "2" - }, - "1.9.1": { - "protocol_version": "108", - "pack_format": "2" - }, - "1.9.2": { - "protocol_version": "109", - "pack_format": "2" - }, - "1.9.3": { - "protocol_version": "110", - "pack_format": "2" - }, - "1.9.4": { - "protocol_version": "110", - "pack_format": "2" - }, - "1.10": { - "protocol_version": "210", - "pack_format": "2" - }, - "1.10.0": { - "protocol_version": "210", - "pack_format": "2" - }, - "1.10.1": { - "protocol_version": "210", - "pack_format": "2" - }, - "1.10.2": { - "protocol_version": "210", - "pack_format": "2" - }, - "1.11": { - "protocol_version": "315", - "pack_format": "3" - }, - "1.11.0": { - "protocol_version": "315", - "pack_format": "3" - }, - "1.11.1": { - "protocol_version": "316", - "pack_format": "3" - }, - "1.11.2": { - "protocol_version": "316", - "pack_format": "3" - }, - "1.12": { - "protocol_version": "335", - "pack_format": "3" - }, - "1.12.0": { - "protocol_version": "335", - "pack_format": "3" - }, - "1.12.1": { - "protocol_version": "338", - "pack_format": "3" - }, - "1.12.2": { - "protocol_version": "340", - "pack_format": "3" - }, - "1.13": { - "protocol_version": "393", - "pack_format": "4" - }, - "1.13.0": { - "protocol_version": "393", - "pack_format": "4" - }, - "1.13.1": { - "protocol_version": "401", - "pack_format": "4" - }, - "1.13.2": { - "protocol_version": "404", - "pack_format": "4" - }, - "1.14": { - "protocol_version": "477", - "pack_format": "4" - }, - "1.14.0": { - "protocol_version": "477", - "pack_format": "4" - }, - "1.14.1": { - "protocol_version": "480", - "pack_format": "4" - }, - "1.14.2": { - "protocol_version": "485", - "pack_format": "4" - }, - "1.14.3": { - "protocol_version": "490", - "pack_format": "4" - }, - "1.14.4": { - "protocol_version": "498", - "pack_format": "4" - }, - "1.15": { - "protocol_version": "573", - "pack_format": "5" - }, - "1.15.0": { - "protocol_version": "573", - "pack_format": "5" - }, - "1.15.1": { - "protocol_version": "575", - "pack_format": "5" - }, - "1.15.2": { - "protocol_version": "578", - "pack_format": "5" - }, - "1.16": { - "protocol_version": "735", - "pack_format": "5" - }, - "1.16.0": { - "protocol_version": "735", - "pack_format": "5" - }, - "1.16.1": { - "protocol_version": "736", - "pack_format": "5" - }, - "1.16.2": { - "protocol_version": "751", - "pack_format": "6" - }, - "1.16.3": { - "protocol_version": "753", - "pack_format": "6" - }, - "1.16.4": { - "protocol_version": "754", - "pack_format": "6" - }, - "1.16.5": { - "protocol_version": "754", - "pack_format": "6" - }, - "1.17": { - "protocol_version": "755", - "pack_format": "7" - }, - "1.17.0": { - "protocol_version": "755", - "pack_format": "7" - }, - "1.17.1": { - "protocol_version": "756", - "pack_format": "7" - }, - "1.18": { - "protocol_version": "757", - "pack_format": "8" - }, - "1.18.0": { - "protocol_version": "757", - "pack_format": "8" - }, - "1.18.1": { - "protocol_version": "758", - "pack_format": "8" - }, - "1.18.2": { - "protocol_version": "758", - "pack_format": "8" - }, - "1.19": { - "protocol_version": "759", - "pack_format": "9" - }, - "1.19.0": { - "protocol_version": "759", - "pack_format": "9" - }, - "1.19.1": { - "protocol_version": "760", - "pack_format": "9" - }, - "1.19.2": { - "protocol_version": "760", - "pack_format": "9" - }, - "1.19.3": { - "protocol_version": "761", - "pack_format": "12" - }, - "1.19.4": { - "protocol_version": "762", - "pack_format": "13" - }, - "1.20": { - "protocol_version": "763", - "pack_format": "15" - }, - "1.20.0": { - "protocol_version": "763", - "pack_format": "15" - }, - "1.20.1": { - "protocol_version": "763", - "pack_format": "15" - }, - "1.20.2": { - "protocol_version": "764", - "pack_format": "18" - }, - "1.20.3": { - "protocol_version": "765", - "pack_format": "22" - }, - "1.20.4": { - "protocol_version": "765", - "pack_format": "22" - }, - "1.20.5": { - "protocol_version": "766", - "pack_format": "32" - }, - "1.20.6": { - "protocol_version": "766", - "pack_format": "32" - }, - "1.21": { - "protocol_version": "767", - "pack_format": "34" - }, - "1.21.1": { - "protocol_version": "767", - "pack_format": "34" - }, - "1.21.2": { - "protocol_version": "768", - "pack_format": "42" - }, - "1.21.3": { - "protocol_version": "768", - "pack_format": "42" - } + "1.7.2": { + "protocol_version": "4", + "pack_format": "1" + }, + "1.7.3": { + "protocol_version": "4", + "pack_format": "1" + }, + "1.7.4": { + "protocol_version": "4", + "pack_format": "1" + }, + "1.7.5": { + "protocol_version": "4", + "pack_format": "1" + }, + "1.7.6": { + "protocol_version": "5", + "pack_format": "1" + }, + "1.7.7": { + "protocol_version": "5", + "pack_format": "1" + }, + "1.7.8": { + "protocol_version": "5", + "pack_format": "1" + }, + "1.7.9": { + "protocol_version": "5", + "pack_format": "1" + }, + "1.7.10": { + "protocol_version": "5", + "pack_format": "1" + }, + "1.8": { + "protocol_version": "47", + "pack_format": "1" + }, + "1.8.0": { + "protocol_version": "47", + "pack_format": "1" + }, + "1.8.1": { + "protocol_version": "47", + "pack_format": "1" + }, + "1.8.2": { + "protocol_version": "47", + "pack_format": "1" + }, + "1.8.3": { + "protocol_version": "47", + "pack_format": "1" + }, + "1.8.4": { + "protocol_version": "47", + "pack_format": "1" + }, + "1.8.5": { + "protocol_version": "47", + "pack_format": "1" + }, + "1.8.6": { + "protocol_version": "47", + "pack_format": "1" + }, + "1.8.7": { + "protocol_version": "47", + "pack_format": "1" + }, + "1.8.8": { + "protocol_version": "47", + "pack_format": "1" + }, + "1.8.9": { + "protocol_version": "47", + "pack_format": "1" + }, + "1.9": { + "protocol_version": "107", + "pack_format": "2" + }, + "1.9.0": { + "protocol_version": "107", + "pack_format": "2" + }, + "1.9.1": { + "protocol_version": "108", + "pack_format": "2" + }, + "1.9.2": { + "protocol_version": "109", + "pack_format": "2" + }, + "1.9.3": { + "protocol_version": "110", + "pack_format": "2" + }, + "1.9.4": { + "protocol_version": "110", + "pack_format": "2" + }, + "1.10": { + "protocol_version": "210", + "pack_format": "2" + }, + "1.10.0": { + "protocol_version": "210", + "pack_format": "2" + }, + "1.10.1": { + "protocol_version": "210", + "pack_format": "2" + }, + "1.10.2": { + "protocol_version": "210", + "pack_format": "2" + }, + "1.11": { + "protocol_version": "315", + "pack_format": "3" + }, + "1.11.0": { + "protocol_version": "315", + "pack_format": "3" + }, + "1.11.1": { + "protocol_version": "316", + "pack_format": "3" + }, + "1.11.2": { + "protocol_version": "316", + "pack_format": "3" + }, + "1.12": { + "protocol_version": "335", + "pack_format": "3" + }, + "1.12.0": { + "protocol_version": "335", + "pack_format": "3" + }, + "1.12.1": { + "protocol_version": "338", + "pack_format": "3" + }, + "1.12.2": { + "protocol_version": "340", + "pack_format": "3" + }, + "1.13": { + "protocol_version": "393", + "pack_format": "4" + }, + "1.13.0": { + "protocol_version": "393", + "pack_format": "4" + }, + "1.13.1": { + "protocol_version": "401", + "pack_format": "4" + }, + "1.13.2": { + "protocol_version": "404", + "pack_format": "4" + }, + "1.14": { + "protocol_version": "477", + "pack_format": "4" + }, + "1.14.0": { + "protocol_version": "477", + "pack_format": "4" + }, + "1.14.1": { + "protocol_version": "480", + "pack_format": "4" + }, + "1.14.2": { + "protocol_version": "485", + "pack_format": "4" + }, + "1.14.3": { + "protocol_version": "490", + "pack_format": "4" + }, + "1.14.4": { + "protocol_version": "498", + "pack_format": "4" + }, + "1.15": { + "protocol_version": "573", + "pack_format": "5" + }, + "1.15.0": { + "protocol_version": "573", + "pack_format": "5" + }, + "1.15.1": { + "protocol_version": "575", + "pack_format": "5" + }, + "1.15.2": { + "protocol_version": "578", + "pack_format": "5" + }, + "1.16": { + "protocol_version": "735", + "pack_format": "5" + }, + "1.16.0": { + "protocol_version": "735", + "pack_format": "5" + }, + "1.16.1": { + "protocol_version": "736", + "pack_format": "5" + }, + "1.16.2": { + "protocol_version": "751", + "pack_format": "6" + }, + "1.16.3": { + "protocol_version": "753", + "pack_format": "6" + }, + "1.16.4": { + "protocol_version": "754", + "pack_format": "6" + }, + "1.16.5": { + "protocol_version": "754", + "pack_format": "6" + }, + "1.17": { + "protocol_version": "755", + "pack_format": "7" + }, + "1.17.0": { + "protocol_version": "755", + "pack_format": "7" + }, + "1.17.1": { + "protocol_version": "756", + "pack_format": "7" + }, + "1.18": { + "protocol_version": "757", + "pack_format": "8" + }, + "1.18.0": { + "protocol_version": "757", + "pack_format": "8" + }, + "1.18.1": { + "protocol_version": "758", + "pack_format": "8" + }, + "1.18.2": { + "protocol_version": "758", + "pack_format": "8" + }, + "1.19": { + "protocol_version": "759", + "pack_format": "9" + }, + "1.19.0": { + "protocol_version": "759", + "pack_format": "9" + }, + "1.19.1": { + "protocol_version": "760", + "pack_format": "9" + }, + "1.19.2": { + "protocol_version": "760", + "pack_format": "9" + }, + "1.19.3": { + "protocol_version": "761", + "pack_format": "12" + }, + "1.19.4": { + "protocol_version": "762", + "pack_format": "13" + }, + "1.20": { + "protocol_version": "763", + "pack_format": "15" + }, + "1.20.0": { + "protocol_version": "763", + "pack_format": "15" + }, + "1.20.1": { + "protocol_version": "763", + "pack_format": "15" + }, + "1.20.2": { + "protocol_version": "764", + "pack_format": "18" + }, + "1.20.3": { + "protocol_version": "765", + "pack_format": "22" + }, + "1.20.4": { + "protocol_version": "765", + "pack_format": "22" + }, + "1.20.5": { + "protocol_version": "766", + "pack_format": "32" + }, + "1.20.6": { + "protocol_version": "766", + "pack_format": "32" + }, + "1.21": { + "protocol_version": "767", + "pack_format": "34" + }, + "1.21.1": { + "protocol_version": "767", + "pack_format": "34" + }, + "1.21.2": { + "protocol_version": "768", + "pack_format": "42" + }, + "1.21.3": { + "protocol_version": "768", + "pack_format": "42" + }, + "1.21.4": { + "protocol_version": "769", + "pack_format": "46" + } } \ No newline at end of file From 6c107dac58e693646274d6251ebbfd9d334f1382 Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Thu, 9 Jan 2025 16:57:18 -0500 Subject: [PATCH 22/54] Add TODO in ArmorMoverConverter --- .../resourcepack/forwards/impl/textures/ArmorMoverConverter.java | 1 + 1 file changed, 1 insertion(+) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java index 7eb0c8ab..24789e80 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java @@ -14,6 +14,7 @@ public class ArmorMoverConverter extends Converter { private final List MATERIALS = new ArrayList<>(); + // TODO: Trims/Wolf Armor/Turtle/Llama/Horse/Elytra public ArmorMoverConverter(PackConverter packConverter) { super(packConverter); MATERIALS.add("chainmail"); From 7981108237adc1ee4e87dc1f0bc9ba48655d2dbb Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Thu, 9 Jan 2025 23:25:39 -0500 Subject: [PATCH 23/54] Fix Leather Armor Layers & Cleanup Code in ArmorMoverConverter --- .../impl/textures/ArmorMoverConverter.java | 67 +++++++++---------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java index 24789e80..3b6ce78b 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java @@ -51,48 +51,47 @@ public void convert(Pack pack) throws IOException { Path humanoidPath = equipmentFolderPath.resolve("humanoid"); Path humanoidLeggingsPath = equipmentFolderPath.resolve("humanoid_leggings"); - - // TODO: Cleanup this messy for loop for (String material : MATERIALS) { - Path layer1Path = modelsArmorPath.resolve(material + "_layer_1.png"); - if (layer1Path.toFile().exists() && !humanoidPath.toFile().exists()) { - humanoidPath.toFile().mkdirs(); - } - - Path layer2Path = modelsArmorPath.resolve(material + "_layer_2.png"); - if (layer2Path.toFile().exists() && !humanoidLeggingsPath.toFile().exists()) { - humanoidLeggingsPath.toFile().mkdirs(); - } - - if (layer1Path.toFile().exists()) { - Files.move(layer1Path, humanoidPath.resolve(material + ".png")); + moveArmorLayers(material, modelsArmorPath, humanoidPath, humanoidLeggingsPath); + if (material.equals("leather")) { + moveLeatherArmorFiles(modelsPath, humanoidPath, humanoidLeggingsPath); } + } - if (layer2Path.toFile().exists()) { - Files.move(layer2Path, humanoidLeggingsPath.resolve(material + ".png")); - } + modelsPath.toFile().delete(); + } - if (material.equals("leather")) { - Path overlayLayer1 = modelsPath.resolve("_layer_1_overlay.png"); - if (overlayLayer1.toFile().exists() && !humanoidPath.toFile().exists()) { - humanoidLeggingsPath.toFile().mkdirs(); - } + private void ensureFolder(Path filePath, Path intendedFolderPath) { + if (filePath.toFile().exists() && !intendedFolderPath.toFile().exists()) { + intendedFolderPath.toFile().mkdirs(); + } + } - Path overlayLayer2 = modelsPath.resolve("_layer_2_overlay.png"); - if (overlayLayer2.toFile().exists() && !humanoidLeggingsPath.toFile().exists()) { - humanoidPath.toFile().mkdirs(); - } + private void moveArmorLayers(String material, Path modelsArmorPath, Path humanoidPath, Path humanoidLeggingsPath) throws IOException { + Path layer1Path = modelsArmorPath.resolve(material + "_layer_1.png"); + ensureFolder(layer1Path, humanoidPath); + if (layer1Path.toFile().exists()) { + Files.move(layer1Path, humanoidPath.resolve(material + ".png")); + } - if (overlayLayer1.toFile().exists()) { - Files.move(overlayLayer1, humanoidPath.resolve(material + "_overlay.png")); - } + Path layer2Path = modelsArmorPath.resolve(material + "_layer_2.png"); + ensureFolder(layer2Path, humanoidLeggingsPath); + if (layer2Path.toFile().exists()) { + Files.move(layer2Path, humanoidLeggingsPath.resolve(material + ".png")); + } + } - if (overlayLayer2.toFile().exists()) { - Files.move(overlayLayer2, humanoidLeggingsPath.resolve(material + "_overlay.png")); - } - } + private void moveLeatherArmorFiles(Path modelsPath, Path humanoidPath, Path humanoidLeggingsPath) throws IOException { + Path overlayLayer1 = modelsPath.resolve("leather_layer_1_overlay.png"); + ensureFolder(overlayLayer1, humanoidPath); + if (overlayLayer1.toFile().exists()) { + Files.move(overlayLayer1, humanoidPath.resolve("leather_overlay.png")); } - modelsPath.toFile().delete(); + Path overlayLayer2 = modelsPath.resolve("leather_layer_2_overlay.png"); + ensureFolder(overlayLayer2, humanoidLeggingsPath); + if (overlayLayer2.toFile().exists()) { + Files.move(overlayLayer2, humanoidLeggingsPath.resolve("leather_overlay.png")); + } } } From 0d53bfc66dcb8dbac94b6573ce7ac3fea9db2f6f Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Thu, 9 Jan 2025 23:37:26 -0500 Subject: [PATCH 24/54] Fix Leather Armor Overlay For Real This Time --- .../forwards/impl/textures/ArmorMoverConverter.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java index 3b6ce78b..cc5c6cd1 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java @@ -54,10 +54,11 @@ public void convert(Pack pack) throws IOException { for (String material : MATERIALS) { moveArmorLayers(material, modelsArmorPath, humanoidPath, humanoidLeggingsPath); if (material.equals("leather")) { - moveLeatherArmorFiles(modelsPath, humanoidPath, humanoidLeggingsPath); + moveLeatherArmorFiles(modelsArmorPath, humanoidPath, humanoidLeggingsPath); } } + modelsArmorPath.toFile().delete(); // TODO/NOTE: For some reason, it will only delete "models" folder if I delete this first modelsPath.toFile().delete(); } @@ -81,14 +82,14 @@ private void moveArmorLayers(String material, Path modelsArmorPath, Path humanoi } } - private void moveLeatherArmorFiles(Path modelsPath, Path humanoidPath, Path humanoidLeggingsPath) throws IOException { - Path overlayLayer1 = modelsPath.resolve("leather_layer_1_overlay.png"); + private void moveLeatherArmorFiles(Path modelsArmorPath, Path humanoidPath, Path humanoidLeggingsPath) throws IOException { + Path overlayLayer1 = modelsArmorPath.resolve("leather_layer_1_overlay.png"); ensureFolder(overlayLayer1, humanoidPath); if (overlayLayer1.toFile().exists()) { Files.move(overlayLayer1, humanoidPath.resolve("leather_overlay.png")); } - Path overlayLayer2 = modelsPath.resolve("leather_layer_2_overlay.png"); + Path overlayLayer2 = modelsArmorPath.resolve("leather_layer_2_overlay.png"); ensureFolder(overlayLayer2, humanoidLeggingsPath); if (overlayLayer2.toFile().exists()) { Files.move(overlayLayer2, humanoidLeggingsPath.resolve("leather_overlay.png")); From 2e6c4ea53b2fdc257e99a4c43eef813f27f9d242 Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Mon, 27 Jan 2025 15:59:09 -0500 Subject: [PATCH 25/54] Update README --- README.MD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.MD b/README.MD index 5c84fadc..1d46af50 100644 --- a/README.MD +++ b/README.MD @@ -1,7 +1,7 @@ # Resource Pack Converter [![](https://jitpack.io/v/agentdid127/ResourcePackConverter.svg)](https://jitpack.io/#agentdid127/ResourcePackConverter) -This is a program that converts most issues with resource packs between any version from 1.7.2 all the way to 1.20.3. +This is a program that converts most issues with resource packs between any version from 1.7.2 all the way to 1.21.4. This should convert most things, but if you notice anything that does not work correctly, or should be added, create an issue on Github. From 9d27dd5bb42c34cab78154a529c929c0993c6b22 Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Sat, 8 Feb 2025 02:37:42 -0500 Subject: [PATCH 26/54] Fix item renaming bug --- .../backwards/impl/PackMetaConverter.java | 2 +- .../forwards/impl/BlockStateConverter.java | 8 +- .../forwards/impl/MCPatcherConverter.java | 4 +- .../forwards/impl/ModelConverter.java | 16 +- .../forwards/impl/NameConverter.java | 211 +++++------ .../forwards/impl/PackMetaConverter.java | 27 +- .../impl/textures/ArmorMoverConverter.java | 16 +- .../library/utilities/Mapping.java | 18 +- .../resourcepack/library/utilities/Util.java | 64 ++-- library/src/main/resources/protocol.json | 340 +++++++++--------- 10 files changed, 361 insertions(+), 345 deletions(-) diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/PackMetaConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/PackMetaConverter.java index 1a09457b..f2cc1238 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/PackMetaConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/PackMetaConverter.java @@ -33,7 +33,7 @@ public void convert(Pack pack) throws IOException { JsonObject versionObj = Util.getVersionObjectByProtocol(packConverter.getGson(), version); if (versionObj != null) { - versionInt = Integer.parseInt(versionObj.get("pack_format").getAsString()); + versionInt = versionObj.get("pack_format").getAsInt(); } JsonObject json = JsonUtil.readJson(packConverter.getGson(), file); diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.java index 624f74de..134868f9 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.java @@ -130,26 +130,26 @@ private void updateModelObject(JsonObject value) { if (from < Util.getVersionProtocol(packConverter.getGson(), "1.13") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.13")) { - val = nameConverter.getBlockMapping().remap(val); + val = nameConverter.getBlockMapping_1_13().remap(val); prefix = prefix.replaceAll("blocks", "block"); anyChanges = true; } if (from < Util.getVersionProtocol(packConverter.getGson(), "1.14") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.14")) { - val = nameConverter.getNewBlockMapping().remap(val); + val = nameConverter.getBlockMapping_1_14().remap(val); anyChanges = true; } if (from < Util.getVersionProtocol(packConverter.getGson(), "1.17") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.17")) { - val = nameConverter.getBlockMapping17().remap(val); + val = nameConverter.getBlockMapping_1_17().remap(val); anyChanges = true; } if (from < Util.getVersionProtocol(packConverter.getGson(), "1.19") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.19")) { - val = nameConverter.getBlockMapping19().remap(val); + val = nameConverter.getBlockMapping_1_19().remap(val); anyChanges = true; } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java index a99c0bec..d0074e3d 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java @@ -105,9 +105,9 @@ protected String replaceTextures(PropertiesEx prop) { NameConverter nameConverter = packConverter.getConverter(NameConverter.class); String properties = prop.getProperty("texture"); if (properties.startsWith("textures/blocks/")) - properties = "textures/block/" + nameConverter.getBlockMapping(); + properties = "textures/block/" + nameConverter.getBlockMapping_1_13(); else if (properties.startsWith("textures/items/")) - properties = "textures/item/" + nameConverter.getItemMapping(); + properties = "textures/item/" + nameConverter.getItemMapping_1_13(); return properties; } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java index 7fb468ad..5dc2d68f 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java @@ -125,18 +125,18 @@ protected void remapModelJson(Path path) throws IOException { // 1.13 Mappings if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.13")) { if (value.startsWith("block/")) { - value = "block/" + nameConverter.getBlockMapping() + value = "block/" + nameConverter.getBlockMapping_1_13() .remap(value.substring("block/".length())).toLowerCase() .replaceAll("[()]", ""); Logger.debug(value.substring("block/".length()).toLowerCase() .replaceAll("[()]", "")); - Logger.debug(nameConverter.getBlockMapping() + Logger.debug(nameConverter.getBlockMapping_1_13() .remap(value.substring("block/".length())).toLowerCase() .replaceAll("[()]", "")); } else if (value.startsWith("item/")) { - value = "item/" + nameConverter.getItemMapping() + value = "item/" + nameConverter.getItemMapping_1_13() .remap(value.substring("item/".length())).toLowerCase() .replaceAll("[()]", ""); } else @@ -146,18 +146,18 @@ protected void remapModelJson(Path path) throws IOException { // 1.14 Mappings if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.14")) { if (value.startsWith("block/")) - value = "block/" + nameConverter.getNewBlockMapping() + value = "block/" + nameConverter.getBlockMapping_1_14() .remap(value.substring("block/".length())); } // 1.17 Mappings if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.17")) { if (value.startsWith("block/")) { - value = "block/" + nameConverter.getBlockMapping17() + value = "block/" + nameConverter.getBlockMapping_1_17() .remap(value.substring("block/".length())).toLowerCase() .replaceAll("[()]", ""); } else if (value.startsWith("item/")) { - value = "item/" + nameConverter.getItemMapping17() + value = "item/" + nameConverter.getItemMapping_1_17() .remap(value.substring("item/".length())).toLowerCase() .replaceAll("[()]", ""); } @@ -167,7 +167,7 @@ protected void remapModelJson(Path path) throws IOException { // 1.19 Mappings if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.19")) { if (value.startsWith("block/")) { - value = "block/" + nameConverter.getBlockMapping19() + value = "block/" + nameConverter.getBlockMapping_1_19() .remap(value.substring("block/".length())).toLowerCase() .replaceAll("[()]", ""); } @@ -177,7 +177,7 @@ protected void remapModelJson(Path path) throws IOException { // Dyes if (value.startsWith("item/") && value.contains("dye")) { if (version > Util.getVersionProtocol(packConverter.getGson(), "1.13")) - value = "item/" + nameConverter.getNewItemMapping() + value = "item/" + nameConverter.getItemMapping_1_14() .remap(value.substring("item/".length())); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java index 29f4234a..b57d7131 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java @@ -17,41 +17,52 @@ import java.util.Arrays; import java.util.List; import java.util.Objects; +import java.util.stream.Stream; public class NameConverter extends Converter { private final int to; private final int from; - private final Mapping blockMapping; - private final Mapping newBlockMapping; - private final Mapping blockMapping17; - private final Mapping blockMapping19; - private final Mapping itemMapping; - private final Mapping newItemMapping; - private final Mapping itemMapping17; private final Mapping entityMapping; - private final Mapping langMapping; - private final Mapping langMapping14; - private final Mapping blockMapping203; - private final Mapping itemMapping203; + + private final Mapping blockMapping_1_13; + private final Mapping itemMapping_1_13; + + private final Mapping blockMapping_1_14; + private final Mapping itemMapping_1_14; + + private final Mapping blockMapping_1_17; + private final Mapping itemMapping_1_17; + + private final Mapping blockMapping_1_19; + + private final Mapping blockMapping_1_20_3; + private final Mapping itemMapping1_20_3; public NameConverter(PackConverter packConverter, int from, int to) { super(packConverter); + this.from = from; this.to = to; + Gson gson = packConverter.getGson(); - blockMapping = new Mapping(gson, "blocks", "1_13", false); - newBlockMapping = new Mapping(gson, "blocks", "1_14", false); - blockMapping17 = new Mapping(gson, "blocks", "1_17", false); - blockMapping19 = new Mapping(gson, "blocks", "1_19", false); - itemMapping = new Mapping(gson, "items", "1_13", false); - newItemMapping = new Mapping(gson, "items", "1_14", false); - itemMapping17 = new Mapping(gson, "items", "1_17", false); entityMapping = new Mapping(gson, "entities", "*", false); - langMapping = new Mapping(gson, "lang", "1_13", false); - langMapping14 = new Mapping(gson, "lang", "1_14", false); - blockMapping203 = new Mapping(gson, "blocks", "1_20_3", false); - itemMapping203 = new Mapping(gson, "items", "1_20_3", false); + +// TODO/(Not used): langMapping_1_13 = new Mapping(gson, "lang", "1_13", false); + blockMapping_1_13 = new Mapping(gson, "blocks", "1_13", false); + itemMapping_1_13 = new Mapping(gson, "items", "1_13", false); + +// TODO/(Not used): langMapping_1_14 = new Mapping(gson, "lang", "1_14", false); + blockMapping_1_14 = new Mapping(gson, "blocks", "1_14", false); + itemMapping_1_14 = new Mapping(gson, "items", "1_14", false); + + blockMapping_1_17 = new Mapping(gson, "blocks", "1_17", false); + itemMapping_1_17 = new Mapping(gson, "items", "1_17", false); + + blockMapping_1_19 = new Mapping(gson, "blocks", "1_19", false); + + blockMapping_1_20_3 = new Mapping(gson, "blocks", "1_20_3", false); + itemMapping1_20_3 = new Mapping(gson, "items", "1_20_3", false); } /** @@ -63,6 +74,7 @@ public NameConverter(PackConverter packConverter, int from, int to) { @Override public void convert(Pack pack) throws IOException { Path minecraftPath = pack.getWorkingPath().resolve("assets/minecraft".replace("/", File.separator)); + // Less than 1.12 if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.12.2") && to > Util.getVersionProtocol(packConverter.getGson(), "1.13")) { @@ -100,7 +112,7 @@ public void convert(Pack pack) throws IOException { } // Update all blocks for 1.13 - renameAll(blockMapping, ".json", modelsPath.resolve("block")); + renameAll(blockMapping_1_13, ".json", modelsPath.resolve("block")); if (modelsPath.resolve("items").toFile().exists()) { if (modelsPath.resolve("item").toFile().exists()) { FileUtil.deleteDirectoryAndContents(modelsPath.resolve("item")); @@ -110,12 +122,13 @@ public void convert(Pack pack) throws IOException { } // Update all items for 1.13 - renameAll(itemMapping, ".json", modelsPath.resolve("item")); + renameAll(itemMapping_1_13, ".json", modelsPath.resolve("item")); // Update 1.14 items if (to > Util.getVersionProtocol(packConverter.getGson(), "1.13")) { Path itemModelPath = modelsPath.resolve("iem"); - renameAll(newItemMapping, ".json", itemModelPath); + renameAll(itemMapping_1_14, ".json", itemModelPath); + if (!itemModelPath.resolve("ink_sac.json").toFile().exists() && itemModelPath.resolve("black_dye.json").toFile().exists()) { Files.copy(itemModelPath.resolve("black_dye.json"), itemModelPath.resolve("ink_sac.json")); @@ -138,47 +151,49 @@ public void convert(Pack pack) throws IOException { } if (to > Util.getVersionProtocol(packConverter.getGson(), "1.19")) { - renameAll(blockMapping19, ".json", modelsPath.resolve("block")); + renameAll(blockMapping_1_19, ".json", modelsPath.resolve("block")); } if (to > Util.getVersionProtocol(packConverter.getGson(), "1.20.3")) { - renameAll(itemMapping203, ".json", modelsPath.resolve("item")); - renameAll(blockMapping203, ".json", modelsPath.resolve("block")); + renameAll(itemMapping1_20_3, ".json", modelsPath.resolve("item")); + renameAll(blockMapping_1_20_3, ".json", modelsPath.resolve("block")); } } // Update BlockStates Path blockStates = pack.getWorkingPath().resolve("assets/minecraft/blockstates".replace("/", File.separator)); if (blockStates.toFile().exists()) { - renameAll(blockMapping, ".json", blockStates); + renameAll(blockMapping_1_13, ".json", blockStates); } // Update textures Path texturesPath = pack.getWorkingPath().resolve("assets/minecraft/textures".replace("/", File.separator)); if (texturesPath.toFile().exists()) { Path blockPath = texturesPath.resolve("block"); - if (texturesPath.resolve("blocks").toFile().exists()) + if (texturesPath.resolve("blocks").toFile().exists()) { Files.move(texturesPath.resolve("blocks"), blockPath); + } if (from < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { - renameAll(blockMapping, ".png", blockPath); - renameAll(blockMapping, ".png.mcmeta", blockPath); + renameAll(blockMapping_1_13, ".png", blockPath); + renameAll(blockMapping_1_13, ".png.mcmeta", blockPath); } if (to > Util.getVersionProtocol(packConverter.getGson(), "1.13")) { - renameAll(newBlockMapping, ".png", blockPath); - renameAll(newBlockMapping, ".png.mcmeta", blockPath); + renameAll(blockMapping_1_14, ".png", blockPath); + renameAll(blockMapping_1_14, ".png.mcmeta", blockPath); } Path itemPath = texturesPath.resolve("item"); if (from < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { - renameAll(itemMapping, ".png", itemPath); - renameAll(itemMapping, ".png.mcmeta", itemPath); + renameAll(itemMapping_1_13, ".png", itemPath); + renameAll(itemMapping_1_13, ".png.mcmeta", itemPath); } if (to > Util.getVersionProtocol(packConverter.getGson(), "1.13.2")) { - renameAll(newItemMapping, ".png", itemPath); - renameAll(newItemMapping, ".png.mcmeta", itemPath); + renameAll(itemMapping_1_14, ".png", itemPath); + renameAll(itemMapping_1_14, ".png.mcmeta", itemPath); + Path itemModelPath = modelsPath.resolve("item"); if (!itemModelPath.resolve("ink_sac.png").toFile().exists() && itemModelPath.resolve("black_dye.png").toFile().exists()) { @@ -224,10 +239,10 @@ public void convert(Pack pack) throws IOException { // 1.17 Squid if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.17") && from < Util.getVersionProtocol(packConverter.getGson(), "1.17")) { - renameAll(blockMapping17, ".png", blockPath); - renameAll(itemMapping17, ".png", texturesPath.resolve("item")); - renameAll(blockMapping17, ".png", modelsPath.resolve("block")); - renameAll(itemMapping17, ".png", modelsPath.resolve("item")); + renameAll(blockMapping_1_17, ".png", blockPath); + renameAll(itemMapping_1_17, ".png", itemPath); + renameAll(blockMapping_1_17, ".png", modelsPath.resolve("block")); + renameAll(itemMapping_1_17, ".png", modelsPath.resolve("item")); Path squidFolderPath = entityPath.resolve("squid"); if (!squidFolderPath.toFile().exists()) { @@ -246,7 +261,7 @@ public void convert(Pack pack) throws IOException { if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.19") && from < Util.getVersionProtocol(packConverter.getGson(), "1.19")) { - renameAll(blockMapping19, ".png", blockPath); + renameAll(blockMapping_1_19, ".png", blockPath); } // 1.13 End Crystals @@ -268,8 +283,8 @@ public void convert(Pack pack) throws IOException { /** * Finds files in entity folder * - * @param path - * @throws IOException + * @param path The input path + * @throws IOException The IO exception */ protected void findEntityFiles(Path path) throws IOException { if (path.toFile().exists()) { @@ -286,9 +301,7 @@ protected void findEntityFiles(Path path) throws IOException { /** * Finds files in folders called - * - * @param path - * @throws IOException + * @param path The input path */ protected void findFiles(Path path) { if (path.toFile().exists()) { @@ -324,10 +337,10 @@ protected void findFiles(Path path) { /** * Renames folder * - * @param mapping - * @param extension - * @param path - * @throws IOException + * @param mapping The input mapping + * @param extension The file extension + * @param path The input path + * @throws IOException The IO exception */ protected void renameAll(Mapping mapping, String extension, Path path) throws IOException { if (path.toFile().exists()) { @@ -338,10 +351,11 @@ protected void renameAll(Mapping mapping, String extension, Path path) throws IO if ((path.endsWith("blockstates") || path.endsWith("textures/block"))) { grasses.forEach(name -> { String newName = mapping.remap(name); - Boolean ret = FileUtil.renameFile(Paths.get(path + File.separator + name + extension), - newName + extension); - if (ret == null) + Boolean ret = FileUtil.renameFile(Paths.get(path + File.separator + name + extension), newName + extension); + if (ret == null) { return; + } + if (ret) { Logger.debug("Renamed: " + name + extension + "->" + newName + extension); } else if (!ret) { @@ -360,73 +374,66 @@ protected void renameAll(Mapping mapping, String extension, Path path) throws IO } Logger.addTab(); - Files.list(path) - .filter(path1 -> path.toString().endsWith(extension)) - .forEach(path1 -> { - String baseName = path1.getFileName().toString().substring(0, path1.getFileName().toString().length() - extension.length()); + try (Stream pathStream = Files.list(path).filter(path1 -> path1.toString().endsWith(extension))) { + pathStream.forEach(path1 -> { + String baseName = path1.getFileName().toString().substring(0, path1.getFileName().toString().length() - extension.length()); + + // skip the already renamed grass blocks + if (grasses.contains(baseName) && (path.endsWith("blockstates") || path.endsWith("textures/block"))) { + return; + } + + String remappedName = mapping.remap(baseName); + if (remappedName != null && !remappedName.equals(baseName)) { + Path newPath = path1.getParent().resolve(remappedName + extension); + if (newPath.toFile().exists()) { + // Same note from Slicer.java line 38 + newPath.toFile().delete(); + } - // skip the already renamed grass blocks - if (grasses.contains(baseName) && (path.endsWith("blockstates") || path.endsWith("textures/block"))) { + Boolean renameSuccess = FileUtil.renameFile(path1, newPath); + if (renameSuccess == null) { return; } - String remappedName = mapping.remap(baseName); - if (remappedName != null && !remappedName.equals(baseName)) { - Path newPath = path1.getParent().resolve(remappedName + extension); - if (newPath.toFile().exists()) { - // Same note from Slicer.java line 38 - newPath.toFile().delete(); - } - - Boolean renameSuccess = FileUtil.renameFile(path1, newPath); - if (renameSuccess == null) { - return; - } - - if (renameSuccess) { - Logger.debug("Renamed: " + path1.getFileName().toString() + "->" + newPath.getFileName()); - } else if (!renameSuccess) { - Logger.log("Failed to rename: " + path1.getFileName().toString() + "->" + newPath.getFileName()); - } + if (renameSuccess) { + Logger.debug("Renamed: " + path1.getFileName().toString() + "->" + newPath.getFileName()); + } else if (!renameSuccess) { + Logger.log("Failed to rename: " + path1.getFileName().toString() + "->" + newPath.getFileName()); } - }); + } + }); + } + Logger.subTab(); } } - public Mapping getBlockMapping() { - return blockMapping; - } - - public Mapping getItemMapping() { - return itemMapping; - } - - public Mapping getNewBlockMapping() { - return newBlockMapping; + public Mapping getBlockMapping_1_13() { + return blockMapping_1_13; } - public Mapping getNewItemMapping() { - return newItemMapping; + public Mapping getItemMapping_1_13() { + return itemMapping_1_13; } - public Mapping getItemMapping17() { - return itemMapping17; + public Mapping getBlockMapping_1_14() { + return blockMapping_1_14; } - public Mapping getBlockMapping17() { - return blockMapping17; + public Mapping getItemMapping_1_14() { + return itemMapping_1_14; } - public Mapping getBlockMapping19() { - return blockMapping19; + public Mapping getItemMapping_1_17() { + return itemMapping_1_17; } - public Mapping getLangMapping() { - return langMapping; + public Mapping getBlockMapping_1_17() { + return blockMapping_1_17; } - public Mapping getLangMapping14() { - return langMapping14; + public Mapping getBlockMapping_1_19() { + return blockMapping_1_19; } } \ No newline at end of file diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java index deb10ac4..b503a436 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java @@ -12,8 +12,8 @@ // Reference: https://minecraft.wiki/w/Pack_format public class PackMetaConverter extends Converter { - private int to; - private int from; + private final int to; + private final int from; public PackMetaConverter(PackConverter packConverter, int from, int to) { super(packConverter); @@ -24,49 +24,52 @@ public PackMetaConverter(PackConverter packConverter, int from, int to) { /** * Converts MCMeta to newer version * - * @param pack - * @throws IOException + * @param pack The input pack + * @throws IOException The IO Exception */ @Override public void convert(Pack pack) throws IOException { Path file = pack.getWorkingPath().resolve("pack.mcmeta"); - if (!file.toFile().exists()) + if (!file.toFile().exists()) { return; + } int versionInt = 4; JsonObject versionObj = Util.getVersionObjectByProtocol(packConverter.getGson(), to); if (versionObj != null) { - versionInt = Integer.parseInt(versionObj.get("pack_format").getAsString()); + versionInt = versionObj.get("pack_format").getAsInt(); } JsonObject json = JsonUtil.readJson(packConverter.getGson(), file); - if (json == null) { json = new JsonObject(); } { JsonObject meta = json.getAsJsonObject("meta"); - if (meta == null) + if (meta == null) { meta = new JsonObject(); + } + meta.addProperty("game_version", Util.getVersionFromProtocol(packConverter.getGson(), to)); json.add("meta", meta); } { JsonObject packObject = json.getAsJsonObject("pack"); - if (packObject == null) + if (packObject == null) { packObject = new JsonObject(); - packObject.addProperty("pack_format", versionInt); + } + packObject.addProperty("pack_format", versionInt); if (from < Util.getVersionProtocol(packConverter.getGson(), "1.20.2") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.20.2")) { JsonObject fromVersion = Util.getVersionObjectByProtocol(packConverter.getGson(), from); JsonObject toVersion = Util.getVersionObjectByProtocol(packConverter.getGson(), to); JsonObject supportedFormats = new JsonObject(); - supportedFormats.addProperty("min_inclusive", fromVersion != null ? Integer.parseInt(fromVersion.get("pack_format").getAsString()) : versionInt); - supportedFormats.addProperty("max_inclusive", toVersion != null ? Integer.parseInt(toVersion.get("pack_format").getAsString()) : versionInt); + supportedFormats.addProperty("min_inclusive", fromVersion != null ? fromVersion.get("pack_format").getAsInt() : versionInt); + supportedFormats.addProperty("max_inclusive", toVersion != null ? toVersion.get("pack_format").getAsInt() : versionInt); packObject.add("supported_formats", supportedFormats); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java index cc5c6cd1..3812d19a 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java @@ -62,35 +62,33 @@ public void convert(Pack pack) throws IOException { modelsPath.toFile().delete(); } - private void ensureFolder(Path filePath, Path intendedFolderPath) { + private Path ensureFolder(Path filePath, Path intendedFolderPath) { if (filePath.toFile().exists() && !intendedFolderPath.toFile().exists()) { intendedFolderPath.toFile().mkdirs(); } + + return filePath; } private void moveArmorLayers(String material, Path modelsArmorPath, Path humanoidPath, Path humanoidLeggingsPath) throws IOException { - Path layer1Path = modelsArmorPath.resolve(material + "_layer_1.png"); - ensureFolder(layer1Path, humanoidPath); + Path layer1Path = ensureFolder(modelsArmorPath.resolve(material + "_layer_1.png"), humanoidPath); if (layer1Path.toFile().exists()) { Files.move(layer1Path, humanoidPath.resolve(material + ".png")); } - Path layer2Path = modelsArmorPath.resolve(material + "_layer_2.png"); - ensureFolder(layer2Path, humanoidLeggingsPath); + Path layer2Path = ensureFolder(modelsArmorPath.resolve(material + "_layer_2.png"), humanoidLeggingsPath); if (layer2Path.toFile().exists()) { Files.move(layer2Path, humanoidLeggingsPath.resolve(material + ".png")); } } private void moveLeatherArmorFiles(Path modelsArmorPath, Path humanoidPath, Path humanoidLeggingsPath) throws IOException { - Path overlayLayer1 = modelsArmorPath.resolve("leather_layer_1_overlay.png"); - ensureFolder(overlayLayer1, humanoidPath); + Path overlayLayer1 = ensureFolder(modelsArmorPath.resolve("leather_layer_1_overlay.png"), humanoidPath); if (overlayLayer1.toFile().exists()) { Files.move(overlayLayer1, humanoidPath.resolve("leather_overlay.png")); } - Path overlayLayer2 = modelsArmorPath.resolve("leather_layer_2_overlay.png"); - ensureFolder(overlayLayer2, humanoidLeggingsPath); + Path overlayLayer2 = ensureFolder(modelsArmorPath.resolve("leather_layer_2_overlay.png"), humanoidLeggingsPath); if (overlayLayer2.toFile().exists()) { Files.move(overlayLayer2, humanoidLeggingsPath.resolve("leather_overlay.png")); } diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Mapping.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Mapping.java index 62f8d127..f8c96a00 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Mapping.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Mapping.java @@ -1,12 +1,12 @@ package com.agentdid127.resourcepack.library.utilities; -import java.util.HashMap; -import java.util.Map; - import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import java.util.HashMap; +import java.util.Map; + public class Mapping { protected final Map mapping = new HashMap<>(); @@ -15,12 +15,12 @@ public Mapping(Gson gson, String path, String key, boolean backwards) { } protected void load(Gson gson, String source, String path, String key) { - JsonObject object = JsonUtil.readJsonResource(gson, "/" + source + "/" + path + ".json") - .getAsJsonObject(key); - if (object == null) - return; - for (Map.Entry entry : object.entrySet()) - this.mapping.put(entry.getKey(), entry.getValue().getAsString()); + JsonObject object = JsonUtil.readJsonResource(gson, "/" + source + "/" + path + ".json").getAsJsonObject(key); + if (object != null) { + for (Map.Entry entry : object.entrySet()) { + this.mapping.put(entry.getKey(), entry.getValue().getAsString()); + } + } } /** diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Util.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Util.java index c5e4b70e..6cbfd9ec 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Util.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Util.java @@ -27,9 +27,11 @@ private Util() { */ public static BufferedImage readImageResource(String path) { try (InputStream stream = PackConverter.class.getResourceAsStream(path)) { - if (stream == null) + if (stream == null) { return null; - return ImageIO.read(stream); + } else { + return ImageIO.read(stream); + } } catch (IOException e) { throw new RuntimeException(e); } @@ -44,14 +46,15 @@ public static BufferedImage readImageResource(String path) { */ public static String getVersionFromProtocol(Gson gson, int protocol) { JsonObject protocols = JsonUtil.readJsonResource(gson, "/protocol.json"); - if (protocols == null) return null; - - for (Map.Entry entry : protocols.entrySet()) { - JsonObject versionObj = entry.getValue().getAsJsonObject(); - if (Integer.parseInt(versionObj.get("protocol_version").getAsString()) == protocol) { - return entry.getKey(); + if (protocols != null) { + for (Map.Entry entry : protocols.entrySet()) { + JsonObject versionObj = entry.getValue().getAsJsonObject(); + if (versionObj.get("protocol_version").getAsInt() == protocol) { + return entry.getKey(); + } } } + return null; } @@ -64,14 +67,15 @@ public static String getVersionFromProtocol(Gson gson, int protocol) { */ public static JsonObject getVersionObjectByProtocol(Gson gson, int protocol) { JsonObject protocols = JsonUtil.readJsonResource(gson, "/protocol.json"); - if (protocols == null) return null; - - for (Map.Entry entry : protocols.entrySet()) { - JsonObject versionObj = entry.getValue().getAsJsonObject(); - if (Integer.parseInt(versionObj.get("protocol_version").getAsString()) == protocol) { - return versionObj; + if (protocols != null) { + for (Map.Entry entry : protocols.entrySet()) { + JsonObject versionObj = entry.getValue().getAsJsonObject(); + if (versionObj.get("protocol_version").getAsInt() == protocol) { + return versionObj; + } } } + return null; } @@ -96,21 +100,22 @@ public static JsonObject getVersionObject(Gson gson, String version) { */ public static int getVersionProtocol(Gson gson, String version) { JsonObject versionObj = getVersionObject(gson, version); - return versionObj == null ? 0 : Integer.parseInt(versionObj.get("protocol_version").getAsString()); + return versionObj == null ? 0 : versionObj.get("protocol_version").getAsInt(); } public static int getLatestProtocol(Gson gson) { JsonObject protocols = JsonUtil.readJsonResource(gson, "/protocol.json"); - if (protocols == null) return 0; - int latestProtocol = 0; - for (Map.Entry entry : protocols.entrySet()) { - JsonObject versionObj = entry.getValue().getAsJsonObject(); - int protocol = Integer.parseInt(versionObj.get("protocol_version").getAsString()); - if (protocol > latestProtocol) { - latestProtocol = protocol; + if (protocols != null) { + for (Map.Entry entry : protocols.entrySet()) { + JsonObject versionObj = entry.getValue().getAsJsonObject(); + int protocol = versionObj.get("protocol_version").getAsInt(); + if (protocol > latestProtocol) { + latestProtocol = protocol; + } } } + return latestProtocol; } @@ -122,20 +127,23 @@ public static int getLatestProtocol(Gson gson) { */ public static String[] getSupportedVersions(Gson gson) { JsonObject protocols = JsonUtil.readJsonResource(gson, "/protocol.json"); - if (protocols == null) + if (protocols == null) { return null; - return protocols.entrySet() - .stream() - .map(Map.Entry::getKey) - .toArray(String[]::new); + } else { + return protocols.entrySet() + .stream() + .map(Map.Entry::getKey) + .toArray(String[]::new); + } } public static String readFromFile(Path path) throws IOException { BufferedReader br = new BufferedReader(new FileReader(path.toFile())); StringBuilder resultStringBuilder = new StringBuilder(); String line; - while ((line = br.readLine()) != null) + while ((line = br.readLine()) != null) { resultStringBuilder.append(line).append("\n"); + } br.close(); return resultStringBuilder.toString(); } diff --git a/library/src/main/resources/protocol.json b/library/src/main/resources/protocol.json index f472f36a..4944f2c5 100644 --- a/library/src/main/resources/protocol.json +++ b/library/src/main/resources/protocol.json @@ -1,342 +1,342 @@ { "1.7.2": { - "protocol_version": "4", - "pack_format": "1" + "protocol_version": 4, + "pack_format": 1 }, "1.7.3": { - "protocol_version": "4", - "pack_format": "1" + "protocol_version": 4, + "pack_format": 1 }, "1.7.4": { - "protocol_version": "4", - "pack_format": "1" + "protocol_version": 4, + "pack_format": 1 }, "1.7.5": { - "protocol_version": "4", - "pack_format": "1" + "protocol_version": 4, + "pack_format": 1 }, "1.7.6": { - "protocol_version": "5", - "pack_format": "1" + "protocol_version": 5, + "pack_format": 1 }, "1.7.7": { - "protocol_version": "5", - "pack_format": "1" + "protocol_version": 5, + "pack_format": 1 }, "1.7.8": { - "protocol_version": "5", - "pack_format": "1" + "protocol_version": 5, + "pack_format": 1 }, "1.7.9": { - "protocol_version": "5", - "pack_format": "1" + "protocol_version": 5, + "pack_format": 1 }, "1.7.10": { - "protocol_version": "5", - "pack_format": "1" + "protocol_version": 5, + "pack_format": 1 }, "1.8": { - "protocol_version": "47", - "pack_format": "1" + "protocol_version": 47, + "pack_format": 1 }, "1.8.0": { - "protocol_version": "47", - "pack_format": "1" + "protocol_version": 47, + "pack_format": 1 }, "1.8.1": { - "protocol_version": "47", - "pack_format": "1" + "protocol_version": 47, + "pack_format": 1 }, "1.8.2": { - "protocol_version": "47", - "pack_format": "1" + "protocol_version": 47, + "pack_format": 1 }, "1.8.3": { - "protocol_version": "47", - "pack_format": "1" + "protocol_version": 47, + "pack_format": 1 }, "1.8.4": { - "protocol_version": "47", - "pack_format": "1" + "protocol_version": 47, + "pack_format": 1 }, "1.8.5": { - "protocol_version": "47", - "pack_format": "1" + "protocol_version": 47, + "pack_format": 1 }, "1.8.6": { - "protocol_version": "47", - "pack_format": "1" + "protocol_version": 47, + "pack_format": 1 }, "1.8.7": { - "protocol_version": "47", - "pack_format": "1" + "protocol_version": 47, + "pack_format": 1 }, "1.8.8": { - "protocol_version": "47", - "pack_format": "1" + "protocol_version": 47, + "pack_format": 1 }, "1.8.9": { - "protocol_version": "47", - "pack_format": "1" + "protocol_version": 47, + "pack_format": 1 }, "1.9": { - "protocol_version": "107", - "pack_format": "2" + "protocol_version": 107, + "pack_format": 2 }, "1.9.0": { - "protocol_version": "107", - "pack_format": "2" + "protocol_version": 107, + "pack_format": 2 }, "1.9.1": { - "protocol_version": "108", - "pack_format": "2" + "protocol_version": 108, + "pack_format": 2 }, "1.9.2": { - "protocol_version": "109", - "pack_format": "2" + "protocol_version": 109, + "pack_format": 2 }, "1.9.3": { - "protocol_version": "110", - "pack_format": "2" + "protocol_version": 110, + "pack_format": 2 }, "1.9.4": { - "protocol_version": "110", - "pack_format": "2" + "protocol_version": 110, + "pack_format": 2 }, "1.10": { - "protocol_version": "210", - "pack_format": "2" + "protocol_version": 210, + "pack_format": 2 }, "1.10.0": { - "protocol_version": "210", - "pack_format": "2" + "protocol_version": 210, + "pack_format": 2 }, "1.10.1": { - "protocol_version": "210", - "pack_format": "2" + "protocol_version": 210, + "pack_format": 2 }, "1.10.2": { - "protocol_version": "210", - "pack_format": "2" + "protocol_version": 210, + "pack_format": 2 }, "1.11": { - "protocol_version": "315", - "pack_format": "3" + "protocol_version": 315, + "pack_format": 3 }, "1.11.0": { - "protocol_version": "315", - "pack_format": "3" + "protocol_version": 315, + "pack_format": 3 }, "1.11.1": { - "protocol_version": "316", - "pack_format": "3" + "protocol_version": 316, + "pack_format": 3 }, "1.11.2": { - "protocol_version": "316", - "pack_format": "3" + "protocol_version": 316, + "pack_format": 3 }, "1.12": { - "protocol_version": "335", - "pack_format": "3" + "protocol_version": 335, + "pack_format": 3 }, "1.12.0": { - "protocol_version": "335", - "pack_format": "3" + "protocol_version": 335, + "pack_format": 3 }, "1.12.1": { - "protocol_version": "338", - "pack_format": "3" + "protocol_version": 338, + "pack_format": 3 }, "1.12.2": { - "protocol_version": "340", - "pack_format": "3" + "protocol_version": 340, + "pack_format": 3 }, "1.13": { - "protocol_version": "393", - "pack_format": "4" + "protocol_version": 393, + "pack_format": 4 }, "1.13.0": { - "protocol_version": "393", - "pack_format": "4" + "protocol_version": 393, + "pack_format": 4 }, "1.13.1": { - "protocol_version": "401", - "pack_format": "4" + "protocol_version": 401, + "pack_format": 4 }, "1.13.2": { - "protocol_version": "404", - "pack_format": "4" + "protocol_version": 404, + "pack_format": 4 }, "1.14": { - "protocol_version": "477", - "pack_format": "4" + "protocol_version": 477, + "pack_format": 4 }, "1.14.0": { - "protocol_version": "477", - "pack_format": "4" + "protocol_version": 477, + "pack_format": 4 }, "1.14.1": { - "protocol_version": "480", - "pack_format": "4" + "protocol_version": 480, + "pack_format": 4 }, "1.14.2": { - "protocol_version": "485", - "pack_format": "4" + "protocol_version": 485, + "pack_format": 4 }, "1.14.3": { - "protocol_version": "490", - "pack_format": "4" + "protocol_version": 490, + "pack_format": 4 }, "1.14.4": { - "protocol_version": "498", - "pack_format": "4" + "protocol_version": 498, + "pack_format": 4 }, "1.15": { - "protocol_version": "573", - "pack_format": "5" + "protocol_version": 573, + "pack_format": 5 }, "1.15.0": { - "protocol_version": "573", - "pack_format": "5" + "protocol_version": 573, + "pack_format": 5 }, "1.15.1": { - "protocol_version": "575", - "pack_format": "5" + "protocol_version": 575, + "pack_format": 5 }, "1.15.2": { - "protocol_version": "578", - "pack_format": "5" + "protocol_version": 578, + "pack_format": 5 }, "1.16": { - "protocol_version": "735", - "pack_format": "5" + "protocol_version": 735, + "pack_format": 5 }, "1.16.0": { - "protocol_version": "735", - "pack_format": "5" + "protocol_version": 735, + "pack_format": 5 }, "1.16.1": { - "protocol_version": "736", - "pack_format": "5" + "protocol_version": 736, + "pack_format": 5 }, "1.16.2": { - "protocol_version": "751", - "pack_format": "6" + "protocol_version": 751, + "pack_format": 6 }, "1.16.3": { - "protocol_version": "753", - "pack_format": "6" + "protocol_version": 753, + "pack_format": 6 }, "1.16.4": { - "protocol_version": "754", - "pack_format": "6" + "protocol_version": 754, + "pack_format": 6 }, "1.16.5": { - "protocol_version": "754", - "pack_format": "6" + "protocol_version": 754, + "pack_format": 6 }, "1.17": { - "protocol_version": "755", - "pack_format": "7" + "protocol_version": 755, + "pack_format": 7 }, "1.17.0": { - "protocol_version": "755", - "pack_format": "7" + "protocol_version": 755, + "pack_format": 7 }, "1.17.1": { - "protocol_version": "756", - "pack_format": "7" + "protocol_version": 756, + "pack_format": 7 }, "1.18": { - "protocol_version": "757", - "pack_format": "8" + "protocol_version": 757, + "pack_format": 8 }, "1.18.0": { - "protocol_version": "757", - "pack_format": "8" + "protocol_version": 757, + "pack_format": 8 }, "1.18.1": { - "protocol_version": "758", - "pack_format": "8" + "protocol_version": 758, + "pack_format": 8 }, "1.18.2": { - "protocol_version": "758", - "pack_format": "8" + "protocol_version": 758, + "pack_format": 8 }, "1.19": { - "protocol_version": "759", - "pack_format": "9" + "protocol_version": 759, + "pack_format": 9 }, "1.19.0": { - "protocol_version": "759", - "pack_format": "9" + "protocol_version": 759, + "pack_format": 9 }, "1.19.1": { - "protocol_version": "760", - "pack_format": "9" + "protocol_version": 760, + "pack_format": 9 }, "1.19.2": { - "protocol_version": "760", - "pack_format": "9" + "protocol_version": 760, + "pack_format": 9 }, "1.19.3": { - "protocol_version": "761", - "pack_format": "12" + "protocol_version": 761, + "pack_format": 12 }, "1.19.4": { - "protocol_version": "762", - "pack_format": "13" + "protocol_version": 762, + "pack_format": 13 }, "1.20": { - "protocol_version": "763", - "pack_format": "15" + "protocol_version": 763, + "pack_format": 15 }, "1.20.0": { - "protocol_version": "763", - "pack_format": "15" + "protocol_version": 763, + "pack_format": 15 }, "1.20.1": { - "protocol_version": "763", - "pack_format": "15" + "protocol_version": 763, + "pack_format": 15 }, "1.20.2": { - "protocol_version": "764", - "pack_format": "18" + "protocol_version": 764, + "pack_format": 18 }, "1.20.3": { - "protocol_version": "765", - "pack_format": "22" + "protocol_version": 765, + "pack_format": 22 }, "1.20.4": { - "protocol_version": "765", - "pack_format": "22" + "protocol_version": 765, + "pack_format": 22 }, "1.20.5": { - "protocol_version": "766", - "pack_format": "32" + "protocol_version": 766, + "pack_format": 32 }, "1.20.6": { - "protocol_version": "766", - "pack_format": "32" + "protocol_version": 766, + "pack_format": 32 }, "1.21": { - "protocol_version": "767", - "pack_format": "34" + "protocol_version": 767, + "pack_format": 34 }, "1.21.1": { - "protocol_version": "767", - "pack_format": "34" + "protocol_version": 767, + "pack_format": 34 }, "1.21.2": { - "protocol_version": "768", - "pack_format": "42" + "protocol_version": 768, + "pack_format": 42 }, "1.21.3": { - "protocol_version": "768", - "pack_format": "42" + "protocol_version": 768, + "pack_format": 42 }, "1.21.4": { - "protocol_version": "769", - "pack_format": "46" + "protocol_version": 769, + "pack_format": 46 } } \ No newline at end of file From 2fc578e3f1fdcd4512598da6bfea33b626e66e03 Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Sat, 8 Feb 2025 03:12:47 -0500 Subject: [PATCH 27/54] Use try-with-resources --- .../com/agentdid127/resourcepack/Main.java | 14 ++++++------- .../com/agentdid127/resourcepack/GUI.java | 18 ++++++++-------- .../backwards/BackwardsPackConverter.java | 21 +++++++++++-------- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/Applications/Console/src/main/java/com/agentdid127/resourcepack/Main.java b/Applications/Console/src/main/java/com/agentdid127/resourcepack/Main.java index 5155d27f..c1afe279 100644 --- a/Applications/Console/src/main/java/com/agentdid127/resourcepack/Main.java +++ b/Applications/Console/src/main/java/com/agentdid127/resourcepack/Main.java @@ -13,7 +13,7 @@ public class Main { /** * Main class. Runs program - * + * * @param args * @throws IOException */ @@ -32,12 +32,10 @@ public static void main(String[] args) throws IOException { PrintStream out = System.out; GsonBuilder gsonBuilder = new GsonBuilder(); Gson gson = gsonBuilder.disableHtmlEscaping().create(); - - if (Util.getVersionProtocol(gson, from) > Util.getVersionProtocol(gson, to)) - new BackwardsPackConverter(from, to, light, minify, optionSet.valueOf(Options.INPUT_DIR), debug, out) - .runDir(); - else - new ForwardsPackConverter(from, to, light, minify, optionSet.valueOf(Options.INPUT_DIR), debug, out) - .runDir(); + if (Util.getVersionProtocol(gson, from) > Util.getVersionProtocol(gson, to)) { + new BackwardsPackConverter(from, to, light, minify, optionSet.valueOf(Options.INPUT_DIR), debug, out).runDir(); + } else { + new ForwardsPackConverter(from, to, light, minify, optionSet.valueOf(Options.INPUT_DIR), debug, out).runDir(); + } } } \ No newline at end of file diff --git a/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java b/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java index 684fd9d7..60feb87e 100644 --- a/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java +++ b/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java @@ -13,6 +13,7 @@ import java.io.PrintStream; import java.nio.file.Paths; import java.util.Arrays; +import java.util.Objects; public class GUI { static JFrame frame; @@ -27,13 +28,12 @@ public class GUI { private JButton convertButton; private PrintStream out; - private GsonBuilder gsonBuilder = new GsonBuilder(); - private Gson gson = gsonBuilder.disableHtmlEscaping().create(); + private final GsonBuilder gsonBuilder = new GsonBuilder(); + private final Gson gson = gsonBuilder.disableHtmlEscaping().create(); public GUI() { String[] versions = Util.getSupportedVersions(gson); - - for (String item : versions) { + for (String item : versions == null ? new String[]{} : versions) { initialVersionBox.addItem(item); finalVersionBox.addItem(item); } @@ -41,23 +41,23 @@ public GUI() { convertButton.addActionListener(e -> { out = redirectSystemStreams(); - String from = initialVersionBox.getSelectedItem().toString(); - String to = finalVersionBox.getSelectedItem().toString(); + String from = Objects.requireNonNull(initialVersionBox.getSelectedItem()).toString(); + String to = Objects.requireNonNull(finalVersionBox.getSelectedItem()).toString(); String light = "none"; boolean minify = minifyCheckBox.isSelected(); new Thread(() -> { convertButton.setVisible(false); try { - if (Util.getVersionProtocol(gson, from) > Util.getVersionProtocol(gson, to)) + if (Util.getVersionProtocol(gson, from) > Util.getVersionProtocol(gson, to)) { new BackwardsPackConverter(from, to, light, minify, Paths.get("./"), false, out).runDir(); - else + } else { new ForwardsPackConverter(from, to, light, minify, Paths.get("./"), false, out).runDir(); + } } catch (Exception exception) { out.println(Arrays.toString(exception.getStackTrace())); } convertButton.setVisible(true); - return; }).start(); }); } diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/BackwardsPackConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/BackwardsPackConverter.java index 67abc86e..740e9aa0 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/BackwardsPackConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/BackwardsPackConverter.java @@ -9,17 +9,17 @@ import com.agentdid127.resourcepack.library.utilities.Util; import com.google.gson.GsonBuilder; -import java.io.IOException; import java.io.PrintStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.Objects; +import java.util.stream.Stream; public class BackwardsPackConverter extends PackConverter { Path INPUT_DIR; public BackwardsPackConverter(String from, String to, String light, boolean minify, Path input, boolean debug, - PrintStream out) { + PrintStream out) { GsonBuilder gsonBuilder = new GsonBuilder().disableHtmlEscaping().setLenient(); if (!minify) gsonBuilder.setPrettyPrinting(); @@ -105,12 +105,15 @@ public void runPack(Pack pack) { } } - public void runDir() throws IOException { - Files.list(INPUT_DIR) - .map(Pack::parse) - .filter(Objects::nonNull) - .forEach(pack -> { - runPack(pack); - }); + public void runDir() { + try (Stream pathStream = Files.list(INPUT_DIR)) { + try (Stream packStream = pathStream.map(Pack::parse).filter(Objects::nonNull)) { + packStream.forEach(this::runPack); + } catch (Exception exception) { + Util.propagate(exception); + } + } catch (Exception exception) { + Util.propagate(exception); + } } } From e6c319bdaecf0738f671ccfcd1c7d7e9e4d65551 Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Sat, 8 Feb 2025 03:25:00 -0500 Subject: [PATCH 28/54] Use more try-with-resources --- .../backwards/BackwardsPackConverter.java | 11 +- .../backwards/impl/LangConverter.java | 101 ++++++++---------- .../backwards/impl/MCPatcherConverter.java | 97 +++++++++-------- .../backwards/impl/NameConverter.java | 2 +- .../forwards/impl/MCPatcherConverter.java | 95 ++++++++-------- 5 files changed, 155 insertions(+), 151 deletions(-) diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/BackwardsPackConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/BackwardsPackConverter.java index 740e9aa0..dda2f908 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/BackwardsPackConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/BackwardsPackConverter.java @@ -54,15 +54,14 @@ private void converterRunner(String from, String to, String light) { this.registerConverter(new InventoryConverter(this)); } - if (protocolFrom >= Util.getVersionProtocol(gson, "1.15") - && protocolTo < Util.getVersionProtocol(gson, "1.15")) { + if (protocolFrom >= Util.getVersionProtocol(gson, "1.15") && protocolTo < Util.getVersionProtocol(gson, "1.15")) { this.registerConverter(new EnchantConverter(this)); this.registerConverter(new ChestConverter(this)); } - if (protocolFrom >= Util.getVersionProtocol(gson, "1.14") - && protocolTo < Util.getVersionProtocol(gson, "1.14")) + if (protocolFrom >= Util.getVersionProtocol(gson, "1.14") && protocolTo < Util.getVersionProtocol(gson, "1.14")) { this.registerConverter(new PaintingConverter(this)); + } this.registerConverter(new ParticleTextureConverter(this, protocolFrom, protocolTo)); @@ -79,9 +78,9 @@ private void converterRunner(String from, String to, String light) { this.registerConverter(new BlockStateConverter(this, protocolFrom, protocolTo)); this.registerConverter(new ModelConverter(this, light, protocolFrom, protocolTo)); - if (protocolFrom >= Util.getVersionProtocol(gson, "1.9") - && protocolTo < Util.getVersionProtocol(gson, "1.9")) + if (protocolFrom >= Util.getVersionProtocol(gson, "1.9") && protocolTo < Util.getVersionProtocol(gson, "1.9")) { this.registerConverter(new CompassConverter(this, protocolTo)); + } } public void runPack(Pack pack) { diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/LangConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/LangConverter.java index f86fb5ee..03ab867e 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/LangConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/LangConverter.java @@ -10,50 +10,49 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import java.io.*; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.Map; +import java.util.stream.Stream; public class LangConverter extends Converter { - private String version; - private String from; + private final String from; + private final String to; - public LangConverter(PackConverter packConverter, String fromIn, String versionIn) { + public LangConverter(PackConverter packConverter, String from, String to) { super(packConverter); - version = versionIn; - from = fromIn; + this.from = from; + this.to = to; } /** * Moves Lang (properties) to JSON - * + * * @param pack * @throws IOException */ @Override public void convert(Pack pack) throws IOException { - Path langPath = pack.getWorkingPath() - .resolve("assets/minecraft/lang".replace("/", File.separator)); - if (!langPath.toFile().exists()) + Path langPath = pack.getWorkingPath().resolve("assets/minecraft/lang".replace("/", File.separator)); + if (!langPath.toFile().exists()) { return; - ArrayList models = new ArrayList(); - Files.list(langPath) - .filter(path1 -> path1.toString().endsWith(".json")) - .forEach(model -> { - PropertiesEx out = new PropertiesEx(); - try (InputStream input = new FileInputStream(model.toString())) { - JsonObject object = JsonUtil.readJson(packConverter.getGson(), model, JsonObject.class); + } - if (Util.getVersionProtocol(packConverter.getGson(), from) > Util - .getVersionProtocol(packConverter.getGson(), "1.12") - && ((Util.getVersionProtocol(packConverter.getGson(), version) < Util - .getVersionProtocol(packConverter.getGson(), "1.13")) - && (Util.getVersionProtocol(packConverter.getGson(), version) > Util - .getVersionProtocol(packConverter.getGson(), "1.13.2")))) { - JsonObject id = JsonUtil.readJsonResource(packConverter.getGson(), "/backwards/lang.json") - .getAsJsonObject("1_13"); + ArrayList models = new ArrayList<>(); + try (Stream pathStream = Files.list(langPath).filter(path1 -> path1.toString().endsWith(".json"))) { + pathStream.forEach(model -> { + PropertiesEx out = new PropertiesEx(); + try { + JsonObject object = JsonUtil.readJson(packConverter.getGson(), model, JsonObject.class); + if (Util.getVersionProtocol(packConverter.getGson(), from) > Util.getVersionProtocol(packConverter.getGson(), "1.12") + && ((Util.getVersionProtocol(packConverter.getGson(), to) < Util.getVersionProtocol(packConverter.getGson(), "1.13")) + && (Util.getVersionProtocol(packConverter.getGson(), to) > Util.getVersionProtocol(packConverter.getGson(), "1.13.2")))) { + JsonObject id = JsonUtil.readJsonResource(packConverter.getGson(), "/backwards/lang.json").getAsJsonObject("1_13"); + if (object != null) { object.keySet().forEach(key -> { String value = object.get(key).getAsString(); for (Map.Entry id2 : id.entrySet()) { @@ -63,11 +62,11 @@ public void convert(Pack pack) throws IOException { } }); } + } - if (Util.getVersionProtocol(packConverter.getGson(), version) <= Util - .getVersionProtocol(packConverter.getGson(), "1.14")) { - JsonObject id = JsonUtil.readJsonResource(packConverter.getGson(), "/backwards/lang.json") - .getAsJsonObject("1_14"); + if (Util.getVersionProtocol(packConverter.getGson(), to) <= Util.getVersionProtocol(packConverter.getGson(), "1.14")) { + JsonObject id = JsonUtil.readJsonResource(packConverter.getGson(), "/backwards/lang.json").getAsJsonObject("1_14"); + if (object != null) { object.keySet().forEach(key -> { String value = object.get(key).getAsString(); for (Map.Entry id2 : id.entrySet()) @@ -75,34 +74,28 @@ public void convert(Pack pack) throws IOException { out.setProperty(id2.getValue().getAsString(), value); }); } - - input.close(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } - try { - int modelNoJson = model.getFileName().toString().indexOf(".json"); - String file2 = model.getFileName().toString().substring(0, modelNoJson); - Logger.debug("Saving: " + file2 + ".lang"); - out.store( - new FileOutputStream( - pack.getWorkingPath() - .resolve(("assets/minecraft/lang/" + file2 + ".lang").replace("/", - File.separator)) - .toFile()), - ""); - } catch (IOException e) { - e.printStackTrace(); - } + try { + int modelNoJson = model.getFileName().toString().indexOf(".json"); + String file2 = model.getFileName().toString().substring(0, modelNoJson); + Logger.debug("Saving: " + file2 + ".lang"); + out.store(Files.newOutputStream(pack.getWorkingPath().resolve(("assets/minecraft/lang/" + file2 + ".lang").replace("/", File.separator)).toFile().toPath()), ""); + } catch (IOException e) { + e.printStackTrace(); + } + + models.add(model.getFileName().toString()); + }); + } - models.add(model.getFileName().toString()); - }); - for (int i = 0; i < models.size(); i++) { - Path langFilePath = pack.getWorkingPath() - .resolve(("assets/minecraft/lang/" + models.get(i)).replace("/", File.separator)); + for (String model : models) { + Path langFilePath = pack.getWorkingPath().resolve(("assets/minecraft/lang/" + model).replace("/", File.separator)); Logger.debug("Deleting: " + langFilePath); Files.delete(langFilePath); } diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/MCPatcherConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/MCPatcherConverter.java index 53aecfcd..d3fcdd59 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/MCPatcherConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/MCPatcherConverter.java @@ -9,9 +9,16 @@ import com.agentdid127.resourcepack.library.utilities.Util; import com.google.gson.JsonObject; -import java.io.*; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Objects; +import java.util.stream.Stream; @Deprecated // will be removed when extensions are made public class MCPatcherConverter extends Converter { @@ -21,73 +28,72 @@ public MCPatcherConverter(PackConverter packConverter) { /** * Parent conversion for MCPatcher - * + * * @param pack * @throws IOException */ @Override public void convert(Pack pack) throws IOException { - Path models = pack.getWorkingPath() - .resolve("assets/minecraft/mcpatcher".replace("/", File.separator)); - if (models.toFile().exists()) + Path models = pack.getWorkingPath().resolve("assets/minecraft/mcpatcher".replace("/", File.separator)); + if (models.toFile().exists()) { findFiles(models); + } // remapModelJson(models.resolve("item")); // remapModelJson(models.resolve("block")); } /** * Finds all files in Path path - * + * * @param path * @throws IOException */ protected void findFiles(Path path) throws IOException { File directory = path.toFile(); - for (File file : directory.listFiles()) { - if (file.isDirectory()) - continue; - remapProperties(file.toPath()); - findFiles(file.toPath()); + for (File file : Objects.requireNonNull(directory.listFiles())) { + if (!file.isDirectory()) { + remapProperties(file.toPath()); + findFiles(file.toPath()); + } } } /** * Remaps properties to work in newer versions - * + * * @param path * @throws IOException */ protected void remapProperties(Path path) throws IOException { - if (!path.toFile().exists()) - return; - Files.list(path) - .filter(path1 -> path1.toString().endsWith(".properties")) - .forEach(model -> { - try (InputStream input = new FileInputStream(model.toString())) { + if (path.toFile().exists()) { + try (Stream pathStream = Files.list(path).filter(path1 -> path1.toString().endsWith(".properties"))) { + pathStream.forEach(model -> { + Path inputStreamPath = Paths.get(model.toString()); + try (InputStream input = Files.newInputStream(inputStreamPath)) { Logger.debug("Updating:" + model.getFileName()); PropertiesEx prop = new PropertiesEx(); prop.load(input); - - try (OutputStream output = new FileOutputStream(model.toString())) { + try (OutputStream output = Files.newOutputStream(inputStreamPath)) { // updates textures - if (prop.containsKey("texture")) + if (prop.containsKey("texture")) { prop.setProperty("texture", replaceTextures(prop)); + } // Updates Item IDs - if (prop.containsKey("matchItems")) - prop.setProperty("matchItems", - updateID("matchItems", prop, "regular").replaceAll("\"", "")); + if (prop.containsKey("matchItems")) { + prop.setProperty("matchItems", updateID("matchItems", prop, "regular").replaceAll("\"", "")); + } - if (prop.containsKey("items")) + if (prop.containsKey("items")) { prop.setProperty("items", updateID("items", prop, "regular").replaceAll("\"", "")); + } - if (prop.containsKey("matchBlocks")) - prop.setProperty("matchBlocks", - updateID("matchBlocks", prop, "regular").replaceAll("\"", "")); + if (prop.containsKey("matchBlocks")) { + prop.setProperty("matchBlocks", updateID("matchBlocks", prop, "regular").replaceAll("\"", "")); + } // Saves File prop.store(output, ""); - output.close(); } catch (IOException io) { io.printStackTrace(); } @@ -95,44 +101,47 @@ protected void remapProperties(Path path) throws IOException { throw Util.propagate(e); } }); + } + } } /** * Replaces texture paths with blocks and items - * + * * @param prop * @return */ protected String replaceTextures(PropertiesEx prop) { NameConverter nameConverter = packConverter.getConverter(NameConverter.class); String properties = prop.getProperty("texture"); - if (properties.startsWith("textures/block/")) + if (properties.startsWith("textures/block/")) { properties = "textures/blocks/" + nameConverter.getBlockMapping(); - else if (properties.startsWith("textures/item/")) + } else if (properties.startsWith("textures/item/")) { properties = "textures/items/" + nameConverter.getItemMapping(); + } return properties; } /** * Fixes item IDs and switches them from a numerical id to minecraft: something - * + * * @param type * @param prop * @return */ protected String updateID(String type, PropertiesEx prop, String selection) { - JsonObject id = JsonUtil.readJsonResource(packConverter.getGson(), "/backwards/ids.json").get(selection) - .getAsJsonObject(); + JsonObject id = JsonUtil.readJsonResource(packConverter.getGson(), "/backwards/ids.json").get(selection).getAsJsonObject(); String[] split = prop.getProperty(type).split(" "); - String properties2 = " "; - for (int i = 0; i < split.length; i++) - if (id.get(split[i]) != null) + StringBuilder properties2 = new StringBuilder(" "); + for (int i = 0; i < split.length; i++) { + if (id.get(split[i]) != null) { split[i] = id.get(split[i]).getAsString(); - for (String item : split) - properties2 += item + " "; - properties2.substring(0, properties2.length() - 1); - if (prop.containsKey("metadata")) - prop.remove("metadata"); - return properties2; + } + } + Arrays.stream(split).forEach(item -> properties2.append(item).append(" ")); + // TODO/NOTE: Might of broken this? Originally returned properties2.toString() & ignored the line below + String output = properties2.substring(0, properties2.length() - 1); + prop.remove("metadata"); + return output; } } diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/NameConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/NameConverter.java index 5c8097ac..e329d7a0 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/NameConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/NameConverter.java @@ -334,7 +334,7 @@ protected void renameAll(Mapping mapping, String extension, Path path) throws IO } Files.list(path) - .filter(path1 -> path.toString().endsWith(extension)) + .filter(path1 -> path1.toString().endsWith(extension)) .forEach(path1 -> { String baseName = path1.getFileName().toString().substring(0, path1.getFileName().toString().length() - extension.length()); // NOTE: skip the already renamed grass blocks diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java index d0074e3d..d6512f2c 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java @@ -12,6 +12,8 @@ import java.io.*; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Arrays; +import java.util.stream.Stream; @Deprecated // will be removed when extensions are made public class MCPatcherConverter extends Converter { @@ -21,7 +23,7 @@ public MCPatcherConverter(PackConverter packConverter) { /** * Parent conversion for MCPatcher - * + * * @param pack * @throws IOException */ @@ -37,7 +39,7 @@ public void convert(Pack pack) throws IOException { /** * Finds all files in the specified path - * + * * @param path * @throws IOException */ @@ -53,84 +55,85 @@ protected void findFiles(Path path) throws IOException { /** * Remaps properties to work in newer versions - * + * * @param path * @throws IOException */ protected void remapProperties(Path path) throws IOException { - if (!path.toFile().exists()) - return; + if (path.toFile().exists()) { + try (Stream pathStream = Files.list(path).filter(path1 -> path1.toString().endsWith(".properties"))) { + pathStream.forEach(model -> { + try (InputStream input = new FileInputStream(model.toString())) { + Logger.debug("Updating:" + model.getFileName()); - Files.list(path).filter(path1 -> path1.toString().endsWith(".properties")).forEach(model -> { - try (InputStream input = new FileInputStream(model.toString())) { - Logger.debug("Updating:" + model.getFileName()); + PropertiesEx prop = new PropertiesEx(); + prop.load(input); - PropertiesEx prop = new PropertiesEx(); - prop.load(input); + try (OutputStream output = new FileOutputStream(model.toString())) { + // updates textures + if (prop.containsKey("texture")) + prop.setProperty("texture", replaceTextures(prop)); - try (OutputStream output = new FileOutputStream(model.toString())) { - // updates textures - if (prop.containsKey("texture")) - prop.setProperty("texture", replaceTextures(prop)); + // Updates Item IDs + if (prop.containsKey("matchItems")) + prop.setProperty("matchItems", updateID("matchItems", prop, "regular").replaceAll("\"", "")); - // Updates Item IDs - if (prop.containsKey("matchItems")) - prop.setProperty("matchItems", updateID("matchItems", prop, "regular").replaceAll("\"", "")); + if (prop.containsKey("items")) + prop.setProperty("items", updateID("items", prop, "regular").replaceAll("\"", "")); - if (prop.containsKey("items")) - prop.setProperty("items", updateID("items", prop, "regular").replaceAll("\"", "")); + if (prop.containsKey("matchBlocks")) + prop.setProperty("matchBlocks", updateID("matchBlocks", prop, "regular").replaceAll("\"", "")); - if (prop.containsKey("matchBlocks")) - prop.setProperty("matchBlocks", updateID("matchBlocks", prop, "regular").replaceAll("\"", "")); - - // Saves File - prop.store(output, ""); - output.close(); - } catch (IOException io) { - io.printStackTrace(); - } - } catch (IOException e) { - throw Util.propagate(e); + // Saves File + prop.store(output, ""); + } catch (IOException io) { + io.printStackTrace(); + } + } catch (IOException e) { + throw Util.propagate(e); + } + }); } - }); + } } /** * Replaces texture paths with blocks and items - * + * * @param prop * @return */ protected String replaceTextures(PropertiesEx prop) { NameConverter nameConverter = packConverter.getConverter(NameConverter.class); String properties = prop.getProperty("texture"); - if (properties.startsWith("textures/blocks/")) + if (properties.startsWith("textures/blocks/")) { properties = "textures/block/" + nameConverter.getBlockMapping_1_13(); - else if (properties.startsWith("textures/items/")) + } else if (properties.startsWith("textures/items/")) { properties = "textures/item/" + nameConverter.getItemMapping_1_13(); + } return properties; } /** * Fixes item IDs and switches them from a numerical id to minecraft: something - * + * * @param type * @param prop * @return */ protected String updateID(String type, PropertiesEx prop, String selection) { - JsonObject id = JsonUtil.readJsonResource(packConverter.getGson(), "/forwards/ids.json").get(selection) - .getAsJsonObject(); + JsonObject id = JsonUtil.readJsonResource(packConverter.getGson(), "/forwards/ids.json").get(selection).getAsJsonObject(); String[] split = prop.getProperty(type).split(" "); - String properties2 = " "; - for (int i = 0; i < split.length; i++) - if (id.get(split[i]) != null) + StringBuilder properties2 = new StringBuilder(" "); + for (int i = 0; i < split.length; i++) { + if (id.get(split[i]) != null) { split[i] = "minecraft:" + id.get(split[i]).getAsString(); - for (String item : split) - properties2 += item + " "; - properties2.substring(0, properties2.length() - 1); - if (prop.containsKey("metadata")) - prop.remove("metadata"); - return properties2; + } + } + Arrays.stream(split).forEach(item -> properties2.append(item).append(" ")); + // TODO/NOTE: Might of broken this? Originally returned properties2.toString() & ignored the line below + String output = properties2.substring(0, properties2.length() - 1); + prop.remove("metadata"); + return output; } } From 94f8d91a198c66f65133ccda2306ddd3163ffea5 Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Sat, 8 Feb 2025 03:27:36 -0500 Subject: [PATCH 29/54] Use updated gson 'setStrictness' --- .../backwards/BackwardsPackConverter.java | 15 +- .../forwards/ForwardsPackConverter.java | 6 +- .../library/utilities/JsonUtil.java | 177 +++++++++--------- 3 files changed, 101 insertions(+), 97 deletions(-) diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/BackwardsPackConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/BackwardsPackConverter.java index dda2f908..2031a351 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/BackwardsPackConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/BackwardsPackConverter.java @@ -8,6 +8,7 @@ import com.agentdid127.resourcepack.library.utilities.Logger; import com.agentdid127.resourcepack.library.utilities.Util; import com.google.gson.GsonBuilder; +import com.google.gson.Strictness; import java.io.PrintStream; import java.nio.file.Files; @@ -20,9 +21,10 @@ public class BackwardsPackConverter extends PackConverter { public BackwardsPackConverter(String from, String to, String light, boolean minify, Path input, boolean debug, PrintStream out) { - GsonBuilder gsonBuilder = new GsonBuilder().disableHtmlEscaping().setLenient(); - if (!minify) + GsonBuilder gsonBuilder = new GsonBuilder().disableHtmlEscaping().setStrictness(Strictness.LENIENT); + if (!minify) { gsonBuilder.setPrettyPrinting(); + } gson = gsonBuilder.create(); Logger.setDebug(debug); Logger.setStream(out); @@ -54,12 +56,14 @@ private void converterRunner(String from, String to, String light) { this.registerConverter(new InventoryConverter(this)); } - if (protocolFrom >= Util.getVersionProtocol(gson, "1.15") && protocolTo < Util.getVersionProtocol(gson, "1.15")) { + if (protocolFrom >= Util.getVersionProtocol(gson, "1.15") && + protocolTo < Util.getVersionProtocol(gson, "1.15")) { this.registerConverter(new EnchantConverter(this)); this.registerConverter(new ChestConverter(this)); } - if (protocolFrom >= Util.getVersionProtocol(gson, "1.14") && protocolTo < Util.getVersionProtocol(gson, "1.14")) { + if (protocolFrom >= Util.getVersionProtocol(gson, "1.14") && + protocolTo < Util.getVersionProtocol(gson, "1.14")) { this.registerConverter(new PaintingConverter(this)); } @@ -78,7 +82,8 @@ private void converterRunner(String from, String to, String light) { this.registerConverter(new BlockStateConverter(this, protocolFrom, protocolTo)); this.registerConverter(new ModelConverter(this, light, protocolFrom, protocolTo)); - if (protocolFrom >= Util.getVersionProtocol(gson, "1.9") && protocolTo < Util.getVersionProtocol(gson, "1.9")) { + if (protocolFrom >= Util.getVersionProtocol(gson, "1.9") && + protocolTo < Util.getVersionProtocol(gson, "1.9")) { this.registerConverter(new CompassConverter(this, protocolTo)); } } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java index 2a7aaa5a..dc95bafc 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java @@ -8,6 +8,7 @@ import com.agentdid127.resourcepack.library.utilities.Logger; import com.agentdid127.resourcepack.library.utilities.Util; import com.google.gson.GsonBuilder; +import com.google.gson.Strictness; import java.io.IOException; import java.io.PrintStream; @@ -20,9 +21,10 @@ public class ForwardsPackConverter extends PackConverter { public ForwardsPackConverter(String from, String to, String light, boolean minify, Path input, boolean debug, PrintStream out) { - GsonBuilder gsonBuilder = new GsonBuilder().setLenient(); - if (!minify) + GsonBuilder gsonBuilder = new GsonBuilder().setStrictness(Strictness.LENIENT); + if (!minify) { gsonBuilder.setPrettyPrinting(); + } gson = gsonBuilder.create(); Logger.setDebug(debug); Logger.setStream(out); diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/JsonUtil.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/JsonUtil.java index 14e0fb0b..033a2f73 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/JsonUtil.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/JsonUtil.java @@ -1,10 +1,7 @@ package com.agentdid127.resourcepack.library.utilities; import com.agentdid127.resourcepack.library.PackConverter; -import com.google.gson.Gson; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; +import com.google.gson.*; import com.google.gson.stream.JsonReader; import java.io.IOException; @@ -17,90 +14,90 @@ import java.util.Collections; public class JsonUtil { - public static JsonArray add(JsonArray lhs, JsonArray rhs) { - return add(lhs, rhs, (byte) 1); - } - - public static JsonArray add(JsonArray lhs, JsonArray rhs, byte sign) { - JsonArray newArray = new JsonArray(); - for (int i = 0; i < 3; i++) - newArray.add(add(lhs, rhs, i, sign)); - return newArray; - } - - public static float add(JsonArray lhs, JsonArray rhs, int i, byte sign) { - return lhs.get(i).getAsFloat() + sign * rhs.get(i).getAsFloat(); - } - - public static float multiply(JsonArray lhs, JsonArray rhs, int i) { - return lhs.get(i).getAsFloat() * rhs.get(i).getAsFloat(); - } - - public static float divide(JsonArray lhs, JsonArray rhs, int i) { - return lhs.get(i).getAsFloat() / rhs.get(i).getAsFloat(); - } - - public static JsonArray subtract(JsonArray lhs, JsonArray rhs) { - return add(lhs, rhs, (byte) -1); - } - - public static JsonArray multiply(JsonArray lhs, JsonArray rhs) { - JsonArray newArray = new JsonArray(); - for (int i = 0; i < 3; i++) - newArray.add(multiply(lhs, rhs, i)); - return newArray; - } - - public static JsonArray divide(JsonArray lhs, JsonArray rhs) { - JsonArray newArray = new JsonArray(); - for (int i = 0; i < 3; i++) - newArray.add(divide(lhs, rhs, i)); - return newArray; - } - - public static JsonArray asArray(Gson gson, String raw) { - return gson.fromJson(raw, JsonArray.class); - } - - public static void writeJson(Gson gson, Path out, JsonElement json) throws IOException { - Files.write(out, Collections.singleton(gson.toJson(json)), StandardCharsets.UTF_8); - } - - public static boolean isJson(Gson gson, String Json) { - try { - gson.fromJson(Json, Object.class); - return true; - } catch (com.google.gson.JsonSyntaxException ex) { - return false; - } - } - - public static T readJson(Gson gson, Path path, Class clazz) throws IOException { - String json = Util.readFromFile(path); - if (!isJson(gson, json)) - return null; - JsonReader reader = new JsonReader(new StringReader(json)); - reader.setLenient(true); - return gson.fromJson(reader, clazz); - } - - public static JsonObject readJson(Gson gson, Path path) throws IOException { - return readJson(gson, path, JsonObject.class); - } - - public static T readJsonResource(Gson gson, String path, Class clazz) { - try (InputStream stream = PackConverter.class.getResourceAsStream(path)) { - if (stream == null) - return null; - try (InputStreamReader streamReader = new InputStreamReader(stream)) { - return gson.fromJson(streamReader, clazz); - } - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public static JsonObject readJsonResource(Gson gson, String path) { - return readJsonResource(gson, path, JsonObject.class); - } + public static JsonArray add(JsonArray lhs, JsonArray rhs) { + return add(lhs, rhs, (byte) 1); + } + + public static JsonArray add(JsonArray lhs, JsonArray rhs, byte sign) { + JsonArray newArray = new JsonArray(); + for (int i = 0; i < 3; i++) + newArray.add(add(lhs, rhs, i, sign)); + return newArray; + } + + public static float add(JsonArray lhs, JsonArray rhs, int i, byte sign) { + return lhs.get(i).getAsFloat() + sign * rhs.get(i).getAsFloat(); + } + + public static float multiply(JsonArray lhs, JsonArray rhs, int i) { + return lhs.get(i).getAsFloat() * rhs.get(i).getAsFloat(); + } + + public static float divide(JsonArray lhs, JsonArray rhs, int i) { + return lhs.get(i).getAsFloat() / rhs.get(i).getAsFloat(); + } + + public static JsonArray subtract(JsonArray lhs, JsonArray rhs) { + return add(lhs, rhs, (byte) -1); + } + + public static JsonArray multiply(JsonArray lhs, JsonArray rhs) { + JsonArray newArray = new JsonArray(); + for (int i = 0; i < 3; i++) + newArray.add(multiply(lhs, rhs, i)); + return newArray; + } + + public static JsonArray divide(JsonArray lhs, JsonArray rhs) { + JsonArray newArray = new JsonArray(); + for (int i = 0; i < 3; i++) + newArray.add(divide(lhs, rhs, i)); + return newArray; + } + + public static JsonArray asArray(Gson gson, String raw) { + return gson.fromJson(raw, JsonArray.class); + } + + public static void writeJson(Gson gson, Path out, JsonElement json) throws IOException { + Files.write(out, Collections.singleton(gson.toJson(json)), StandardCharsets.UTF_8); + } + + public static boolean isJson(Gson gson, String Json) { + try { + gson.fromJson(Json, Object.class); + return true; + } catch (com.google.gson.JsonSyntaxException ex) { + return false; + } + } + + public static T readJson(Gson gson, Path path, Class clazz) throws IOException { + String json = Util.readFromFile(path); + if (!isJson(gson, json)) + return null; + JsonReader reader = new JsonReader(new StringReader(json)); + reader.setStrictness(Strictness.LENIENT); + return gson.fromJson(reader, clazz); + } + + public static JsonObject readJson(Gson gson, Path path) throws IOException { + return readJson(gson, path, JsonObject.class); + } + + public static T readJsonResource(Gson gson, String path, Class clazz) { + try (InputStream stream = PackConverter.class.getResourceAsStream(path)) { + if (stream == null) + return null; + try (InputStreamReader streamReader = new InputStreamReader(stream)) { + return gson.fromJson(streamReader, clazz); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public static JsonObject readJsonResource(Gson gson, String path) { + return readJsonResource(gson, path, JsonObject.class); + } } From f793f397737c2c3d95e77ec58d50278033818699 Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Sat, 8 Feb 2025 03:31:48 -0500 Subject: [PATCH 30/54] Fix error when moving 'fishing_hook' particle --- .../impl/textures/ParticleTextureConverter.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java index d0044972..9cfbe0ab 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java @@ -32,15 +32,16 @@ public ParticleTextureConverter(PackConverter packConverter, int from, int to) { @Override public void convert(Pack pack) throws IOException { Path texturesPath = pack.getWorkingPath().resolve("assets/minecraft/textures".replace("/", File.separator)); - if (!texturesPath.toFile().exists()) + if (!texturesPath.toFile().exists()) { return; + } Path particlePath = texturesPath.resolve("particle"); - if (!particlePath.toFile().exists()) + if (!particlePath.toFile().exists()) { return; + } Gson gson = packConverter.getGson(); - JsonObject particlesJson = JsonUtil.readJsonResource(gson, "/forwards/particles.json", JsonObject.class); assert particlesJson != null; @@ -65,7 +66,11 @@ public void convert(Pack pack) throws IOException { to >= Util.getVersionProtocol(gson, "1.14")) { Slicer.runSlicer(gson, slice, particlePath, SlicerConverter.PredicateRunnable.class, from, false); Path entityPath = texturesPath.resolve("entity"); - FileUtil.moveIfExists(particlePath.resolve("fishing_hook.png"), entityPath.resolve("fishing_hook.png")); + Path newFishingHookPath = entityPath.resolve("fishing_hook.png"); + if (newFishingHookPath.toFile().exists()) { + newFishingHookPath.toFile().delete(); + } + FileUtil.moveIfExists(particlePath.resolve("fishing_hook.png"), newFishingHookPath); } } } \ No newline at end of file From 593dc64b8bcab165e3b6a37b8b42227b9b965c03 Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Sat, 8 Feb 2025 17:18:53 -0500 Subject: [PATCH 31/54] Work on fixing model conversion --- conversions/Forwards/pom.xml | 4 +- .../forwards/ForwardsPackConverter.java | 2 +- .../forwards/impl/AnimationConverter.java | 64 +- .../forwards/impl/BlockStateConverter.java | 118 +-- .../forwards/impl/ModelConverter.java | 829 +++++++++--------- .../forwards/impl/NameConverter.java | 10 +- 6 files changed, 510 insertions(+), 517 deletions(-) diff --git a/conversions/Forwards/pom.xml b/conversions/Forwards/pom.xml index f4ddff0b..97dc06c6 100644 --- a/conversions/Forwards/pom.xml +++ b/conversions/Forwards/pom.xml @@ -13,8 +13,8 @@ org.apache.maven.plugins maven-compiler-plugin - 11 - 11 + 16 + 16 diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java index dc95bafc..c42c3312 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java @@ -53,7 +53,7 @@ private void converterRunner(String from, String to, String light) { this.registerConverter(new SpacesConverter(this)); } - this.registerConverter(new ModelConverter(this, light, protocolTo, protocolFrom)); + this.registerConverter(new ModelConverter(this, light, protocolFrom, protocolTo)); if (protocolFrom <= Util.getVersionProtocol(gson, "1.12.2") && protocolTo >= Util.getVersionProtocol(gson, "1.13")) { diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/AnimationConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/AnimationConverter.java index 1df3f78f..f969ae17 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/AnimationConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/AnimationConverter.java @@ -13,6 +13,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.stream.Stream; public class AnimationConverter extends Converter { public AnimationConverter(PackConverter packConverter) { @@ -21,51 +22,48 @@ public AnimationConverter(PackConverter packConverter) { @Override public void convert(Pack pack) throws IOException { - fixAnimations(pack.getWorkingPath().resolve( - "assets/minecraft/textures/block".replace("/", File.separator))); - fixAnimations(pack.getWorkingPath().resolve( - "assets/minecraft/textures/item".replace("/", File.separator))); + Path texturesPath = pack.getWorkingPath().resolve("assets/minecraft/textures".replace("/", File.separator)); + fixAnimations(texturesPath.resolve("block")); + fixAnimations(texturesPath.resolve("item")); } /** * Updates animated images to newer versions - * + * * @param animations * @throws IOException */ protected void fixAnimations(Path animations) throws IOException { if (!animations.toFile().exists()) return; - Files.list(animations) - .filter(file -> file.toString().endsWith(".png.mcmeta")) - .forEach(file -> { - try { - JsonObject json = JsonUtil.readJson(packConverter.getGson(), file); - - if (json != null) { - boolean anyChanges = false; - JsonElement animationElement = json.get("animation"); - if (animationElement instanceof JsonObject) { - JsonObject animationObject = (JsonObject) animationElement; - - // TODO: Confirm this doesn't break any packs - animationObject.remove("width"); - animationObject.remove("height"); - - anyChanges = true; - } + Logger.addTab(); + try (Stream pathStream = Files.list(animations).filter(file -> file.toString().endsWith(".png.mcmeta"))) { + pathStream.forEach(file -> { + try { + JsonObject json = JsonUtil.readJson(packConverter.getGson(), file); + if (json != null) { + boolean anyChanges = false; + JsonElement animationElement = json.get("animation"); + if (animationElement instanceof JsonObject animationObject) { + // TODO: Confirm this doesn't break any packs + animationObject.remove("width"); + animationObject.remove("height"); + anyChanges = true; + } - if (anyChanges) { - JsonUtil.writeJson(packConverter.getGson(), file, json); - Logger.debug("Converted " + file.getFileName()); - } - } else { - Logger.log("File: " + file.getFileName() + " is not a valid JSON file."); + if (anyChanges) { + JsonUtil.writeJson(packConverter.getGson(), file, json); + Logger.debug("Converted " + file.getFileName()); } - } catch (IOException e) { - Logger.log("Failed to convert file: " + file.getFileName()); - Util.propagate(e); + } else { + Logger.log("File: " + file.getFileName() + " is not a valid JSON file."); } - }); + } catch (IOException e) { + Logger.log("Failed to convert file: " + file.getFileName()); + Util.propagate(e); + } + }); + } + Logger.subTab(); } } \ No newline at end of file diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.java index 134868f9..d6d4c564 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.java @@ -15,21 +15,23 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Map; +import java.util.stream.Stream; public class BlockStateConverter extends Converter { + private final int from; + private final int to; private boolean anyChanges; - private int from, to; public BlockStateConverter(PackConverter packConverter, int from, int to) { super(packConverter); - this.anyChanges = false; this.from = from; this.to = to; + this.anyChanges = false; } /** * Updates blockstates in blockstates folder - * + * * @param pack * @throws IOException */ @@ -38,77 +40,79 @@ public void convert(Pack pack) throws IOException { Path states = pack.getWorkingPath().resolve("assets/minecraft/blockstates".replace("/", File.separator)); if (!states.toFile().exists()) return; - Files.list(states) - .filter(file -> file.toString().endsWith(".json")) - .forEach(file -> { - try { - JsonObject json = JsonUtil.readJson(packConverter.getGson(), file); - if (json != null) { - // process multipart - if (json.has("multipart")) { - JsonElement multipart = json.get("multipart"); - if (multipart.isJsonArray()) { - JsonArray multipartArray = multipart.getAsJsonArray(); - for (JsonElement element : multipartArray) { - JsonObject multipartObject = element.getAsJsonObject(); - for (Map.Entry entry : multipartObject.entrySet()) - updateModelPath(entry); - } + Logger.addTab(); + try (Stream pathStream = Files.list(states).filter(file -> file.toString().endsWith(".json"))) { + pathStream.forEach(file -> { + try { + JsonObject json = JsonUtil.readJson(packConverter.getGson(), file); + if (json != null) { + // process multipart + if (json.has("multipart")) { + JsonElement multipart = json.get("multipart"); + if (multipart.isJsonArray()) { + JsonArray multipartArray = multipart.getAsJsonArray(); + for (JsonElement element : multipartArray) { + JsonObject multipartObject = element.getAsJsonObject(); + for (Map.Entry entry : multipartObject.entrySet()) + updateModelPath(entry); } } + } - // process variants - if (json.has("variants")) { - JsonElement variants = json.get("variants"); - if (variants.isJsonObject()) { - JsonObject variantsObject = variants.getAsJsonObject(); - // change "normal" key to "" - if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.12.2") - && to >= Util.getVersionProtocol(packConverter.getGson(), "1.13") - && variantsObject.has("normal")) { - JsonElement normal = variantsObject.get("normal"); - if (normal instanceof JsonObject || normal instanceof JsonArray) { - variantsObject.add("", normal); - variantsObject.remove("normal"); - anyChanges = true; - } + // process variants + if (json.has("variants")) { + JsonElement variants = json.get("variants"); + if (variants.isJsonObject()) { + JsonObject variantsObject = variants.getAsJsonObject(); + // change "normal" key to "" + if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.12.2") + && to >= Util.getVersionProtocol(packConverter.getGson(), "1.13") + && variantsObject.has("normal")) { + JsonElement normal = variantsObject.get("normal"); + if (normal instanceof JsonObject || normal instanceof JsonArray) { + variantsObject.add("", normal); + variantsObject.remove("normal"); + anyChanges = true; } - - // update model paths to prepend block - for (Map.Entry entry : variantsObject.entrySet()) - updateModelPath(entry); } - } - if (anyChanges) { - JsonUtil.writeJson(packConverter.getGson(), file, json); - Logger.debug("Converted " + file.getFileName()); + // update model paths to prepend block + for (Map.Entry entry : variantsObject.entrySet()) + updateModelPath(entry); } - } else { - Logger.log("Failed to convert: " + file.getFileName() + " as JSON is invalid."); } - } catch (IOException e) { - Util.propagate(e); + + if (anyChanges) { + JsonUtil.writeJson(packConverter.getGson(), file, json); + Logger.debug("Converted " + file.getFileName()); + } + } else { + Logger.log("Failed to convert: " + file.getFileName() + " as JSON is invalid."); } - }); + } catch (IOException e) { + Util.propagate(e); + } + }); + } + Logger.subTab(); } /** * Updates Model paths - * + * * @param entry */ private void updateModelPath(Map.Entry entry) { - if (entry.getValue() instanceof JsonObject) { - JsonObject value = (JsonObject) entry.getValue(); - if (value.has("model")) + if (entry.getValue() instanceof JsonObject value) { + if (value.has("model")) { updateModelObject(value); + } } else if (entry.getValue() instanceof JsonArray) { for (JsonElement jsonElement : ((JsonArray) entry.getValue())) { - if (jsonElement instanceof JsonObject) { - JsonObject value = (JsonObject) jsonElement; - if (value.has("model")) + if (jsonElement instanceof JsonObject value) { + if (value.has("model")) { updateModelObject(value); + } } } } @@ -119,8 +123,7 @@ private void updateModelObject(JsonObject value) { String[] split = value.get("model").getAsString().split("/"); String val = split[split.length - 1]; - String prefix = value.get("model").getAsString().substring(0, - value.get("model").getAsString().length() - val.length()); + String prefix = value.get("model").getAsString().substring(0, value.get("model").getAsString().length() - val.length()); if (from < Util.getVersionProtocol(packConverter.getGson(), "1.9") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.9")) { @@ -159,7 +162,8 @@ private void updateModelObject(JsonObject value) { anyChanges = true; } - if (anyChanges) + if (anyChanges) { value.addProperty("model", prefix + val); + } } } \ No newline at end of file diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java index 5dc2d68f..0ae23fdd 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java @@ -16,424 +16,417 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Map; +import java.util.Objects; +import java.util.stream.Stream; public class ModelConverter extends Converter { - private int version; - private int from; - protected String light = "none"; - - public ModelConverter(PackConverter packConverter, String lightIn, int versionIn, int fromIn) { - super(packConverter); - light = lightIn; - version = versionIn; - from = fromIn; - } - - /** - * Runs findfiles with the directory Models - * - * @param pack - * @throws IOException - */ - @Override - public void convert(Pack pack) throws IOException { - Path models = pack.getWorkingPath() - .resolve("assets/minecraft/models".replace("/", File.separator)); - if (!models.toFile().exists()) - return; - findFiles(models); - } - - /** - * Recursively finds files with Path path and runs remapModelJson - * - * @param path - * @throws IOException - */ - protected void findFiles(Path path) throws IOException { - File directory = path.toFile(); - for (File file : directory.listFiles()) { - if (file.isDirectory()) - continue; - remapModelJson(file.toPath()); - findFiles(file.toPath()); - } - } - - /** - * Updates model Json to newer versions - * - * @param path - * @throws IOException - */ - protected void remapModelJson(Path path) throws IOException { - if (!path.toFile().exists()) - return; - Files.list(path) - .filter(path1 -> path1.toString().endsWith(".json")) - .forEach(model -> { - try { - JsonObject jsonObject; - if (JsonUtil.readJson(packConverter.getGson(), model) != null - && JsonUtil.readJson(packConverter.getGson(), model).isJsonObject()) - jsonObject = JsonUtil.readJson(packConverter.getGson(), model); - else { - Logger.debug("Could not convert model: " + model.getFileName()); - Logger.addTab(); - if (JsonUtil.readJson(packConverter.getGson(), model) == null) - Logger.debug("Check for Syntax Errors in file."); - else Logger.debug("File is not JSON Object."); - Logger.subTab(); - return; - } - - // GUI light system for 1.15.2 - if (!light.equals("none") && (light.equals("front") || light.equals("side"))) - jsonObject.addProperty("gui_light", light); - - // minify the json so we can replace spaces in paths easily - // TODO Improvement: handle this in a cleaner way? - String content = jsonObject.toString(); - content = content.replaceAll("items/", "item/"); - content = content.replaceAll("blocks/", "block/"); - content = content.replaceAll(" ", "_"); - - // handle the remapping of textures, for models that use default texture names - jsonObject = packConverter.getGson().fromJson(content, JsonObject.class); - if (jsonObject.keySet().isEmpty() || jsonObject.entrySet().isEmpty()) { - Logger.debug("Model '" + model.getFileName() + "' was empty, skipping..."); - return; - } - - if (jsonObject.has("textures") && jsonObject.get("textures").isJsonObject()) { - NameConverter nameConverter = packConverter.getConverter(NameConverter.class); - - JsonObject initialTextureObject = jsonObject.getAsJsonObject("textures"); - JsonObject textureObject = initialTextureObject.deepCopy(); - for (Map.Entry entry : initialTextureObject.entrySet()) { - String value = entry.getValue().getAsString(); - textureObject.remove(entry.getKey()); - - // 1.8 mappings - if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.9")) { - if (entry.getKey().equals("layer0") - && (!value.startsWith(path.getFileName().toString()) - && !value.startsWith("minecraft:" + path.getFileName().toString()))) - value = path.getFileName() + "/" + value; - } - - // 1.13 Mappings - if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.13")) { - if (value.startsWith("block/")) { - value = "block/" + nameConverter.getBlockMapping_1_13() - .remap(value.substring("block/".length())).toLowerCase() - .replaceAll("[()]", ""); - - Logger.debug(value.substring("block/".length()).toLowerCase() - .replaceAll("[()]", "")); - Logger.debug(nameConverter.getBlockMapping_1_13() - .remap(value.substring("block/".length())).toLowerCase() - .replaceAll("[()]", "")); - - } else if (value.startsWith("item/")) { - value = "item/" + nameConverter.getItemMapping_1_13() - .remap(value.substring("item/".length())).toLowerCase() - .replaceAll("[()]", ""); - } else - value = value.toLowerCase().replaceAll("[()]", ""); - } - - // 1.14 Mappings - if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.14")) { - if (value.startsWith("block/")) - value = "block/" + nameConverter.getBlockMapping_1_14() - .remap(value.substring("block/".length())); - } - - // 1.17 Mappings - if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.17")) { - if (value.startsWith("block/")) { - value = "block/" + nameConverter.getBlockMapping_1_17() - .remap(value.substring("block/".length())).toLowerCase() - .replaceAll("[()]", ""); - } else if (value.startsWith("item/")) { - value = "item/" + nameConverter.getItemMapping_1_17() - .remap(value.substring("item/".length())).toLowerCase() - .replaceAll("[()]", ""); - } - value = value.toLowerCase().replaceAll("[()]", ""); - } - - // 1.19 Mappings - if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.19")) { - if (value.startsWith("block/")) { - value = "block/" + nameConverter.getBlockMapping_1_19() - .remap(value.substring("block/".length())).toLowerCase() - .replaceAll("[()]", ""); - } - value = value.toLowerCase().replaceAll("[()]", ""); - } - - // Dyes - if (value.startsWith("item/") && value.contains("dye")) { - if (version > Util.getVersionProtocol(packConverter.getGson(), "1.13")) - value = "item/" + nameConverter.getItemMapping_1_14() - .remap(value.substring("item/".length())); - } - - // 1.19.3 Mappings - if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.19.3") - && from < Util.getVersionProtocol(packConverter.getGson(), "1.19.3")) { - if (!value.startsWith("minecraft:") && !value.startsWith("#")) - value = "minecraft:" + value; - } - - if (!textureObject.has(entry.getKey())) - textureObject.addProperty(entry.getKey(), value); - } - - jsonObject.remove("textures"); - jsonObject.add("textures", textureObject); - } - - // Fix Display Model For Packs (<= 1.8.9) - if (jsonObject.has("display") - && from <= Util.getVersionProtocol(packConverter.getGson(), "1.8")) { - JsonObject display = updateDisplay(packConverter.getGson(), - jsonObject.remove("display").getAsJsonObject()); - jsonObject.add("display", display); - } - - if (jsonObject.has("overrides")) { - for (Map.Entry entry : jsonObject.entrySet()) { - if (entry.getKey().equals("overrides")) { - JsonArray overrides = jsonObject.get("overrides").getAsJsonArray(); - JsonArray overrides2 = new JsonArray(); - for (int i = 0; i < overrides.size(); i++) { - JsonObject object = overrides.get(i).getAsJsonObject(); - for (Map.Entry json : object.entrySet()) { - if (json.getKey().equals("model")) - object.addProperty(json.getKey(), - json.getValue().getAsString().replaceAll("[()]", "")); - else - object.add(json.getKey(), json.getValue()); - } - overrides2.add(object); - } - jsonObject.add(entry.getKey(), overrides2); - } - } - } - - // Parent Stuff - if (jsonObject.has("parent")) { - // Change parent to lowercase - for (Map.Entry entry : jsonObject.entrySet()) { - if (entry.getKey().equals("parent")) { - String parent = entry.getValue().getAsString().toLowerCase(); - - parent = parent.replace(" ", "_"); - - // Get block/item parents renamed - if (from < Util.getVersionProtocol(packConverter.getGson(), "1.13") - && version >= Util.getVersionProtocol(packConverter.getGson(), "1.13")) { - if (parent.startsWith("block/")) - parent = setParent("block/", "/forwards/blocks.json", parent, "1_13"); - else if (parent.startsWith("item/")) - parent = setParent("item/", "/forwards/items.json", parent, "1_13"); - } - - if (from < Util.getVersionProtocol(packConverter.getGson(), "1.14") - && version >= Util.getVersionProtocol(packConverter.getGson(), "1.14")) { - if (parent.startsWith("block/")) - parent = setParent("block/", "/forwards/blocks.json", parent, "1_14"); - else if (parent.startsWith("item/")) - parent = setParent("item/", "/forwards/items.json", parent, "1_14"); - } - - if (from < Util.getVersionProtocol(packConverter.getGson(), "1.17") - && version >= Util.getVersionProtocol(packConverter.getGson(), "1.17")) { - if (parent.startsWith("block/")) - parent = setParent("block/", "/forwards/blocks.json", parent, "1_17"); - else if (parent.startsWith("item/")) - parent = setParent("item/", "/forwards/items.json", parent, "1_17"); - } - - if (from < Util.getVersionProtocol(packConverter.getGson(), "1.19") - && version >= Util.getVersionProtocol(packConverter.getGson(), "1.19")) { - if (parent.startsWith("block/")) - parent = setParent("block/", "/forwards/blocks.json", parent, "1_19"); - } - - if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.19.3") - && from < Util.getVersionProtocol(packConverter.getGson(), "1.19.3")) { - if (!parent.startsWith("minecraft:")) - parent = "minecraft:" + parent; - } - - jsonObject.addProperty(entry.getKey(), parent); - } - } - } - - if (!JsonUtil.readJson(packConverter.getGson(), model).equals(jsonObject)) { - Logger.debug("Updating Model: " + model.getFileName()); - JsonUtil.writeJson(packConverter.getGson(), model, jsonObject); - } - } catch (IOException e) { - throw Util.propagate(e); - } - }); - } - - /** - * Gets parent object and sets a new one - * - * @param prefix prefix of file path - * @param path File path of json control - * @param parent Parent String - * @return New string with changed parent. - */ - protected String setParent(String prefix, String path, String parent, String item) { - String parent2 = parent.replace(prefix, ""); - JsonObject file = JsonUtil.readJsonResource(packConverter.getGson(), path).getAsJsonObject(item); - if (file == null) { - Logger.debug("Prefix Failed on: " + parent); - return ""; - } - - return file.has(parent2) ? prefix + file.get(parent2).getAsString() : parent; - } - - protected static JsonObject updateDisplay(Gson gson, JsonObject display) { - JsonObject defaults = JsonUtil.readJsonResource(gson, "/forwards/display.json"); - if (display == null) { - return defaults.deepCopy(); - } - - // First Person - if (display.has("firstperson")) { - JsonObject firstPerson = display.remove("firstperson").getAsJsonObject(); - display.add("firstperson_righthand", - updateDisplayFirstPerson(gson, firstPerson)); - } else if (!display.has("firstperson_righthand")) { - JsonObject rightHand = defaults.get("firstperson_righthand") - .getAsJsonObject().deepCopy(); - display.add("firstperson_righthand", rightHand); - } - - if (!display.has("firstperson_lefthand")) { - display.add("firstperson_lefthand", - getLeftHand(gson, - display.get("firstperson_righthand").getAsJsonObject().deepCopy())); - } - - // Third Person - if (display.has("thirdperson")) { - JsonObject thirdPerson = display.remove("thirdperson").getAsJsonObject(); - display.add("thirdperson_righthand", - updateDisplayThirdPerson(gson, thirdPerson)); - } else if (!display.has("thirdperson_righthand")) { - JsonObject rightHand = defaults.get("thirdperson_righthand") - .getAsJsonObject().deepCopy(); - display.add("thirdperson_righthand", rightHand); - } - - if (!display.has("thirdperson_lefthand")) { - display.add("thirdperson_lefthand", - getLeftHand(gson, - display.get("thirdperson_righthand").getAsJsonObject().deepCopy())); - } - - if (!display.has("ground")) { - display.add("ground", - defaults.get("ground").getAsJsonObject().deepCopy()); - } - - if (!display.has("head")) { - display.add("head", - defaults.get("head").getAsJsonObject().deepCopy()); - } - - return display; - } - - private static JsonObject getLeftHand(Gson gson, JsonObject old) { - JsonObject newObject = old.deepCopy(); - if (old.has("rotation")) { - JsonArray oldRotation = newObject.remove("rotation").getAsJsonArray(); - JsonArray rotation = new JsonArray(); - rotation.add(oldRotation.get(0).getAsNumber()); - rotation.add(0 - oldRotation.get(1).getAsDouble()); - rotation.add(0 - oldRotation.get(2).getAsDouble()); - newObject.add("rotation", - rotation); - } - - return newObject; - } - - private static JsonObject updateDisplayFirstPerson(Gson gson, JsonObject old) { - JsonObject newObject = old.deepCopy(); - if (old.has("rotation")) { - JsonArray rotation = newObject.remove("rotation").getAsJsonArray(); - newObject.add("rotation", - JsonUtil.add( - rotation, - JsonUtil.asArray(gson, "[0, 45, 0]"))); - } - - if (old.has("translation")) { - JsonArray translation = newObject.remove("translation").getAsJsonArray(); - newObject.add("translation", - JsonUtil.add( - JsonUtil.multiply( - JsonUtil.subtract( - translation, - JsonUtil.asArray(gson, "[0, 4, 2]")), - JsonUtil.asArray(gson, "[0.4, 0.4, 0.4]")), - JsonUtil.asArray(gson, "[1.13, 3.2, 1.13]"))); - } - - if (old.has("scale")) { - JsonArray scale = newObject.remove("scale").getAsJsonArray(); - newObject.add("scale", - JsonUtil.multiply( - scale, - JsonUtil.asArray(gson, "[0.4, 0.4, 0.4]"))); - } - - return newObject; - } - - private static JsonObject updateDisplayThirdPerson(Gson gson, JsonObject old) { - JsonObject newObject = old.deepCopy(); - if (old.has("rotation")) { - JsonArray rotation = newObject.remove("rotation").getAsJsonArray(); - newObject.add("rotation", - JsonUtil.add( - JsonUtil.multiply( - rotation, - JsonUtil.asArray(gson, "[1, -1, -1]")), - JsonUtil.asArray(gson, "[0, 0, 20]"))); - } - - if (old.has("translation")) { - JsonArray translation = newObject.remove("translation").getAsJsonArray(); - newObject.add("translation", - JsonUtil.add( - JsonUtil.multiply( - translation, - JsonUtil.asArray(gson, "[1, 1, -1]")), - JsonUtil.asArray(gson, "[0, 2.75, -3]"))); - } - - // For keeping order - if (old.has("scale")) { - JsonArray scale = newObject.remove("scale").getAsJsonArray(); - newObject.add("scale", scale); - } - - return newObject; - } + private final int from; + private final int to; + protected String light = "none"; + + public ModelConverter(PackConverter packConverter, String light, int from, int to) { + super(packConverter); + this.light = light; + this.from = from; + this.to = to; + } + + /** + * Runs findfiles with the directory Models + * + * @param pack + * @throws IOException + */ + @Override + public void convert(Pack pack) throws IOException { + Path models = pack.getWorkingPath().resolve("assets/minecraft/models".replace("/", File.separator)); + if (models.toFile().exists()) { + Logger.addTab(); + findFiles(models); + Logger.subTab(); + } + } + + /** + * Recursively finds files with Path path and runs remapModelJson + * + * @param path + * @throws IOException + */ + protected void findFiles(Path path) throws IOException { + File directory = path.toFile(); + for (File file : Objects.requireNonNull(directory.listFiles())) { + Path filePath = file.toPath(); + if (!file.isDirectory()) { + remapModelJson(filePath.getParent(), filePath); + } else { + remapModelJsons(file.toPath()); + } + } + } + + /** + * Updates model Json to newer versions + * + * @param rootPath + * @throws IOException + */ + protected void remapModelJsons(Path rootPath) throws IOException { + if (rootPath.toFile().exists()) { + try (Stream pathStream = Files.list(rootPath).filter(path1 -> path1.toString().endsWith(".json"))) { + pathStream.forEach(modelPath -> { + try { + this.remapModelJson(rootPath, modelPath); + } catch (IOException e) { + Util.propagate(e); + } + }); + } + } + } + + protected void remapModelJson(Path rootPath, Path model) throws IOException { + if (!model.toFile().exists()) { + return; + } + + try { + JsonObject jsonObject; + if (JsonUtil.readJson(packConverter.getGson(), model) != null && JsonUtil.readJson(packConverter.getGson(), model).isJsonObject()) { + jsonObject = JsonUtil.readJson(packConverter.getGson(), model); + } else { + Logger.debug("Could not convert model: " + model.getFileName()); + Logger.addTab(); + if (JsonUtil.readJson(packConverter.getGson(), model) == null) { + Logger.debug("Check for Syntax Errors in file."); + } else { + Logger.debug("File is not JSON Object."); + } + Logger.subTab(); + return; + } + + // GUI light system for 1.15.2 + if (!light.equals("none") && (light.equals("front") || light.equals("side"))) { + Logger.log("Model did not have light, adding light '" + light + "'"); + jsonObject.addProperty("gui_light", light); + } + + if (jsonObject.has("textures") && jsonObject.get("textures").isJsonObject()) { + NameConverter nameConverter = packConverter.getConverter(NameConverter.class); + + JsonObject initialTextureObject = jsonObject.getAsJsonObject("textures"); + JsonObject textureObject = initialTextureObject.deepCopy(); + for (Map.Entry entry : initialTextureObject.entrySet()) { + String value = entry.getValue().getAsString(); + textureObject.remove(entry.getKey()); + + // 1.8 mappings + if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.9")) { + if (entry.getKey().equals("layer0") && (!value.startsWith(rootPath.getFileName().toString()) && !value.startsWith("minecraft:" + rootPath.getFileName()))) + value = rootPath.getFileName() + "/" + value; + } + + // 1.13 Mappings + if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.13")) { + if (value.startsWith("block/")) { + value = "block/" + nameConverter.getBlockMapping_1_13() + .remap(value.substring("block/".length())).toLowerCase() + .replaceAll("[()]", ""); + Logger.debug(value.substring("block/".length()).toLowerCase() + .replaceAll("[()]", "")); + Logger.debug(nameConverter.getBlockMapping_1_13() + .remap(value.substring("block/".length())).toLowerCase() + .replaceAll("[()]", "")); + } else if (value.startsWith("item/")) { + value = "item/" + nameConverter.getItemMapping_1_13() + .remap(value.substring("item/".length())).toLowerCase() + .replaceAll("[()]", ""); + } else { + value = value.toLowerCase().replaceAll("[()]", ""); + } + } + + // 1.14 Mappings + if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.14")) { + if (value.startsWith("block/")) { + value = "block/" + nameConverter.getBlockMapping_1_14().remap(value.substring("block/".length())); + } + + // Dyes + if (value.startsWith("item/") && value.contains("dye")) { + value = "item/" + nameConverter.getItemMapping_1_14().remap(value.substring("item/".length())); + } + } + + // 1.17 Mappings + if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.17")) { + if (value.startsWith("block/")) { + value = "block/" + nameConverter.getBlockMapping_1_17() + .remap(value.substring("block/".length())).toLowerCase() + .replaceAll("[()]", ""); + } else if (value.startsWith("item/")) { + value = "item/" + nameConverter.getItemMapping_1_17() + .remap(value.substring("item/".length())).toLowerCase() + .replaceAll("[()]", ""); + } + + value = value.toLowerCase().replaceAll("[()]", ""); + } + + // 1.19 Mappings + if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.19")) { + if (value.startsWith("block/")) { + value = "block/" + nameConverter.getBlockMapping_1_19() + .remap(value.substring("block/".length())).toLowerCase() + .replaceAll("[()]", ""); + } + + value = value.toLowerCase().replaceAll("[()]", ""); + } + + // 1.19.3 Mappings + if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.19.3") + && from < Util.getVersionProtocol(packConverter.getGson(), "1.19.3")) { + if (!value.startsWith("minecraft:") && !value.startsWith("#")) { + value = "minecraft:" + value; + } + } + + if (!textureObject.has(entry.getKey())) { + textureObject.addProperty(entry.getKey(), value); + } + } + + jsonObject.remove("textures"); + jsonObject.add("textures", textureObject); + } + + // Fix Display Model For Packs (<= 1.8.9) + if (jsonObject.has("display") && + from <= Util.getVersionProtocol(packConverter.getGson(), "1.8") && + to >= Util.getVersionProtocol(packConverter.getGson(), "1.9")) { + JsonObject display = updateDisplay(packConverter.getGson(), jsonObject.remove("display").getAsJsonObject()); + jsonObject.add("display", display); + } + + if (jsonObject.has("overrides")) { + for (Map.Entry entry : jsonObject.entrySet()) { + if (entry.getKey().equals("overrides")) { + JsonArray overrides = jsonObject.get("overrides").getAsJsonArray(); + JsonArray overridesArray = new JsonArray(); + for (int i = 0; i < overrides.size(); i++) { + JsonObject object = overrides.get(i).getAsJsonObject(); + for (Map.Entry json : object.entrySet()) { + if (json.getKey().equals("model")) { + object.addProperty(json.getKey(), json.getValue().getAsString().replaceAll("[()]", "")); + } else { + object.add(json.getKey(), json.getValue()); + } + } + overridesArray.add(object); + } + jsonObject.add(entry.getKey(), overridesArray); + } + } + } + + // Parent Stuff + if (jsonObject.has("parent")) { + // Change parent to lowercase + for (Map.Entry entry : jsonObject.entrySet()) { + if (entry.getKey().equals("parent")) { + String parent = entry.getValue().getAsString().toLowerCase().replace(" ", "_"); + + // Get block/item parents renamed + if (from < Util.getVersionProtocol(packConverter.getGson(), "1.13") + && to >= Util.getVersionProtocol(packConverter.getGson(), "1.13")) { + if (parent.startsWith("block/")) { + parent = setParent("block/", "/forwards/blocks.json", parent, "1_13"); + } else if (parent.startsWith("item/")) { + parent = setParent("item/", "/forwards/items.json", parent, "1_13"); + } + } + + if (from < Util.getVersionProtocol(packConverter.getGson(), "1.14") + && to >= Util.getVersionProtocol(packConverter.getGson(), "1.14")) { + if (parent.startsWith("block/")) { + parent = setParent("block/", "/forwards/blocks.json", parent, "1_14"); + } else if (parent.startsWith("item/")) { + parent = setParent("item/", "/forwards/items.json", parent, "1_14"); + } + } + + if (from < Util.getVersionProtocol(packConverter.getGson(), "1.17") + && to >= Util.getVersionProtocol(packConverter.getGson(), "1.17")) { + if (parent.startsWith("block/")) { + parent = setParent("block/", "/forwards/blocks.json", parent, "1_17"); + } else if (parent.startsWith("item/")) { + parent = setParent("item/", "/forwards/items.json", parent, "1_17"); + } + } + + if (from < Util.getVersionProtocol(packConverter.getGson(), "1.19") + && to >= Util.getVersionProtocol(packConverter.getGson(), "1.19")) { + if (parent.startsWith("block/")) { + parent = setParent("block/", "/forwards/blocks.json", parent, "1_19"); + } + } + + if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.19.3") + && from < Util.getVersionProtocol(packConverter.getGson(), "1.19.3")) { + if (!parent.startsWith("minecraft:")) { + parent = "minecraft:" + parent; + } + } + + jsonObject.addProperty(entry.getKey(), parent); + } + } + } + + if (!JsonUtil.readJson(packConverter.getGson(), model).equals(jsonObject)) { + Logger.debug("Updating Model: " + model.getFileName()); + JsonUtil.writeJson(packConverter.getGson(), model, jsonObject); + } else { + Logger.debug("Skipping Model: " + model.getFileName()); + } + } catch (IOException e) { + throw Util.propagate(e); + } + } + + /** + * Gets parent object and sets a new one + * + * @param prefix prefix of file path + * @param path File path of json control + * @param parent Parent String + * @return New string with changed parent. + */ + protected String setParent(String prefix, String path, String parent, String item) { + String parent2 = parent.replace(prefix, ""); + JsonObject file = JsonUtil.readJsonResource(packConverter.getGson(), path).getAsJsonObject(item); + if (file == null) { + Logger.debug("Prefix Failed on: " + parent); + return ""; + } else { + return file.has(parent2) ? prefix + file.get(parent2).getAsString() : parent; + } + } + + protected static JsonObject updateDisplay(Gson gson, JsonObject display) { + JsonObject defaults = JsonUtil.readJsonResource(gson, "/forwards/display.json"); + if (display == null) { + return defaults.deepCopy(); + } + + // First Person + if (display.has("firstperson")) { + JsonObject firstPerson = display.remove("firstperson").getAsJsonObject(); + display.add("firstperson_righthand", updateDisplayFirstPerson(gson, firstPerson)); + } else if (!display.has("firstperson_righthand")) { + JsonObject rightHand = defaults.get("firstperson_righthand").getAsJsonObject().deepCopy(); + display.add("firstperson_righthand", rightHand); + } + + if (!display.has("firstperson_lefthand")) { + display.add("firstperson_lefthand", getLeftHand(display.get("firstperson_righthand").getAsJsonObject().deepCopy())); + } + + // Third Person + if (display.has("thirdperson")) { + JsonObject thirdPerson = display.remove("thirdperson").getAsJsonObject(); + display.add("thirdperson_righthand", updateDisplayThirdPerson(gson, thirdPerson)); + } else if (!display.has("thirdperson_righthand")) { + JsonObject rightHand = defaults.get("thirdperson_righthand").getAsJsonObject().deepCopy(); + display.add("thirdperson_righthand", rightHand); + } + + if (!display.has("thirdperson_lefthand")) { + display.add("thirdperson_lefthand", getLeftHand(display.get("thirdperson_righthand").getAsJsonObject().deepCopy())); + } + + if (!display.has("ground")) { + display.add("ground", defaults.get("ground").getAsJsonObject().deepCopy()); + } + + if (!display.has("head")) { + display.add("head", defaults.get("head").getAsJsonObject().deepCopy()); + } + + return display; + } + + private static JsonObject getLeftHand(JsonObject old) { + JsonObject newObject = old.deepCopy(); + if (old.has("rotation")) { + JsonArray oldRotation = newObject.remove("rotation").getAsJsonArray(); + JsonArray rotation = new JsonArray(); + rotation.add(oldRotation.get(0).getAsNumber()); + rotation.add(0 - oldRotation.get(1).getAsDouble()); + rotation.add(0 - oldRotation.get(2).getAsDouble()); + newObject.add("rotation", rotation); + } + + return newObject; + } + + private static JsonObject updateDisplayFirstPerson(Gson gson, JsonObject old) { + JsonObject newObject = old.deepCopy(); + if (old.has("rotation")) { + JsonArray rotation = newObject.remove("rotation").getAsJsonArray(); + newObject.add("rotation", JsonUtil.add(rotation, JsonUtil.asArray(gson, "[0, 45, 0]"))); + } + + if (old.has("translation")) { + JsonArray translation = newObject.remove("translation").getAsJsonArray(); + newObject.add("translation", + JsonUtil.add( + JsonUtil.multiply( + JsonUtil.subtract( + translation, + JsonUtil.asArray(gson, "[0, 4, 2]")), + JsonUtil.asArray(gson, "[0.4, 0.4, 0.4]")), + JsonUtil.asArray(gson, "[1.13, 3.2, 1.13]"))); + } + + if (old.has("scale")) { + JsonArray scale = newObject.remove("scale").getAsJsonArray(); + newObject.add("scale", JsonUtil.multiply(scale, JsonUtil.asArray(gson, "[0.4, 0.4, 0.4]"))); + } + + return newObject; + } + + private static JsonObject updateDisplayThirdPerson(Gson gson, JsonObject old) { + JsonObject newObject = old.deepCopy(); + if (old.has("rotation")) { + JsonArray rotation = newObject.remove("rotation").getAsJsonArray(); + newObject.add("rotation", + JsonUtil.add( + JsonUtil.multiply( + rotation, + JsonUtil.asArray(gson, "[1, -1, -1]")), + JsonUtil.asArray(gson, "[0, 0, 20]"))); + } + + if (old.has("translation")) { + JsonArray translation = newObject.remove("translation").getAsJsonArray(); + newObject.add("translation", + JsonUtil.add( + JsonUtil.multiply( + translation, + JsonUtil.asArray(gson, "[1, 1, -1]")), + JsonUtil.asArray(gson, "[0, 2.75, -3]"))); + } + + // For keeping order + if (old.has("scale")) { + JsonArray scale = newObject.remove("scale").getAsJsonArray(); + newObject.add("scale", scale); + } + + return newObject; + } } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java index b57d7131..1a249390 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java @@ -74,7 +74,7 @@ public NameConverter(PackConverter packConverter, int from, int to) { @Override public void convert(Pack pack) throws IOException { Path minecraftPath = pack.getWorkingPath().resolve("assets/minecraft".replace("/", File.separator)); - + Logger.addTab(); // Less than 1.12 if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.12.2") && to > Util.getVersionProtocol(packConverter.getGson(), "1.13")) { @@ -278,6 +278,7 @@ public void convert(Pack pack) throws IOException { findEntityFiles(entityPath); } } + Logger.subTab(); } /** @@ -309,12 +310,12 @@ protected void findFiles(Path path) { for (File file : Objects.requireNonNull(directory.listFiles())) { if (file.isDirectory()) { if (file.getName().equals("items")) { - Logger.debug("Found Items folder, renaming"); + Logger.debug("Found Items folder, renaming.."); FileUtil.renameFile(path.resolve(file.getName()), file.getName().replaceAll("items", "item")); } if (file.getName().equals("blocks")) { - Logger.debug("Found blocks folder, renaming"); + Logger.debug("Found blocks folder, renaming.."); FileUtil.renameFile(path.resolve(file.getName()), file.getName().replaceAll("blocks", "block")); } @@ -373,7 +374,6 @@ protected void renameAll(Mapping mapping, String extension, Path path) throws IO } } - Logger.addTab(); try (Stream pathStream = Files.list(path).filter(path1 -> path1.toString().endsWith(extension))) { pathStream.forEach(path1 -> { String baseName = path1.getFileName().toString().substring(0, path1.getFileName().toString().length() - extension.length()); @@ -404,8 +404,6 @@ protected void renameAll(Mapping mapping, String extension, Path path) throws IO } }); } - - Logger.subTab(); } } From 8c3c1d49ad759f0baacabf1a0d00cbbf1f6f936d Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Sat, 8 Feb 2025 18:00:42 -0500 Subject: [PATCH 32/54] More fixing on model conversion --- .../forwards/impl/ModelConverter.java | 54 ++++++++----------- 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java index 0ae23fdd..3345a1cf 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java @@ -123,32 +123,26 @@ protected void remapModelJson(Path rootPath, Path model) throws IOException { // 1.8 mappings if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.9")) { - if (entry.getKey().equals("layer0") && (!value.startsWith(rootPath.getFileName().toString()) && !value.startsWith("minecraft:" + rootPath.getFileName()))) + if (entry.getKey().equals("layer0") && (!value.startsWith(rootPath.getFileName().toString()) && !value.startsWith("minecraft:" + rootPath.getFileName()))) { value = rootPath.getFileName() + "/" + value; + } } // 1.13 Mappings - if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.13")) { - if (value.startsWith("block/")) { - value = "block/" + nameConverter.getBlockMapping_1_13() - .remap(value.substring("block/".length())).toLowerCase() - .replaceAll("[()]", ""); - Logger.debug(value.substring("block/".length()).toLowerCase() - .replaceAll("[()]", "")); - Logger.debug(nameConverter.getBlockMapping_1_13() - .remap(value.substring("block/".length())).toLowerCase() - .replaceAll("[()]", "")); - } else if (value.startsWith("item/")) { - value = "item/" + nameConverter.getItemMapping_1_13() - .remap(value.substring("item/".length())).toLowerCase() - .replaceAll("[()]", ""); + if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.12.2") && + to >= Util.getVersionProtocol(packConverter.getGson(), "1.13")) { + if (value.startsWith("blocks/")) { + value = "block/" + nameConverter.getBlockMapping_1_13().remap(value.substring("blocks/".length())).toLowerCase().replaceAll("[()]", ""); + } else if (value.startsWith("items/")) { + value = "item/" + nameConverter.getItemMapping_1_13().remap(value.substring("items/".length())).toLowerCase().replaceAll("[()]", ""); } else { value = value.toLowerCase().replaceAll("[()]", ""); } } // 1.14 Mappings - if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.14")) { + if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.13.2") && + to >= Util.getVersionProtocol(packConverter.getGson(), "1.14")) { if (value.startsWith("block/")) { value = "block/" + nameConverter.getBlockMapping_1_14().remap(value.substring("block/".length())); } @@ -160,34 +154,30 @@ protected void remapModelJson(Path rootPath, Path model) throws IOException { } // 1.17 Mappings - if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.17")) { + if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.16.5") && + to >= Util.getVersionProtocol(packConverter.getGson(), "1.17")) { if (value.startsWith("block/")) { - value = "block/" + nameConverter.getBlockMapping_1_17() - .remap(value.substring("block/".length())).toLowerCase() - .replaceAll("[()]", ""); + value = "block/" + nameConverter.getBlockMapping_1_17().remap(value.substring("block/".length())).toLowerCase().replaceAll("[()]", ""); } else if (value.startsWith("item/")) { - value = "item/" + nameConverter.getItemMapping_1_17() - .remap(value.substring("item/".length())).toLowerCase() - .replaceAll("[()]", ""); + value = "item/" + nameConverter.getItemMapping_1_17().remap(value.substring("item/".length())).toLowerCase().replaceAll("[()]", ""); } value = value.toLowerCase().replaceAll("[()]", ""); } // 1.19 Mappings - if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.19")) { + if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.18.2") && + to >= Util.getVersionProtocol(packConverter.getGson(), "1.19")) { if (value.startsWith("block/")) { - value = "block/" + nameConverter.getBlockMapping_1_19() - .remap(value.substring("block/".length())).toLowerCase() - .replaceAll("[()]", ""); + value = "block/" + nameConverter.getBlockMapping_1_19().remap(value.substring("block/".length())).toLowerCase().replaceAll("[()]", ""); } value = value.toLowerCase().replaceAll("[()]", ""); } // 1.19.3 Mappings - if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.19.3") - && from < Util.getVersionProtocol(packConverter.getGson(), "1.19.3")) { + if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.19.2") && + to >= Util.getVersionProtocol(packConverter.getGson(), "1.19.3")) { if (!value.startsWith("minecraft:") && !value.startsWith("#")) { value = "minecraft:" + value; } @@ -305,13 +295,13 @@ protected void remapModelJson(Path rootPath, Path model) throws IOException { * @return New string with changed parent. */ protected String setParent(String prefix, String path, String parent, String item) { - String parent2 = parent.replace(prefix, ""); + String parentWithoutPrefix = parent.replace(prefix, ""); JsonObject file = JsonUtil.readJsonResource(packConverter.getGson(), path).getAsJsonObject(item); if (file == null) { Logger.debug("Prefix Failed on: " + parent); - return ""; + return parent; } else { - return file.has(parent2) ? prefix + file.get(parent2).getAsString() : parent; + return file.has(parentWithoutPrefix) ? prefix + file.get(parentWithoutPrefix).getAsString() : parent; } } From 8e74e49d77019fbcfd835a92ab9c1ad58af4b1bb Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Sat, 8 Feb 2025 18:12:10 -0500 Subject: [PATCH 33/54] Fix build issue --- conversions/Forwards/pom.xml | 12 ------------ .../forwards/impl/AnimationConverter.java | 3 ++- .../forwards/impl/BlockStateConverter.java | 6 ++++-- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/conversions/Forwards/pom.xml b/conversions/Forwards/pom.xml index 97dc06c6..61f01879 100644 --- a/conversions/Forwards/pom.xml +++ b/conversions/Forwards/pom.xml @@ -7,18 +7,6 @@ com.agentdid127.resourcepack 2.2.5 - - - - org.apache.maven.plugins - maven-compiler-plugin - - 16 - 16 - - - - 4.0.0 com.agentdid127.resourcepack diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/AnimationConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/AnimationConverter.java index f969ae17..781f9d44 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/AnimationConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/AnimationConverter.java @@ -44,7 +44,8 @@ protected void fixAnimations(Path animations) throws IOException { if (json != null) { boolean anyChanges = false; JsonElement animationElement = json.get("animation"); - if (animationElement instanceof JsonObject animationObject) { + if (animationElement instanceof JsonObject) { + JsonObject animationObject = animationElement.getAsJsonObject(); // TODO: Confirm this doesn't break any packs animationObject.remove("width"); animationObject.remove("height"); diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.java index d6d4c564..8109f969 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.java @@ -103,13 +103,15 @@ public void convert(Pack pack) throws IOException { * @param entry */ private void updateModelPath(Map.Entry entry) { - if (entry.getValue() instanceof JsonObject value) { + if (entry.getValue() instanceof JsonObject) { + JsonObject value = entry.getValue().getAsJsonObject(); if (value.has("model")) { updateModelObject(value); } } else if (entry.getValue() instanceof JsonArray) { for (JsonElement jsonElement : ((JsonArray) entry.getValue())) { - if (jsonElement instanceof JsonObject value) { + if (jsonElement instanceof JsonObject) { + JsonObject value = jsonElement.getAsJsonObject(); if (value.has("model")) { updateModelObject(value); } From 1af54d991de60d59bab36ba465b38bad78f4e9d1 Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Sat, 8 Feb 2025 18:21:24 -0500 Subject: [PATCH 34/54] Add tabbing to printing for stuff --- .../forwards/impl/LangConverter.java | 131 ++++++++--------- .../forwards/impl/MCPatcherConverter.java | 43 ++++-- .../forwards/impl/SpacesConverter.java | 43 +++--- .../impl/textures/SlicerConverter.java | 133 ++++++++++-------- .../library/utilities/PropertiesEx.java | 6 +- 5 files changed, 190 insertions(+), 166 deletions(-) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/LangConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/LangConverter.java index 5e2cb3dd..5331fc99 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/LangConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/LangConverter.java @@ -10,108 +10,99 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import java.io.*; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Enumeration; import java.util.Map; +import java.util.stream.Stream; public class LangConverter extends Converter { - private String version; - private String from; + private final String from; + private final String to; - public LangConverter(PackConverter packConverter, String fromIn, String versionIn) { + public LangConverter(PackConverter packConverter, String from, String to) { super(packConverter); - version = versionIn; - from = fromIn; + this.from = from; + this.to = to; } /** * Moves Lang (properties) to JSON - * + * * @param pack * @throws IOException */ @Override public void convert(Pack pack) throws IOException { Path langPath = pack.getWorkingPath().resolve("assets/minecraft/lang".replace("/", File.separator)); - if (!langPath.toFile().exists()) + if (!langPath.toFile().exists()) { return; + } ArrayList models = new ArrayList(); - Files.list(langPath) - .filter(path1 -> path1.toString().endsWith(".lang")) - .forEach(model -> { - JsonObject out = new JsonObject(); - try (InputStream input = new FileInputStream(model.toString())) { - PropertiesEx prop = new PropertiesEx(); - prop.load(input); - if (Util.getVersionProtocol(packConverter.getGson(), from) <= Util - .getVersionProtocol(packConverter.getGson(), "1.12") - && ((Util.getVersionProtocol(packConverter.getGson(), version) >= Util - .getVersionProtocol(packConverter.getGson(), "1.13")) - && (Util.getVersionProtocol(packConverter.getGson(), version) <= Util - .getVersionProtocol(packConverter.getGson(), "1.13.2")))) { - JsonObject id = JsonUtil.readJsonResource(packConverter.getGson(), "/forwards/lang.json") - .getAsJsonObject("1_13"); - - Enumeration enums = (Enumeration) prop.propertyNames(); - while (enums.hasMoreElements()) { - String key = enums.nextElement(); - String value = prop.getProperty(key); - for (Map.Entry id2 : id.entrySet()) { - if (key.equals(id2.getKey())) - out.addProperty(id2.getValue().getAsString(), value); - else - out.addProperty(key, value); - } + try (Stream pathStream = Files.list(langPath).filter(path1 -> path1.toString().endsWith(".lang"))) { + pathStream.forEach(lang -> { + JsonObject out = new JsonObject(); + try (InputStream input = Files.newInputStream(Paths.get(lang.toString()))) { + PropertiesEx prop = new PropertiesEx(); + prop.load(input); + if (Util.getVersionProtocol(packConverter.getGson(), from) <= Util.getVersionProtocol(packConverter.getGson(), "1.12") + && ((Util.getVersionProtocol(packConverter.getGson(), to) >= Util.getVersionProtocol(packConverter.getGson(), "1.13")) + && (Util.getVersionProtocol(packConverter.getGson(), to) <= Util.getVersionProtocol(packConverter.getGson(), "1.13.2")))) { + JsonObject id = JsonUtil.readJsonResource(packConverter.getGson(), "/forwards/lang.json").getAsJsonObject("1_13"); + Enumeration enums = (Enumeration) prop.propertyNames(); + while (enums.hasMoreElements()) { + String key = enums.nextElement(); + String value = prop.getProperty(key); + for (Map.Entry id2 : id.entrySet()) { + if (key.equals(id2.getKey())) + out.addProperty(id2.getValue().getAsString(), value); + else + out.addProperty(key, value); } - // Saves File } - if (Util.getVersionProtocol(packConverter.getGson(), version) > Util - .getVersionProtocol(packConverter.getGson(), "1.14")) { - JsonObject id = JsonUtil.readJsonResource(packConverter.getGson(), "/forwards/lang.json") - .getAsJsonObject("1_14"); + } - Enumeration enums = (Enumeration) prop.propertyNames(); - while (enums.hasMoreElements()) { - String key = enums.nextElement(); - String value = prop.getProperty(key); - for (Map.Entry id2 : id.entrySet()) { - if (key.equals(id2.getKey())) - out.addProperty(id2.getValue().getAsString(), value); - else - out.addProperty(key, value); - } + if (Util.getVersionProtocol(packConverter.getGson(), to) > Util.getVersionProtocol(packConverter.getGson(), "1.14")) { + JsonObject id = JsonUtil.readJsonResource(packConverter.getGson(), "/forwards/lang.json").getAsJsonObject("1_14"); + Enumeration enums = (Enumeration) prop.propertyNames(); + while (enums.hasMoreElements()) { + String key = enums.nextElement(); + String value = prop.getProperty(key); + for (Map.Entry id2 : id.entrySet()) { + if (key.equals(id2.getKey())) + out.addProperty(id2.getValue().getAsString(), value); + else + out.addProperty(key, value); } - // Saves File } - input.close(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); } + } catch (IOException e) { + e.printStackTrace(); + } - try { - int modelNoLang = model.getFileName().toString().indexOf(".lang"); - String file2 = model.getFileName().toString().substring(0, modelNoLang); - Logger.debug("Saving: " + file2 + ".json"); - Path outLangPath = pack.getWorkingPath() - .resolve(("assets/minecraft/lang/" + file2 + ".json").replace("/", File.separator)); - JsonUtil.writeJson(packConverter.getGson(), outLangPath, out); + try { + int modelNoLang = lang.getFileName().toString().indexOf(".lang"); + String file2 = lang.getFileName().toString().substring(0, modelNoLang); + Logger.debug("Saving: " + file2 + ".json"); + Path outLangPath = pack.getWorkingPath().resolve(("assets/minecraft/lang/" + file2 + ".json").replace("/", File.separator)); + JsonUtil.writeJson(packConverter.getGson(), outLangPath, out); - } catch (IOException e) { - e.printStackTrace(); - } + } catch (IOException e) { + e.printStackTrace(); + } - models.add(model.getFileName().toString()); - }); + models.add(lang.getFileName().toString()); + }); + } - for (int i = 0; i < models.size(); i++) { - Path langFilePath = pack.getWorkingPath() - .resolve(("assets/minecraft/lang/" + models.get(i)).replace("/", File.separator)); + for (String model : models) { + Path langFilePath = pack.getWorkingPath().resolve(("assets/minecraft/lang/" + model).replace("/", File.separator)); Logger.debug("Deleting: " + langFilePath); Files.delete(langFilePath); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java index d6512f2c..0e157590 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java @@ -9,10 +9,15 @@ import com.agentdid127.resourcepack.library.utilities.Util; import com.google.gson.JsonObject; -import java.io.*; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Arrays; +import java.util.Objects; import java.util.stream.Stream; @Deprecated // will be removed when extensions are made @@ -29,10 +34,12 @@ public MCPatcherConverter(PackConverter packConverter) { */ @Override public void convert(Pack pack) throws IOException { - Path models = pack.getWorkingPath() - .resolve("assets/minecraft/optifine".replace("/", File.separator)); - if (models.toFile().exists()) + Path models = pack.getWorkingPath().resolve("assets/minecraft/optifine".replace("/", File.separator)); + if (models.toFile().exists()) { + Logger.addTab(); findFiles(models); + Logger.subTab(); + } // remapModelJson(models.resolve("item")); // remapModelJson(models.resolve("block")); } @@ -45,11 +52,12 @@ public void convert(Pack pack) throws IOException { */ protected void findFiles(Path path) throws IOException { File directory = path.toFile(); - for (File file : directory.listFiles()) { - if (!file.isDirectory()) - continue; - remapProperties(file.toPath()); - findFiles(file.toPath()); + for (File file : Objects.requireNonNull(directory.listFiles())) { + if (!file.isDirectory()) { + remapProperties(file.toPath()); + } else { + findFiles(file.toPath()); + } } } @@ -63,26 +71,31 @@ protected void remapProperties(Path path) throws IOException { if (path.toFile().exists()) { try (Stream pathStream = Files.list(path).filter(path1 -> path1.toString().endsWith(".properties"))) { pathStream.forEach(model -> { - try (InputStream input = new FileInputStream(model.toString())) { + Path inputStreamPath = Paths.get(model.toString()); + try (InputStream input = Files.newInputStream(inputStreamPath)) { Logger.debug("Updating:" + model.getFileName()); PropertiesEx prop = new PropertiesEx(); prop.load(input); - try (OutputStream output = new FileOutputStream(model.toString())) { + try (OutputStream output = Files.newOutputStream(inputStreamPath)) { // updates textures - if (prop.containsKey("texture")) + if (prop.containsKey("texture")) { prop.setProperty("texture", replaceTextures(prop)); + } // Updates Item IDs - if (prop.containsKey("matchItems")) + if (prop.containsKey("matchItems")) { prop.setProperty("matchItems", updateID("matchItems", prop, "regular").replaceAll("\"", "")); + } - if (prop.containsKey("items")) + if (prop.containsKey("items")) { prop.setProperty("items", updateID("items", prop, "regular").replaceAll("\"", "")); + } - if (prop.containsKey("matchBlocks")) + if (prop.containsKey("matchBlocks")) { prop.setProperty("matchBlocks", updateID("matchBlocks", prop, "regular").replaceAll("\"", "")); + } // Saves File prop.store(output, ""); diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/SpacesConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/SpacesConverter.java index 59ab3ccb..04c92459 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/SpacesConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/SpacesConverter.java @@ -10,6 +10,7 @@ import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Objects; public class SpacesConverter extends Converter { public SpacesConverter(PackConverter packConverter) { @@ -18,51 +19,53 @@ public SpacesConverter(PackConverter packConverter) { /** * Runs findFiles - * + * * @param pack * @throws IOException */ @Override public void convert(Pack pack) throws IOException { Path assets = pack.getWorkingPath().resolve("assets"); - if (!assets.toFile().exists()) - return; - findFiles(assets); + if (assets.toFile().exists()) { + Logger.addTab(); + findFiles(assets); + Logger.subTab(); + } } /** * Recursively finds files to fix Spaces - * + * * @param path - * @throws IOException */ - protected void findFiles(Path path) throws IOException { - if (!path.toFile().exists()) - return; - File directory = path.toFile(); - for (File file : directory.listFiles()) { - String dir = fixSpaces(file.toPath()); - if (file.isDirectory()) - findFiles(Paths.get(dir)); + protected void findFiles(Path path) { + if (path.toFile().exists()) { + File directory = path.toFile(); + for (File file : Objects.requireNonNull(directory.listFiles())) { + String dir = fixSpaces(file.toPath()); + if (file.isDirectory()) { + findFiles(Paths.get(dir)); + } + } } } /** * Replaces spaces in files with underscores - * + * * @param path * @return - * @throws IOException */ - protected String fixSpaces(Path path) throws IOException { - if (!path.getFileName().toString().contains(" ")) + protected String fixSpaces(Path path) { + if (!path.getFileName().toString().contains(" ")) { return path.toString(); + } String noSpaces = path.getFileName().toString().replaceAll(" ", "_"); - Boolean ret = FileUtil.renameFile(path, noSpaces); - if (ret == null) + if (ret == null) { return "null"; + } if (ret) { Logger.debug("Renamed: " + path.getFileName().toString() + "->" + noSpaces); diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.java index b7e65a7a..60096ba0 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.java @@ -1,74 +1,91 @@ package com.agentdid127.resourcepack.forwards.impl.textures; -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; - import com.agentdid127.resourcepack.forwards.impl.textures.slicing.Slice; import com.agentdid127.resourcepack.forwards.impl.textures.slicing.Slicer; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.JsonUtil; +import com.agentdid127.resourcepack.library.utilities.Logger; import com.agentdid127.resourcepack.library.utilities.Util; import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; + public class SlicerConverter extends Converter { - private int from; - - public SlicerConverter(PackConverter converter, int from) { - super(converter); - this.from = from; - } - - @Override - public void convert(Pack pack) throws IOException { - Path texturesPath = pack.getWorkingPath().resolve("assets/minecraft/textures".replace("/", File.separator)); - if (!texturesPath.toFile().exists()) - return; - Path guiPath = texturesPath.resolve("gui"); - if (!guiPath.toFile().exists()) - return; // No need to do any slicing. - Path spritesPath = guiPath.resolve("sprites"); - if (!spritesPath.toFile().exists()) - spritesPath.toFile().mkdirs(); - Gson gson = packConverter.getGson(); - JsonArray array = JsonUtil.readJsonResource(gson, "/forwards/gui.json", JsonArray.class); - Slice[] slices = Slice.parseArray(array); - for (Slice slice : slices) - Slicer.runSlicer(gson, slice, guiPath, PredicateRunnable.class, from, true); - } - - public static class PredicateRunnable { - public static boolean run(Gson gson, int from, JsonObject predicate) { - if (predicate.has("protocol")) { - JsonObject protocol = predicate.getAsJsonObject("protocol"); - - Integer min_inclusive = null; - Integer max_inclusive = null; - - JsonElement min_inclusive_prim = protocol.get("min_inclusive"); - if (min_inclusive_prim.isJsonPrimitive() && min_inclusive_prim.getAsJsonPrimitive().isNumber()) - min_inclusive = min_inclusive_prim.getAsInt(); - - if (min_inclusive == null) - min_inclusive = 4; // hardcoded bruh - - JsonElement max_inclusive_prim = protocol.get("max_inclusive"); - if (max_inclusive_prim.isJsonPrimitive() && max_inclusive_prim.getAsJsonPrimitive().isNumber()) - max_inclusive = max_inclusive_prim.getAsInt(); - - if (max_inclusive == null) - max_inclusive = Util.getLatestProtocol(gson); - - if (from < min_inclusive || from > max_inclusive) - return false; - } - - return true; - } - } + private final int from; + + public SlicerConverter(PackConverter converter, int from) { + super(converter); + this.from = from; + } + + @Override + public void convert(Pack pack) throws IOException { + Path texturesPath = pack.getWorkingPath().resolve("assets/minecraft/textures".replace("/", File.separator)); + if (!texturesPath.toFile().exists()) { + return; + } + + Path guiPath = texturesPath.resolve("gui"); + if (!guiPath.toFile().exists()) { + return; // No need to do any slicing. + } + + Path spritesPath = guiPath.resolve("sprites"); + if (!spritesPath.toFile().exists()) { + spritesPath.toFile().mkdirs(); + } + + Gson gson = packConverter.getGson(); + JsonArray array = JsonUtil.readJsonResource(gson, "/forwards/gui.json", JsonArray.class); + if (array != null) { + Logger.addTab(); + Slice[] slices = Slice.parseArray(array); + for (Slice slice : slices) { + Slicer.runSlicer(gson, slice, guiPath, PredicateRunnable.class, from, true); + } + Logger.subTab(); + } + } + + public static class PredicateRunnable { + public static boolean run(Gson gson, int from, JsonObject predicate) { + if (predicate.has("protocol")) { + JsonObject protocol = predicate.getAsJsonObject("protocol"); + + Integer min_inclusive = null; + Integer max_inclusive = null; + + JsonElement min_inclusive_prim = protocol.get("min_inclusive"); + if (min_inclusive_prim.isJsonPrimitive() && min_inclusive_prim.getAsJsonPrimitive().isNumber()) { + min_inclusive = min_inclusive_prim.getAsInt(); + } + + if (min_inclusive == null) { + min_inclusive = 4; // hardcoded bruh + } + + JsonElement max_inclusive_prim = protocol.get("max_inclusive"); + if (max_inclusive_prim.isJsonPrimitive() && max_inclusive_prim.getAsJsonPrimitive().isNumber()) { + max_inclusive = max_inclusive_prim.getAsInt(); + } + + if (max_inclusive == null) { + max_inclusive = Util.getLatestProtocol(gson); + } + + if (from < min_inclusive || from > max_inclusive) { + return false; + } + } + + return true; + } + } } \ No newline at end of file diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/PropertiesEx.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/PropertiesEx.java index 8a5972e3..2e8c64f3 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/PropertiesEx.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/PropertiesEx.java @@ -10,8 +10,8 @@ import java.util.Properties; public class PropertiesEx extends Properties { - private static final char[] hexDigit = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', - 'D', 'E', 'F' }; + private static final char[] hexDigit = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', + 'D', 'E', 'F'}; private static void writeComments(BufferedWriter bw, String comments) throws IOException { bw.write("#"); @@ -19,7 +19,7 @@ private static void writeComments(BufferedWriter bw, String comments) throws IOE int current = 0; int last = 0; - for (char[] uu = new char[] { '\\', 'u', '\u0000', '\u0000', '\u0000', '\u0000' }; current < len; ++current) { + for (char[] uu = new char[]{'\\', 'u', '\u0000', '\u0000', '\u0000', '\u0000'}; current < len; ++current) { char c = comments.charAt(current); if (c > 255 || c == '\n' || c == '\r') { if (last != current) From 84456f26c42813ce8e511e2ecacca11c70f86b0f Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Sat, 8 Feb 2025 18:28:09 -0500 Subject: [PATCH 35/54] Fix MCPatcherConverter --- .../forwards/impl/MCPatcherConverter.java | 112 ++++++++++-------- .../forwards/impl/ModelConverter.java | 8 +- 2 files changed, 67 insertions(+), 53 deletions(-) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java index 0e157590..5fee691e 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java @@ -34,10 +34,10 @@ public MCPatcherConverter(PackConverter packConverter) { */ @Override public void convert(Pack pack) throws IOException { - Path models = pack.getWorkingPath().resolve("assets/minecraft/optifine".replace("/", File.separator)); - if (models.toFile().exists()) { + Path optifinePath = pack.getWorkingPath().resolve("assets/minecraft/optifine".replace("/", File.separator)); + if (optifinePath.toFile().exists()) { Logger.addTab(); - findFiles(models); + findFiles(optifinePath); Logger.subTab(); } // remapModelJson(models.resolve("item")); @@ -45,18 +45,33 @@ public void convert(Pack pack) throws IOException { } /** - * Finds all files in the specified path + * Finds all files in the specified rootPath * - * @param path + * @param rootPath * @throws IOException */ - protected void findFiles(Path path) throws IOException { - File directory = path.toFile(); + protected void findFiles(Path rootPath) throws IOException { + File directory = rootPath.toFile(); for (File file : Objects.requireNonNull(directory.listFiles())) { + Path filePath = file.toPath(); if (!file.isDirectory()) { - remapProperties(file.toPath()); + remapProperties(filePath); } else { - findFiles(file.toPath()); + remapPropertiesFolder(filePath); + } + } + } + + protected void remapPropertiesFolder(Path rootPath) throws IOException { + if (rootPath.toFile().exists()) { + try (Stream pathStream = Files.list(rootPath).filter(path1 -> path1.toString().endsWith(".properties"))) { + pathStream.forEach(propertyPath -> { + try { + this.remapProperties(propertyPath); + } catch (IOException e) { + Util.propagate(e); + } + }); } } } @@ -64,49 +79,48 @@ protected void findFiles(Path path) throws IOException { /** * Remaps properties to work in newer versions * - * @param path + * @param rootPath + * @param propertyPath * @throws IOException */ - protected void remapProperties(Path path) throws IOException { - if (path.toFile().exists()) { - try (Stream pathStream = Files.list(path).filter(path1 -> path1.toString().endsWith(".properties"))) { - pathStream.forEach(model -> { - Path inputStreamPath = Paths.get(model.toString()); - try (InputStream input = Files.newInputStream(inputStreamPath)) { - Logger.debug("Updating:" + model.getFileName()); - - PropertiesEx prop = new PropertiesEx(); - prop.load(input); - - try (OutputStream output = Files.newOutputStream(inputStreamPath)) { - // updates textures - if (prop.containsKey("texture")) { - prop.setProperty("texture", replaceTextures(prop)); - } - - // Updates Item IDs - if (prop.containsKey("matchItems")) { - prop.setProperty("matchItems", updateID("matchItems", prop, "regular").replaceAll("\"", "")); - } - - if (prop.containsKey("items")) { - prop.setProperty("items", updateID("items", prop, "regular").replaceAll("\"", "")); - } - - if (prop.containsKey("matchBlocks")) { - prop.setProperty("matchBlocks", updateID("matchBlocks", prop, "regular").replaceAll("\"", "")); - } - - // Saves File - prop.store(output, ""); - } catch (IOException io) { - io.printStackTrace(); - } - } catch (IOException e) { - throw Util.propagate(e); - } - }); + protected void remapProperties(Path propertyPath) throws IOException { + if (!propertyPath.toFile().exists()) { + return; + } + + Path inputStreamPath = Paths.get(propertyPath.toString()); + try (InputStream input = Files.newInputStream(inputStreamPath)) { + Logger.debug("Updating:" + propertyPath.getFileName()); + + PropertiesEx prop = new PropertiesEx(); + prop.load(input); + + try (OutputStream output = Files.newOutputStream(inputStreamPath)) { + // updates textures + if (prop.containsKey("texture")) { + prop.setProperty("texture", replaceTextures(prop)); + } + + // Updates Item IDs + if (prop.containsKey("matchItems")) { + prop.setProperty("matchItems", updateID("matchItems", prop, "regular").replaceAll("\"", "")); + } + + if (prop.containsKey("items")) { + prop.setProperty("items", updateID("items", prop, "regular").replaceAll("\"", "")); + } + + if (prop.containsKey("matchBlocks")) { + prop.setProperty("matchBlocks", updateID("matchBlocks", prop, "regular").replaceAll("\"", "")); + } + + // Saves File + prop.store(output, ""); + } catch (IOException io) { + io.printStackTrace(); } + } catch (IOException e) { + throw Util.propagate(e); } } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java index 3345a1cf..f3084176 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java @@ -48,13 +48,13 @@ public void convert(Pack pack) throws IOException { } /** - * Recursively finds files with Path path and runs remapModelJson + * Recursively finds files with Path rootPath and runs remapModelJson * - * @param path + * @param rootPath * @throws IOException */ - protected void findFiles(Path path) throws IOException { - File directory = path.toFile(); + protected void findFiles(Path rootPath) throws IOException { + File directory = rootPath.toFile(); for (File file : Objects.requireNonNull(directory.listFiles())) { Path filePath = file.toPath(); if (!file.isDirectory()) { From 0ba026ce680731b0ee8382172f3b2ad7b4fd6dbc Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Sat, 8 Feb 2025 18:29:48 -0500 Subject: [PATCH 36/54] Add more tabbing to logging --- .../agentdid127/resourcepack/forwards/impl/LangConverter.java | 4 ++++ .../forwards/impl/textures/ParticleTextureConverter.java | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/LangConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/LangConverter.java index 5331fc99..1632e51b 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/LangConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/LangConverter.java @@ -44,6 +44,8 @@ public void convert(Pack pack) throws IOException { return; } + Logger.addTab(); + ArrayList models = new ArrayList(); try (Stream pathStream = Files.list(langPath).filter(path1 -> path1.toString().endsWith(".lang"))) { pathStream.forEach(lang -> { @@ -106,5 +108,7 @@ public void convert(Pack pack) throws IOException { Logger.debug("Deleting: " + langFilePath); Files.delete(langFilePath); } + + Logger.subTab(); } } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java index 9cfbe0ab..cfadeda8 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java @@ -41,6 +41,8 @@ public void convert(Pack pack) throws IOException { return; } + Logger.addTab(); + Gson gson = packConverter.getGson(); JsonObject particlesJson = JsonUtil.readJsonResource(gson, "/forwards/particles.json", JsonObject.class); assert particlesJson != null; @@ -72,5 +74,7 @@ public void convert(Pack pack) throws IOException { } FileUtil.moveIfExists(particlePath.resolve("fishing_hook.png"), newFishingHookPath); } + + Logger.subTab(); } } \ No newline at end of file From 4182a7210d149743c2705e3e6b152de92e7ed26c Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Sun, 9 Feb 2025 21:50:20 -0500 Subject: [PATCH 37/54] Refactor RPC API --- .../com/agentdid127/resourcepack/Main.java | 20 +- .../com/agentdid127/resourcepack/GUI.java | 26 +- .../backwards/BackwardsPackConverter.java | 100 +- .../backwards/impl/BlockStateConverter.java | 133 +-- .../backwards/impl/DeleteFileConverter.java | 41 +- .../backwards/impl/EnchantPathConverter.java | 7 + .../backwards/impl/LangConverter.java | 20 +- .../backwards/impl/MCPatcherConverter.java | 6 + .../backwards/impl/ModelConverter.java | 936 +++++++++--------- .../backwards/impl/NameConverter.java | 13 +- .../backwards/impl/PackMetaConverter.java | 27 +- .../backwards/impl/ParticleConverter.java | 18 +- .../impl/textures/ChestConverter.java | 25 +- .../impl/textures/CompassConverter.java | 18 +- .../impl/textures/EnchantConverter.java | 28 +- .../impl/textures/InventoryConverter.java | 14 +- .../impl/textures/MapIconConverter.java | 8 +- .../impl/textures/PaintingConverter.java | 78 +- .../textures/ParticleTextureConverter.java | 39 +- .../impl/textures/WaterConverter.java | 55 +- .../forwards/ForwardsPackConverter.java | 165 +-- .../forwards/impl/AnimationConverter.java | 6 + .../forwards/impl/AtlasConverter.java | 44 +- .../forwards/impl/BlockStateConverter.java | 31 +- .../forwards/impl/EnchantPathConverter.java | 14 +- .../forwards/impl/ImageFormatConverter.java | 15 +- .../forwards/impl/LangConverter.java | 20 +- .../forwards/impl/MCPatcherConverter.java | 6 + .../forwards/impl/ModelConverter.java | 5 + .../forwards/impl/NameConverter.java | 5 + .../forwards/impl/PackMetaConverter.java | 6 + .../forwards/impl/ParticleConverter.java | 23 +- .../forwards/impl/SoundsConverter.java | 37 +- .../forwards/impl/SpacesConverter.java | 7 + .../impl/textures/ArmorMoverConverter.java | 16 +- .../impl/textures/ChestConverter.java | 7 + .../impl/textures/CompassConverter.java | 8 +- .../impl/textures/CreativeTabsConverter.java | 48 +- .../impl/textures/EnchantConverter.java | 24 +- .../impl/textures/InventoryConverter.java | 6 + .../impl/textures/MapIconConverter.java | 8 +- .../impl/textures/MapIconSlicerConverter.java | 33 +- .../textures/MobEffectAtlasConverter.java | 60 +- .../impl/textures/OffHandCreator.java | 121 +-- .../impl/textures/PaintingConverter.java | 25 +- .../textures/ParticleTextureConverter.java | 5 + .../impl/textures/SlicerConverter.java | 9 +- .../impl/textures/TitleConverter.java | 35 +- .../impl/textures/WaterConverter.java | 52 +- ...Creator.java => WidgetSlidersCreator.java} | 30 +- .../impl/textures/SlidersCreator.html | 2 +- .../resourcepack/library/Converter.java | 3 + 52 files changed, 1356 insertions(+), 1132 deletions(-) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/{SlidersCreator.java => WidgetSlidersCreator.java} (66%) diff --git a/Applications/Console/src/main/java/com/agentdid127/resourcepack/Main.java b/Applications/Console/src/main/java/com/agentdid127/resourcepack/Main.java index c1afe279..568147f0 100644 --- a/Applications/Console/src/main/java/com/agentdid127/resourcepack/Main.java +++ b/Applications/Console/src/main/java/com/agentdid127/resourcepack/Main.java @@ -5,10 +5,12 @@ import com.agentdid127.resourcepack.library.utilities.Util; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.Strictness; import joptsimple.OptionSet; import java.io.IOException; import java.io.PrintStream; +import java.nio.file.Path; public class Main { /** @@ -24,18 +26,24 @@ public static void main(String[] args) throws IOException { return; } - String from = optionSet.valueOf(Options.FROM); - String to = optionSet.valueOf(Options.TO); + Path inputPath = optionSet.valueOf(Options.INPUT_DIR); String light = optionSet.valueOf(Options.LIGHT); boolean minify = optionSet.has(Options.MINIFY); boolean debug = optionSet.valueOf(Options.DEBUG); PrintStream out = System.out; - GsonBuilder gsonBuilder = new GsonBuilder(); + + GsonBuilder gsonBuilder = new GsonBuilder().disableHtmlEscaping().setStrictness(Strictness.LENIENT); + if (!minify) { + gsonBuilder.setPrettyPrinting(); + } Gson gson = gsonBuilder.disableHtmlEscaping().create(); - if (Util.getVersionProtocol(gson, from) > Util.getVersionProtocol(gson, to)) { - new BackwardsPackConverter(from, to, light, minify, optionSet.valueOf(Options.INPUT_DIR), debug, out).runDir(); + + int from = Util.getVersionProtocol(gson, optionSet.valueOf(Options.FROM)); + int to = Util.getVersionProtocol(gson, optionSet.valueOf(Options.TO)); + if (from > to) { + new BackwardsPackConverter(gson, from, to, inputPath, debug, out).runDir(); } else { - new ForwardsPackConverter(from, to, light, minify, optionSet.valueOf(Options.INPUT_DIR), debug, out).runDir(); + new ForwardsPackConverter(gson, from, to, light, inputPath, debug, out).runDir(); } } } \ No newline at end of file diff --git a/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java b/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java index 60feb87e..ecccd347 100644 --- a/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java +++ b/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java @@ -5,12 +5,14 @@ import com.agentdid127.resourcepack.library.utilities.Util; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.Strictness; import javax.swing.*; import java.awt.*; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; +import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; import java.util.Objects; @@ -28,10 +30,12 @@ public class GUI { private JButton convertButton; private PrintStream out; - private final GsonBuilder gsonBuilder = new GsonBuilder(); - private final Gson gson = gsonBuilder.disableHtmlEscaping().create(); + private final Gson gson; public GUI() { + GsonBuilder gsonBuilder = new GsonBuilder().disableHtmlEscaping().setStrictness(Strictness.LENIENT); + this.gson = gsonBuilder.disableHtmlEscaping().create(); + String[] versions = Util.getSupportedVersions(gson); for (String item : versions == null ? new String[]{} : versions) { initialVersionBox.addItem(item); @@ -40,19 +44,23 @@ public GUI() { convertButton.addActionListener(e -> { out = redirectSystemStreams(); - - String from = Objects.requireNonNull(initialVersionBox.getSelectedItem()).toString(); - String to = Objects.requireNonNull(finalVersionBox.getSelectedItem()).toString(); + int from = Util.getVersionProtocol(gson, Objects.requireNonNull(initialVersionBox.getSelectedItem()).toString()); + int to = Util.getVersionProtocol(gson, Objects.requireNonNull(finalVersionBox.getSelectedItem()).toString()); String light = "none"; - boolean minify = minifyCheckBox.isSelected(); new Thread(() -> { convertButton.setVisible(false); try { - if (Util.getVersionProtocol(gson, from) > Util.getVersionProtocol(gson, to)) { - new BackwardsPackConverter(from, to, light, minify, Paths.get("./"), false, out).runDir(); + Gson gson = this.gson; + if (!minify) { + gson = gsonBuilder.setPrettyPrinting().create(); + } + + Path dotPath = Paths.get("./"); + if (from > to) { + new BackwardsPackConverter(gson, from, to, dotPath, false, out).runDir(); } else { - new ForwardsPackConverter(from, to, light, minify, Paths.get("./"), false, out).runDir(); + new ForwardsPackConverter(gson, from, to, light, dotPath, false, out).runDir(); } } catch (Exception exception) { out.println(Arrays.toString(exception.getStackTrace())); diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/BackwardsPackConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/BackwardsPackConverter.java index 2031a351..45821116 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/BackwardsPackConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/BackwardsPackConverter.java @@ -7,8 +7,7 @@ import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.Logger; import com.agentdid127.resourcepack.library.utilities.Util; -import com.google.gson.GsonBuilder; -import com.google.gson.Strictness; +import com.google.gson.Gson; import java.io.PrintStream; import java.nio.file.Files; @@ -18,74 +17,41 @@ public class BackwardsPackConverter extends PackConverter { Path INPUT_DIR; + private final int from; + private final int to; - public BackwardsPackConverter(String from, String to, String light, boolean minify, Path input, boolean debug, - PrintStream out) { - GsonBuilder gsonBuilder = new GsonBuilder().disableHtmlEscaping().setStrictness(Strictness.LENIENT); - if (!minify) { - gsonBuilder.setPrettyPrinting(); - } - gson = gsonBuilder.create(); + public BackwardsPackConverter(Gson gson, int from, int to, Path input, boolean debug, PrintStream out) { + this.gson = gson; Logger.setDebug(debug); Logger.setStream(out); Logger.log("Converting packs from: " + from + " to " + to); + this.from = from; + this.to = to; this.INPUT_DIR = input; - converterRunner(from, to, light); + this.setupConverters(); } - private void converterRunner(String from, String to, String light) { - int protocolFrom = Util.getVersionProtocol(gson, from); - int protocolTo = Util.getVersionProtocol(gson, to); - - // This needs to be run first, other converters might reference - // new directory names. - this.registerConverter(new NameConverter(this, protocolFrom, protocolTo)); - this.registerConverter(new PackMetaConverter(this, protocolTo)); - - this.registerConverter(new DeleteFileConverter(this, protocolFrom, protocolTo)); - + private void setupConverters() { + this.registerConverter(new NameConverter(this, from, to)); // This needs to be run first, other converters might reference new directory names. + this.registerConverter(new PackMetaConverter(this, to)); + this.registerConverter(new DeleteFileConverter(this, from, to)); // TODO: backwards TitleConverter for going from 1.20 to below - - if (protocolFrom >= Util.getVersionProtocol(gson, "1.19.4") - && protocolTo < Util.getVersionProtocol(gson, "1.19.4")) - this.registerConverter(new EnchantPathConverter(this)); - - if (protocolFrom >= Util.getVersionProtocol(gson, "1.18") - && protocolTo < Util.getVersionProtocol(gson, "1.18")) { - this.registerConverter(new ParticleConverter(this)); - this.registerConverter(new InventoryConverter(this)); - } - - if (protocolFrom >= Util.getVersionProtocol(gson, "1.15") && - protocolTo < Util.getVersionProtocol(gson, "1.15")) { - this.registerConverter(new EnchantConverter(this)); - this.registerConverter(new ChestConverter(this)); - } - - if (protocolFrom >= Util.getVersionProtocol(gson, "1.14") && - protocolTo < Util.getVersionProtocol(gson, "1.14")) { - this.registerConverter(new PaintingConverter(this)); - } - - this.registerConverter(new ParticleTextureConverter(this, protocolFrom, protocolTo)); - - if (protocolFrom >= Util.getVersionProtocol(gson, "1.13") - && protocolTo < Util.getVersionProtocol(gson, "1.13")) { - this.registerConverter(new LangConverter(this, from, to)); - // this.registerConverter(new SoundsConverter(this)); - // this.registerConverter(new AnimationConverter(this)); - this.registerConverter(new MapIconConverter(this)); - this.registerConverter(new MCPatcherConverter(this)); - this.registerConverter(new WaterConverter(this)); - } - - this.registerConverter(new BlockStateConverter(this, protocolFrom, protocolTo)); - this.registerConverter(new ModelConverter(this, light, protocolFrom, protocolTo)); - - if (protocolFrom >= Util.getVersionProtocol(gson, "1.9") && - protocolTo < Util.getVersionProtocol(gson, "1.9")) { - this.registerConverter(new CompassConverter(this, protocolTo)); - } + this.registerConverter(new EnchantPathConverter(this)); + this.registerConverter(new ParticleConverter(this)); + this.registerConverter(new InventoryConverter(this)); + this.registerConverter(new EnchantConverter(this)); + this.registerConverter(new ChestConverter(this)); + this.registerConverter(new PaintingConverter(this)); + this.registerConverter(new ParticleTextureConverter(this, from, to)); + this.registerConverter(new LangConverter(this, from, to)); +// this.registerConverter(new SoundsConverter(this)); // return from >= Util.getVersionProtocol(gson, "1.13") && to <= Util.getVersionProtocol(gson, "1.12.2"); +// this.registerConverter(new AnimationConverter(this)); // return from >= Util.getVersionProtocol(gson, "1.13") && to <= Util.getVersionProtocol(gson, "1.12.2"); + this.registerConverter(new MapIconConverter(this)); + this.registerConverter(new MCPatcherConverter(this)); + this.registerConverter(new WaterConverter(this)); + this.registerConverter(new BlockStateConverter(this, from, to)); + this.registerConverter(new ModelConverter(this, from, to)); + this.registerConverter(new CompassConverter(this, to)); } public void runPack(Pack pack) { @@ -95,10 +61,12 @@ public void runPack(Pack pack) { pack.getHandler().setup(); Logger.log("Running Converters"); for (Converter converter : converters.values()) { - Logger.addTab(); - Logger.log("Running " + converter.getClass().getSimpleName()); - converter.convert(pack); - Logger.subTab(); + if (converter.shouldConvert(gson, from, to)) { + Logger.addTab(); + Logger.log("Running " + converter.getClass().getSimpleName()); + converter.convert(pack); + Logger.subTab(); + } } pack.getHandler().finish(); Logger.subTab(); diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/BlockStateConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/BlockStateConverter.java index e39d45f3..9bd7dff2 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/BlockStateConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/BlockStateConverter.java @@ -6,6 +6,7 @@ import com.agentdid127.resourcepack.library.utilities.JsonUtil; import com.agentdid127.resourcepack.library.utilities.Logger; import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -15,9 +16,11 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Map; +import java.util.stream.Stream; public class BlockStateConverter extends Converter { - private int from, to; + private final int from; + private final int to; private boolean anyChanges; public BlockStateConverter(PackConverter packConverter, int from, int to) { @@ -26,80 +29,86 @@ public BlockStateConverter(PackConverter packConverter, int from, int to) { this.to = to; } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return true; + } + /** * Updates blockstates in blockstates folder - * + * * @param pack * @throws IOException */ @Override public void convert(Pack pack) throws IOException { - Path blockstatesPath = pack.getWorkingPath() - .resolve("assets/minecraft/blockstates".replace("/", File.separator)); - if (!blockstatesPath.toFile().exists()) + Path blockstatesPath = pack.getWorkingPath().resolve("assets/minecraft/blockstates".replace("/", File.separator)); + if (!blockstatesPath.toFile().exists()) { return; - Files.list(blockstatesPath) - .filter(file -> file.toString().endsWith(".json")) - .forEach(file -> { - try { - JsonObject json = JsonUtil.readJson(packConverter.getGson(), file); - anyChanges = false; - - // process multipart - JsonArray multipartArray = json.getAsJsonArray("multipart"); - - if (multipartArray != null) { - if (to < Util.getVersionProtocol(packConverter.getGson(), "1.9")) { - // TODO: Convert Multipart to variants - Files.delete(file); - return; - } else { - for (int i = 0; i < multipartArray.size(); i++) { - JsonObject multipartObject = multipartArray.get(i) - .getAsJsonObject(); - for (Map.Entry entry : multipartObject.entrySet()) - updateModelPath(entry); - } + } + + try (Stream pathStream = Files.list(blockstatesPath).filter(file -> file.toString().endsWith(".json"))) { + pathStream.forEach(file -> { + try { + JsonObject json = JsonUtil.readJson(packConverter.getGson(), file); + anyChanges = false; + + // process multipart + JsonArray multipartArray = json.getAsJsonArray("multipart"); + + if (multipartArray != null) { + if (to < Util.getVersionProtocol(packConverter.getGson(), "1.9")) { + // TODO: Convert Multipart to variants + Files.delete(file); + return; + } else { + for (int i = 0; i < multipartArray.size(); i++) { + JsonObject multipartObject = multipartArray.get(i) + .getAsJsonObject(); + for (Map.Entry entry : multipartObject.entrySet()) + updateModelPath(entry); } } + } - // process variants - JsonObject variantsObject = json.getAsJsonObject("variants"); - if (variantsObject != null) { - // change "normal" key to "" - if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.13") - && to < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { - - if (!variantsObject.has("")) { - // TODO: find a better way to deal with this. - Files.delete(file); - return; - } - JsonElement normal = variantsObject.get(""); - if (normal instanceof JsonObject || normal instanceof JsonArray) { - variantsObject.add("normal", normal); - variantsObject.remove(""); - anyChanges = true; - } - } + // process variants + JsonObject variantsObject = json.getAsJsonObject("variants"); + if (variantsObject != null) { + // change "normal" key to "" + if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.13") + && to < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { - // update model paths to prepend block - for (Map.Entry entry : variantsObject.entrySet()) - updateModelPath(entry); - } - if (anyChanges) { - JsonUtil.writeJson(packConverter.getGson(), file, json); - Logger.debug("Converted " + file.getFileName()); + if (!variantsObject.has("")) { + // TODO: find a better way to deal with this. + Files.delete(file); + return; + } + JsonElement normal = variantsObject.get(""); + if (normal instanceof JsonObject || normal instanceof JsonArray) { + variantsObject.add("normal", normal); + variantsObject.remove(""); + anyChanges = true; + } } - } catch (IOException e) { - Util.propagate(e); + + // update model paths to prepend block + for (Map.Entry entry : variantsObject.entrySet()) + updateModelPath(entry); + } + if (anyChanges) { + JsonUtil.writeJson(packConverter.getGson(), file, json); + Logger.debug("Converted " + file.getFileName()); } - }); + } catch (IOException e) { + Util.propagate(e); + } + }); + } } /** * Updates Model paths - * + * * @param entry */ private void updateModelPath(Map.Entry entry) { @@ -109,9 +118,7 @@ private void updateModelPath(Map.Entry entry) { if (value.has("model")) { String[] split = value.get("model").getAsString().split("/"); String val = split[split.length - 1]; - String prefix = value.get("model").getAsString().substring(0, - value.get("model").getAsString().length() - val.length()); - + String prefix = value.get("model").getAsString().substring(0, value.get("model").getAsString().length() - val.length()); if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.19.3") && to < Util.getVersionProtocol(packConverter.getGson(), "1.19.3")) { prefix = prefix.replaceAll("minecraft:", ""); @@ -143,8 +150,9 @@ private void updateModelPath(Map.Entry entry) { anyChanges = true; } - if (anyChanges) + if (anyChanges) { value.addProperty("model", prefix + val); + } } } else if (entry.getValue() instanceof JsonArray) { // some states have arrays for (JsonElement jsonElement : ((JsonArray) entry.getValue())) { @@ -187,8 +195,9 @@ private void updateModelPath(Map.Entry entry) { anyChanges = true; } - if (anyChanges) + if (anyChanges) { value.addProperty("model", prefix + val); + } } } } diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/DeleteFileConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/DeleteFileConverter.java index 11a54e53..19263206 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/DeleteFileConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/DeleteFileConverter.java @@ -6,6 +6,7 @@ import com.agentdid127.resourcepack.library.utilities.FileUtil; import com.agentdid127.resourcepack.library.utilities.JsonUtil; import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -16,7 +17,8 @@ import java.nio.file.Path; public class DeleteFileConverter extends Converter { - int from, to; + private final int from; + private final int to; public DeleteFileConverter(PackConverter packConverter, int from, int to) { super(packConverter); @@ -25,12 +27,14 @@ public DeleteFileConverter(PackConverter packConverter, int from, int to) { } @Override - public void convert(Pack pack) throws IOException { - Path models = pack.getWorkingPath() - .resolve("assets/minecraft/models".replace("/", File.separator)); - Path textures = pack.getWorkingPath() - .resolve("assets/minecraft/textures".replace("/", File.separator)); + public boolean shouldConvert(Gson gson, int from, int to) { + return true; + } + @Override + public void convert(Pack pack) throws IOException { + Path models = pack.getWorkingPath().resolve("assets/minecraft/models".replace("/", File.separator)); + Path textures = pack.getWorkingPath().resolve("assets/minecraft/textures".replace("/", File.separator)); for (int i = from; i > to; i--) { deleteBlocks(models, textures, i); deleteItems(models, textures, i); @@ -39,33 +43,39 @@ public void convert(Pack pack) throws IOException { findFiles(models); findFiles(textures); - if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.19.3") - && to < Util.getVersionProtocol(packConverter.getGson(), "1.19.3")) { - Path atlases = pack.getWorkingPath() - .resolve("assets/minecraft/atlases".replace("/", File.separator)); - if (atlases.toFile().exists()) + && to <= Util.getVersionProtocol(packConverter.getGson(), "1.19.2")) { + Path atlases = pack.getWorkingPath().resolve("assets/minecraft/atlases".replace("/", File.separator)); + if (atlases.toFile().exists()) { FileUtil.deleteDirectoryAndContents(atlases); + } } } protected void findFiles(Path path) throws IOException { if (!path.toFile().exists()) return; + File directory = path.toFile(); File[] filesList = directory.listFiles(); - for (File file : filesList) - if (file.isDirectory()) + + assert filesList != null; + for (File file : filesList) { + if (file.isDirectory()) { findFiles(file.toPath()); + } + } + filesList = directory.listFiles(); - if (filesList.length == 0) + assert filesList != null; + if (filesList.length == 0) { Files.deleteIfExists(directory.toPath()); + } } public void deleteBlocks(Path models, Path textures, int version) throws IOException { String protocol = Util.getVersionFromProtocol(packConverter.getGson(), version); JsonObject blocks = JsonUtil.readJsonResource(packConverter.getGson(), "/backwards/delete/blocks.json"); - if (blocks.has(protocol)) { Path blockMPath, blockTPath; if (version < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { @@ -89,7 +99,6 @@ public void deleteBlocks(Path models, Path textures, int version) throws IOExcep public void deleteItems(Path models, Path textures, int version) throws IOException { String protocol = Util.getVersionFromProtocol(packConverter.getGson(), version); JsonObject items = JsonUtil.readJsonResource(packConverter.getGson(), "/backwards/delete/items.json"); - if (items.has(protocol)) { Path itemMPath, itemTPath; if (version < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/EnchantPathConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/EnchantPathConverter.java index 25333c85..37d65854 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/EnchantPathConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/EnchantPathConverter.java @@ -3,6 +3,8 @@ import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import java.io.File; import java.io.IOException; @@ -14,6 +16,11 @@ public EnchantPathConverter(PackConverter packConverter) { super(packConverter); } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from >= Util.getVersionProtocol(gson, "1.19.4") && to <= Util.getVersionProtocol(gson, "1.19.3"); + } + @Override public void convert(Pack pack) throws IOException { Path miscPath = pack.getWorkingPath().resolve("assets/minecraft/textures/misc".replace("/", File.separator)); diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/LangConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/LangConverter.java index 03ab867e..a20a0f4d 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/LangConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/LangConverter.java @@ -7,6 +7,7 @@ import com.agentdid127.resourcepack.library.utilities.Logger; import com.agentdid127.resourcepack.library.utilities.PropertiesEx; import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -20,15 +21,20 @@ import java.util.stream.Stream; public class LangConverter extends Converter { - private final String from; - private final String to; + private final int from; + private final int to; - public LangConverter(PackConverter packConverter, String from, String to) { + public LangConverter(PackConverter packConverter, int from, int to) { super(packConverter); this.from = from; this.to = to; } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from >= Util.getVersionProtocol(gson, "1.13") && to <= Util.getVersionProtocol(gson, "1.12.2"); + } + /** * Moves Lang (properties) to JSON * @@ -48,9 +54,9 @@ public void convert(Pack pack) throws IOException { PropertiesEx out = new PropertiesEx(); try { JsonObject object = JsonUtil.readJson(packConverter.getGson(), model, JsonObject.class); - if (Util.getVersionProtocol(packConverter.getGson(), from) > Util.getVersionProtocol(packConverter.getGson(), "1.12") - && ((Util.getVersionProtocol(packConverter.getGson(), to) < Util.getVersionProtocol(packConverter.getGson(), "1.13")) - && (Util.getVersionProtocol(packConverter.getGson(), to) > Util.getVersionProtocol(packConverter.getGson(), "1.13.2")))) { + if (from > Util.getVersionProtocol(packConverter.getGson(), "1.12") + && ((to < Util.getVersionProtocol(packConverter.getGson(), "1.13")) + && (to > Util.getVersionProtocol(packConverter.getGson(), "1.13.2")))) { JsonObject id = JsonUtil.readJsonResource(packConverter.getGson(), "/backwards/lang.json").getAsJsonObject("1_13"); if (object != null) { object.keySet().forEach(key -> { @@ -64,7 +70,7 @@ public void convert(Pack pack) throws IOException { } } - if (Util.getVersionProtocol(packConverter.getGson(), to) <= Util.getVersionProtocol(packConverter.getGson(), "1.14")) { + if (to <= Util.getVersionProtocol(packConverter.getGson(), "1.14")) { JsonObject id = JsonUtil.readJsonResource(packConverter.getGson(), "/backwards/lang.json").getAsJsonObject("1_14"); if (object != null) { object.keySet().forEach(key -> { diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/MCPatcherConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/MCPatcherConverter.java index d3fcdd59..0fa8da23 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/MCPatcherConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/MCPatcherConverter.java @@ -7,6 +7,7 @@ import com.agentdid127.resourcepack.library.utilities.Logger; import com.agentdid127.resourcepack.library.utilities.PropertiesEx; import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import com.google.gson.JsonObject; import java.io.File; @@ -26,6 +27,11 @@ public MCPatcherConverter(PackConverter packConverter) { super(packConverter); } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from >= Util.getVersionProtocol(gson, "1.13") && to <= Util.getVersionProtocol(gson, "1.12.2"); + } + /** * Parent conversion for MCPatcher * diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/ModelConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/ModelConverter.java index 732f1d3e..0f6fbdc5 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/ModelConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/ModelConverter.java @@ -18,472 +18,476 @@ import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.Objects; public class ModelConverter extends Converter { - private int version; - private int from; - protected String light = "none"; - - public ModelConverter(PackConverter packConverter, String lightIn, int fromIn, int versionIn) { - super(packConverter); - light = lightIn; - from = fromIn; - version = versionIn; - } - - /** - * Runs findfiles with the directory Models - * - * @param pack - * @throws IOException - */ - @Override - public void convert(Pack pack) throws IOException { - Path models = pack.getWorkingPath() - .resolve("assets/minecraft/models".replace("/", File.separator)); - if (!models.toFile().exists()) - return; - findFiles(models); - } - - /** - * Recursively finds files with Path path and runs remapModelJson - * - * @param path - * @throws IOException - */ - protected void findFiles(Path path) throws IOException { - File directory = path.toFile(); - for (File file : directory.listFiles()) { - if (file.isDirectory()) - continue; - remapModelJson(file.toPath()); - findFiles(file.toPath()); - } - } - - /** - * Updates model Json to newer versions - * - * @param models Model path - * @throws IOException - */ - protected void remapModelJson(Path models) throws IOException { - if (!models.toFile().exists()) - return; - Files.list(models) - .filter(path1 -> path1.toString().endsWith(".json")) - .forEach(model -> { - try { - JsonObject jsonObject; - if (JsonUtil.readJson(packConverter.getGson(), model) != null - && JsonUtil.readJson(packConverter.getGson(), model).isJsonObject()) - jsonObject = JsonUtil.readJson(packConverter.getGson(), model); - else { - Logger.debug("Could not convert model: " + model.getFileName()); - Logger.addTab(); - if (JsonUtil.readJson(packConverter.getGson(), model) == null) - Logger.debug("Check for Syntax Errors in file."); - else - Logger.debug("File is not JSON Object."); - Logger.subTab(); - return; - } - - // Parent Stuff - if (jsonObject.has("parent")) { - // Change parent to lowercase - for (Map.Entry entry : jsonObject.entrySet()) { - if (entry.getKey().equals("parent")) { - String parent = entry.getValue().getAsString().toLowerCase(); - jsonObject.addProperty(entry.getKey(), getParent(parent)); - } - } - - if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.9") - && version < Util.getVersionProtocol(packConverter.getGson(), "1.9")) { - jsonObject = mergeParent(models, jsonObject, jsonObject.get("parent").getAsString()); - } - } - - // GUI light system for 1.15.2 - if (version < Util.getVersionProtocol(packConverter.getGson(), "1.15.2")) { - jsonObject.remove("gui_light"); - } - // minify the json so we can replace spaces in paths easily - // TODO Improvement: handle this in a cleaner way? - - // handle the remapping of textures, for models that use default texture names - if (jsonObject.has("textures") && jsonObject.get("textures").isJsonObject()) { - NameConverter nameConverter = packConverter.getConverter(NameConverter.class); - JsonObject initialTextureObject = jsonObject.getAsJsonObject("textures"); - JsonObject textureObject = initialTextureObject.deepCopy(); - for (Map.Entry entry : initialTextureObject.entrySet()) { - String value = entry.getValue().getAsString(); - textureObject.remove(entry.getKey()); - - if (version < Util.getVersionProtocol(packConverter.getGson(), "1.19.3") - && from >= Util.getVersionProtocol(packConverter.getGson(), "1.19.3")) { - value = value.replaceAll("minecraft:", ""); - } - // 1.19 Mappings - if (version < Util.getVersionProtocol(packConverter.getGson(), "1.19")) - if (value.startsWith("block/")) - value = "block/" + nameConverter.getBlockMapping19() - .remap(value.substring("block/".length())).toLowerCase() - .replaceAll("[()]", ""); - value = value.toLowerCase().replaceAll("[()]", ""); - - // 1.17 Mappings - if (version < Util.getVersionProtocol(packConverter.getGson(), "1.17")) { - if (value.startsWith("block/")) - value = "block/" + nameConverter.getBlockMapping17() - .remap(value.substring("block/".length())).toLowerCase() - .replaceAll("[()]", ""); - else if (value.startsWith("item/")) - value = "item/" + nameConverter.getItemMapping17() - .remap(value.substring("item/".length())).toLowerCase() - .replaceAll("[()]", ""); - value = value.toLowerCase().replaceAll("[()]", ""); - } - - // 1.14 Mappings - if (version < Util.getVersionProtocol(packConverter.getGson(), "1.14")) - if (value.startsWith("block/")) - value = "block/" - + nameConverter.getNewBlockMapping() - .remap(value.substring("block/".length())); - - // Dyes - if (value.startsWith("item/") && value.contains("dye")) - if (version < Util.getVersionProtocol(packConverter.getGson(), "1.14")) - value = "item/" - + nameConverter.getNewItemMapping() - .remap(value.substring("item/".length())); - - // 1.13 Mappings - if (version < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { - if (value.startsWith("block/")) { - List same = Arrays.asList("snow"); - String remap = nameConverter.getBlockMapping() - .remap(value.substring("block/".length())).toLowerCase() - .replaceAll("[()]", ""); - for (String s : same) { - if (s.equals(value.substring("block/".length()))) { - remap = s; - } - } - value = "blocks/" + remap; - } else if (value.startsWith("item/")) - value = "items/" + nameConverter.getItemMapping() - .remap(value.substring("item/".length())).toLowerCase() - .replaceAll("[()]", ""); - else - value = value.toLowerCase().replaceAll("[()]", ""); - } - - if (!textureObject.has(entry.getKey())) - textureObject.addProperty(entry.getKey(), value); - } - - jsonObject.remove("textures"); - jsonObject.add("textures", textureObject); - } - - // fix display settings for packs for 1.8 - if (jsonObject.has("display") && from > Util.getVersionProtocol(packConverter.getGson(), "1.8") - && version == Util.getVersionProtocol(packConverter.getGson(), "1.8")) { - JsonElement display = jsonObject.remove("display"); - - if (display.isJsonObject()) { - jsonObject.add("display", - updateDisplay(packConverter.getGson(), display.getAsJsonObject())); - } - } - - if (jsonObject.has("overrides")) { - for (Map.Entry entry : jsonObject.entrySet()) { - if (entry.getKey().equals("overrides")) { - JsonArray overrides = jsonObject.get("overrides").getAsJsonArray(); - JsonArray overrides2 = new JsonArray(); - for (int i = 0; i < overrides.size(); i++) { - JsonObject object = overrides.get(i).getAsJsonObject(); - for (Map.Entry json : object.entrySet()) { - if (json.getKey().equals("model")) - object.addProperty(json.getKey(), - json.getValue().getAsString().replaceAll("[()]", "")); - else - object.add(json.getKey(), json.getValue()); - } - overrides2.add(object); - } - jsonObject.add(entry.getKey(), overrides2); - } - } - } - - if (!JsonUtil.readJson(packConverter.getGson(), model).equals(jsonObject)) { - Logger.debug("Updating Model: " + model.getFileName()); - JsonUtil.writeJson(packConverter.getGson(), model, jsonObject); - } - } catch (IOException e) { - throw Util.propagate(e); - } - }); - } - - private String getParent(String parent) { - parent = parent.replace(" ", "_"); - - // Get block/item parents renamed - if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.19.3") - && version < Util.getVersionProtocol(packConverter.getGson(), "1.19.3")) - parent = parent.replaceAll("minecraft:", ""); - - if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.19") - && version < Util.getVersionProtocol(packConverter.getGson(), "1.19")) - if (parent.startsWith("block/")) - parent = setParent("block/", "/backwards/blocks.json", parent, "1_19"); - - if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.17") - && version < Util.getVersionProtocol(packConverter.getGson(), "1.17")) { - if (parent.startsWith("block/")) - parent = setParent("block/", "/backwards/blocks.json", parent, "1_17"); - if (parent.startsWith("item/")) - parent = setParent("item/", "/backwards/items.json", parent, "1_17"); - } - - if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.14") - && version < Util.getVersionProtocol(packConverter.getGson(), "1.14")) { - if (parent.startsWith("block/")) - parent = setParent("block/", "/backwards/blocks.json", parent, "1_14"); - if (parent.startsWith("item/")) - parent = setParent("item/", "/backwards/items.json", parent, "1_14"); - } - - if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.13") - && version < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { - - if (parent.startsWith("block/")) - parent = setParent("block/", "/backwards/blocks.json", parent, "1_13"); - if (parent.startsWith("item/")) - parent = setParent("item/", "/backwards/items.json", parent, "1_13"); - - } - return parent; - } - - protected JsonObject mergeParent(Path models, JsonObject current, String parent) { - JsonObject jsonObject = current.deepCopy(); - if (parent == null || !models.resolve(parent + ".json").toFile().exists()) - return jsonObject; - - if (!current.has("parent")) - return jsonObject; - - Path parentPath = models.resolve(parent + ".json"); - try { - JsonObject parentObj = JsonUtil.readJson(packConverter.getGson(), parentPath); - if (parentObj != null) { - jsonObject.remove("parent"); - if (parentObj.has("parent")) { - String parentStr = parentObj.get("parent").getAsString(); - String parentVal = parentStr == null ? null : getParent(parentStr); - jsonObject = mergeParent(models, parentObj, parentVal); - } - - if (!jsonObject.has("elements") && current.has("elements")) - jsonObject.add("elements", current.get("elements")); - - if (!jsonObject.has("elements") && parentObj.has("elements")) - jsonObject.add("elements", parentObj.get("elements")); - - if (!jsonObject.has("display") && parentObj.has("display")) - jsonObject.add("display", parentObj.get("display")); - - JsonObject textures = new JsonObject(); - if (jsonObject.has("textures")) - textures = jsonObject.remove("textures").getAsJsonObject(); - - if (current.has("textures")) { - for (String s : current.get("textures").getAsJsonObject().keySet()) - if (!textures.has(s)) - textures.add(s, current.get("textures").getAsJsonObject().get(s)); - } - - if (parentObj.has("textures")) { - JsonObject parentTextures = parentObj.get("textures").getAsJsonObject(); - for (String s : parentTextures.keySet()) - if (!textures.has(s)) - textures.add(s, parentTextures.get(s)); - } - - for (int i = 0; i < 5; i++) { - JsonObject textures2 = new JsonObject(); - for (String s : textures.keySet()) { - if (textures.get(s).getAsString().startsWith("#") && - textures.has(textures.get(s).getAsString().substring(1))) { - textures2.add(s, - textures.get(textures.get(s).getAsString().substring(1))); - } else { - textures2.add(s, textures.get(s)); - } - } - textures = textures2; - } - - if (textures.keySet().size() > 0) - jsonObject.add("textures", textures); - } - } catch (IOException e) { - } - - return jsonObject; - } - - /** - * Gets parent object and sets a new one - * - * @param prefix prefix of file path - * @param path File path of json control - * @param parent Parent String - * @return New string with changed parent. - */ - protected String setParent(String prefix, String path, String parent, String item) { - String parent2 = parent.replace(prefix, ""); - JsonObject file = JsonUtil.readJsonResource(packConverter.getGson(), path).getAsJsonObject(item); - if (file == null) { - Logger.debug("Prefix Failed on: " + parent); - return ""; - } - return file.has(parent2) ? prefix + file.get(parent2).getAsString() : parent; - } - - protected static JsonObject updateDisplay(Gson gson, JsonObject display) { - JsonObject defaults = JsonUtil.readJsonResource(gson, "/backwards/display.json"); - if (display == null) - return defaults.deepCopy(); - - // First Person - boolean found = false; - JsonObject firstPerson = defaults.get("firstperson").getAsJsonObject().deepCopy(); - if (display.has("firstperson_righthand")) { - firstPerson = updateDisplayFirstPerson(gson, display.remove("firstperson_righthand").getAsJsonObject()); - found = true; - } - if (display.has("firstperson_lefthand")) { - JsonObject firstPersonLeft = display.remove("firstperson_lefthand").getAsJsonObject(); - if (!found) { - firstPerson = updateDisplayFirstPerson(gson, getLeftHand(gson, firstPersonLeft)); - } - } - display.remove("firstperson"); - display.add("firstperson", firstPerson); - - // Third Person - found = false; - JsonObject thirdPerson = defaults.get("thirdperson").getAsJsonObject().deepCopy(); - if (display.has("thirdperson_righthand")) { - thirdPerson = updateDisplayThirdPerson(gson, display.remove("thirdperson_righthand").getAsJsonObject()); - found = true; - } - if (display.has("thirdperson_lefthand")) { - JsonObject thirdPersonLeft = display.remove("thirdperson_lefthand").getAsJsonObject(); - if (!found) { - thirdPerson = updateDisplayThirdPerson(gson, getLeftHand(gson, thirdPersonLeft)); - } - } - display.remove("thirdperson"); - display.add("thirdperson", thirdPerson); - - if (display.has("ground")) { - display.remove("ground"); - } - - if (display.has("head")) { - display.remove("head"); - } - - return display; - } - - private static JsonObject getLeftHand(Gson gson, JsonObject old) { - JsonObject newObject = old.deepCopy(); - if (old.has("rotation")) { - JsonArray oldRotation = newObject.remove("rotation").getAsJsonArray(); - JsonArray rotation = new JsonArray(); - rotation.add(oldRotation.get(0).getAsNumber()); - rotation.add(0 - oldRotation.get(1).getAsDouble()); - rotation.add(0 - oldRotation.get(2).getAsDouble()); - newObject.add("rotation", - rotation); - } - - return newObject; - } - - private static JsonObject updateDisplayFirstPerson(Gson gson, JsonObject old) { - JsonObject newObject = old.deepCopy(); - if (old.has("rotation")) { - JsonArray rotation = newObject.remove("rotation").getAsJsonArray(); - newObject.add("rotation", - JsonUtil.subtract( - rotation, - JsonUtil.asArray(gson, "[0, 45, 0]"))); - } - - if (old.has("translation")) { - JsonArray translation = newObject.remove("translation").getAsJsonArray(); - newObject.add("translation", - JsonUtil.add( - JsonUtil.divide( - JsonUtil.subtract( - translation, - JsonUtil.asArray(gson, "[1.13, 3.2, 1.13]")), - JsonUtil.asArray(gson, "[0.4, 0.4, 0.4]")), - JsonUtil.asArray(gson, "[0, 4, 2]"))); - - } - - if (old.has("scale")) { - JsonArray scale = newObject.remove("scale").getAsJsonArray(); - newObject.add("scale", - JsonUtil.divide( - scale, - JsonUtil.asArray(gson, "[0.4, 0.4, 0.4]"))); - } - - return newObject; - } - - private static JsonObject updateDisplayThirdPerson(Gson gson, JsonObject old) { - JsonObject newObject = old.deepCopy(); - if (old.has("rotation")) { - JsonArray rotation = newObject.remove("rotation").getAsJsonArray(); - newObject.add("rotation", - JsonUtil.divide( - JsonUtil.subtract( - rotation, - JsonUtil.asArray(gson, "[0, 0, 20]")), - JsonUtil.asArray(gson, "[1, -1, -1]"))); - } - - if (old.has("translation")) { - JsonArray translation = newObject.remove("translation").getAsJsonArray(); - newObject.add("translation", - JsonUtil.divide( - JsonUtil.subtract( - translation, - JsonUtil.asArray(gson, "[0, 2.75, -3]")), - JsonUtil.asArray(gson, "[1, 1, -1]"))); - } - - // For keeping order - if (old.has("scale")) { - JsonArray scale = newObject.remove("scale").getAsJsonArray(); - newObject.add("scale", scale); - } - - return newObject; - } + private final int to; + private final int from; + + public ModelConverter(PackConverter packConverter, int from, int to) { + super(packConverter); + this.from = from; + this.to = to; + } + + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return true; + } + + /** + * Runs findfiles with the directory Models + * + * @param pack + * @throws IOException + */ + @Override + public void convert(Pack pack) throws IOException { + Path models = pack.getWorkingPath().resolve("assets/minecraft/models".replace("/", File.separator)); + if (models.toFile().exists()) { + findFiles(models); + } + } + + /** + * Recursively finds files with Path path and runs remapModelJson + * + * @param path + * @throws IOException + */ + protected void findFiles(Path path) throws IOException { + File directory = path.toFile(); + for (File file : Objects.requireNonNull(directory.listFiles())) { + if (file.isDirectory()) + continue; + remapModelJson(file.toPath()); + findFiles(file.toPath()); + } + } + + /** + * Updates model Json to newer versions + * + * @param models Model path + * @throws IOException + */ + protected void remapModelJson(Path models) throws IOException { + if (!models.toFile().exists()) + return; + Files.list(models) + .filter(path1 -> path1.toString().endsWith(".json")) + .forEach(model -> { + try { + JsonObject jsonObject; + if (JsonUtil.readJson(packConverter.getGson(), model) != null + && JsonUtil.readJson(packConverter.getGson(), model).isJsonObject()) + jsonObject = JsonUtil.readJson(packConverter.getGson(), model); + else { + Logger.debug("Could not convert model: " + model.getFileName()); + Logger.addTab(); + if (JsonUtil.readJson(packConverter.getGson(), model) == null) + Logger.debug("Check for Syntax Errors in file."); + else + Logger.debug("File is not JSON Object."); + Logger.subTab(); + return; + } + + // Parent Stuff + if (jsonObject.has("parent")) { + // Change parent to lowercase + for (Map.Entry entry : jsonObject.entrySet()) { + if (entry.getKey().equals("parent")) { + String parent = entry.getValue().getAsString().toLowerCase(); + jsonObject.addProperty(entry.getKey(), getParent(parent)); + } + } + + if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.9") + && to < Util.getVersionProtocol(packConverter.getGson(), "1.9")) { + jsonObject = mergeParent(models, jsonObject, jsonObject.get("parent").getAsString()); + } + } + + // GUI light system for 1.15.2 + if (to < Util.getVersionProtocol(packConverter.getGson(), "1.15.2")) { + jsonObject.remove("gui_light"); + } + + // minify the json so we can replace spaces in paths easily + // TODO Improvement: handle this in a cleaner way? + + // handle the remapping of textures, for models that use default texture names + if (jsonObject.has("textures") && jsonObject.get("textures").isJsonObject()) { + NameConverter nameConverter = packConverter.getConverter(NameConverter.class); + JsonObject initialTextureObject = jsonObject.getAsJsonObject("textures"); + JsonObject textureObject = initialTextureObject.deepCopy(); + for (Map.Entry entry : initialTextureObject.entrySet()) { + String value = entry.getValue().getAsString(); + textureObject.remove(entry.getKey()); + + if (to < Util.getVersionProtocol(packConverter.getGson(), "1.19.3") + && from >= Util.getVersionProtocol(packConverter.getGson(), "1.19.3")) { + value = value.replaceAll("minecraft:", ""); + } + // 1.19 Mappings + if (to < Util.getVersionProtocol(packConverter.getGson(), "1.19")) + if (value.startsWith("block/")) + value = "block/" + nameConverter.getBlockMapping19() + .remap(value.substring("block/".length())).toLowerCase() + .replaceAll("[()]", ""); + value = value.toLowerCase().replaceAll("[()]", ""); + + // 1.17 Mappings + if (to < Util.getVersionProtocol(packConverter.getGson(), "1.17")) { + if (value.startsWith("block/")) + value = "block/" + nameConverter.getBlockMapping17() + .remap(value.substring("block/".length())).toLowerCase() + .replaceAll("[()]", ""); + else if (value.startsWith("item/")) + value = "item/" + nameConverter.getItemMapping17() + .remap(value.substring("item/".length())).toLowerCase() + .replaceAll("[()]", ""); + value = value.toLowerCase().replaceAll("[()]", ""); + } + + // 1.14 Mappings + if (to < Util.getVersionProtocol(packConverter.getGson(), "1.14")) + if (value.startsWith("block/")) + value = "block/" + + nameConverter.getNewBlockMapping() + .remap(value.substring("block/".length())); + + // Dyes + if (value.startsWith("item/") && value.contains("dye")) + if (to < Util.getVersionProtocol(packConverter.getGson(), "1.14")) + value = "item/" + + nameConverter.getNewItemMapping() + .remap(value.substring("item/".length())); + + // 1.13 Mappings + if (to < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { + if (value.startsWith("block/")) { + List same = Arrays.asList("snow"); + String remap = nameConverter.getBlockMapping() + .remap(value.substring("block/".length())).toLowerCase() + .replaceAll("[()]", ""); + for (String s : same) { + if (s.equals(value.substring("block/".length()))) { + remap = s; + } + } + value = "blocks/" + remap; + } else if (value.startsWith("item/")) + value = "items/" + nameConverter.getItemMapping() + .remap(value.substring("item/".length())).toLowerCase() + .replaceAll("[()]", ""); + else + value = value.toLowerCase().replaceAll("[()]", ""); + } + + if (!textureObject.has(entry.getKey())) + textureObject.addProperty(entry.getKey(), value); + } + + jsonObject.remove("textures"); + jsonObject.add("textures", textureObject); + } + + // fix display settings for packs for 1.8 + if (jsonObject.has("display") && from > Util.getVersionProtocol(packConverter.getGson(), "1.8") + && to == Util.getVersionProtocol(packConverter.getGson(), "1.8")) { + JsonElement display = jsonObject.remove("display"); + + if (display.isJsonObject()) { + jsonObject.add("display", + updateDisplay(packConverter.getGson(), display.getAsJsonObject())); + } + } + + if (jsonObject.has("overrides")) { + for (Map.Entry entry : jsonObject.entrySet()) { + if (entry.getKey().equals("overrides")) { + JsonArray overrides = jsonObject.get("overrides").getAsJsonArray(); + JsonArray overrides2 = new JsonArray(); + for (int i = 0; i < overrides.size(); i++) { + JsonObject object = overrides.get(i).getAsJsonObject(); + for (Map.Entry json : object.entrySet()) { + if (json.getKey().equals("model")) + object.addProperty(json.getKey(), + json.getValue().getAsString().replaceAll("[()]", "")); + else + object.add(json.getKey(), json.getValue()); + } + overrides2.add(object); + } + jsonObject.add(entry.getKey(), overrides2); + } + } + } + + if (!JsonUtil.readJson(packConverter.getGson(), model).equals(jsonObject)) { + Logger.debug("Updating Model: " + model.getFileName()); + JsonUtil.writeJson(packConverter.getGson(), model, jsonObject); + } + } catch (IOException e) { + throw Util.propagate(e); + } + }); + } + + private String getParent(String parent) { + parent = parent.replace(" ", "_"); + + // Get block/item parents renamed + if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.19.3") + && to < Util.getVersionProtocol(packConverter.getGson(), "1.19.3")) + parent = parent.replaceAll("minecraft:", ""); + + if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.19") + && to < Util.getVersionProtocol(packConverter.getGson(), "1.19")) + if (parent.startsWith("block/")) + parent = setParent("block/", "/backwards/blocks.json", parent, "1_19"); + + if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.17") + && to < Util.getVersionProtocol(packConverter.getGson(), "1.17")) { + if (parent.startsWith("block/")) + parent = setParent("block/", "/backwards/blocks.json", parent, "1_17"); + if (parent.startsWith("item/")) + parent = setParent("item/", "/backwards/items.json", parent, "1_17"); + } + + if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.14") + && to < Util.getVersionProtocol(packConverter.getGson(), "1.14")) { + if (parent.startsWith("block/")) + parent = setParent("block/", "/backwards/blocks.json", parent, "1_14"); + if (parent.startsWith("item/")) + parent = setParent("item/", "/backwards/items.json", parent, "1_14"); + } + + if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.13") + && to < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { + + if (parent.startsWith("block/")) + parent = setParent("block/", "/backwards/blocks.json", parent, "1_13"); + if (parent.startsWith("item/")) + parent = setParent("item/", "/backwards/items.json", parent, "1_13"); + + } + return parent; + } + + protected JsonObject mergeParent(Path models, JsonObject current, String parent) { + JsonObject jsonObject = current.deepCopy(); + if (parent == null || !models.resolve(parent + ".json").toFile().exists()) + return jsonObject; + + if (!current.has("parent")) + return jsonObject; + + Path parentPath = models.resolve(parent + ".json"); + try { + JsonObject parentObj = JsonUtil.readJson(packConverter.getGson(), parentPath); + if (parentObj != null) { + jsonObject.remove("parent"); + if (parentObj.has("parent")) { + String parentStr = parentObj.get("parent").getAsString(); + String parentVal = parentStr == null ? null : getParent(parentStr); + jsonObject = mergeParent(models, parentObj, parentVal); + } + + if (!jsonObject.has("elements") && current.has("elements")) + jsonObject.add("elements", current.get("elements")); + + if (!jsonObject.has("elements") && parentObj.has("elements")) + jsonObject.add("elements", parentObj.get("elements")); + + if (!jsonObject.has("display") && parentObj.has("display")) + jsonObject.add("display", parentObj.get("display")); + + JsonObject textures = new JsonObject(); + if (jsonObject.has("textures")) + textures = jsonObject.remove("textures").getAsJsonObject(); + + if (current.has("textures")) { + for (String s : current.get("textures").getAsJsonObject().keySet()) + if (!textures.has(s)) + textures.add(s, current.get("textures").getAsJsonObject().get(s)); + } + + if (parentObj.has("textures")) { + JsonObject parentTextures = parentObj.get("textures").getAsJsonObject(); + for (String s : parentTextures.keySet()) + if (!textures.has(s)) + textures.add(s, parentTextures.get(s)); + } + + for (int i = 0; i < 5; i++) { + JsonObject textures2 = new JsonObject(); + for (String s : textures.keySet()) { + if (textures.get(s).getAsString().startsWith("#") && + textures.has(textures.get(s).getAsString().substring(1))) { + textures2.add(s, + textures.get(textures.get(s).getAsString().substring(1))); + } else { + textures2.add(s, textures.get(s)); + } + } + textures = textures2; + } + + if (textures.keySet().size() > 0) + jsonObject.add("textures", textures); + } + } catch (IOException e) { + } + + return jsonObject; + } + + /** + * Gets parent object and sets a new one + * + * @param prefix prefix of file path + * @param path File path of json control + * @param parent Parent String + * @return New string with changed parent. + */ + protected String setParent(String prefix, String path, String parent, String item) { + String parent2 = parent.replace(prefix, ""); + JsonObject file = JsonUtil.readJsonResource(packConverter.getGson(), path).getAsJsonObject(item); + if (file == null) { + Logger.debug("Prefix Failed on: " + parent); + return ""; + } + return file.has(parent2) ? prefix + file.get(parent2).getAsString() : parent; + } + + protected static JsonObject updateDisplay(Gson gson, JsonObject display) { + JsonObject defaults = JsonUtil.readJsonResource(gson, "/backwards/display.json"); + if (display == null) + return defaults.deepCopy(); + + // First Person + boolean found = false; + JsonObject firstPerson = defaults.get("firstperson").getAsJsonObject().deepCopy(); + if (display.has("firstperson_righthand")) { + firstPerson = updateDisplayFirstPerson(gson, display.remove("firstperson_righthand").getAsJsonObject()); + found = true; + } + if (display.has("firstperson_lefthand")) { + JsonObject firstPersonLeft = display.remove("firstperson_lefthand").getAsJsonObject(); + if (!found) { + firstPerson = updateDisplayFirstPerson(gson, getLeftHand(gson, firstPersonLeft)); + } + } + display.remove("firstperson"); + display.add("firstperson", firstPerson); + + // Third Person + found = false; + JsonObject thirdPerson = defaults.get("thirdperson").getAsJsonObject().deepCopy(); + if (display.has("thirdperson_righthand")) { + thirdPerson = updateDisplayThirdPerson(gson, display.remove("thirdperson_righthand").getAsJsonObject()); + found = true; + } + if (display.has("thirdperson_lefthand")) { + JsonObject thirdPersonLeft = display.remove("thirdperson_lefthand").getAsJsonObject(); + if (!found) { + thirdPerson = updateDisplayThirdPerson(gson, getLeftHand(gson, thirdPersonLeft)); + } + } + display.remove("thirdperson"); + display.add("thirdperson", thirdPerson); + + if (display.has("ground")) { + display.remove("ground"); + } + + if (display.has("head")) { + display.remove("head"); + } + + return display; + } + + private static JsonObject getLeftHand(Gson gson, JsonObject old) { + JsonObject newObject = old.deepCopy(); + if (old.has("rotation")) { + JsonArray oldRotation = newObject.remove("rotation").getAsJsonArray(); + JsonArray rotation = new JsonArray(); + rotation.add(oldRotation.get(0).getAsNumber()); + rotation.add(0 - oldRotation.get(1).getAsDouble()); + rotation.add(0 - oldRotation.get(2).getAsDouble()); + newObject.add("rotation", + rotation); + } + + return newObject; + } + + private static JsonObject updateDisplayFirstPerson(Gson gson, JsonObject old) { + JsonObject newObject = old.deepCopy(); + if (old.has("rotation")) { + JsonArray rotation = newObject.remove("rotation").getAsJsonArray(); + newObject.add("rotation", + JsonUtil.subtract( + rotation, + JsonUtil.asArray(gson, "[0, 45, 0]"))); + } + + if (old.has("translation")) { + JsonArray translation = newObject.remove("translation").getAsJsonArray(); + newObject.add("translation", + JsonUtil.add( + JsonUtil.divide( + JsonUtil.subtract( + translation, + JsonUtil.asArray(gson, "[1.13, 3.2, 1.13]")), + JsonUtil.asArray(gson, "[0.4, 0.4, 0.4]")), + JsonUtil.asArray(gson, "[0, 4, 2]"))); + + } + + if (old.has("scale")) { + JsonArray scale = newObject.remove("scale").getAsJsonArray(); + newObject.add("scale", + JsonUtil.divide( + scale, + JsonUtil.asArray(gson, "[0.4, 0.4, 0.4]"))); + } + + return newObject; + } + + private static JsonObject updateDisplayThirdPerson(Gson gson, JsonObject old) { + JsonObject newObject = old.deepCopy(); + if (old.has("rotation")) { + JsonArray rotation = newObject.remove("rotation").getAsJsonArray(); + newObject.add("rotation", + JsonUtil.divide( + JsonUtil.subtract( + rotation, + JsonUtil.asArray(gson, "[0, 0, 20]")), + JsonUtil.asArray(gson, "[1, -1, -1]"))); + } + + if (old.has("translation")) { + JsonArray translation = newObject.remove("translation").getAsJsonArray(); + newObject.add("translation", + JsonUtil.divide( + JsonUtil.subtract( + translation, + JsonUtil.asArray(gson, "[0, 2.75, -3]")), + JsonUtil.asArray(gson, "[1, 1, -1]"))); + } + + // For keeping order + if (old.has("scale")) { + JsonArray scale = newObject.remove("scale").getAsJsonArray(); + newObject.add("scale", scale); + } + + return newObject; + } } \ No newline at end of file diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/NameConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/NameConverter.java index e329d7a0..8eb228b0 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/NameConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/NameConverter.java @@ -19,8 +19,8 @@ import java.util.stream.Stream; public class NameConverter extends Converter { - private int to; - private int from; + private final int from; + private final int to; private final Mapping blockMapping; private final Mapping newBlockMapping; @@ -33,7 +33,7 @@ public class NameConverter extends Converter { private final Mapping langMapping; private final Mapping langMapping14; private final Mapping blockMapping203; - private final Mapping itemMapping203; +// private final Mapping itemMapping203; public NameConverter(PackConverter packConverter, int from, int to) { super(packConverter); @@ -51,7 +51,12 @@ public NameConverter(PackConverter packConverter, int from, int to) { langMapping = new Mapping(gson, "lang", "1_13", true); langMapping14 = new Mapping(gson, "lang", "1_14", true); blockMapping203 = new Mapping(gson, "blocks", "1_20_3", true); - itemMapping203 = new Mapping(gson, "items", "1_20_3", true); +// TODO/(not used?): itemMapping203 = new Mapping(gson, "items", "1_20_3", true); + } + + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return true; } /** diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/PackMetaConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/PackMetaConverter.java index f2cc1238..28a0c2ee 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/PackMetaConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/PackMetaConverter.java @@ -5,18 +5,24 @@ import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.JsonUtil; import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import com.google.gson.JsonObject; import java.io.IOException; import java.nio.file.Path; public class PackMetaConverter extends Converter { - private int version; + private final int to; private int versionInt = 4; - public PackMetaConverter(PackConverter packConverter, int versionIn) { + public PackMetaConverter(PackConverter packConverter, int to) { super(packConverter); - version = versionIn; + this.to = to; + } + + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return true; } /** @@ -28,10 +34,11 @@ public PackMetaConverter(PackConverter packConverter, int versionIn) { @Override public void convert(Pack pack) throws IOException { Path file = pack.getWorkingPath().resolve("pack.mcmeta"); - if (!file.toFile().exists()) + if (!file.toFile().exists()) { return; + } - JsonObject versionObj = Util.getVersionObjectByProtocol(packConverter.getGson(), version); + JsonObject versionObj = Util.getVersionObjectByProtocol(packConverter.getGson(), to); if (versionObj != null) { versionInt = versionObj.get("pack_format").getAsInt(); } @@ -39,16 +46,20 @@ public void convert(Pack pack) throws IOException { JsonObject json = JsonUtil.readJson(packConverter.getGson(), file); { JsonObject meta = json.getAsJsonObject("meta"); - if (meta == null) + if (meta == null) { meta = new JsonObject(); - meta.addProperty("game_version", Util.getVersionFromProtocol(packConverter.getGson(), version)); + } + + meta.addProperty("game_version", Util.getVersionFromProtocol(packConverter.getGson(), to)); json.add("meta", meta); } { JsonObject packObject = json.getAsJsonObject("pack"); - if (packObject == null) + if (packObject == null) { packObject = new JsonObject(); + } + packObject.addProperty("pack_format", versionInt); json.add("pack", packObject); } diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/ParticleConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/ParticleConverter.java index 446667e1..a99bb076 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/ParticleConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/ParticleConverter.java @@ -3,6 +3,8 @@ import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import java.io.File; import java.io.IOException; @@ -14,13 +16,19 @@ public ParticleConverter(PackConverter packConverter) { super(packConverter); } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from >= Util.getVersionProtocol(gson, "1.18") && to <= Util.getVersionProtocol(gson, "1.17.1"); + } + @Override public void convert(Pack pack) throws IOException { Path particles = pack.getWorkingPath().resolve("assets/minecraft/particles".replace("/", File.separator)); - if (!particles.toFile().exists()) - return; - Path blockMarkerPath = particles.resolve("block_marker.json"); - if (blockMarkerPath.toFile().exists()) - Files.move(blockMarkerPath, particles.resolve("light.json")); + if (particles.toFile().exists()) { + Path blockMarkerPath = particles.resolve("block_marker.json"); + if (blockMarkerPath.toFile().exists()) { + Files.move(blockMarkerPath, particles.resolve("light.json")); + } + } } } diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/ChestConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/ChestConverter.java index fd1a2b63..0596b6aa 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/ChestConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/ChestConverter.java @@ -4,6 +4,8 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.ImageConverter; +import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import java.io.File; import java.io.IOException; @@ -14,18 +16,23 @@ public ChestConverter(PackConverter packConverter) { super(packConverter); } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from >= Util.getVersionProtocol(gson, "1.15") && to <= Util.getVersionProtocol(gson, "1.14.4"); + } + /** * Fixes Chest Textures in 1.15 Remaps textures, and updates images - * + * * @param pack * @throws IOException */ @Override public void convert(Pack pack) throws IOException { - Path imagePath = pack.getWorkingPath() - .resolve("assets/minecraft/textures/entity/chest".replace("/", File.separator)); - if (!imagePath.toFile().exists()) + Path imagePath = pack.getWorkingPath().resolve("assets/minecraft/textures/entity/chest".replace("/", File.separator)); + if (!imagePath.toFile().exists()) { return; + } // Double chest doubleChest(imagePath, "normal"); @@ -41,19 +48,21 @@ public void convert(Pack pack) throws IOException { /** * Fixes Normal chests - * + * * @param imagePath * @param name * @throws IOException */ private void chest(Path imagePath, String name) throws IOException { int defaultW = 64, defaultH = 64; - if (!imagePath.resolve(name + ".png").toFile().exists()) + if (!imagePath.resolve(name + ".png").toFile().exists()) { return; + } ImageConverter normal = new ImageConverter(defaultW, defaultH, imagePath.resolve(name + ".png")); - if (!normal.fileIsPowerOfTwo()) + if (!normal.fileIsPowerOfTwo()) { return; + } // Create a new Image normal.newImage(defaultW, defaultH); @@ -88,7 +97,7 @@ private void chest(Path imagePath, String name) throws IOException { /** * Splits Double Chests into 2 images - * + * * @param imagePath * @param name * @throws IOException diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/CompassConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/CompassConverter.java index 29090e56..b9a8903c 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/CompassConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/CompassConverter.java @@ -5,28 +5,34 @@ import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.ImageConverter; import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import java.io.File; import java.io.IOException; import java.nio.file.Path; public class CompassConverter extends Converter { - private int to; - private Path items; + private final int to; public CompassConverter(PackConverter packConverter, int to) { super(packConverter); this.to = to; } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from >= Util.getVersionProtocol(gson, "1.9") && to <= Util.getVersionProtocol(gson, "1.8.9"); + } + @Override public void convert(Pack pack) throws IOException { String itemsT = "items"; - if (to > Util.getVersionProtocol(packConverter.getGson(), "1.13")) + if (to > Util.getVersionProtocol(packConverter.getGson(), "1.13")) { itemsT = "item"; - Path compassPath = pack.getWorkingPath() - .resolve(("assets/minecraft/textures/" + itemsT + "/compass.png").replace("/", File.separator)); - items = compassPath.getParent(); + } + + Path compassPath = pack.getWorkingPath().resolve(("assets/minecraft/textures/" + itemsT + "/compass.png").replace("/", File.separator)); + Path items = compassPath.getParent(); if (compassPath.toFile().exists()) { ImageConverter imageConverter = new ImageConverter(16, 16 * 32, compassPath); if (!imageConverter.fileIsPowerOfTwo()) diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/EnchantConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/EnchantConverter.java index 0f43ed4e..3b0ffa5f 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/EnchantConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/EnchantConverter.java @@ -4,6 +4,8 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.ImageConverter; +import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import java.io.File; import java.io.IOException; @@ -15,18 +17,20 @@ public EnchantConverter(PackConverter packConverter) { } @Override - public void convert(Pack pack) throws IOException { - Path paintingPath = pack.getWorkingPath() - .resolve("assets/minecraft/textures/misc/enchanted_item_glint.png".replace("/", File.separator)); - if (!paintingPath.toFile().exists()) - return; - - ImageConverter imageConverter = new ImageConverter(64, 64, paintingPath); - if (!imageConverter.fileIsPowerOfTwo()) - return; + public boolean shouldConvert(Gson gson, int from, int to) { + return from >= Util.getVersionProtocol(gson, "1.15") && to <= Util.getVersionProtocol(gson, "1.14.4"); + } - imageConverter.newImage(64, 64); - imageConverter.grayscale(); - imageConverter.store(); + @Override + public void convert(Pack pack) throws IOException { + Path paintingPath = pack.getWorkingPath().resolve("assets/minecraft/textures/misc/enchanted_item_glint.png".replace("/", File.separator)); + if (paintingPath.toFile().exists()) { + ImageConverter imageConverter = new ImageConverter(64, 64, paintingPath); + if (imageConverter.fileIsPowerOfTwo()) { + imageConverter.newImage(64, 64); + imageConverter.grayscale(); + imageConverter.store(); + } + } } } diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/InventoryConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/InventoryConverter.java index c595c400..86303dad 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/InventoryConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/InventoryConverter.java @@ -4,6 +4,8 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.ImageConverter; +import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import java.io.File; import java.io.IOException; @@ -14,12 +16,17 @@ public InventoryConverter(PackConverter packConverter) { super(packConverter); } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from >= Util.getVersionProtocol(gson, "1.18") && to <= Util.getVersionProtocol(gson, "1.17.1"); + } + @Override public void convert(Pack pack) throws IOException { - Path imagePath = pack.getWorkingPath() - .resolve("assets/minecraft/textures/gui/container/inventory.png".replace("/", File.separator)); - if (!imagePath.toFile().exists()) + Path imagePath = pack.getWorkingPath().resolve("assets/minecraft/textures/gui/container/inventory.png".replace("/", File.separator)); + if (!imagePath.toFile().exists()) { return; + } int defaultW = 256, defaultH = 256; ImageConverter image = new ImageConverter(defaultW, defaultH, imagePath); @@ -27,7 +34,6 @@ public void convert(Pack pack) throws IOException { image.subImage(0, 0, 256, 256, 0, 0); image.subImage(0, 198, 16, 230, 0, 166); image.subImage(16, 198, 32, 230, 104, 166); - image.store(); } } diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/MapIconConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/MapIconConverter.java index dc107284..13f3401e 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/MapIconConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/MapIconConverter.java @@ -5,6 +5,7 @@ import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.Logger; import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import javax.imageio.ImageIO; import java.awt.*; @@ -32,9 +33,14 @@ public MapIconConverter(PackConverter packConverter) { mapping.put(pack(72, 0), pack(8, 16)); } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from >= Util.getVersionProtocol(gson, "1.13") && to <= Util.getVersionProtocol(gson, "1.12.2"); + } + /** * Converts maps - * + * * @param pack * @throws IOException */ diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/PaintingConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/PaintingConverter.java index 7f460500..fccfbe36 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/PaintingConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/PaintingConverter.java @@ -4,6 +4,8 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.ImageConverter; +import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import java.io.File; import java.io.IOException; @@ -12,27 +14,33 @@ import java.util.ArrayList; public class PaintingConverter extends Converter { - private ArrayList paintings = new ArrayList<>(); + private final ArrayList paintings = new ArrayList<>(); public PaintingConverter(PackConverter packConverter) { super(packConverter); } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from >= Util.getVersionProtocol(gson, "1.14") && to <= Util.getVersionProtocol(gson, "1.13.2"); + } + /** * Remaps painting image to multiple images. - * + * * @param pack * @throws IOException */ @Override public void convert(Pack pack) throws IOException { - Path paintingPath = pack.getWorkingPath() - .resolve("assets/minecraft/textures/painting".replace("/", File.separator)); - if (!paintingPath.toFile().exists()) + Path paintingPath = pack.getWorkingPath().resolve("assets/minecraft/textures/painting".replace("/", File.separator)); + if (!paintingPath.toFile().exists()) { return; + } File[] paintingFiles = paintingPath.toFile().listFiles(); String filename = ""; + assert paintingFiles != null; for (File file : paintingFiles) { if (file.getName().endsWith(".png")) { filename = file.getName(); @@ -44,53 +52,53 @@ public void convert(Pack pack) throws IOException { normal.newImage(256, 256); // 16x16 - painting(normal, paintingPath, "kebab.png", 0, 0, 1, 1); - painting(normal, paintingPath, "aztec.png", 16, 0, 1, 1); - painting(normal, paintingPath, "alban.png", 32, 0, 1, 1); - painting(normal, paintingPath, "aztec2.png", 48, 0, 1, 1); - painting(normal, paintingPath, "bomb.png", 64, 0, 1, 1); - painting(normal, paintingPath, "plant.png", 80, 0, 1, 1); - painting(normal, paintingPath, "wasteland.png", 96, 0, 1, 1); - painting(normal, paintingPath, "back.png", 192, 0, 1, 1); + painting(normal, paintingPath, "kebab.png", 0, 0); + painting(normal, paintingPath, "aztec.png", 16, 0); + painting(normal, paintingPath, "alban.png", 32, 0); + painting(normal, paintingPath, "aztec2.png", 48, 0); + painting(normal, paintingPath, "bomb.png", 64, 0); + painting(normal, paintingPath, "plant.png", 80, 0); + painting(normal, paintingPath, "wasteland.png", 96, 0); + painting(normal, paintingPath, "back.png", 192, 0); // 32x16 - painting(normal, paintingPath, "pool.png", 0, 32, 2, 1); - painting(normal, paintingPath, "courbet.png", 32, 32, 2, 1); - painting(normal, paintingPath, "sea.png", 64, 32, 2, 1); - painting(normal, paintingPath, "sunset.png", 96, 32, 2, 1); - painting(normal, paintingPath, "creebet.png", 128, 32, 2, 1); + painting(normal, paintingPath, "pool.png", 0, 32); + painting(normal, paintingPath, "courbet.png", 32, 32); + painting(normal, paintingPath, "sea.png", 64, 32); + painting(normal, paintingPath, "sunset.png", 96, 32); + painting(normal, paintingPath, "creebet.png", 128, 32); // 16x3 - painting(normal, paintingPath, "wanderer.png", 0, 64, 1, 2); - painting(normal, paintingPath, "graham.png", 16, 64, 1, 2); + painting(normal, paintingPath, "wanderer.png", 0, 64); + painting(normal, paintingPath, "graham.png", 16, 64); // 64x48 - painting(normal, paintingPath, "skeleton.png", 192, 64, 4, 3); - painting(normal, paintingPath, "donkey_kong.png", 192, 112, 4, 3); + painting(normal, paintingPath, "skeleton.png", 192, 64); + painting(normal, paintingPath, "donkey_kong.png", 192, 112); // 64x32 - painting(normal, paintingPath, "fighters.png", 0, 96, 4, 2); + painting(normal, paintingPath, "fighters.png", 0, 96); // 32x32 - painting(normal, paintingPath, "match.png", 0, 128, 2, 2); - painting(normal, paintingPath, "bust.png", 32, 128, 2, 2); - painting(normal, paintingPath, "stage.png", 64, 128, 2, 2); - painting(normal, paintingPath, "void.png", 96, 128, 2, 2); - painting(normal, paintingPath, "skull_and_roses.png", 128, 128, 2, 2); - painting(normal, paintingPath, "wither.png", 160, 128, 2, 2); + painting(normal, paintingPath, "match.png", 0, 128); + painting(normal, paintingPath, "bust.png", 32, 128); + painting(normal, paintingPath, "stage.png", 64, 128); + painting(normal, paintingPath, "void.png", 96, 128); + painting(normal, paintingPath, "skull_and_roses.png", 128, 128); + painting(normal, paintingPath, "wither.png", 160, 128); // 64x64 - painting(normal, paintingPath, "pointer.png", 0, 192, 4, 4); - painting(normal, paintingPath, "pigscene.png", 64, 192, 4, 4); - painting(normal, paintingPath, "burning_skull.png", 128, 192, 4, 4); + painting(normal, paintingPath, "pointer.png", 0, 192); + painting(normal, paintingPath, "pigscene.png", 64, 192); + painting(normal, paintingPath, "burning_skull.png", 128, 192); normal.store(paintingPath.resolve("paintings_kristoffer_zetterstrand.png")); - for (String item : paintings) + for (String item : paintings) { Files.deleteIfExists(paintingPath.resolve(item)); + } } - private void painting(ImageConverter normal, Path paintingPath, String name, int x, int y, int scaleX, - int scaleY) + private void painting(ImageConverter normal, Path paintingPath, String name, int x, int y) throws IOException { if (paintingPath.resolve(name).toFile().exists()) { normal.addImage(paintingPath.resolve(name), x, y); diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/ParticleTextureConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/ParticleTextureConverter.java index 860d94b3..1d4b8406 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/ParticleTextureConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/ParticleTextureConverter.java @@ -5,16 +5,17 @@ import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.ImageConverter; import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; +import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.nio.file.Path; -import javax.imageio.ImageIO; - public class ParticleTextureConverter extends Converter { - int from, to; + private final int from; + private final int to; public ParticleTextureConverter(PackConverter packConverter, int from, int to) { super(packConverter); @@ -22,27 +23,36 @@ public ParticleTextureConverter(PackConverter packConverter, int from, int to) { this.to = to; } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return true; + } + /** * Updates Particles - * + * * @param pack * @throws IOException */ @Override public void convert(Pack pack) throws IOException { Path texturesPath = pack.getWorkingPath().resolve("assets/minecraft/textures".replace("/", File.separator)); - if (!texturesPath.toFile().exists()) + if (!texturesPath.toFile().exists()) { return; + } Path particleFolderPath = texturesPath.resolve("particle"); - if (!particleFolderPath.toFile().exists()) + if (!particleFolderPath.toFile().exists()) { return; + } Path particlesImagePath = particleFolderPath.resolve("particles.png"); - if (!particlesImagePath.toFile().exists()) + if (!particlesImagePath.toFile().exists()) { return; + } - int defaultW = 128, defaultH = 128; + // Default W/H is 128 + int defaultW, defaultH; // Particles if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.14") @@ -148,8 +158,9 @@ public void convert(Pack pack) throws IOException { Path entityPath = texturesPath.resolve("entity"); Path fishingHookPath = entityPath.resolve("fishing_hook.png"); - if (fishingHookPath.toFile().exists()) + if (fishingHookPath.toFile().exists()) { converter.addImage(fishingHookPath, 8, 16); + } converter.store(); } @@ -159,11 +170,11 @@ public void convert(Pack pack) throws IOException { defaultW = 128; defaultH = 128; ImageConverter converter = new ImageConverter(defaultW, defaultH, particlesImagePath); - if (!converter.fileIsPowerOfTwo()) - return; - converter.newImage(128, 128); - converter.subImage(0, 0, 128, 128, 0, 0); - converter.store(); + if (converter.fileIsPowerOfTwo()) { + converter.newImage(128, 128); + converter.subImage(0, 0, 128, 128, 0, 0); + converter.store(); + } } } } diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/WaterConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/WaterConverter.java index d153ffe8..885302cf 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/WaterConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/WaterConverter.java @@ -4,35 +4,42 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.ImageConverter; -import java.awt.Color; +import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; + +import java.awt.*; import java.io.File; import java.io.IOException; import java.nio.file.Path; public class WaterConverter extends Converter { - public WaterConverter(PackConverter packConverter) { - super(packConverter); - } + public WaterConverter(PackConverter packConverter) { + super(packConverter); + } + + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from >= Util.getVersionProtocol(gson, "1.13") && to <= Util.getVersionProtocol(gson, "1.12.2"); + } - @Override - public void convert(Pack pack) throws IOException { - Path blocksFolder = pack.getWorkingPath() - .resolve("assets/minecraft/textures/blocks".replace("/", File.separator)); - if (!blocksFolder.toFile().exists()) - return; - colorize(blocksFolder.resolve("water_flow.png"), 32, 1024); - colorize(blocksFolder.resolve("water_still.png"), 32, 1024); - colorize(blocksFolder.resolve("water_overlay.png"), 32, 32); - } + @Override + public void convert(Pack pack) throws IOException { + Path blocksFolder = pack.getWorkingPath().resolve("assets/minecraft/textures/blocks".replace("/", File.separator)); + if (blocksFolder.toFile().exists()) { + colorize(blocksFolder.resolve("water_flow.png"), 32, 1024); + colorize(blocksFolder.resolve("water_still.png"), 32, 1024); + colorize(blocksFolder.resolve("water_overlay.png"), 32, 32); + } + } - private void colorize(Path path, int w, int h) throws IOException { - if (!path.toFile().exists()) - return; - ImageConverter imageConverter = new ImageConverter(w, h, path); - if (!imageConverter.fileIsPowerOfTwo()) - return; - imageConverter.newImage(w, h); - imageConverter.colorize(new Color(45, 63, 244, 170)); - imageConverter.store(); - } + private void colorize(Path path, int w, int h) throws IOException { + if (path.toFile().exists()) { + ImageConverter imageConverter = new ImageConverter(w, h, path); + if (imageConverter.fileIsPowerOfTwo()) { + imageConverter.newImage(w, h); + imageConverter.colorize(new Color(45, 63, 244, 170)); + imageConverter.store(); + } + } + } } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java index c42c3312..fc5adc1c 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java @@ -7,131 +7,63 @@ import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.Logger; import com.agentdid127.resourcepack.library.utilities.Util; -import com.google.gson.GsonBuilder; -import com.google.gson.Strictness; +import com.google.gson.Gson; import java.io.IOException; import java.io.PrintStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.Objects; +import java.util.stream.Stream; public class ForwardsPackConverter extends PackConverter { Path INPUT_DIR; + private final int from; + private final int to; - public ForwardsPackConverter(String from, String to, String light, boolean minify, Path input, boolean debug, + public ForwardsPackConverter(Gson gson, int from, int to, String light, Path input, boolean debug, PrintStream out) { - GsonBuilder gsonBuilder = new GsonBuilder().setStrictness(Strictness.LENIENT); - if (!minify) { - gsonBuilder.setPrettyPrinting(); - } - gson = gsonBuilder.create(); + this.gson = gson; Logger.setDebug(debug); Logger.setStream(out); Logger.log("Converting packs from: " + from + " to " + to); + this.from = from; + this.to = to; this.INPUT_DIR = input; - converterRunner(from, to, light); + this.setupConverters(light); } - private void converterRunner(String from, String to, String light) { - int protocolFrom = Util.getVersionProtocol(gson, from); - int protocolTo = Util.getVersionProtocol(gson, to); - - // This needs to be run first, other converters might reference - // new directory names. - this.registerConverter(new NameConverter(this, protocolFrom, protocolTo)); - this.registerConverter(new PackMetaConverter(this, protocolFrom, protocolTo)); - - if (protocolFrom < Util.getVersionProtocol(gson, "1.9") - && protocolTo >= Util.getVersionProtocol(gson, "1.9")) { - this.registerConverter(new CompassConverter(this, protocolTo)); - this.registerConverter(new OffHandCreator(this)); - } - - if (protocolFrom < Util.getVersionProtocol(gson, "1.11") - && protocolTo >= Util.getVersionProtocol(gson, "1.11")) { - this.registerConverter(new SpacesConverter(this)); - } - - this.registerConverter(new ModelConverter(this, light, protocolFrom, protocolTo)); - - if (protocolFrom <= Util.getVersionProtocol(gson, "1.12.2") - && protocolTo >= Util.getVersionProtocol(gson, "1.13")) { - this.registerConverter(new SoundsConverter(this)); - this.registerConverter(new AnimationConverter(this)); - this.registerConverter(new MapIconConverter(this)); - this.registerConverter(new MCPatcherConverter(this)); - this.registerConverter(new WaterConverter(this)); - } - - this.registerConverter(new BlockStateConverter(this, protocolFrom, protocolTo)); - - if (protocolTo >= Util.getVersionProtocol(gson, "1.13")) { - this.registerConverter(new LangConverter(this, from, to)); - } - - this.registerConverter(new ParticleTextureConverter(this, protocolFrom, protocolTo)); - if (protocolFrom < Util.getVersionProtocol(gson, "1.15") && protocolTo >= Util.getVersionProtocol(gson, "1.15")) { - this.registerConverter(new ChestConverter(this)); - } - - if (protocolFrom <= Util.getVersionProtocol(gson, "1.13") - && protocolTo >= Util.getVersionProtocol(gson, "1.14.4")) { - this.registerConverter(new PaintingConverter(this)); - } - - if (protocolFrom <= Util.getVersionProtocol(gson, "1.13.2") - && protocolTo >= Util.getVersionProtocol(gson, "1.14")) { - this.registerConverter(new MobEffectAtlasConverter(this, protocolFrom)); - } - - if (protocolFrom < Util.getVersionProtocol(gson, "1.15") - && protocolTo >= Util.getVersionProtocol(gson, "1.15")) { - this.registerConverter(new EnchantConverter(this)); - } - - if (protocolFrom < Util.getVersionProtocol(gson, "1.18") - && protocolTo >= Util.getVersionProtocol(gson, "1.18")) { - this.registerConverter(new ParticleConverter(this)); - } - + private void setupConverters(String light) { + this.registerConverter(new NameConverter(this, from, to)); // This needs to be run first, other converters might reference new directory names. + this.registerConverter(new PackMetaConverter(this, from, to)); + this.registerConverter(new CompassConverter(this, to)); + this.registerConverter(new OffHandCreator(this)); + this.registerConverter(new SpacesConverter(this)); + this.registerConverter(new ModelConverter(this, light, from, to)); + this.registerConverter(new SoundsConverter(this)); + this.registerConverter(new AnimationConverter(this)); + this.registerConverter(new MapIconConverter(this)); + this.registerConverter(new MCPatcherConverter(this)); + this.registerConverter(new WaterConverter(this)); + this.registerConverter(new BlockStateConverter(this, from, to)); + this.registerConverter(new LangConverter(this, from, to)); + this.registerConverter(new ParticleTextureConverter(this, from, to)); + this.registerConverter(new PaintingConverter(this)); + this.registerConverter(new MobEffectAtlasConverter(this, from)); + this.registerConverter(new ChestConverter(this)); + this.registerConverter(new EnchantConverter(this)); + this.registerConverter(new ParticleConverter(this)); this.registerConverter(new InventoryConverter(this)); - - if (protocolFrom < Util.getVersionProtocol(gson, "1.19.3") - && protocolTo >= Util.getVersionProtocol(gson, "1.19.3")) { - this.registerConverter(new AtlasConverter(this)); - this.registerConverter(new CreativeTabsConverter(this)); - } - - if (protocolFrom < Util.getVersionProtocol(gson, "1.19.4") - && protocolTo >= Util.getVersionProtocol(gson, "1.19.4")) { - this.registerConverter(new EnchantPathConverter(this)); - this.registerConverter(new SlidersCreator(this)); - } - - if (protocolFrom < Util.getVersionProtocol(gson, "1.20") - && protocolTo >= Util.getVersionProtocol(gson, "1.20")) { - this.registerConverter(new TitleConverter(this)); - } - - if (protocolFrom < Util.getVersionProtocol(gson, "1.20.2") - && protocolTo >= Util.getVersionProtocol(gson, "1.20.2")) { - this.registerConverter(new SlicerConverter(this, protocolFrom)); - } - - if (protocolFrom < Util.getVersionProtocol(gson, "1.20.3") - && protocolTo >= Util.getVersionProtocol(gson, "1.20.3")) { - this.registerConverter(new ImageFormatConverter(this)); - } - - if (protocolFrom < Util.getVersionProtocol(gson, "1.20.5") - && protocolTo >= Util.getVersionProtocol(gson, "1.20.5")) { - this.registerConverter(new MapIconSlicerConverter(this, protocolFrom)); - } - - if (protocolFrom < Util.getVersionProtocol(gson, "1.21.2") && protocolTo >= Util.getVersionProtocol(gson, "1.21.2")) { - this.registerConverter(new ArmorMoverConverter(this)); - } + this.registerConverter(new AtlasConverter(this)); + this.registerConverter(new CreativeTabsConverter(this)); + this.registerConverter(new EnchantPathConverter(this)); + this.registerConverter(new WidgetSlidersCreator(this)); + this.registerConverter(new TitleConverter(this)); + this.registerConverter(new SlicerConverter(this, from)); + this.registerConverter(new ImageFormatConverter(this)); + this.registerConverter(new MapIconSlicerConverter(this, from)); + this.registerConverter(new ArmorMoverConverter(this)); + // Shaders } public void runPack(Pack pack) { @@ -141,10 +73,12 @@ public void runPack(Pack pack) { Logger.addTab(); Logger.log("Running Converters"); for (Converter converter : converters.values()) { - Logger.addTab(); - Logger.log("Running " + converter.getClass().getSimpleName()); - converter.convert(pack); - Logger.subTab(); + if (converter.shouldConvert(gson, from, to)) { + Logger.addTab(); + Logger.log("Running " + converter.getClass().getSimpleName()); + converter.convert(pack); + Logger.subTab(); + } } Logger.subTab(); pack.getHandler().finish(); @@ -156,9 +90,10 @@ public void runPack(Pack pack) { } public void runDir() throws IOException { - Files.list(INPUT_DIR) - .map(Pack::parse) - .filter(Objects::nonNull) - .forEach(pack -> runPack(pack)); + try (Stream pathStream = Files.list(INPUT_DIR)) { + try (Stream packStream = pathStream.map(Pack::parse).filter(Objects::nonNull)) { + packStream.forEach(this::runPack); + } + } } } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/AnimationConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/AnimationConverter.java index 781f9d44..1ec57758 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/AnimationConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/AnimationConverter.java @@ -6,6 +6,7 @@ import com.agentdid127.resourcepack.library.utilities.JsonUtil; import com.agentdid127.resourcepack.library.utilities.Logger; import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -20,6 +21,11 @@ public AnimationConverter(PackConverter packConverter) { super(packConverter); } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from <= Util.getVersionProtocol(gson, "1.12.2") && to >= Util.getVersionProtocol(gson, "1.13"); + } + @Override public void convert(Pack pack) throws IOException { Path texturesPath = pack.getWorkingPath().resolve("assets/minecraft/textures".replace("/", File.separator)); diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/AtlasConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/AtlasConverter.java index 44d1ecb0..fa014bee 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/AtlasConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/AtlasConverter.java @@ -3,15 +3,18 @@ import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.nio.file.Path; +import java.util.Objects; public class AtlasConverter extends Converter { JsonObject out = new JsonObject(); @@ -21,15 +24,22 @@ public AtlasConverter(PackConverter packConverter) { super(packConverter); } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from <= Util.getVersionProtocol(gson, "1.19.2") && to >= Util.getVersionProtocol(gson, "1.19.3"); + } + @Override public void convert(Pack pack) throws IOException { Path atlasesPath = pack.getWorkingPath().resolve("assets/minecraft/atlases".replace("/", File.separator)); - if (!atlasesPath.toFile().exists()) + if (!atlasesPath.toFile().exists()) { atlasesPath.toFile().mkdirs(); + } Path texturesPath = pack.getWorkingPath().resolve("assets/minecraft/textures".replace("/", File.separator)); - if (texturesPath.toFile().exists()) { - for (File file : texturesPath.toFile().listFiles()) { + File texturesFile = texturesPath.toFile(); + if (texturesFile.exists()) { + for (File file : Objects.requireNonNull(texturesFile.listFiles())) { JsonObject source = new JsonObject(); if (file.isDirectory()) { source.addProperty("type", "directory"); @@ -48,7 +58,7 @@ public void convert(Pack pack) throws IOException { File output = atlasesPath.resolve("blocks.json").toFile(); if (!output.exists()) { - OutputStream os = new FileOutputStream(output); + OutputStream os = Files.newOutputStream(output.toPath()); os.write(packConverter.getGson().toJson(out).getBytes(StandardCharsets.UTF_8)); os.close(); } @@ -57,18 +67,18 @@ public void convert(Pack pack) throws IOException { public void findFiles(Path directory, String prefix) { File directoryFile = directory.toFile(); - if (!directoryFile.isDirectory()) - return; - for (File file : directoryFile.listFiles()) { - JsonObject source = new JsonObject(); - if (!file.isDirectory()) - continue; - source.addProperty("type", "directory"); - source.addProperty("source", prefix + "/" + file.getName()); - source.addProperty("prefix", prefix + "/" + file.getName() + "/"); - sources.add(source); - String nextPrefix = prefix + "/" + file.getName(); - findFiles(directory.resolve(file.getName()), nextPrefix); + if (directoryFile.isDirectory()) { + for (File file : Objects.requireNonNull(directoryFile.listFiles())) { + JsonObject source = new JsonObject(); + if (file.isDirectory()) { + source.addProperty("type", "directory"); + source.addProperty("source", prefix + "/" + file.getName()); + source.addProperty("prefix", prefix + "/" + file.getName() + "/"); + sources.add(source); + String nextPrefix = prefix + "/" + file.getName(); + findFiles(directory.resolve(file.getName()), nextPrefix); + } + } } } } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.java index 8109f969..667842a3 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.java @@ -6,6 +6,7 @@ import com.agentdid127.resourcepack.library.utilities.JsonUtil; import com.agentdid127.resourcepack.library.utilities.Logger; import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -29,6 +30,11 @@ public BlockStateConverter(PackConverter packConverter, int from, int to) { this.anyChanges = false; } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return true; + } + /** * Updates blockstates in blockstates folder * @@ -38,8 +44,10 @@ public BlockStateConverter(PackConverter packConverter, int from, int to) { @Override public void convert(Pack pack) throws IOException { Path states = pack.getWorkingPath().resolve("assets/minecraft/blockstates".replace("/", File.separator)); - if (!states.toFile().exists()) + if (!states.toFile().exists()) { return; + } + Logger.addTab(); try (Stream pathStream = Files.list(states).filter(file -> file.toString().endsWith(".json"))) { pathStream.forEach(file -> { @@ -53,8 +61,9 @@ public void convert(Pack pack) throws IOException { JsonArray multipartArray = multipart.getAsJsonArray(); for (JsonElement element : multipartArray) { JsonObject multipartObject = element.getAsJsonObject(); - for (Map.Entry entry : multipartObject.entrySet()) + for (Map.Entry entry : multipartObject.entrySet()) { updateModelPath(entry); + } } } } @@ -77,8 +86,9 @@ public void convert(Pack pack) throws IOException { } // update model paths to prepend block - for (Map.Entry entry : variantsObject.entrySet()) + for (Map.Entry entry : variantsObject.entrySet()) { updateModelPath(entry); + } } } @@ -127,45 +137,46 @@ private void updateModelObject(JsonObject value) { String val = split[split.length - 1]; String prefix = value.get("model").getAsString().substring(0, value.get("model").getAsString().length() - val.length()); - if (from < Util.getVersionProtocol(packConverter.getGson(), "1.9") + if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.8.9") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.9")) { prefix = "block/" + prefix; anyChanges = true; } - if (from < Util.getVersionProtocol(packConverter.getGson(), "1.13") + if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.12.2") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.13")) { val = nameConverter.getBlockMapping_1_13().remap(val); prefix = prefix.replaceAll("blocks", "block"); anyChanges = true; } - if (from < Util.getVersionProtocol(packConverter.getGson(), "1.14") + if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.13.2") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.14")) { val = nameConverter.getBlockMapping_1_14().remap(val); anyChanges = true; } - if (from < Util.getVersionProtocol(packConverter.getGson(), "1.17") + if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.16.5") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.17")) { val = nameConverter.getBlockMapping_1_17().remap(val); anyChanges = true; } - if (from < Util.getVersionProtocol(packConverter.getGson(), "1.19") + if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.18.2") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.19")) { val = nameConverter.getBlockMapping_1_19().remap(val); anyChanges = true; } - if (from < Util.getVersionProtocol(packConverter.getGson(), "1.19.3") + if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.19.2") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.19.3")) { prefix = "minecraft:" + prefix; anyChanges = true; } + String result = prefix + val; if (anyChanges) { - value.addProperty("model", prefix + val); + value.addProperty("model", result); } } } \ No newline at end of file diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/EnchantPathConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/EnchantPathConverter.java index ae7feef1..de234696 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/EnchantPathConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/EnchantPathConverter.java @@ -3,6 +3,8 @@ import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import java.io.File; import java.io.IOException; @@ -14,10 +16,14 @@ public EnchantPathConverter(PackConverter packConverter) { super(packConverter); } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from <= Util.getVersionProtocol(gson, "1.19.3") && to >= Util.getVersionProtocol(gson, "1.19.4"); + } + @Override public void convert(Pack pack) throws IOException { Path miscPath = pack.getWorkingPath().resolve("assets/minecraft/textures/misc".replace("/", File.separator)); - if (miscPath.resolve("enchanted_item_glint.png").toFile().exists()) { Files.copy(miscPath.resolve("enchanted_item_glint.png"), miscPath.resolve("enchanted_glint_entity.png")); Files.copy(miscPath.resolve("enchanted_item_glint.png"), miscPath.resolve("enchanted_glint_item.png")); @@ -25,10 +31,8 @@ public void convert(Pack pack) throws IOException { } if (miscPath.resolve("enchanted_item_glint.png.mcmeta").toFile().exists()) { - Files.copy(miscPath.resolve("enchanted_item_glint.png.mcmeta"), - miscPath.resolve("enchanted_glint_entity.png.mcmeta")); - Files.copy(miscPath.resolve("enchanted_item_glint.png.mcmeta"), - miscPath.resolve("enchanted_glint_item.png.mcmeta")); + Files.copy(miscPath.resolve("enchanted_item_glint.png.mcmeta"), miscPath.resolve("enchanted_glint_entity.png.mcmeta")); + Files.copy(miscPath.resolve("enchanted_item_glint.png.mcmeta"), miscPath.resolve("enchanted_glint_item.png.mcmeta")); Files.delete(miscPath.resolve("enchanted_item_glint.png.mcmeta")); } } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ImageFormatConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ImageFormatConverter.java index 57983fd8..d2b27452 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ImageFormatConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ImageFormatConverter.java @@ -3,6 +3,8 @@ import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; @@ -10,12 +12,12 @@ import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Objects; /** * Converts Images to only use PNG formats. */ public class ImageFormatConverter extends Converter { - private static final String[] types = new String[]{"jpg", "jpeg", "raw", "ico", "bmp"}; /** @@ -27,6 +29,11 @@ public ImageFormatConverter(PackConverter packConverter) { super(packConverter); } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from <= Util.getVersionProtocol(gson, "1.20.2") && to >= Util.getVersionProtocol(gson, "1.20.3"); + } + /** * Converts other types of images to PNG images. * @param pack Pack to convert @@ -36,12 +43,10 @@ public ImageFormatConverter(PackConverter packConverter) { public void convert(Pack pack) throws IOException { // All textures in the game Path texturesPath = pack.getWorkingPath().resolve(Paths.get("assets", "minecraft", "textures")); - // check for invalid images for all of these types. for (String type : types) { findImage(texturesPath, type); } - } /** @@ -58,7 +63,7 @@ protected void findImage(Path path, String type) throws IOException { } // Check each file - for (File file : directory.listFiles()) { + for (File file : Objects.requireNonNull(directory.listFiles())) { if (file.isDirectory()) findImage(file.toPath(), type); else { @@ -79,10 +84,8 @@ protected void findImage(Path path, String type) throws IOException { protected void remapFile(File file, String oldFormat) throws IOException { // Get the image BufferedImage image = ImageIO.read(file); - // Output the correct format ImageIO.write(image, "png", new File(file.getAbsolutePath().replaceAll(oldFormat, "png"))); - // Delete the old image. if (file.exists()) { file.delete(); diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/LangConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/LangConverter.java index 1632e51b..e6541cf1 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/LangConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/LangConverter.java @@ -7,6 +7,7 @@ import com.agentdid127.resourcepack.library.utilities.Logger; import com.agentdid127.resourcepack.library.utilities.PropertiesEx; import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -22,15 +23,20 @@ import java.util.stream.Stream; public class LangConverter extends Converter { - private final String from; - private final String to; + private final int from; + private final int to; - public LangConverter(PackConverter packConverter, String from, String to) { + public LangConverter(PackConverter packConverter, int from, int to) { super(packConverter); this.from = from; this.to = to; } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return to >= Util.getVersionProtocol(gson, "1.13"); + } + /** * Moves Lang (properties) to JSON * @@ -53,9 +59,9 @@ public void convert(Pack pack) throws IOException { try (InputStream input = Files.newInputStream(Paths.get(lang.toString()))) { PropertiesEx prop = new PropertiesEx(); prop.load(input); - if (Util.getVersionProtocol(packConverter.getGson(), from) <= Util.getVersionProtocol(packConverter.getGson(), "1.12") - && ((Util.getVersionProtocol(packConverter.getGson(), to) >= Util.getVersionProtocol(packConverter.getGson(), "1.13")) - && (Util.getVersionProtocol(packConverter.getGson(), to) <= Util.getVersionProtocol(packConverter.getGson(), "1.13.2")))) { + if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.12") + && ((to >= Util.getVersionProtocol(packConverter.getGson(), "1.13")) + && (to <= Util.getVersionProtocol(packConverter.getGson(), "1.13.2")))) { JsonObject id = JsonUtil.readJsonResource(packConverter.getGson(), "/forwards/lang.json").getAsJsonObject("1_13"); Enumeration enums = (Enumeration) prop.propertyNames(); while (enums.hasMoreElements()) { @@ -70,7 +76,7 @@ public void convert(Pack pack) throws IOException { } } - if (Util.getVersionProtocol(packConverter.getGson(), to) > Util.getVersionProtocol(packConverter.getGson(), "1.14")) { + if (to > Util.getVersionProtocol(packConverter.getGson(), "1.14")) { JsonObject id = JsonUtil.readJsonResource(packConverter.getGson(), "/forwards/lang.json").getAsJsonObject("1_14"); Enumeration enums = (Enumeration) prop.propertyNames(); while (enums.hasMoreElements()) { diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java index 5fee691e..49955679 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java @@ -7,6 +7,7 @@ import com.agentdid127.resourcepack.library.utilities.Logger; import com.agentdid127.resourcepack.library.utilities.PropertiesEx; import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import com.google.gson.JsonObject; import java.io.File; @@ -26,6 +27,11 @@ public MCPatcherConverter(PackConverter packConverter) { super(packConverter); } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from <= Util.getVersionProtocol(gson, "1.12.2") && to >= Util.getVersionProtocol(gson, "1.13"); + } + /** * Parent conversion for MCPatcher * diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java index f3084176..3181ae86 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java @@ -31,6 +31,11 @@ public ModelConverter(PackConverter packConverter, String light, int from, int t this.to = to; } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return true; + } + /** * Runs findfiles with the directory Models * diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java index 1a249390..0c7c1581 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java @@ -65,6 +65,11 @@ public NameConverter(PackConverter packConverter, int from, int to) { itemMapping1_20_3 = new Mapping(gson, "items", "1_20_3", false); } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return true; + } + /** * Fixes folder names and file names * diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java index b503a436..b85a0f65 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java @@ -5,6 +5,7 @@ import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.JsonUtil; import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import com.google.gson.JsonObject; import java.io.IOException; @@ -21,6 +22,11 @@ public PackMetaConverter(PackConverter packConverter, int from, int to) { this.to = to; } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return true; + } + /** * Converts MCMeta to newer version * diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ParticleConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ParticleConverter.java index 7f059231..1df7175f 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ParticleConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ParticleConverter.java @@ -3,6 +3,8 @@ import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import java.io.File; import java.io.IOException; @@ -10,32 +12,37 @@ import java.nio.file.Path; public class ParticleConverter extends Converter { - // Set it up. public ParticleConverter(PackConverter packConverter) { super(packConverter); } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from <= Util.getVersionProtocol(gson, "1.17.1") && to >= Util.getVersionProtocol(gson, "1.18"); + } + @Override public void convert(Pack pack) throws IOException { - Path particlesFolderPath = pack.getWorkingPath() - .resolve("assets/minecraft/particles".replace("/", File.separator)); - if (!particlesFolderPath.toFile().exists()) + Path particlesFolderPath = pack.getWorkingPath().resolve("assets/minecraft/particles".replace("/", File.separator)); + if (!particlesFolderPath.toFile().exists()) { return; + } // Check if the two merged files exist. boolean barrier = false; boolean light = false; - - if (particlesFolderPath.resolve("barrier.json").toFile().exists()) + if (particlesFolderPath.resolve("barrier.json").toFile().exists()) { barrier = true; - else if (particlesFolderPath.resolve("light.json").toFile().exists()) + } else if (particlesFolderPath.resolve("light.json").toFile().exists()) { light = true; + } // Move around files depending on what exists or what doesn't exist. if (barrier) { Files.move(particlesFolderPath.resolve("barrier.json"), particlesFolderPath.resolve("block_marker.json")); - if (light) + if (light) { Files.delete(particlesFolderPath.resolve("light.json")); + } } else if (light) { Files.move(particlesFolderPath.resolve("light.json"), particlesFolderPath.resolve("block_marker.json")); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/SoundsConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/SoundsConverter.java index caea50ee..b3757fc8 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/SoundsConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/SoundsConverter.java @@ -6,10 +6,8 @@ import com.agentdid127.resourcepack.library.utilities.FileUtil; import com.agentdid127.resourcepack.library.utilities.JsonUtil; import com.agentdid127.resourcepack.library.utilities.Logger; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; +import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.*; import java.io.File; import java.io.IOException; @@ -21,22 +19,26 @@ public SoundsConverter(PackConverter packConverter) { super(packConverter); } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from <= Util.getVersionProtocol(gson, "1.12.2") && to >= Util.getVersionProtocol(gson, "1.13"); + } + /** * Updates Sounds - * + * * @param pack * @throws IOException */ @Override public void convert(Pack pack) throws IOException { - Path soundsJsonPath = pack.getWorkingPath() - .resolve("assets/minecraft/sounds.json".replace("/", File.separator)); - if (!soundsJsonPath.toFile().exists()) + Path soundsJsonPath = pack.getWorkingPath().resolve("assets/minecraft/sounds.json".replace("/", File.separator)); + if (!soundsJsonPath.toFile().exists()) { return; + } JsonObject sounds = JsonUtil.readJson(packConverter.getGson(), soundsJsonPath); JsonObject newSoundsObject = new JsonObject(); - for (Map.Entry entry : sounds.entrySet()) { if (entry.getValue().isJsonObject()) { JsonObject soundObject = entry.getValue().getAsJsonObject(); @@ -46,17 +48,15 @@ public void convert(Pack pack) throws IOException { JsonArray newSoundsArray = new JsonArray(); for (JsonElement jsonElement : soundsArray) { String sound; - - if (jsonElement instanceof JsonObject) + if (jsonElement instanceof JsonObject) { sound = ((JsonObject) jsonElement).get("name").getAsString(); - else if (jsonElement instanceof JsonPrimitive) + } else if (jsonElement instanceof JsonPrimitive) { sound = jsonElement.getAsString(); - else - throw new IllegalArgumentException( - "Unknown element type: " + jsonElement.getClass().getSimpleName()); + } else { + throw new IllegalArgumentException("Unknown element type: " + jsonElement.getClass().getSimpleName()); + } - Path baseSoundsPath = pack.getWorkingPath() - .resolve("assets/minecraft/sounds".replace("/", File.separator)); + Path baseSoundsPath = pack.getWorkingPath().resolve("assets/minecraft/sounds".replace("/", File.separator)); Path path = baseSoundsPath.resolve(sound + ".ogg"); if (!FileUtil.fileExistsCorrectCasing(path)) { String rewrite = path.toFile().getCanonicalPath().substring( @@ -75,8 +75,9 @@ else if (jsonElement instanceof JsonPrimitive) if (jsonElement instanceof JsonObject) { ((JsonObject) jsonElement).addProperty("name", sound); newSound = jsonElement; - } else if (jsonElement instanceof JsonPrimitive) + } else if (jsonElement instanceof JsonPrimitive) { newSound = new JsonPrimitive(jsonElement.getAsString()); + } newSoundsArray.add(newSound); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/SpacesConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/SpacesConverter.java index 04c92459..b87a7191 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/SpacesConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/SpacesConverter.java @@ -5,6 +5,8 @@ import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.FileUtil; import com.agentdid127.resourcepack.library.utilities.Logger; +import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import java.io.File; import java.io.IOException; @@ -17,6 +19,11 @@ public SpacesConverter(PackConverter packConverter) { super(packConverter); } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from <= Util.getVersionProtocol(gson, "1.10.2") && to >= Util.getVersionProtocol(gson, "1.11"); + } + /** * Runs findFiles * diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java index 3812d19a..6a87e0ef 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java @@ -3,6 +3,8 @@ import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import java.io.File; import java.io.IOException; @@ -14,7 +16,7 @@ public class ArmorMoverConverter extends Converter { private final List MATERIALS = new ArrayList<>(); - // TODO: Trims/Wolf Armor/Turtle/Llama/Horse/Elytra + // TODO: Trims/Wolf Armor/Llama/Horse/Elytra public ArmorMoverConverter(PackConverter packConverter) { super(packConverter); MATERIALS.add("chainmail"); @@ -25,6 +27,11 @@ public ArmorMoverConverter(PackConverter packConverter) { MATERIALS.add("netherite"); } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from <= Util.getVersionProtocol(gson, "1.21.1") && to >= Util.getVersionProtocol(gson, "1.21.2"); + } + @Override public void convert(Pack pack) throws IOException { Path texturesPath = pack.getWorkingPath().resolve("assets/minecraft/textures/".replace("/", File.separator)); @@ -58,6 +65,13 @@ public void convert(Pack pack) throws IOException { } } + // Special + Path turtleLayer1 = modelsArmorPath.resolve("turtle_layer_1.png"); + if (turtleLayer1.toFile().exists()) { + Files.move(turtleLayer1, humanoidPath.resolve("turtle_scute.png")); + } + + // Cleanup modelsArmorPath.toFile().delete(); // TODO/NOTE: For some reason, it will only delete "models" folder if I delete this first modelsPath.toFile().delete(); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ChestConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ChestConverter.java index 8dc5ac57..eaeca9af 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ChestConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ChestConverter.java @@ -5,6 +5,8 @@ import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.ImageConverter; import com.agentdid127.resourcepack.library.utilities.Logger; +import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import java.io.File; import java.io.IOException; @@ -15,6 +17,11 @@ public ChestConverter(PackConverter packConverter) { super(packConverter); } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from <= Util.getVersionProtocol(gson, "1.14.4") && to >= Util.getVersionProtocol(gson, "1.15"); + } + /** * Fixes Chest Textures in 1.15 Remaps textures, and updates images * diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/CompassConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/CompassConverter.java index 6e8e4d09..7ab18aed 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/CompassConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/CompassConverter.java @@ -5,6 +5,7 @@ import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.ImageConverter; import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import java.io.File; import java.io.IOException; @@ -12,7 +13,7 @@ import java.nio.file.Path; public class CompassConverter extends Converter { - private int to; + private final int to; private Path items; public CompassConverter(PackConverter packConverter, int to) { @@ -20,6 +21,11 @@ public CompassConverter(PackConverter packConverter, int to) { this.to = to; } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from <= Util.getVersionProtocol(gson, "1.8.9") && to >= Util.getVersionProtocol(gson, "1.9"); + } + @Override public void convert(Pack pack) throws IOException { String itemsT = "items"; diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/CreativeTabsConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/CreativeTabsConverter.java index 58156f0e..26cc087f 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/CreativeTabsConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/CreativeTabsConverter.java @@ -1,34 +1,41 @@ package com.agentdid127.resourcepack.forwards.impl.textures; -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; - import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.ImageConverter; +import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; public class CreativeTabsConverter extends Converter { - private static int old_tab_width = 28; - private static int new_tab_width = 26; - private static int old_half = old_tab_width / 2; + private static final int OLD_TAB_WIDTH = 28; + private static final int NEW_TAB_WIDTH = 26; + private static final int OLD_TAB_HALF = OLD_TAB_WIDTH / 2; public CreativeTabsConverter(PackConverter converter) { super(converter); } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from <= Util.getVersionProtocol(gson, "1.19.2") && to >= Util.getVersionProtocol(gson, "1.19.3"); + } + @Override public void convert(Pack pack) throws IOException { - Path guiPath = pack.getWorkingPath().resolve( - "assets/minecraft/textures/gui".replace("/", File.separator)); - if (!guiPath.toFile().exists()) + Path guiPath = pack.getWorkingPath().resolve("assets/minecraft/textures/gui".replace("/", File.separator)); + if (!guiPath.toFile().exists()) { return; + } - Path tabsImage = guiPath - .resolve("container/creative_inventory/tabs.png".replace("/", File.separator)); - if (!tabsImage.toFile().exists()) + Path tabsImage = guiPath.resolve("container/creative_inventory/tabs.png".replace("/", File.separator)); + if (!tabsImage.toFile().exists()) { return; + } int originalWidth = 256; int originalHeight = 256; @@ -60,25 +67,24 @@ public void convert(Pack pack) throws IOException { converter.store(); } - private static void copy_tab(ImageConverter converter, int index, int original_index, int left_padding, - int right_padding) { - int first_tab_start_x = original_index * old_tab_width; - int first_tab_start_end_x = (original_index * old_tab_width) + old_tab_width; + private static void copy_tab(ImageConverter converter, int index, int original_index, int left_padding, int right_padding) { + int first_tab_start_x = original_index * OLD_TAB_WIDTH; + int first_tab_start_end_x = (original_index * OLD_TAB_WIDTH) + OLD_TAB_WIDTH; converter.subImage( first_tab_start_x, 0, - first_tab_start_end_x - old_half, + first_tab_start_end_x - OLD_TAB_HALF, 160, - (index * new_tab_width) + left_padding, + (index * NEW_TAB_WIDTH) + left_padding, 0); converter.subImage( - first_tab_start_x + old_half, + first_tab_start_x + OLD_TAB_HALF, 0, first_tab_start_end_x, 160, - ((index * new_tab_width) + (old_half - right_padding)), + ((index * NEW_TAB_WIDTH) + (OLD_TAB_HALF - right_padding)), 0); } } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/EnchantConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/EnchantConverter.java index 5e1ae765..9e8fbd78 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/EnchantConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/EnchantConverter.java @@ -4,6 +4,8 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.ImageConverter; +import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import java.awt.*; import java.io.File; @@ -15,17 +17,23 @@ public EnchantConverter(PackConverter packConverter) { super(packConverter); } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from <= Util.getVersionProtocol(gson, "1.14.4") && to >= Util.getVersionProtocol(gson, "1.15"); + } + @Override public void convert(Pack pack) throws IOException { - Path itemGlintPath = pack.getWorkingPath() - .resolve("assets/minecraft/textures/misc/enchanted_item_glint.png".replace("/", File.separator)); - if (!itemGlintPath.toFile().exists()) + Path itemGlintPath = pack.getWorkingPath().resolve("assets/minecraft/textures/misc/enchanted_item_glint.png".replace("/", File.separator)); + if (!itemGlintPath.toFile().exists()) { return; + } + ImageConverter imageConverter = new ImageConverter(64, 64, itemGlintPath); - if (!imageConverter.fileIsPowerOfTwo()) - return; - imageConverter.newImage(64, 64); - imageConverter.colorize(new Color(94, 9, 178, 120)); - imageConverter.store(); + if (imageConverter.fileIsPowerOfTwo()) { + imageConverter.newImage(64, 64); + imageConverter.colorize(new Color(94, 9, 178, 120)); + imageConverter.store(); + } } } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/InventoryConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/InventoryConverter.java index 17b745ef..db854163 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/InventoryConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/InventoryConverter.java @@ -4,6 +4,7 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.ImageConverter; +import com.google.gson.Gson; import java.io.File; import java.io.IOException; @@ -14,6 +15,11 @@ public InventoryConverter(PackConverter packConverter) { super(packConverter); } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return true; + } + @Override public void convert(Pack pack) throws IOException { Path imagePath = pack.getWorkingPath() diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter.java index 7382f3cc..63f69cb0 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter.java @@ -5,6 +5,7 @@ import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.Logger; import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import javax.imageio.ImageIO; import java.awt.*; @@ -32,9 +33,14 @@ public MapIconConverter(PackConverter packConverter) { mapping.put(pack(8, 16), pack(72, 0)); } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from <= Util.getVersionProtocol(gson, "1.12.2") && to >= Util.getVersionProtocol(gson, "1.13"); + } + /** * Converts maps - * + * * @param pack * @throws IOException */ diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconSlicerConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconSlicerConverter.java index e0f568fa..5b7c5662 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconSlicerConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconSlicerConverter.java @@ -6,6 +6,7 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.JsonUtil; +import com.agentdid127.resourcepack.library.utilities.Util; import com.google.gson.Gson; import com.google.gson.JsonObject; @@ -14,31 +15,35 @@ import java.nio.file.Path; public class MapIconSlicerConverter extends Converter { - private final int protocolFrom; + private final int from; - public MapIconSlicerConverter(PackConverter packConverter, int protocolFrom) { + public MapIconSlicerConverter(PackConverter packConverter, int from) { super(packConverter); - this.protocolFrom = protocolFrom; + this.from = from; + } + + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from <= Util.getVersionProtocol(gson, "1.20.4") && to >= Util.getVersionProtocol(gson, "1.20.5"); } - /** - * Converts maps - * - * @param pack - * @throws IOException - */ @Override public void convert(Pack pack) throws IOException { Path texturesPath = pack.getWorkingPath().resolve("assets/minecraft/textures".replace("/", File.separator)); - if (!texturesPath.toFile().exists()) + if (!texturesPath.toFile().exists()) { return; + } + Path mapIconsPath = texturesPath.resolve("map/".replace("/", File.separator)); - if (!mapIconsPath.toFile().exists()) + if (!mapIconsPath.toFile().exists()) { return; + } + Gson gson = packConverter.getGson(); JsonObject mapIconsJson = JsonUtil.readJsonResource(gson, "/forwards/map_icons.json", JsonObject.class); - assert mapIconsJson != null; - Slice slice = Slice.parse(mapIconsJson); - Slicer.runSlicer(gson, slice, mapIconsPath, SlicerConverter.PredicateRunnable.class, protocolFrom, false); + if (mapIconsJson != null) { + Slice slice = Slice.parse(mapIconsJson); + Slicer.runSlicer(gson, slice, mapIconsPath, SlicerConverter.PredicateRunnable.class, from, false); + } } } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MobEffectAtlasConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MobEffectAtlasConverter.java index e6aefc72..8d258370 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MobEffectAtlasConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MobEffectAtlasConverter.java @@ -10,37 +10,43 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.JsonUtil; +import com.agentdid127.resourcepack.library.utilities.Util; import com.google.gson.Gson; import com.google.gson.JsonObject; public class MobEffectAtlasConverter extends Converter { - private int from; + private final int from; - public MobEffectAtlasConverter(PackConverter packConverter, int from) { - super(packConverter); - this.from = from; - } + public MobEffectAtlasConverter(PackConverter packConverter, int from) { + super(packConverter); + this.from = from; + } - /** - * Slices the mob effect images from inventory.png for 1.14+ - * - * @param pack - * @throws IOException - */ - @Override - public void convert(Pack pack) throws IOException { - Path texturesPath = pack.getWorkingPath().resolve("assets/minecraft/textures".replace("/", File.separator)); - if (!texturesPath.toFile().exists()) - return; - Path containerPath = texturesPath.resolve("gui/container".replace("/", File.separator)); - if (!containerPath.toFile().exists()) - return; - Path inventoryPath = containerPath.resolve("inventory.png"); - if (!inventoryPath.toFile().exists()) - return; - Gson gson = packConverter.getGson(); - JsonObject effectJson = JsonUtil.readJsonResource(gson, "/forwards/mob_effect.json", JsonObject.class); - Slice slice = Slice.parse(effectJson); - Slicer.runSlicer(gson, slice, texturesPath, SlicerConverter.PredicateRunnable.class, from, false); - } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from <= Util.getVersionProtocol(gson, "1.13.2") && to >= Util.getVersionProtocol(gson, "1.14"); + } + + /** + * Slices the mob effect images from inventory.png for 1.14+ + * + * @param pack + * @throws IOException + */ + @Override + public void convert(Pack pack) throws IOException { + Path texturesPath = pack.getWorkingPath().resolve("assets/minecraft/textures".replace("/", File.separator)); + if (!texturesPath.toFile().exists()) + return; + Path containerPath = texturesPath.resolve("gui/container".replace("/", File.separator)); + if (!containerPath.toFile().exists()) + return; + Path inventoryPath = containerPath.resolve("inventory.png"); + if (!inventoryPath.toFile().exists()) + return; + Gson gson = packConverter.getGson(); + JsonObject effectJson = JsonUtil.readJsonResource(gson, "/forwards/mob_effect.json", JsonObject.class); + Slice slice = Slice.parse(effectJson); + Slicer.runSlicer(gson, slice, texturesPath, SlicerConverter.PredicateRunnable.class, from, false); + } } \ No newline at end of file diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/OffHandCreator.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/OffHandCreator.java index 955b6895..529e382e 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/OffHandCreator.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/OffHandCreator.java @@ -1,75 +1,78 @@ package com.agentdid127.resourcepack.forwards.impl.textures; -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; - import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.ImageConverter; +import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; -public class OffHandCreator extends Converter { - public OffHandCreator(PackConverter packConverter) { - super(packConverter); - } - - @Override - public void convert(Pack pack) throws IOException { - Path widgetsPath = pack.getWorkingPath() - .resolve("assets/minecraft/textures/gui/widgets.png".replace("/", File.separator)); - if (!widgetsPath.toFile().exists()) - return; - - ImageConverter converter = new ImageConverter(256, 256, widgetsPath); +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; - int hotbar_end_x = 182; +public class OffHandCreator extends Converter { + public OffHandCreator(PackConverter packConverter) { + super(packConverter); + } - int hotbar_offhand_width = 29; - int hotbar_offhand_height = 24; + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from <= Util.getVersionProtocol(gson, "1.8.9") && to >= Util.getVersionProtocol(gson, "1.9"); + } - int hotbar_offhand_l_x = 24; - int hotbar_offhand_r_x = 60; - int hotbar_offhand_y = 22; + @Override + public void convert(Pack pack) throws IOException { + Path widgetsPath = pack.getWorkingPath().resolve("assets/minecraft/textures/gui/widgets.png".replace("/", File.separator)); + if (!widgetsPath.toFile().exists()) { + return; + } - int slice_w = 11; - int slice_h = 22; + ImageConverter converter = new ImageConverter(256, 256, widgetsPath); + int hotbar_end_x = 182; + int hotbar_offhand_width = 29; + int hotbar_offhand_height = 24; + int hotbar_offhand_l_x = 24; + int hotbar_offhand_r_x = 60; + int hotbar_offhand_y = 22; + int slice_w = 11; + int slice_h = 22; - converter.fillEmpty(hotbar_offhand_l_x, hotbar_offhand_y, hotbar_offhand_width, hotbar_offhand_height); - converter.fillEmpty(hotbar_offhand_r_x, hotbar_offhand_y, hotbar_offhand_width, hotbar_offhand_height); + converter.fillEmpty(hotbar_offhand_l_x, hotbar_offhand_y, hotbar_offhand_width, hotbar_offhand_height); + converter.fillEmpty(hotbar_offhand_r_x, hotbar_offhand_y, hotbar_offhand_width, hotbar_offhand_height); - // OffHand (Left) - converter.subImage( - 0, - 0, - slice_w, - slice_h, - hotbar_offhand_l_x, - hotbar_offhand_y + 1); - converter.subImage( - hotbar_end_x - slice_w, - 0, - hotbar_end_x, - slice_h, - hotbar_offhand_l_x + slice_w, - hotbar_offhand_y + 1); + // OffHand (Left) + converter.subImage( + 0, + 0, + slice_w, + slice_h, + hotbar_offhand_l_x, + hotbar_offhand_y + 1); + converter.subImage( + hotbar_end_x - slice_w, + 0, + hotbar_end_x, + slice_h, + hotbar_offhand_l_x + slice_w, + hotbar_offhand_y + 1); - // OffHand (Right) - converter.subImage( - 0, - 0, - slice_w, - slice_h, - hotbar_offhand_r_x, - hotbar_offhand_y + 1); - converter.subImage( - hotbar_end_x - slice_w, - 0, - hotbar_end_x, - slice_h, - hotbar_offhand_r_x + slice_w, - hotbar_offhand_y + 1); + // OffHand (Right) + converter.subImage( + 0, + 0, + slice_w, + slice_h, + hotbar_offhand_r_x, + hotbar_offhand_y + 1); + converter.subImage( + hotbar_end_x - slice_w, + 0, + hotbar_end_x, + slice_h, + hotbar_offhand_r_x + slice_w, + hotbar_offhand_y + 1); - converter.store(); - } + converter.store(); + } } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/PaintingConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/PaintingConverter.java index dcb5d670..ad8e6326 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/PaintingConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/PaintingConverter.java @@ -6,6 +6,7 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.JsonUtil; +import com.agentdid127.resourcepack.library.utilities.Util; import com.google.gson.Gson; import com.google.gson.JsonObject; @@ -18,25 +19,35 @@ public PaintingConverter(PackConverter packConverter) { super(packConverter); } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from <= Util.getVersionProtocol(gson, "1.13") && to >= Util.getVersionProtocol(gson, "1.14.4"); + } + /** * Slices the paintings_kristoffer_zetterstrand painting image into multiple for * 1.14+ - * + * * @param pack * @throws IOException */ @Override public void convert(Pack pack) throws IOException { Path texturesPath = pack.getWorkingPath().resolve("assets/minecraft/textures".replace("/", File.separator)); - if (!texturesPath.toFile().exists()) + if (!texturesPath.toFile().exists()) { return; + } + Path paintingPath = texturesPath.resolve("painting"); - if (!paintingPath.toFile().exists()) + if (!paintingPath.toFile().exists()) { return; + } + Gson gson = packConverter.getGson(); - JsonObject effectJson = JsonUtil.readJsonResource(gson, "/forwards/paintings_kristoffer_zetterstrand.json", - JsonObject.class); - Slice slice = Slice.parse(effectJson); - Slicer.runSlicer(gson, slice, paintingPath, null, -1, false); + JsonObject effectJson = JsonUtil.readJsonResource(gson, "/forwards/paintings_kristoffer_zetterstrand.json", JsonObject.class); + if (effectJson != null) { + Slice slice = Slice.parse(effectJson); + Slicer.runSlicer(gson, slice, paintingPath, null, -1, false); + } } } \ No newline at end of file diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java index cfadeda8..2fe6e32d 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java @@ -23,6 +23,11 @@ public ParticleTextureConverter(PackConverter packConverter, int from, int to) { this.to = to; } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return true; + } + /** * Slice particles.png into multiple for 1.14+ * diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.java index 60096ba0..bb04222f 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.java @@ -25,6 +25,11 @@ public SlicerConverter(PackConverter converter, int from) { this.from = from; } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from <= Util.getVersionProtocol(gson, "1.20.1") && to >= Util.getVersionProtocol(gson, "1.20.2"); + } + @Override public void convert(Pack pack) throws IOException { Path texturesPath = pack.getWorkingPath().resolve("assets/minecraft/textures".replace("/", File.separator)); @@ -80,9 +85,7 @@ public static boolean run(Gson gson, int from, JsonObject predicate) { max_inclusive = Util.getLatestProtocol(gson); } - if (from < min_inclusive || from > max_inclusive) { - return false; - } + return from >= min_inclusive && from <= max_inclusive; } return true; diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/TitleConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/TitleConverter.java index bf6812ef..03d066d1 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/TitleConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/TitleConverter.java @@ -1,47 +1,52 @@ package com.agentdid127.resourcepack.forwards.impl.textures; -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; - import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.ImageConverter; +import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; public class TitleConverter extends Converter { public TitleConverter(PackConverter packConverter) { super(packConverter); } - /** - * Updates Minecraft Title and Minecraft Realms Title - * - * @param pack - * @throws IOException - */ + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from <= Util.getVersionProtocol(gson, "1.19.4") && to >= Util.getVersionProtocol(gson, "1.20"); + } + @Override public void convert(Pack pack) throws IOException { Path texturesPath = pack.getWorkingPath().resolve("assets/minecraft/textures".replace("/", File.separator)); - if (!texturesPath.toFile().exists()) + if (!texturesPath.toFile().exists()) { return; + } Path titleFolderPath = texturesPath.resolve("gui/title".replace("/", File.separator)); - if (!titleFolderPath.toFile().exists()) + if (!titleFolderPath.toFile().exists()) { return; + } Path minecraftTilePath = titleFolderPath.resolve("minecraft.png"); - if (!minecraftTilePath.toFile().exists()) + if (!minecraftTilePath.toFile().exists()) { return; + } int oldWidth = 256, oldHeight = 256; ImageConverter image = new ImageConverter(oldWidth, oldHeight, minecraftTilePath); - if (!image.fileIsPowerOfTwo() || !image.isSquare()) + if (!image.fileIsPowerOfTwo() || !image.isSquare()) { return; + } // Normal Minecraft Title image.newImage(274, 64); - // TODO: fix bigger resolutions not aligning properly?? and having extra space + // TODO: Fix bigger resolutions not aligning properly?? and having extra space // to the right of the image image.subImage(0, 0, 156, 44); image.subImage(0, 45, 119, 90, 155, 0); diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/WaterConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/WaterConverter.java index 3fdb4f2d..dbbafe9e 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/WaterConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/WaterConverter.java @@ -4,35 +4,41 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.ImageConverter; +import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; import java.io.File; import java.io.IOException; import java.nio.file.Path; public class WaterConverter extends Converter { - public WaterConverter(PackConverter packConverter) { - super(packConverter); - } + public WaterConverter(PackConverter packConverter) { + super(packConverter); + } - @Override - public void convert(Pack pack) throws IOException { - Path blockFolder = pack.getWorkingPath() - .resolve("assets/minecraft/textures/block".replace("/", File.separator)); - if (!blockFolder.toFile().exists()) - return; - grayscale(blockFolder.resolve("water_flow.png"), 16, 1024); - grayscale(blockFolder.resolve("water_still.png"), 16, 512); - grayscale(blockFolder.resolve("water_overlay.png"), 16, 16); - } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from <= Util.getVersionProtocol(gson, "1.12.2") && to >= Util.getVersionProtocol(gson, "1.13"); + } - private void grayscale(Path path, int w, int h) throws IOException { - if (!path.toFile().exists()) - return; - ImageConverter imageConverter = new ImageConverter(w, h, path); - if (!imageConverter.fileIsPowerOfTwo()) - return; - imageConverter.newImage(w, h); - imageConverter.grayscale(); - imageConverter.store(); - } + @Override + public void convert(Pack pack) throws IOException { + Path blockFolder = pack.getWorkingPath().resolve("assets/minecraft/textures/block".replace("/", File.separator)); + if (blockFolder.toFile().exists()) { + grayscale(blockFolder.resolve("water_flow.png"), 16, 1024); + grayscale(blockFolder.resolve("water_still.png"), 16, 512); + grayscale(blockFolder.resolve("water_overlay.png"), 16, 16); + } + } + + private void grayscale(Path path, int w, int h) throws IOException { + if (path.toFile().exists()) { + ImageConverter imageConverter = new ImageConverter(w, h, path); + if (imageConverter.fileIsPowerOfTwo()) { + imageConverter.newImage(w, h); + imageConverter.grayscale(); + imageConverter.store(); + } + } + } } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/SlidersCreator.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/WidgetSlidersCreator.java similarity index 66% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/SlidersCreator.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/WidgetSlidersCreator.java index 3c5f2d0a..25a281d2 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/SlidersCreator.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/WidgetSlidersCreator.java @@ -1,33 +1,39 @@ package com.agentdid127.resourcepack.forwards.impl.textures; -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; - import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.ImageConverter; +import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; -public class SlidersCreator extends Converter { - public SlidersCreator(PackConverter packConverter) { +public class WidgetSlidersCreator extends Converter { + public WidgetSlidersCreator(PackConverter packConverter) { super(packConverter); } + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from <= Util.getVersionProtocol(gson, "1.19.3") && to >= Util.getVersionProtocol(gson, "1.19.4"); + } + @Override public void convert(Pack pack) throws IOException { - Path widgetsPath = pack.getWorkingPath() - .resolve("assets/minecraft/textures/gui/widgets.png".replace("/", File.separator)); - if (!widgetsPath.toFile().exists()) + Path widgetsPath = pack.getWorkingPath().resolve("assets/minecraft/textures/gui/widgets.png".replace("/", File.separator)); + if (!widgetsPath.toFile().exists()) { return; + } ImageConverter converter = new ImageConverter(256, 256, widgetsPath); - int button_width = 200; - int button_height = 20; - converter.newImage(256, 256); + int button_width = 200; + int button_height = 20; int y = 46; converter.subImageSized(0, y, button_width, button_height, 0, 0); converter.subImageSized(0, y, button_width, button_height, 0, button_height); diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlidersCreator.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlidersCreator.html index 73f13916..0e4b3a84 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlidersCreator.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlidersCreator.html @@ -88,7 +88,7 @@

Class SlidersCreator

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.SlidersCreator
+
com.agentdid127.resourcepack.forwards.impl.textures.WidgetSlidersCreator
diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/Converter.java b/library/src/main/java/com/agentdid127/resourcepack/library/Converter.java index b7a8d704..50e2a233 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/Converter.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/Converter.java @@ -1,6 +1,7 @@ package com.agentdid127.resourcepack.library; import com.agentdid127.resourcepack.library.pack.Pack; +import com.google.gson.Gson; import java.io.IOException; @@ -11,5 +12,7 @@ public Converter(PackConverter packConverter) { this.packConverter = packConverter; } + public abstract boolean shouldConvert(Gson gson, int from, int to); + public abstract void convert(Pack pack) throws IOException; } From 932c024b19ca6040d36fb51279d4e3d07f33a087 Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Sun, 9 Feb 2025 23:02:58 -0500 Subject: [PATCH 38/54] Refactor Slicer/Move Classes --- .../forwards/ForwardsPackConverter.java | 11 ++-- .../impl/textures/ArmorMoverConverter.java | 11 ++-- .../impl/textures/MapIconConverter.java | 61 ++++++++----------- .../{ => creator}/OffHandCreator.java | 2 +- .../{ => creator}/WidgetSlidersCreator.java | 2 +- .../GuiSlicerConverter.java} | 17 +++--- .../{ => slicer}/MapIconSlicerConverter.java | 8 +-- .../MobEffectAtlasSlicerConverter.java} | 37 +++++------ .../PaintingSlicerConverter.java} | 10 +-- .../ParticlesSlicerConverter.java} | 12 ++-- .../textures/MobEffectAtlasConverter.html | 2 +- .../impl/textures/OffHandCreator.html | 2 +- .../impl/textures/PaintingConverter.html | 2 +- .../textures/ParticleTextureConverter.html | 2 +- .../SlicerConverter.PredicateRunnable.html | 2 +- .../impl/textures/SlicerConverter.html | 2 +- .../impl/textures/SlidersCreator.html | 2 +- .../library/utilities/ImageConverter.java | 42 +++++++------ .../library/utilities}/slicing/Box.java | 10 +-- .../utilities/slicing/PredicateRunnable.java | 8 +++ .../library/utilities}/slicing/Slice.java | 36 +++++------ .../library/utilities}/slicing/Slicer.java | 21 ++----- .../library/utilities}/slicing/Texture.java | 54 ++++++++-------- 23 files changed, 184 insertions(+), 172 deletions(-) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/{ => creator}/OffHandCreator.java (97%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/{ => creator}/WidgetSlidersCreator.java (96%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/{SlicerConverter.java => slicer/GuiSlicerConverter.java} (81%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/{ => slicer}/MapIconSlicerConverter.java (82%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/{MobEffectAtlasConverter.java => slicer/MobEffectAtlasSlicerConverter.java} (60%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/{PaintingConverter.java => slicer/PaintingSlicerConverter.java} (82%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/{ParticleTextureConverter.java => slicer/ParticlesSlicerConverter.java} (85%) rename {conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures => library/src/main/java/com/agentdid127/resourcepack/library/utilities}/slicing/Box.java (80%) create mode 100644 library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/PredicateRunnable.java rename {conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures => library/src/main/java/com/agentdid127/resourcepack/library/utilities}/slicing/Slice.java (75%) rename {conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures => library/src/main/java/com/agentdid127/resourcepack/library/utilities}/slicing/Slicer.java (77%) rename {conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures => library/src/main/java/com/agentdid127/resourcepack/library/utilities}/slicing/Texture.java (78%) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java index fc5adc1c..d8f593cc 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java @@ -2,6 +2,9 @@ import com.agentdid127.resourcepack.forwards.impl.*; import com.agentdid127.resourcepack.forwards.impl.textures.*; +import com.agentdid127.resourcepack.forwards.impl.textures.creator.OffHandCreator; +import com.agentdid127.resourcepack.forwards.impl.textures.creator.WidgetSlidersCreator; +import com.agentdid127.resourcepack.forwards.impl.textures.slicer.*; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; @@ -47,9 +50,9 @@ private void setupConverters(String light) { this.registerConverter(new WaterConverter(this)); this.registerConverter(new BlockStateConverter(this, from, to)); this.registerConverter(new LangConverter(this, from, to)); - this.registerConverter(new ParticleTextureConverter(this, from, to)); - this.registerConverter(new PaintingConverter(this)); - this.registerConverter(new MobEffectAtlasConverter(this, from)); + this.registerConverter(new ParticlesSlicerConverter(this, from, to)); + this.registerConverter(new PaintingSlicerConverter(this)); + this.registerConverter(new MobEffectAtlasSlicerConverter(this, from)); this.registerConverter(new ChestConverter(this)); this.registerConverter(new EnchantConverter(this)); this.registerConverter(new ParticleConverter(this)); @@ -59,7 +62,7 @@ private void setupConverters(String light) { this.registerConverter(new EnchantPathConverter(this)); this.registerConverter(new WidgetSlidersCreator(this)); this.registerConverter(new TitleConverter(this)); - this.registerConverter(new SlicerConverter(this, from)); + this.registerConverter(new GuiSlicerConverter(this, from)); this.registerConverter(new ImageFormatConverter(this)); this.registerConverter(new MapIconSlicerConverter(this, from)); this.registerConverter(new ArmorMoverConverter(this)); diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java index 6a87e0ef..9d911f8d 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java @@ -14,11 +14,9 @@ import java.util.List; public class ArmorMoverConverter extends Converter { - private final List MATERIALS = new ArrayList<>(); + private static final List MATERIALS = new ArrayList<>(); - // TODO: Trims/Wolf Armor/Llama/Horse/Elytra - public ArmorMoverConverter(PackConverter packConverter) { - super(packConverter); + static { MATERIALS.add("chainmail"); MATERIALS.add("diamond"); MATERIALS.add("gold"); @@ -27,6 +25,11 @@ public ArmorMoverConverter(PackConverter packConverter) { MATERIALS.add("netherite"); } + // TODO: Trims/Wolf Armor/Llama/Horse/Elytra + public ArmorMoverConverter(PackConverter packConverter) { + super(packConverter); + } + @Override public boolean shouldConvert(Gson gson, int from, int to) { return from <= Util.getVersionProtocol(gson, "1.21.1") && to >= Util.getVersionProtocol(gson, "1.21.2"); diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter.java index 63f69cb0..87897286 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter.java @@ -17,20 +17,23 @@ import java.util.Map; public class MapIconConverter extends Converter { - protected Map mapping = new HashMap<>(); + private static final Map MAPPING = new HashMap<>(); + + static { + MAPPING.put(pack(0, 0), pack(0, 0)); + MAPPING.put(pack(8, 0), pack(8, 0)); + MAPPING.put(pack(16, 0), pack(16, 0)); + MAPPING.put(pack(24, 0), pack(24, 0)); + MAPPING.put(pack(0, 8), pack(32, 0)); + MAPPING.put(pack(8, 8), pack(40, 0)); + MAPPING.put(pack(16, 8), pack(48, 0)); + MAPPING.put(pack(24, 8), pack(56, 0)); + MAPPING.put(pack(0, 16), pack(64, 0)); + MAPPING.put(pack(8, 16), pack(72, 0)); + } public MapIconConverter(PackConverter packConverter) { super(packConverter); - mapping.put(pack(0, 0), pack(0, 0)); - mapping.put(pack(8, 0), pack(8, 0)); - mapping.put(pack(16, 0), pack(16, 0)); - mapping.put(pack(24, 0), pack(24, 0)); - mapping.put(pack(0, 8), pack(32, 0)); - mapping.put(pack(8, 8), pack(40, 0)); - mapping.put(pack(16, 8), pack(48, 0)); - mapping.put(pack(24, 8), pack(56, 0)); - mapping.put(pack(0, 16), pack(64, 0)); - mapping.put(pack(8, 16), pack(72, 0)); } @Override @@ -38,47 +41,37 @@ public boolean shouldConvert(Gson gson, int from, int to) { return from <= Util.getVersionProtocol(gson, "1.12.2") && to >= Util.getVersionProtocol(gson, "1.13"); } - /** - * Converts maps - * - * @param pack - * @throws IOException - */ @Override public void convert(Pack pack) throws IOException { - Path mapIconsPath = pack.getWorkingPath() - .resolve("assets/minecraft/textures/map/map_icons.png".replace("/", File.separator)); - if (!mapIconsPath.toFile().exists()) + Path mapIconsPath = pack.getWorkingPath().resolve("assets/minecraft/textures/map/map_icons.png".replace("/", File.separator)); + if (!mapIconsPath.toFile().exists()) { return; + } BufferedImage newImage = Util.readImageResource("/forwards/map_icons.png"); - if (newImage == null) + if (newImage == null) { throw new NullPointerException(); + } Graphics2D g2d = (Graphics2D) newImage.getGraphics(); - BufferedImage image = ImageIO.read(mapIconsPath.toFile()); int scale = image.getWidth() / 32; - for (int x = 0; x <= 32 - 8; x += 8) { for (int y = 0; y <= 32 - 8; y += 8) { - Long mapped = mapping.get(pack(x, y)); - if (mapped == null) - continue; - - int newX = (int) (mapped >> 32); - int newY = (int) (long) mapped; - Logger.debug("Mapping " + x + "," + y + " to " + newX + "," + newY); - - g2d.drawImage(image.getSubimage(x * scale, y * scale, 8 * scale, 8 * scale), newX * scale, newY * scale, - null); + Long mapped = MAPPING.get(pack(x, y)); + if (mapped != null) { + int newX = (int) (mapped >> 32); + int newY = (int) (long) mapped; + Logger.debug("Mapping " + x + "," + y + " to " + newX + "," + newY); + g2d.drawImage(image.getSubimage(x * scale, y * scale, 8 * scale, 8 * scale), newX * scale, newY * scale, null); + } } } ImageIO.write(newImage, "png", mapIconsPath.toFile()); } - protected long pack(int x, int y) { + private static long pack(int x, int y) { return (((long) x) << 32) | (y & 0xffffffffL); } } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/OffHandCreator.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/creator/OffHandCreator.java similarity index 97% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/OffHandCreator.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/creator/OffHandCreator.java index 529e382e..05315c9a 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/OffHandCreator.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/creator/OffHandCreator.java @@ -1,4 +1,4 @@ -package com.agentdid127.resourcepack.forwards.impl.textures; +package com.agentdid127.resourcepack.forwards.impl.textures.creator; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/WidgetSlidersCreator.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/creator/WidgetSlidersCreator.java similarity index 96% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/WidgetSlidersCreator.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/creator/WidgetSlidersCreator.java index 25a281d2..35b31036 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/WidgetSlidersCreator.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/creator/WidgetSlidersCreator.java @@ -1,4 +1,4 @@ -package com.agentdid127.resourcepack.forwards.impl.textures; +package com.agentdid127.resourcepack.forwards.impl.textures.creator; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/GuiSlicerConverter.java similarity index 81% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/GuiSlicerConverter.java index bb04222f..c9c042d4 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/GuiSlicerConverter.java @@ -1,13 +1,14 @@ -package com.agentdid127.resourcepack.forwards.impl.textures; +package com.agentdid127.resourcepack.forwards.impl.textures.slicer; -import com.agentdid127.resourcepack.forwards.impl.textures.slicing.Slice; -import com.agentdid127.resourcepack.forwards.impl.textures.slicing.Slicer; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.JsonUtil; import com.agentdid127.resourcepack.library.utilities.Logger; import com.agentdid127.resourcepack.library.utilities.Util; +import com.agentdid127.resourcepack.library.utilities.slicing.PredicateRunnable; +import com.agentdid127.resourcepack.library.utilities.slicing.Slice; +import com.agentdid127.resourcepack.library.utilities.slicing.Slicer; import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; @@ -17,10 +18,10 @@ import java.io.IOException; import java.nio.file.Path; -public class SlicerConverter extends Converter { +public class GuiSlicerConverter extends Converter { private final int from; - public SlicerConverter(PackConverter converter, int from) { + public GuiSlicerConverter(PackConverter converter, int from) { super(converter); this.from = from; } @@ -53,14 +54,14 @@ public void convert(Pack pack) throws IOException { Logger.addTab(); Slice[] slices = Slice.parseArray(array); for (Slice slice : slices) { - Slicer.runSlicer(gson, slice, guiPath, PredicateRunnable.class, from, true); + Slicer.runSlicer(gson, slice, guiPath, new GuiPredicateRunnable(), from, true); } Logger.subTab(); } } - public static class PredicateRunnable { - public static boolean run(Gson gson, int from, JsonObject predicate) { + public static class GuiPredicateRunnable implements PredicateRunnable { + public boolean run(Gson gson, int from, JsonObject predicate) { if (predicate.has("protocol")) { JsonObject protocol = predicate.getAsJsonObject("protocol"); diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconSlicerConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/MapIconSlicerConverter.java similarity index 82% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconSlicerConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/MapIconSlicerConverter.java index 5b7c5662..92191b62 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconSlicerConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/MapIconSlicerConverter.java @@ -1,12 +1,12 @@ -package com.agentdid127.resourcepack.forwards.impl.textures; +package com.agentdid127.resourcepack.forwards.impl.textures.slicer; -import com.agentdid127.resourcepack.forwards.impl.textures.slicing.Slice; -import com.agentdid127.resourcepack.forwards.impl.textures.slicing.Slicer; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.JsonUtil; import com.agentdid127.resourcepack.library.utilities.Util; +import com.agentdid127.resourcepack.library.utilities.slicing.Slice; +import com.agentdid127.resourcepack.library.utilities.slicing.Slicer; import com.google.gson.Gson; import com.google.gson.JsonObject; @@ -43,7 +43,7 @@ public void convert(Pack pack) throws IOException { JsonObject mapIconsJson = JsonUtil.readJsonResource(gson, "/forwards/map_icons.json", JsonObject.class); if (mapIconsJson != null) { Slice slice = Slice.parse(mapIconsJson); - Slicer.runSlicer(gson, slice, mapIconsPath, SlicerConverter.PredicateRunnable.class, from, false); + Slicer.runSlicer(gson, slice, mapIconsPath, new GuiSlicerConverter.GuiPredicateRunnable(), from, false); } } } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MobEffectAtlasConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/MobEffectAtlasSlicerConverter.java similarity index 60% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MobEffectAtlasConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/MobEffectAtlasSlicerConverter.java index 8d258370..e75507aa 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MobEffectAtlasConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/MobEffectAtlasSlicerConverter.java @@ -1,23 +1,23 @@ -package com.agentdid127.resourcepack.forwards.impl.textures; +package com.agentdid127.resourcepack.forwards.impl.textures.slicer; -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; - -import com.agentdid127.resourcepack.forwards.impl.textures.slicing.Slice; -import com.agentdid127.resourcepack.forwards.impl.textures.slicing.Slicer; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.JsonUtil; import com.agentdid127.resourcepack.library.utilities.Util; +import com.agentdid127.resourcepack.library.utilities.slicing.Slice; +import com.agentdid127.resourcepack.library.utilities.slicing.Slicer; import com.google.gson.Gson; import com.google.gson.JsonObject; -public class MobEffectAtlasConverter extends Converter { +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; + +public class MobEffectAtlasSlicerConverter extends Converter { private final int from; - public MobEffectAtlasConverter(PackConverter packConverter, int from) { + public MobEffectAtlasSlicerConverter(PackConverter packConverter, int from) { super(packConverter); this.from = from; } @@ -36,17 +36,20 @@ public boolean shouldConvert(Gson gson, int from, int to) { @Override public void convert(Pack pack) throws IOException { Path texturesPath = pack.getWorkingPath().resolve("assets/minecraft/textures".replace("/", File.separator)); - if (!texturesPath.toFile().exists()) - return; - Path containerPath = texturesPath.resolve("gui/container".replace("/", File.separator)); - if (!containerPath.toFile().exists()) + if (!texturesPath.toFile().exists()) { return; - Path inventoryPath = containerPath.resolve("inventory.png"); - if (!inventoryPath.toFile().exists()) + } + + Path inventoryPath = texturesPath.resolve("gui/container/inventory.png".replace("/", File.separator)); + if (!inventoryPath.toFile().exists()) { return; + } + Gson gson = packConverter.getGson(); JsonObject effectJson = JsonUtil.readJsonResource(gson, "/forwards/mob_effect.json", JsonObject.class); - Slice slice = Slice.parse(effectJson); - Slicer.runSlicer(gson, slice, texturesPath, SlicerConverter.PredicateRunnable.class, from, false); + if (effectJson != null) { + Slice slice = Slice.parse(effectJson); + Slicer.runSlicer(gson, slice, texturesPath, new GuiSlicerConverter.GuiPredicateRunnable(), from, false); + } } } \ No newline at end of file diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/PaintingConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/PaintingSlicerConverter.java similarity index 82% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/PaintingConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/PaintingSlicerConverter.java index ad8e6326..cb12c484 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/PaintingConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/PaintingSlicerConverter.java @@ -1,12 +1,12 @@ -package com.agentdid127.resourcepack.forwards.impl.textures; +package com.agentdid127.resourcepack.forwards.impl.textures.slicer; -import com.agentdid127.resourcepack.forwards.impl.textures.slicing.Slice; -import com.agentdid127.resourcepack.forwards.impl.textures.slicing.Slicer; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.JsonUtil; import com.agentdid127.resourcepack.library.utilities.Util; +import com.agentdid127.resourcepack.library.utilities.slicing.Slice; +import com.agentdid127.resourcepack.library.utilities.slicing.Slicer; import com.google.gson.Gson; import com.google.gson.JsonObject; @@ -14,8 +14,8 @@ import java.io.IOException; import java.nio.file.Path; -public class PaintingConverter extends Converter { - public PaintingConverter(PackConverter packConverter) { +public class PaintingSlicerConverter extends Converter { + public PaintingSlicerConverter(PackConverter packConverter) { super(packConverter); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/ParticlesSlicerConverter.java similarity index 85% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/ParticlesSlicerConverter.java index 2fe6e32d..f69f346f 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/ParticlesSlicerConverter.java @@ -1,11 +1,11 @@ -package com.agentdid127.resourcepack.forwards.impl.textures; +package com.agentdid127.resourcepack.forwards.impl.textures.slicer; -import com.agentdid127.resourcepack.forwards.impl.textures.slicing.Slice; -import com.agentdid127.resourcepack.forwards.impl.textures.slicing.Slicer; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; import com.agentdid127.resourcepack.library.utilities.*; +import com.agentdid127.resourcepack.library.utilities.slicing.Slice; +import com.agentdid127.resourcepack.library.utilities.slicing.Slicer; import com.google.gson.Gson; import com.google.gson.JsonObject; @@ -13,11 +13,11 @@ import java.io.IOException; import java.nio.file.Path; -public class ParticleTextureConverter extends Converter { +public class ParticlesSlicerConverter extends Converter { private final int from; private final int to; - public ParticleTextureConverter(PackConverter packConverter, int from, int to) { + public ParticlesSlicerConverter(PackConverter packConverter, int from, int to) { super(packConverter); this.from = from; this.to = to; @@ -71,7 +71,7 @@ public void convert(Pack pack) throws IOException { if (from <= Util.getVersionProtocol(gson, "1.13.2") && to >= Util.getVersionProtocol(gson, "1.14")) { - Slicer.runSlicer(gson, slice, particlePath, SlicerConverter.PredicateRunnable.class, from, false); + Slicer.runSlicer(gson, slice, particlePath, new GuiSlicerConverter.GuiPredicateRunnable(), from, false); Path entityPath = texturesPath.resolve("entity"); Path newFishingHookPath = entityPath.resolve("fishing_hook.png"); if (newFishingHookPath.toFile().exists()) { diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/MobEffectAtlasConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/MobEffectAtlasConverter.html index d87ae89a..796a75c5 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/MobEffectAtlasConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/MobEffectAtlasConverter.html @@ -88,7 +88,7 @@

Class MobEffectAtlasConv
java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.MobEffectAtlasConverter
+
com.agentdid127.resourcepack.forwards.impl.textures.slicer.MobEffectAtlasSlicerConverter
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/OffHandCreator.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/OffHandCreator.html index 5e1ef2ff..56b5c00b 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/OffHandCreator.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/OffHandCreator.html @@ -88,7 +88,7 @@

Class OffHandCreator

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.OffHandCreator
+
com.agentdid127.resourcepack.forwards.impl.textures.creator.OffHandCreator
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/PaintingConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/PaintingConverter.html index 5e66460b..6c460875 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/PaintingConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/PaintingConverter.html @@ -88,7 +88,7 @@

Class PaintingConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.PaintingConverter
+
com.agentdid127.resourcepack.forwards.impl.textures.slicer.PaintingSlicerConverter
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.html index a582065d..229327e3 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.html @@ -88,7 +88,7 @@

Class ParticleTextureCo
java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.ParticleTextureConverter
+
com.agentdid127.resourcepack.forwards.impl.textures.slicer.ParticlesSlicerConverter
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.PredicateRunnable.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.PredicateRunnable.html index 2ca31727..dbfec8b8 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.PredicateRunnable.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.PredicateRunnable.html @@ -87,7 +87,7 @@

Class SlicerConverter.PredicateRunnable

java.lang.Object -
com.agentdid127.resourcepack.forwards.impl.textures.SlicerConverter.PredicateRunnable
+
com.agentdid127.resourcepack.forwards.impl.textures.slicer.GuiSlicerConverter.PredicateRunnable
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.html index e474c728..4d348f09 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.html @@ -88,7 +88,7 @@

Class SlicerConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.SlicerConverter
+
com.agentdid127.resourcepack.forwards.impl.textures.slicer.GuiSlicerConverter
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlidersCreator.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlidersCreator.html index 0e4b3a84..b4e1b404 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlidersCreator.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlidersCreator.html @@ -88,7 +88,7 @@

Class SlidersCreator

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.WidgetSlidersCreator
+
com.agentdid127.resourcepack.forwards.impl.textures.creator.WidgetSlidersCreator
diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/ImageConverter.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/ImageConverter.java index 777c7daa..8d84bd0c 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/ImageConverter.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/ImageConverter.java @@ -43,20 +43,23 @@ public ImageConverter(Integer defaultWIn, Integer defaultHIn, Path locationIn) t + "' resolution size is not a power of 2. Converting to be so."); int fixed_width = (int) Math.ceil(Math.log(image.getWidth()) / Math.log(2)); - if (fixed_width < 1) + if (fixed_width < 1) { fixed_width = 1; + } int fixed_height = (int) Math.ceil(Math.log(image.getHeight()) / Math.log(2)); - if (fixed_height < 1) + if (fixed_height < 1) { fixed_height = 1; + } newImage = new BufferedImage(fixed_width, fixed_height, image.getType()); Graphics2D g = newImage.createGraphics(); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.drawImage(image, 0, 0, fixed_width, fixed_height, 0, 0, imageWidth, imageHeight, null); g.dispose(); - } else + } else { newImage = image; + } } /** @@ -108,6 +111,7 @@ public void setImage(int defaultWIn, int defaultHIn) throws IOException { Logger.debug("Image '" + location.getFileName() + "' is not a power of 2"); return; } + image = newImage; defaultW = defaultWIn; defaultH = defaultHIn; @@ -143,10 +147,10 @@ public void newImage(int newWidth, int newHeight) { * @throws IOException */ public void addImage(Path imagePath, int x, int y) throws IOException { - if (!imagePath.toFile().exists()) - return; - BufferedImage image = ImageIO.read(imagePath.toFile()); - g2d.drawImage(image, scaleX(x), scaleY(y), null); + if (imagePath.toFile().exists()) { + BufferedImage image = ImageIO.read(imagePath.toFile()); + g2d.drawImage(image, scaleX(x), scaleY(y), null); + } } /** @@ -197,8 +201,7 @@ public void subImage(int x, int y, int x2, int y2, int storeX, int storeY, boole int width2 = (int) (x2 * scaleW - x * scaleW); int height2 = (int) (y2 * scaleH - y * scaleH); BufferedImage part = getSubImage(scaleX(x), scaleY(y), width2, height2); - g2d.drawImage(createFlipped(part, flip), Math.round((float) (storeX * scaleW)), - Math.round((float) (storeY * scaleH)), null); + g2d.drawImage(createFlipped(part, flip), Math.round((float) (storeX * scaleW)), Math.round((float) (storeY * scaleH)), null); } /** @@ -222,8 +225,7 @@ public void subImage(int x, int y, int x2, int y2, int storeX, int storeY, int f int y3 = (int) (y * scaleH); BufferedImage part = getSubImage(x3, y3, width2, height2); - g2d.drawImage(createFlipped(part, flip), Math.round((float) (storeX * scaleW)), - Math.round((float) (storeY * scaleH)), null); + g2d.drawImage(createFlipped(part, flip), Math.round((float) (storeX * scaleW)), Math.round((float) (storeY * scaleH)), null); } public void subImageSized(int x, int y, int width, int height, int storeX, int storeY) { @@ -257,8 +259,10 @@ public void colorizeClipped(Color color) { for (int x = 0; x < this.getWidth(); x++) { int imageRGBA = newImage.getRGB(x, y); int alpha = (imageRGBA >> 24) & 0xFF; - if (alpha == 0) + if (alpha == 0) { continue; + } + int grayscaleValue = (imageRGBA >> 16) & 0xFF; int red = (grayscaleValue * color.getRed()) / 255; int green = (grayscaleValue * color.getGreen()) / 255; @@ -297,13 +301,15 @@ public void grayscale() { */ private static BufferedImage createFlipped(BufferedImage image, int flip) { AffineTransform at = new AffineTransform(); - if (flip != 1) + if (flip != 1) { return image; - at.concatenate(AffineTransform.getScaleInstance(1, -1)); - at.concatenate(AffineTransform.getTranslateInstance(0, -image.getHeight())); - at.concatenate(AffineTransform.getScaleInstance(-1, 1)); - at.concatenate(AffineTransform.getTranslateInstance(-image.getWidth(), 0)); - return createTransformed(image, at); + } else { + at.concatenate(AffineTransform.getScaleInstance(1, -1)); + at.concatenate(AffineTransform.getTranslateInstance(0, -image.getHeight())); + at.concatenate(AffineTransform.getScaleInstance(-1, 1)); + at.concatenate(AffineTransform.getTranslateInstance(-image.getWidth(), 0)); + return createTransformed(image, at); + } } /** diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicing/Box.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/Box.java similarity index 80% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicing/Box.java rename to library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/Box.java index 1f1b7ef7..ed9efe73 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicing/Box.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/Box.java @@ -1,12 +1,12 @@ -package com.agentdid127.resourcepack.forwards.impl.textures.slicing; +package com.agentdid127.resourcepack.library.utilities.slicing; import com.google.gson.JsonObject; public class Box { - private int x; - private int y; - private int width; - private int height; + private final int x; + private final int y; + private final int width; + private final int height; public Box(int x, int y, int width, int height) { this.x = x; diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/PredicateRunnable.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/PredicateRunnable.java new file mode 100644 index 00000000..66053e69 --- /dev/null +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/PredicateRunnable.java @@ -0,0 +1,8 @@ +package com.agentdid127.resourcepack.library.utilities.slicing; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; + +public interface PredicateRunnable { + boolean run(Gson gson, int from, JsonObject predicate); +} diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicing/Slice.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/Slice.java similarity index 75% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicing/Slice.java rename to library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/Slice.java index f99f5946..2c809dd5 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicing/Slice.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/Slice.java @@ -1,7 +1,6 @@ -package com.agentdid127.resourcepack.forwards.impl.textures.slicing; +package com.agentdid127.resourcepack.library.utilities.slicing; import com.google.gson.JsonArray; -import com.google.gson.JsonElement; import com.google.gson.JsonObject; import java.io.File; @@ -34,15 +33,15 @@ public int getHeight() { } public void setWidth(int width) { - if (this.width == width) - return; - this.width = width; + if (this.width != width) { + this.width = width; + } } public void setHeight(int height) { - if (this.height == height) - return; - this.height = height; + if (this.height != height) { + this.height = height; + } } public JsonObject getPredicate() { @@ -61,33 +60,34 @@ public static Slice parse(JsonObject object) { Slice slice = new Slice(); slice.path = object.get("path").getAsString(); - if (object.has("name")) + if (object.has("name")) { slice.name = object.get("name").getAsString(); - else + } else { slice.name = null; + } slice.width = object.get("width").getAsInt(); slice.height = object.get("height").getAsInt(); - slice.textures = Texture.parseArray(object.get("textures").getAsJsonArray()); - if (object.has("delete")) + if (object.has("delete")) { slice.delete = object.get("delete").getAsBoolean(); - else + } else { slice.delete = true; + } - if (object.has("predicate")) + if (object.has("predicate")) { slice.predicate = object.get("predicate").getAsJsonObject(); - else + } else { slice.predicate = new JsonObject(); + } return slice; } public static Slice[] parseArray(JsonArray array) { List slices = new LinkedList<>(); - for (JsonElement element : array) - slices.add(Slice.parse(element.getAsJsonObject())); - return slices.toArray(new Slice[] {}); + array.forEach(element -> slices.add(Slice.parse(element.getAsJsonObject()))); + return slices.toArray(new Slice[]{}); } } \ No newline at end of file diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicing/Slicer.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/Slicer.java similarity index 77% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicing/Slicer.java rename to library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/Slicer.java index 79bba225..951a44b8 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicing/Slicer.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/Slicer.java @@ -1,21 +1,19 @@ -package com.agentdid127.resourcepack.forwards.impl.textures.slicing; +package com.agentdid127.resourcepack.library.utilities.slicing; -import com.agentdid127.resourcepack.forwards.impl.textures.SlicerConverter; import com.agentdid127.resourcepack.library.utilities.FileUtil; import com.agentdid127.resourcepack.library.utilities.ImageConverter; import com.agentdid127.resourcepack.library.utilities.JsonUtil; import com.agentdid127.resourcepack.library.utilities.Logger; import com.google.gson.Gson; import com.google.gson.JsonObject; +import com.sun.istack.internal.Nullable; import java.io.IOException; -import java.lang.reflect.Method; import java.nio.file.Path; public class Slicer { - public static void runSlicer(Gson gson, Slice slice, Path root, Class predicateClass, int from, boolean has_metadata) - throws IOException { - if (!SlicerConverter.PredicateRunnable.run(gson, from, slice.getPredicate())) { + public static void runSlicer(Gson gson, Slice slice, Path root, @Nullable PredicateRunnable predicateRunnable, int from, boolean has_metadata) throws IOException { + if (predicateRunnable != null && !predicateRunnable.run(gson, from, slice.getPredicate())) { return; } @@ -43,15 +41,8 @@ public static void runSlicer(Gson gson, Slice slice, Path root, Class pre } FileUtil.ensureParentExists(texturePath); - if (predicateClass != null) { - // Hacky - try { - Method predicateTest = predicateClass.getMethod("run", Gson.class, int.class, JsonObject.class); - if (!((boolean) predicateTest.invoke(null, gson, from, texture.getPredicate()))) - continue; - } catch (Exception exception) { - Logger.log("Failed to get test predicate from predicate class"); - } + if (predicateRunnable != null && !predicateRunnable.run(gson, from, texture.getPredicate())) { + continue; } try { diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicing/Texture.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/Texture.java similarity index 78% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicing/Texture.java rename to library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/Texture.java index 830db3b7..084f0d7a 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicing/Texture.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/Texture.java @@ -1,22 +1,23 @@ -package com.agentdid127.resourcepack.forwards.impl.textures.slicing; - -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; +package com.agentdid127.resourcepack.library.utilities.slicing; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; + public class Texture { - private String path; - private Box box; - private boolean remove; - private JsonObject predicate; - private JsonObject metadata; - - public static HashMap metatdataCache = new HashMap<>(); - static { + private final String path; + private final Box box; + private final boolean remove; + private final JsonObject predicate; + private final JsonObject metadata; + + public static HashMap METADATA_CACHE = new HashMap<>(); + + static { { // Button Widget JsonObject buttonWidget = new JsonObject(); @@ -36,7 +37,7 @@ public class Texture { gui.add("scaling", scaling); buttonWidget.add("gui", gui); - metatdataCache.put("button_widget", buttonWidget); + METADATA_CACHE.put("button_widget", buttonWidget); } } @@ -95,30 +96,33 @@ public JsonObject getMetadata() { public static Texture parse(JsonObject object) { String path = object.get("path").getAsString(); Box box = Box.parse(object.get("box").getAsJsonObject()); - + boolean remove = false; - if (object.has("remove")) - remove = object.get("remove").getAsBoolean(); + if (object.has("remove")) { + remove = object.get("remove").getAsBoolean(); + } JsonObject predicate; - if (object.has("predicate")) + if (object.has("predicate")) { predicate = object.get("predicate").getAsJsonObject(); - else + } else { predicate = new JsonObject(); - + } + JsonObject metadata; if (object.has("metadata")) { JsonElement metadataElement = object.get("metadata"); - metadata = metadataElement.isJsonObject() ? metadataElement.getAsJsonObject() : metatdataCache.getOrDefault(metadataElement.getAsString(), new JsonObject()); - } else metadata = new JsonObject(); + metadata = metadataElement.isJsonObject() ? metadataElement.getAsJsonObject() : METADATA_CACHE.getOrDefault(metadataElement.getAsString(), new JsonObject()); + } else { + metadata = new JsonObject(); + } return new Texture(path, box, remove, predicate, metadata); } public static Texture[] parseArray(JsonArray array) { List textures = new LinkedList<>(); - for (JsonElement element : array) - textures.add(Texture.parse(element.getAsJsonObject())); - return textures.toArray(new Texture[] {}); + array.forEach(element -> textures.add(Texture.parse(element.getAsJsonObject()))); + return textures.toArray(new Texture[]{}); } } From 3aa6a9ce0016d58f0fa4d2071463f50e59bf9612 Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Sun, 9 Feb 2025 23:36:11 -0500 Subject: [PATCH 39/54] Fix build error with Slicer --- .../forwards/impl/textures/slicer/GuiSlicerConverter.java | 3 +-- .../impl/textures/slicer/PaintingSlicerConverter.java | 2 +- .../resourcepack/library/utilities/slicing/Slice.java | 5 +++-- .../resourcepack/library/utilities/slicing/Slicer.java | 3 +-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/GuiSlicerConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/GuiSlicerConverter.java index c9c042d4..4a146582 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/GuiSlicerConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/GuiSlicerConverter.java @@ -52,8 +52,7 @@ public void convert(Pack pack) throws IOException { JsonArray array = JsonUtil.readJsonResource(gson, "/forwards/gui.json", JsonArray.class); if (array != null) { Logger.addTab(); - Slice[] slices = Slice.parseArray(array); - for (Slice slice : slices) { + for (Slice slice : Slice.parseArray(array)) { Slicer.runSlicer(gson, slice, guiPath, new GuiPredicateRunnable(), from, true); } Logger.subTab(); diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/PaintingSlicerConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/PaintingSlicerConverter.java index cb12c484..a653e915 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/PaintingSlicerConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/PaintingSlicerConverter.java @@ -47,7 +47,7 @@ public void convert(Pack pack) throws IOException { JsonObject effectJson = JsonUtil.readJsonResource(gson, "/forwards/paintings_kristoffer_zetterstrand.json", JsonObject.class); if (effectJson != null) { Slice slice = Slice.parse(effectJson); - Slicer.runSlicer(gson, slice, paintingPath, null, -1, false); + Slicer.runSlicer(gson, slice, paintingPath, (gson1, from, predicate) -> true, -1, false); } } } \ No newline at end of file diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/Slice.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/Slice.java index 2c809dd5..ebf78904 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/Slice.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/Slice.java @@ -4,6 +4,7 @@ import com.google.gson.JsonObject; import java.io.File; +import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -85,9 +86,9 @@ public static Slice parse(JsonObject object) { return slice; } - public static Slice[] parseArray(JsonArray array) { + public static List parseArray(JsonArray array) { List slices = new LinkedList<>(); array.forEach(element -> slices.add(Slice.parse(element.getAsJsonObject()))); - return slices.toArray(new Slice[]{}); + return Collections.unmodifiableList(slices); } } \ No newline at end of file diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/Slicer.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/Slicer.java index 951a44b8..b886b4a8 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/Slicer.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/Slicer.java @@ -6,13 +6,12 @@ import com.agentdid127.resourcepack.library.utilities.Logger; import com.google.gson.Gson; import com.google.gson.JsonObject; -import com.sun.istack.internal.Nullable; import java.io.IOException; import java.nio.file.Path; public class Slicer { - public static void runSlicer(Gson gson, Slice slice, Path root, @Nullable PredicateRunnable predicateRunnable, int from, boolean has_metadata) throws IOException { + public static void runSlicer(Gson gson, Slice slice, Path root, /* nullable */ PredicateRunnable predicateRunnable, int from, boolean has_metadata) throws IOException { if (predicateRunnable != null && !predicateRunnable.run(gson, from, slice.getPredicate())) { return; } From f8e1d5754ffc36974391c3abe0a6582f8936a767 Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Mon, 10 Feb 2025 00:47:10 -0500 Subject: [PATCH 40/54] Add post-effect-shaders converter/updater --- .../forwards/ForwardsPackConverter.java | 18 +- ...er.java => ArmorMoverConverter1_21_2.java} | 4 +- ...Converter.java => ChestConverter1_15.java} | 4 +- ...onverter.java => CompassConverter1_9.java} | 4 +- ....java => CreativeTabsConverter1_19_3.java} | 4 +- ...nverter.java => EnchantConverter1_15.java} | 4 +- ...nverter.java => MapIconConverter1_13.java} | 4 +- .../PostEffectShadersConverter1_21_2.java | 169 ++++++++++++++++++ ...Converter.java => TitleConverter1_20.java} | 4 +- ...Converter.java => WaterConverter1_13.java} | 88 ++++----- .../impl/textures/ChestConverter.html | 2 +- .../impl/textures/CompassConverter.html | 2 +- .../impl/textures/CreativeTabsConverter.html | 2 +- .../impl/textures/EnchantConverter.html | 2 +- .../impl/textures/MapIconConverter.html | 2 +- .../impl/textures/TitleConverter.html | 2 +- .../impl/textures/WaterConverter.html | 2 +- 17 files changed, 243 insertions(+), 74 deletions(-) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/{ArmorMoverConverter.java => ArmorMoverConverter1_21_2.java} (97%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/{ChestConverter.java => ChestConverter1_15.java} (97%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/{CompassConverter.java => CompassConverter1_9.java} (94%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/{CreativeTabsConverter.java => CreativeTabsConverter1_19_3.java} (95%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/{EnchantConverter.java => EnchantConverter1_15.java} (91%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/{MapIconConverter.java => MapIconConverter1_13.java} (95%) create mode 100644 conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/PostEffectShadersConverter1_21_2.java rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/{TitleConverter.java => TitleConverter1_20.java} (94%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/{WaterConverter.java => WaterConverter1_13.java} (91%) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java index d8f593cc..009ddf5f 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java @@ -39,34 +39,34 @@ public ForwardsPackConverter(Gson gson, int from, int to, String light, Path inp private void setupConverters(String light) { this.registerConverter(new NameConverter(this, from, to)); // This needs to be run first, other converters might reference new directory names. this.registerConverter(new PackMetaConverter(this, from, to)); - this.registerConverter(new CompassConverter(this, to)); + this.registerConverter(new CompassConverter1_9(this, to)); this.registerConverter(new OffHandCreator(this)); this.registerConverter(new SpacesConverter(this)); this.registerConverter(new ModelConverter(this, light, from, to)); this.registerConverter(new SoundsConverter(this)); this.registerConverter(new AnimationConverter(this)); - this.registerConverter(new MapIconConverter(this)); + this.registerConverter(new MapIconConverter1_13(this)); this.registerConverter(new MCPatcherConverter(this)); - this.registerConverter(new WaterConverter(this)); + this.registerConverter(new WaterConverter1_13(this)); this.registerConverter(new BlockStateConverter(this, from, to)); this.registerConverter(new LangConverter(this, from, to)); this.registerConverter(new ParticlesSlicerConverter(this, from, to)); this.registerConverter(new PaintingSlicerConverter(this)); this.registerConverter(new MobEffectAtlasSlicerConverter(this, from)); - this.registerConverter(new ChestConverter(this)); - this.registerConverter(new EnchantConverter(this)); + this.registerConverter(new ChestConverter1_15(this)); + this.registerConverter(new EnchantConverter1_15(this)); this.registerConverter(new ParticleConverter(this)); this.registerConverter(new InventoryConverter(this)); this.registerConverter(new AtlasConverter(this)); - this.registerConverter(new CreativeTabsConverter(this)); + this.registerConverter(new CreativeTabsConverter1_19_3(this)); this.registerConverter(new EnchantPathConverter(this)); this.registerConverter(new WidgetSlidersCreator(this)); - this.registerConverter(new TitleConverter(this)); + this.registerConverter(new TitleConverter1_20(this)); this.registerConverter(new GuiSlicerConverter(this, from)); this.registerConverter(new ImageFormatConverter(this)); this.registerConverter(new MapIconSlicerConverter(this, from)); - this.registerConverter(new ArmorMoverConverter(this)); - // Shaders + this.registerConverter(new ArmorMoverConverter1_21_2(this)); + this.registerConverter(new PostEffectShadersConverter1_21_2(this)); } public void runPack(Pack pack) { diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter1_21_2.java similarity index 97% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter1_21_2.java index 9d911f8d..57043d47 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter1_21_2.java @@ -13,7 +13,7 @@ import java.util.ArrayList; import java.util.List; -public class ArmorMoverConverter extends Converter { +public class ArmorMoverConverter1_21_2 extends Converter { private static final List MATERIALS = new ArrayList<>(); static { @@ -26,7 +26,7 @@ public class ArmorMoverConverter extends Converter { } // TODO: Trims/Wolf Armor/Llama/Horse/Elytra - public ArmorMoverConverter(PackConverter packConverter) { + public ArmorMoverConverter1_21_2(PackConverter packConverter) { super(packConverter); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ChestConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ChestConverter1_15.java similarity index 97% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ChestConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ChestConverter1_15.java index eaeca9af..d8cd8702 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ChestConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ChestConverter1_15.java @@ -12,8 +12,8 @@ import java.io.IOException; import java.nio.file.Path; -public class ChestConverter extends Converter { - public ChestConverter(PackConverter packConverter) { +public class ChestConverter1_15 extends Converter { + public ChestConverter1_15(PackConverter packConverter) { super(packConverter); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/CompassConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/CompassConverter1_9.java similarity index 94% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/CompassConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/CompassConverter1_9.java index 7ab18aed..94b1f7d2 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/CompassConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/CompassConverter1_9.java @@ -12,11 +12,11 @@ import java.nio.file.Files; import java.nio.file.Path; -public class CompassConverter extends Converter { +public class CompassConverter1_9 extends Converter { private final int to; private Path items; - public CompassConverter(PackConverter packConverter, int to) { + public CompassConverter1_9(PackConverter packConverter, int to) { super(packConverter); this.to = to; } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/CreativeTabsConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/CreativeTabsConverter1_19_3.java similarity index 95% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/CreativeTabsConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/CreativeTabsConverter1_19_3.java index 26cc087f..d0dcce1b 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/CreativeTabsConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/CreativeTabsConverter1_19_3.java @@ -11,12 +11,12 @@ import java.io.IOException; import java.nio.file.Path; -public class CreativeTabsConverter extends Converter { +public class CreativeTabsConverter1_19_3 extends Converter { private static final int OLD_TAB_WIDTH = 28; private static final int NEW_TAB_WIDTH = 26; private static final int OLD_TAB_HALF = OLD_TAB_WIDTH / 2; - public CreativeTabsConverter(PackConverter converter) { + public CreativeTabsConverter1_19_3(PackConverter converter) { super(converter); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/EnchantConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/EnchantConverter1_15.java similarity index 91% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/EnchantConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/EnchantConverter1_15.java index 9e8fbd78..e467685f 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/EnchantConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/EnchantConverter1_15.java @@ -12,8 +12,8 @@ import java.io.IOException; import java.nio.file.Path; -public class EnchantConverter extends Converter { - public EnchantConverter(PackConverter packConverter) { +public class EnchantConverter1_15 extends Converter { + public EnchantConverter1_15(PackConverter packConverter) { super(packConverter); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter1_13.java similarity index 95% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter1_13.java index 87897286..9ac71de3 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter1_13.java @@ -16,7 +16,7 @@ import java.util.HashMap; import java.util.Map; -public class MapIconConverter extends Converter { +public class MapIconConverter1_13 extends Converter { private static final Map MAPPING = new HashMap<>(); static { @@ -32,7 +32,7 @@ public class MapIconConverter extends Converter { MAPPING.put(pack(8, 16), pack(72, 0)); } - public MapIconConverter(PackConverter packConverter) { + public MapIconConverter1_13(PackConverter packConverter) { super(packConverter); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/PostEffectShadersConverter1_21_2.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/PostEffectShadersConverter1_21_2.java new file mode 100644 index 00000000..ffbc551d --- /dev/null +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/PostEffectShadersConverter1_21_2.java @@ -0,0 +1,169 @@ +package com.agentdid127.resourcepack.forwards.impl.textures; + +import com.agentdid127.resourcepack.library.Converter; +import com.agentdid127.resourcepack.library.PackConverter; +import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.JsonUtil; +import com.agentdid127.resourcepack.library.utilities.Logger; +import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.*; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class PostEffectShadersConverter1_21_2 extends Converter { + private static final Map MAPPING = new HashMap<>(); + + static { + // TODO/NOTE: There could be more? + MAPPING.put("largeBlur", "large_blur"); + MAPPING.put("smallBlur", "small_blur"); + MAPPING.put("itemEntity", "item_entity"); + } + + public PostEffectShadersConverter1_21_2(PackConverter packConverter) { + super(packConverter); + } + + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from <= Util.getVersionProtocol(gson, "1.21.1") && to >= Util.getVersionProtocol(gson, "1.21.2"); + } + + @Override + public void convert(Pack pack) throws IOException { + Path minecraftPath = pack.getWorkingPath().resolve("assets/minecraft".replace("/", File.separator)); + if (!minecraftPath.toFile().exists()) { + return; + } + + // Move shaders + Path shadersPostPath = minecraftPath.resolve("shaders/post".replace("/", File.separator)); + if (!shadersPostPath.toFile().exists()) { + return; + } + + Path postEffectPath = minecraftPath.resolve("post_effect"); + if (postEffectPath.toFile().exists()) { + postEffectPath.toFile().delete(); + } + + Files.move(shadersPostPath, postEffectPath); + + // Update shaders + Logger.addTab(); + try (Stream pathStream = Files.list(postEffectPath).filter(file -> file.toString().endsWith(".json"))) { + pathStream.forEach(file -> { + try { + JsonObject json = JsonUtil.readJson(packConverter.getGson(), file); + + // Targets + if (json.has("targets") && json.get("targets").isJsonArray()) { + JsonObject targets = new JsonObject(); + JsonArray targetElements = json.remove("targets").getAsJsonArray(); + for (JsonPrimitive primitive : targetElements.asList().stream().map(JsonElement::getAsJsonPrimitive).filter(JsonPrimitive::isString).collect(Collectors.toList())) { + String target = primitive.getAsString(); + targets.add(MAPPING.getOrDefault(target, target), new JsonObject()); + } + json.add("targets", targets); + } + + // Passes + if (json.has("passes") && json.get("passes").isJsonArray()) { + JsonArray passes = new JsonArray(); + JsonArray passesElements = json.remove("passes").getAsJsonArray(); + for (JsonObject object : passesElements.asList().stream().map(JsonElement::getAsJsonObject).collect(Collectors.toList())) { + passes.add(this.remapPass(object)); + } + json.add("passes", passes); + } + + JsonUtil.writeJson(this.packConverter.getGson(), file, json); + Logger.debug("Saving updated post-effect shader \"" + file.toString() + "\""); + } catch (Exception e) { + Logger.debug("Failed to update post-effect shader \"" + file.toString() + "\": " + e.getMessage()); + } + }); + } catch (Exception e) { + Logger.debug("Failed to update shader, unable to open file stream"); + } + Logger.subTab(); + } + + private String fixNamespace(String name) { + // TODO: Fix for other namespaces + if (!name.startsWith("minecraft:")) { + return "minecraft:" + name; + } else { + return name; + } + } + + private JsonObject remapPass(JsonObject object) { + JsonObject pass = object.deepCopy(); + if (pass.has("name")) { + String name = pass.remove("name").getAsString(); + pass.addProperty("program", fixNamespace("post/" + name)); + } + + if (pass.has("intarget")) { + String inTarget = pass.remove("intarget").getAsString(); + JsonObject inputObject = new JsonObject(); + inputObject.addProperty("sampler_name", "In"); + inputObject.addProperty("target", fixNamespace(MAPPING.getOrDefault(inTarget, inTarget))); + if (pass.has("use_linear_filter") && pass.get("use_linear_filter").isJsonPrimitive()) { + inputObject.addProperty("bilinear", pass.remove("use_linear_filter").getAsBoolean()); + } + + JsonArray inputs = new JsonArray(); + inputs.add(inputObject); + pass.add("inputs", inputs); + } else if (pass.has("use_linear_filter")) { + pass.remove("use_linear_filter"); // TODO/NOTE: ? If this is a thing, idk what to do with it + } + + if (pass.has("auxtargets")) { + JsonArray inputs; + if (pass.has("inputs")) { + inputs = pass.remove("inputs").getAsJsonArray(); + } else { + inputs = new JsonArray(); + } + + JsonArray auxTargets = pass.remove("auxtargets").getAsJsonArray(); + for (JsonObject target : auxTargets.asList().stream().map(JsonElement::getAsJsonObject).collect(Collectors.toList())) { + JsonObject newTarget = target.deepCopy(); + if (newTarget.has("name")) { + String name = newTarget.remove("name").getAsString(); + newTarget.addProperty("sampler_name", name); + } + + if (newTarget.has("id")) { + String id = newTarget.remove("id").getAsString(); + if (id.endsWith(":depth")) { + newTarget.add("use_depth_buffer", new JsonPrimitive(true)); + id = id.substring(0, id.length() - ":depth".length()); + } + newTarget.addProperty("target", fixNamespace(MAPPING.getOrDefault(id, id))); + } + + inputs.add(newTarget); + } + + pass.add("inputs", inputs); + } + + if (pass.has("outtarget")) { + String outTarget = pass.remove("outtarget").getAsString(); + pass.addProperty("output", MAPPING.getOrDefault(outTarget, outTarget)); + } + + return pass; + } +} diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/TitleConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/TitleConverter1_20.java similarity index 94% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/TitleConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/TitleConverter1_20.java index 03d066d1..90883c74 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/TitleConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/TitleConverter1_20.java @@ -11,8 +11,8 @@ import java.io.IOException; import java.nio.file.Path; -public class TitleConverter extends Converter { - public TitleConverter(PackConverter packConverter) { +public class TitleConverter1_20 extends Converter { + public TitleConverter1_20(PackConverter packConverter) { super(packConverter); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/WaterConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/WaterConverter1_13.java similarity index 91% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/WaterConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/WaterConverter1_13.java index dbbafe9e..ede985ed 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/WaterConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/WaterConverter1_13.java @@ -1,44 +1,44 @@ -package com.agentdid127.resourcepack.forwards.impl.textures; - -import com.agentdid127.resourcepack.library.Converter; -import com.agentdid127.resourcepack.library.PackConverter; -import com.agentdid127.resourcepack.library.pack.Pack; -import com.agentdid127.resourcepack.library.utilities.ImageConverter; -import com.agentdid127.resourcepack.library.utilities.Util; -import com.google.gson.Gson; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; - -public class WaterConverter extends Converter { - public WaterConverter(PackConverter packConverter) { - super(packConverter); - } - - @Override - public boolean shouldConvert(Gson gson, int from, int to) { - return from <= Util.getVersionProtocol(gson, "1.12.2") && to >= Util.getVersionProtocol(gson, "1.13"); - } - - @Override - public void convert(Pack pack) throws IOException { - Path blockFolder = pack.getWorkingPath().resolve("assets/minecraft/textures/block".replace("/", File.separator)); - if (blockFolder.toFile().exists()) { - grayscale(blockFolder.resolve("water_flow.png"), 16, 1024); - grayscale(blockFolder.resolve("water_still.png"), 16, 512); - grayscale(blockFolder.resolve("water_overlay.png"), 16, 16); - } - } - - private void grayscale(Path path, int w, int h) throws IOException { - if (path.toFile().exists()) { - ImageConverter imageConverter = new ImageConverter(w, h, path); - if (imageConverter.fileIsPowerOfTwo()) { - imageConverter.newImage(w, h); - imageConverter.grayscale(); - imageConverter.store(); - } - } - } -} +package com.agentdid127.resourcepack.forwards.impl.textures; + +import com.agentdid127.resourcepack.library.Converter; +import com.agentdid127.resourcepack.library.PackConverter; +import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.ImageConverter; +import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; + +public class WaterConverter1_13 extends Converter { + public WaterConverter1_13(PackConverter packConverter) { + super(packConverter); + } + + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from <= Util.getVersionProtocol(gson, "1.12.2") && to >= Util.getVersionProtocol(gson, "1.13"); + } + + @Override + public void convert(Pack pack) throws IOException { + Path blockFolder = pack.getWorkingPath().resolve("assets/minecraft/textures/block".replace("/", File.separator)); + if (blockFolder.toFile().exists()) { + grayscale(blockFolder.resolve("water_flow.png"), 16, 1024); + grayscale(blockFolder.resolve("water_still.png"), 16, 512); + grayscale(blockFolder.resolve("water_overlay.png"), 16, 16); + } + } + + private void grayscale(Path path, int w, int h) throws IOException { + if (path.toFile().exists()) { + ImageConverter imageConverter = new ImageConverter(w, h, path); + if (imageConverter.fileIsPowerOfTwo()) { + imageConverter.newImage(w, h); + imageConverter.grayscale(); + imageConverter.store(); + } + } + } +} diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/ChestConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/ChestConverter.html index 43cc5c9c..291c3f94 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/ChestConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/ChestConverter.html @@ -88,7 +88,7 @@

Class ChestConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.ChestConverter
+
com.agentdid127.resourcepack.forwards.impl.textures.ChestConverter1_15
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/CompassConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/CompassConverter.html index d51807b3..37e1522c 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/CompassConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/CompassConverter.html @@ -88,7 +88,7 @@

Class CompassConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.CompassConverter
+
com.agentdid127.resourcepack.forwards.impl.textures.CompassConverter1_9
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/CreativeTabsConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/CreativeTabsConverter.html index b1238660..fb196734 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/CreativeTabsConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/CreativeTabsConverter.html @@ -88,7 +88,7 @@

Class CreativeTabsConverte
java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.CreativeTabsConverter
+
com.agentdid127.resourcepack.forwards.impl.textures.CreativeTabsConverter1_19_3
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/EnchantConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/EnchantConverter.html index bd85dfd0..154dce6e 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/EnchantConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/EnchantConverter.html @@ -88,7 +88,7 @@

Class EnchantConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.EnchantConverter
+
com.agentdid127.resourcepack.forwards.impl.textures.EnchantConverter1_15
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter.html index e867a45c..06a49478 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter.html @@ -88,7 +88,7 @@

Class MapIconConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.MapIconConverter
+
com.agentdid127.resourcepack.forwards.impl.textures.MapIconConverter1_13
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/TitleConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/TitleConverter.html index 5a40e163..2527c03c 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/TitleConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/TitleConverter.html @@ -88,7 +88,7 @@

Class TitleConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.TitleConverter
+
com.agentdid127.resourcepack.forwards.impl.textures.TitleConverter1_20
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/WaterConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/WaterConverter.html index e868ae5e..5e375f30 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/WaterConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/WaterConverter.html @@ -88,7 +88,7 @@

Class WaterConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.WaterConverter
+
com.agentdid127.resourcepack.forwards.impl.textures.WaterConverter1_13
From c370b234b5cd5739f88084bb14562e937ec5b8f9 Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Mon, 10 Feb 2025 00:55:17 -0500 Subject: [PATCH 41/54] Slight changes in the post-effect-shaders converter --- .../textures/PostEffectShadersConverter1_21_2.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/PostEffectShadersConverter1_21_2.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/PostEffectShadersConverter1_21_2.java index ffbc551d..f0948dd8 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/PostEffectShadersConverter1_21_2.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/PostEffectShadersConverter1_21_2.java @@ -17,6 +17,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +// https://www.minecraft.net/en-us/article/minecraft-java-edition-1-21-2 public class PostEffectShadersConverter1_21_2 extends Converter { private static final Map MAPPING = new HashMap<>(); @@ -54,6 +55,7 @@ public void convert(Pack pack) throws IOException { postEffectPath.toFile().delete(); } + // TODO: Move the corresponding program shader from shaders/program to shaders/post Files.move(shadersPostPath, postEffectPath); // Update shaders @@ -67,9 +69,14 @@ public void convert(Pack pack) throws IOException { if (json.has("targets") && json.get("targets").isJsonArray()) { JsonObject targets = new JsonObject(); JsonArray targetElements = json.remove("targets").getAsJsonArray(); - for (JsonPrimitive primitive : targetElements.asList().stream().map(JsonElement::getAsJsonPrimitive).filter(JsonPrimitive::isString).collect(Collectors.toList())) { - String target = primitive.getAsString(); - targets.add(MAPPING.getOrDefault(target, target), new JsonObject()); + for (JsonElement element : targetElements) { + if (element.isJsonPrimitive() && element.getAsJsonPrimitive().isString()) { + String target = element.getAsString(); + targets.add(MAPPING.getOrDefault(target, target), new JsonObject()); + } else if (element.isJsonObject()) { + // TODO + // For example, [{"name": "potato", "width": 16, "height": 16}] becomes {"potato": {"width": 16, "height": 16}} + } } json.add("targets", targets); } From ea7ac04632ec8acee309004a776d9f7f709589f0 Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Mon, 10 Feb 2025 00:56:36 -0500 Subject: [PATCH 42/54] Implement TODO#2 in post-effect-shaders converter --- .../impl/textures/PostEffectShadersConverter1_21_2.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/PostEffectShadersConverter1_21_2.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/PostEffectShadersConverter1_21_2.java index f0948dd8..eecb261f 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/PostEffectShadersConverter1_21_2.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/PostEffectShadersConverter1_21_2.java @@ -74,8 +74,11 @@ public void convert(Pack pack) throws IOException { String target = element.getAsString(); targets.add(MAPPING.getOrDefault(target, target), new JsonObject()); } else if (element.isJsonObject()) { - // TODO - // For example, [{"name": "potato", "width": 16, "height": 16}] becomes {"potato": {"width": 16, "height": 16}} + JsonObject object = element.getAsJsonObject(); + if (object.has("name")) { + String name = object.remove("name").getAsString(); + targets.add(name, object); + } } } json.add("targets", targets); From 3967b1e96f2a1307d326c0bf567223fabbbbed71 Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Mon, 10 Feb 2025 03:48:58 -0500 Subject: [PATCH 43/54] Reorganize Forward Converters --- .../forwards/ForwardsPackConverter.java | 60 ++++-- .../forwards/impl/EnchantPathConverter.java | 39 ---- .../impl/{ => other}/BlockStateConverter.java | 2 +- .../impl/{ => other}/ModelConverter.java | 2 +- .../impl/{ => other}/NameConverter.java | 2 +- .../impl/{ => other}/PackMetaConverter.java | 2 +- .../ParticleConverter1_18.java} | 6 +- .../SpacesConverter1_11.java} | 6 +- .../other/textures/InventoryConverter.java | 37 ++++ .../textures}/ParticlesSlicerConverter.java | 5 +- .../impl/textures/InventoryConverter.java | 40 ---- .../AnimationConverter1_13.java} | 6 +- .../LangConverter1_13.java} | 7 +- .../MCPatcherConverter1_13.java} | 7 +- .../SoundsConverter1_13.java} | 6 +- .../textures/MapIconConverter1_13.java | 2 +- .../textures/WaterConverter1_13.java | 2 +- .../MobEffectAtlasSlicerConverter1_14.java} | 9 +- .../PaintingSlicerConverter1_14_4.java} | 6 +- .../textures/ChestConverter1_15.java | 2 +- .../textures/EnchantConverter1_15.java | 2 +- .../AtlasConverter1_19_3.java} | 6 +- .../v1_19/EnchantPathConverter1_19_4.java | 41 ++++ .../textures/CreativeTabsConverter1_19_3.java | 2 +- .../textures/WidgetSlidersCreator1_19_4.java} | 6 +- .../ImageFormatConverter1_20_3.java} | 188 +++++++++--------- .../textures/GuiSlicerConverter1_20_2.java} | 6 +- .../MapIconSlicerConverter1_20_5.java} | 8 +- .../textures/TitleConverter1_20.java | 2 +- .../textures/ArmorMoverConverter1_21_2.java | 2 +- .../PostEffectShadersConverter1_21_2.java | 4 +- .../textures/CompassConverter1_9.java | 2 +- .../textures/OffHandCreator1_9.java} | 6 +- .../forwards/impl/AnimationConverter.html | 2 +- .../forwards/impl/AtlasConverter.html | 2 +- .../forwards/impl/BlockStateConverter.html | 2 +- .../forwards/impl/EnchantPathConverter.html | 2 +- .../forwards/impl/LangConverter.html | 2 +- .../forwards/impl/MCPatcherConverter.html | 2 +- .../forwards/impl/ModelConverter.html | 2 +- .../forwards/impl/NameConverter.html | 2 +- .../forwards/impl/PackMetaConverter.html | 2 +- .../forwards/impl/ParticleConverter.html | 2 +- .../forwards/impl/SoundsConverter.html | 2 +- .../forwards/impl/SpacesConverter.html | 2 +- .../impl/textures/ChestConverter.html | 2 +- .../impl/textures/CompassConverter.html | 2 +- .../impl/textures/CreativeTabsConverter.html | 2 +- .../impl/textures/EnchantConverter.html | 2 +- .../impl/textures/MapIconConverter.html | 2 +- .../textures/MobEffectAtlasConverter.html | 2 +- .../impl/textures/OffHandCreator.html | 2 +- .../impl/textures/PaintingConverter.html | 2 +- .../textures/ParticleTextureConverter.html | 2 +- .../SlicerConverter.PredicateRunnable.html | 2 +- .../impl/textures/SlicerConverter.html | 2 +- .../impl/textures/SlidersCreator.html | 2 +- .../impl/textures/TitleConverter.html | 2 +- .../impl/textures/WaterConverter.html | 2 +- docs/deprecated-list.html | 2 +- 60 files changed, 300 insertions(+), 277 deletions(-) delete mode 100644 conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/EnchantPathConverter.java rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{ => other}/BlockStateConverter.java (99%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{ => other}/ModelConverter.java (99%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{ => other}/NameConverter.java (99%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{ => other}/PackMetaConverter.java (98%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{ParticleConverter.java => other/ParticleConverter1_18.java} (90%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{SpacesConverter.java => other/SpacesConverter1_11.java} (93%) create mode 100644 conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/textures/InventoryConverter.java rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{textures/slicer => other/textures}/ParticlesSlicerConverter.java (93%) delete mode 100644 conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/InventoryConverter.java rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{AnimationConverter.java => v1_13/AnimationConverter1_13.java} (94%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{LangConverter.java => v1_13/LangConverter1_13.java} (96%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{MCPatcherConverter.java => v1_13/MCPatcherConverter1_13.java} (96%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{SoundsConverter.java => v1_13/SoundsConverter1_13.java} (95%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{ => v1_13}/textures/MapIconConverter1_13.java (97%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{ => v1_13}/textures/WaterConverter1_13.java (96%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{textures/slicer/MobEffectAtlasSlicerConverter.java => v1_14/textures/MobEffectAtlasSlicerConverter1_14.java} (82%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{textures/slicer/PaintingSlicerConverter.java => v1_14/textures/PaintingSlicerConverter1_14_4.java} (89%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{ => v1_15}/textures/ChestConverter1_15.java (98%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{ => v1_15}/textures/EnchantConverter1_15.java (95%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{AtlasConverter.java => v1_19/AtlasConverter1_19_3.java} (94%) create mode 100644 conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_19/EnchantPathConverter1_19_4.java rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{ => v1_19}/textures/CreativeTabsConverter1_19_3.java (97%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{textures/creator/WidgetSlidersCreator.java => v1_19/textures/WidgetSlidersCreator1_19_4.java} (88%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{ImageFormatConverter.java => v1_20/ImageFormatConverter1_20_3.java} (91%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{textures/slicer/GuiSlicerConverter.java => v1_20/textures/GuiSlicerConverter1_20_2.java} (94%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{textures/slicer/MapIconSlicerConverter.java => v1_20/textures/MapIconSlicerConverter1_20_5.java} (85%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{ => v1_20}/textures/TitleConverter1_20.java (96%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{ => v1_21}/textures/ArmorMoverConverter1_21_2.java (98%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{ => v1_21}/textures/PostEffectShadersConverter1_21_2.java (98%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{ => v1_9}/textures/CompassConverter1_9.java (97%) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/{textures/creator/OffHandCreator.java => v1_9/textures/OffHandCreator1_9.java} (93%) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java index 009ddf5f..e363940d 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java @@ -1,10 +1,30 @@ package com.agentdid127.resourcepack.forwards; -import com.agentdid127.resourcepack.forwards.impl.*; -import com.agentdid127.resourcepack.forwards.impl.textures.*; -import com.agentdid127.resourcepack.forwards.impl.textures.creator.OffHandCreator; -import com.agentdid127.resourcepack.forwards.impl.textures.creator.WidgetSlidersCreator; -import com.agentdid127.resourcepack.forwards.impl.textures.slicer.*; +import com.agentdid127.resourcepack.forwards.impl.other.*; +import com.agentdid127.resourcepack.forwards.impl.other.textures.InventoryConverter; +import com.agentdid127.resourcepack.forwards.impl.other.textures.ParticlesSlicerConverter; +import com.agentdid127.resourcepack.forwards.impl.v1_14.textures.MobEffectAtlasSlicerConverter1_14; +import com.agentdid127.resourcepack.forwards.impl.v1_14.textures.PaintingSlicerConverter1_14_4; +import com.agentdid127.resourcepack.forwards.impl.v1_9.textures.OffHandCreator1_9; +import com.agentdid127.resourcepack.forwards.impl.v1_19.textures.WidgetSlidersCreator1_19_4; +import com.agentdid127.resourcepack.forwards.impl.v1_13.AnimationConverter1_13; +import com.agentdid127.resourcepack.forwards.impl.v1_13.LangConverter1_13; +import com.agentdid127.resourcepack.forwards.impl.v1_13.MCPatcherConverter1_13; +import com.agentdid127.resourcepack.forwards.impl.v1_13.SoundsConverter1_13; +import com.agentdid127.resourcepack.forwards.impl.v1_13.textures.MapIconConverter1_13; +import com.agentdid127.resourcepack.forwards.impl.v1_13.textures.WaterConverter1_13; +import com.agentdid127.resourcepack.forwards.impl.v1_15.textures.ChestConverter1_15; +import com.agentdid127.resourcepack.forwards.impl.v1_15.textures.EnchantConverter1_15; +import com.agentdid127.resourcepack.forwards.impl.v1_19.AtlasConverter1_19_3; +import com.agentdid127.resourcepack.forwards.impl.v1_19.EnchantPathConverter1_19_4; +import com.agentdid127.resourcepack.forwards.impl.v1_19.textures.CreativeTabsConverter1_19_3; +import com.agentdid127.resourcepack.forwards.impl.v1_20.ImageFormatConverter1_20_3; +import com.agentdid127.resourcepack.forwards.impl.v1_20.textures.GuiSlicerConverter1_20_2; +import com.agentdid127.resourcepack.forwards.impl.v1_20.textures.MapIconSlicerConverter1_20_5; +import com.agentdid127.resourcepack.forwards.impl.v1_20.textures.TitleConverter1_20; +import com.agentdid127.resourcepack.forwards.impl.v1_21.textures.ArmorMoverConverter1_21_2; +import com.agentdid127.resourcepack.forwards.impl.v1_21.textures.PostEffectShadersConverter1_21_2; +import com.agentdid127.resourcepack.forwards.impl.v1_9.textures.CompassConverter1_9; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; @@ -40,31 +60,31 @@ private void setupConverters(String light) { this.registerConverter(new NameConverter(this, from, to)); // This needs to be run first, other converters might reference new directory names. this.registerConverter(new PackMetaConverter(this, from, to)); this.registerConverter(new CompassConverter1_9(this, to)); - this.registerConverter(new OffHandCreator(this)); - this.registerConverter(new SpacesConverter(this)); + this.registerConverter(new OffHandCreator1_9(this)); + this.registerConverter(new SpacesConverter1_11(this)); this.registerConverter(new ModelConverter(this, light, from, to)); - this.registerConverter(new SoundsConverter(this)); - this.registerConverter(new AnimationConverter(this)); + this.registerConverter(new SoundsConverter1_13(this)); + this.registerConverter(new AnimationConverter1_13(this)); this.registerConverter(new MapIconConverter1_13(this)); - this.registerConverter(new MCPatcherConverter(this)); + this.registerConverter(new MCPatcherConverter1_13(this)); this.registerConverter(new WaterConverter1_13(this)); this.registerConverter(new BlockStateConverter(this, from, to)); - this.registerConverter(new LangConverter(this, from, to)); + this.registerConverter(new LangConverter1_13(this, from, to)); this.registerConverter(new ParticlesSlicerConverter(this, from, to)); - this.registerConverter(new PaintingSlicerConverter(this)); - this.registerConverter(new MobEffectAtlasSlicerConverter(this, from)); + this.registerConverter(new PaintingSlicerConverter1_14_4(this)); + this.registerConverter(new MobEffectAtlasSlicerConverter1_14(this, from)); this.registerConverter(new ChestConverter1_15(this)); this.registerConverter(new EnchantConverter1_15(this)); - this.registerConverter(new ParticleConverter(this)); + this.registerConverter(new ParticleConverter1_18(this)); this.registerConverter(new InventoryConverter(this)); - this.registerConverter(new AtlasConverter(this)); + this.registerConverter(new AtlasConverter1_19_3(this)); this.registerConverter(new CreativeTabsConverter1_19_3(this)); - this.registerConverter(new EnchantPathConverter(this)); - this.registerConverter(new WidgetSlidersCreator(this)); + this.registerConverter(new EnchantPathConverter1_19_4(this)); + this.registerConverter(new WidgetSlidersCreator1_19_4(this)); this.registerConverter(new TitleConverter1_20(this)); - this.registerConverter(new GuiSlicerConverter(this, from)); - this.registerConverter(new ImageFormatConverter(this)); - this.registerConverter(new MapIconSlicerConverter(this, from)); + this.registerConverter(new GuiSlicerConverter1_20_2(this, from)); + this.registerConverter(new ImageFormatConverter1_20_3(this)); + this.registerConverter(new MapIconSlicerConverter1_20_5(this, from)); this.registerConverter(new ArmorMoverConverter1_21_2(this)); this.registerConverter(new PostEffectShadersConverter1_21_2(this)); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/EnchantPathConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/EnchantPathConverter.java deleted file mode 100644 index de234696..00000000 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/EnchantPathConverter.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.agentdid127.resourcepack.forwards.impl; - -import com.agentdid127.resourcepack.library.Converter; -import com.agentdid127.resourcepack.library.PackConverter; -import com.agentdid127.resourcepack.library.pack.Pack; -import com.agentdid127.resourcepack.library.utilities.Util; -import com.google.gson.Gson; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; - -public class EnchantPathConverter extends Converter { - public EnchantPathConverter(PackConverter packConverter) { - super(packConverter); - } - - @Override - public boolean shouldConvert(Gson gson, int from, int to) { - return from <= Util.getVersionProtocol(gson, "1.19.3") && to >= Util.getVersionProtocol(gson, "1.19.4"); - } - - @Override - public void convert(Pack pack) throws IOException { - Path miscPath = pack.getWorkingPath().resolve("assets/minecraft/textures/misc".replace("/", File.separator)); - if (miscPath.resolve("enchanted_item_glint.png").toFile().exists()) { - Files.copy(miscPath.resolve("enchanted_item_glint.png"), miscPath.resolve("enchanted_glint_entity.png")); - Files.copy(miscPath.resolve("enchanted_item_glint.png"), miscPath.resolve("enchanted_glint_item.png")); - Files.delete(miscPath.resolve("enchanted_item_glint.png")); - } - - if (miscPath.resolve("enchanted_item_glint.png.mcmeta").toFile().exists()) { - Files.copy(miscPath.resolve("enchanted_item_glint.png.mcmeta"), miscPath.resolve("enchanted_glint_entity.png.mcmeta")); - Files.copy(miscPath.resolve("enchanted_item_glint.png.mcmeta"), miscPath.resolve("enchanted_glint_item.png.mcmeta")); - Files.delete(miscPath.resolve("enchanted_item_glint.png.mcmeta")); - } - } -} diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/BlockStateConverter.java similarity index 99% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/BlockStateConverter.java index 667842a3..916be0d7 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/BlockStateConverter.java @@ -1,4 +1,4 @@ -package com.agentdid127.resourcepack.forwards.impl; +package com.agentdid127.resourcepack.forwards.impl.other; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/ModelConverter.java similarity index 99% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/ModelConverter.java index 3181ae86..5ed6ce31 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ModelConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/ModelConverter.java @@ -1,4 +1,4 @@ -package com.agentdid127.resourcepack.forwards.impl; +package com.agentdid127.resourcepack.forwards.impl.other; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/NameConverter.java similarity index 99% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/NameConverter.java index 0c7c1581..04c64df5 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/NameConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/NameConverter.java @@ -1,4 +1,4 @@ -package com.agentdid127.resourcepack.forwards.impl; +package com.agentdid127.resourcepack.forwards.impl.other; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/PackMetaConverter.java similarity index 98% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/PackMetaConverter.java index b85a0f65..a55bc02c 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/PackMetaConverter.java @@ -1,4 +1,4 @@ -package com.agentdid127.resourcepack.forwards.impl; +package com.agentdid127.resourcepack.forwards.impl.other; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ParticleConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/ParticleConverter1_18.java similarity index 90% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ParticleConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/ParticleConverter1_18.java index 1df7175f..a4514138 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ParticleConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/ParticleConverter1_18.java @@ -1,4 +1,4 @@ -package com.agentdid127.resourcepack.forwards.impl; +package com.agentdid127.resourcepack.forwards.impl.other; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; @@ -11,8 +11,8 @@ import java.nio.file.Files; import java.nio.file.Path; -public class ParticleConverter extends Converter { - public ParticleConverter(PackConverter packConverter) { +public class ParticleConverter1_18 extends Converter { + public ParticleConverter1_18(PackConverter packConverter) { super(packConverter); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/SpacesConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/SpacesConverter1_11.java similarity index 93% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/SpacesConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/SpacesConverter1_11.java index b87a7191..e8f17e05 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/SpacesConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/SpacesConverter1_11.java @@ -1,4 +1,4 @@ -package com.agentdid127.resourcepack.forwards.impl; +package com.agentdid127.resourcepack.forwards.impl.other; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; @@ -14,8 +14,8 @@ import java.nio.file.Paths; import java.util.Objects; -public class SpacesConverter extends Converter { - public SpacesConverter(PackConverter packConverter) { +public class SpacesConverter1_11 extends Converter { + public SpacesConverter1_11(PackConverter packConverter) { super(packConverter); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/textures/InventoryConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/textures/InventoryConverter.java new file mode 100644 index 00000000..6b8c717f --- /dev/null +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/textures/InventoryConverter.java @@ -0,0 +1,37 @@ +package com.agentdid127.resourcepack.forwards.impl.other.textures; + +import com.agentdid127.resourcepack.library.Converter; +import com.agentdid127.resourcepack.library.PackConverter; +import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.ImageConverter; +import com.google.gson.Gson; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; + +public class InventoryConverter extends Converter { + public InventoryConverter(PackConverter packConverter) { + super(packConverter); + } + + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return true; + } + + // TODO: Figure out what this is for/make ^ correct range + @Override + public void convert(Pack pack) throws IOException { + Path imagePath = pack.getWorkingPath().resolve("assets/minecraft/textures/gui/container/inventory.png".replace("/", File.separator)); + if (imagePath.toFile().exists()) { + int defaultW = 256, defaultH = 256; + ImageConverter image = new ImageConverter(defaultW, defaultH, imagePath); + image.newImage(defaultH, defaultW); + image.subImage(0, 0, 256, 256, 0, 0); + image.subImage(0, 166, 16, 198, 0, 198); + image.subImage(104, 166, 120, 198, 16, 198); + image.store(); + } + } +} diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/ParticlesSlicerConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/textures/ParticlesSlicerConverter.java similarity index 93% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/ParticlesSlicerConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/textures/ParticlesSlicerConverter.java index f69f346f..22c161df 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/ParticlesSlicerConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/textures/ParticlesSlicerConverter.java @@ -1,5 +1,6 @@ -package com.agentdid127.resourcepack.forwards.impl.textures.slicer; +package com.agentdid127.resourcepack.forwards.impl.other.textures; +import com.agentdid127.resourcepack.forwards.impl.v1_20.textures.GuiSlicerConverter1_20_2; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; @@ -71,7 +72,7 @@ public void convert(Pack pack) throws IOException { if (from <= Util.getVersionProtocol(gson, "1.13.2") && to >= Util.getVersionProtocol(gson, "1.14")) { - Slicer.runSlicer(gson, slice, particlePath, new GuiSlicerConverter.GuiPredicateRunnable(), from, false); + Slicer.runSlicer(gson, slice, particlePath, new GuiSlicerConverter1_20_2.GuiPredicateRunnable(), from, false); Path entityPath = texturesPath.resolve("entity"); Path newFishingHookPath = entityPath.resolve("fishing_hook.png"); if (newFishingHookPath.toFile().exists()) { diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/InventoryConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/InventoryConverter.java deleted file mode 100644 index db854163..00000000 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/InventoryConverter.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.agentdid127.resourcepack.forwards.impl.textures; - -import com.agentdid127.resourcepack.library.Converter; -import com.agentdid127.resourcepack.library.PackConverter; -import com.agentdid127.resourcepack.library.pack.Pack; -import com.agentdid127.resourcepack.library.utilities.ImageConverter; -import com.google.gson.Gson; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; - -public class InventoryConverter extends Converter { - public InventoryConverter(PackConverter packConverter) { - super(packConverter); - } - - @Override - public boolean shouldConvert(Gson gson, int from, int to) { - return true; - } - - @Override - public void convert(Pack pack) throws IOException { - Path imagePath = pack.getWorkingPath() - .resolve("assets/minecraft/textures/gui/container/inventory.png".replace("/", File.separator)); - if (!imagePath.toFile().exists()) - return; - - int defaultW = 256, defaultH = 256; - ImageConverter image = new ImageConverter(defaultW, defaultH, imagePath); - - image.newImage(defaultH, defaultW); - image.subImage(0, 0, 256, 256, 0, 0); - image.subImage(0, 166, 16, 198, 0, 198); - image.subImage(104, 166, 120, 198, 16, 198); - - image.store(); - } -} diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/AnimationConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_13/AnimationConverter1_13.java similarity index 94% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/AnimationConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_13/AnimationConverter1_13.java index 1ec57758..487276c9 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/AnimationConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_13/AnimationConverter1_13.java @@ -1,4 +1,4 @@ -package com.agentdid127.resourcepack.forwards.impl; +package com.agentdid127.resourcepack.forwards.impl.v1_13; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; @@ -16,8 +16,8 @@ import java.nio.file.Path; import java.util.stream.Stream; -public class AnimationConverter extends Converter { - public AnimationConverter(PackConverter packConverter) { +public class AnimationConverter1_13 extends Converter { + public AnimationConverter1_13(PackConverter packConverter) { super(packConverter); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/LangConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_13/LangConverter1_13.java similarity index 96% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/LangConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_13/LangConverter1_13.java index e6541cf1..e15bcbb6 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/LangConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_13/LangConverter1_13.java @@ -1,4 +1,4 @@ -package com.agentdid127.resourcepack.forwards.impl; +package com.agentdid127.resourcepack.forwards.impl.v1_13; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; @@ -22,11 +22,11 @@ import java.util.Map; import java.util.stream.Stream; -public class LangConverter extends Converter { +public class LangConverter1_13 extends Converter { private final int from; private final int to; - public LangConverter(PackConverter packConverter, int from, int to) { + public LangConverter1_13(PackConverter packConverter, int from, int to) { super(packConverter); this.from = from; this.to = to; @@ -51,7 +51,6 @@ public void convert(Pack pack) throws IOException { } Logger.addTab(); - ArrayList models = new ArrayList(); try (Stream pathStream = Files.list(langPath).filter(path1 -> path1.toString().endsWith(".lang"))) { pathStream.forEach(lang -> { diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_13/MCPatcherConverter1_13.java similarity index 96% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_13/MCPatcherConverter1_13.java index 49955679..5d335793 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_13/MCPatcherConverter1_13.java @@ -1,5 +1,6 @@ -package com.agentdid127.resourcepack.forwards.impl; +package com.agentdid127.resourcepack.forwards.impl.v1_13; +import com.agentdid127.resourcepack.forwards.impl.other.NameConverter; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; @@ -22,8 +23,8 @@ import java.util.stream.Stream; @Deprecated // will be removed when extensions are made -public class MCPatcherConverter extends Converter { - public MCPatcherConverter(PackConverter packConverter) { +public class MCPatcherConverter1_13 extends Converter { + public MCPatcherConverter1_13(PackConverter packConverter) { super(packConverter); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/SoundsConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_13/SoundsConverter1_13.java similarity index 95% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/SoundsConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_13/SoundsConverter1_13.java index b3757fc8..bbdd4584 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/SoundsConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_13/SoundsConverter1_13.java @@ -1,4 +1,4 @@ -package com.agentdid127.resourcepack.forwards.impl; +package com.agentdid127.resourcepack.forwards.impl.v1_13; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; @@ -14,8 +14,8 @@ import java.nio.file.Path; import java.util.Map; -public class SoundsConverter extends Converter { - public SoundsConverter(PackConverter packConverter) { +public class SoundsConverter1_13 extends Converter { + public SoundsConverter1_13(PackConverter packConverter) { super(packConverter); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter1_13.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_13/textures/MapIconConverter1_13.java similarity index 97% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter1_13.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_13/textures/MapIconConverter1_13.java index 9ac71de3..709ee387 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter1_13.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_13/textures/MapIconConverter1_13.java @@ -1,4 +1,4 @@ -package com.agentdid127.resourcepack.forwards.impl.textures; +package com.agentdid127.resourcepack.forwards.impl.v1_13.textures; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/WaterConverter1_13.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_13/textures/WaterConverter1_13.java similarity index 96% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/WaterConverter1_13.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_13/textures/WaterConverter1_13.java index ede985ed..1d4917f2 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/WaterConverter1_13.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_13/textures/WaterConverter1_13.java @@ -1,4 +1,4 @@ -package com.agentdid127.resourcepack.forwards.impl.textures; +package com.agentdid127.resourcepack.forwards.impl.v1_13.textures; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/MobEffectAtlasSlicerConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_14/textures/MobEffectAtlasSlicerConverter1_14.java similarity index 82% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/MobEffectAtlasSlicerConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_14/textures/MobEffectAtlasSlicerConverter1_14.java index e75507aa..709508fb 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/MobEffectAtlasSlicerConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_14/textures/MobEffectAtlasSlicerConverter1_14.java @@ -1,5 +1,6 @@ -package com.agentdid127.resourcepack.forwards.impl.textures.slicer; +package com.agentdid127.resourcepack.forwards.impl.v1_14.textures; +import com.agentdid127.resourcepack.forwards.impl.v1_20.textures.GuiSlicerConverter1_20_2; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; @@ -14,10 +15,10 @@ import java.io.IOException; import java.nio.file.Path; -public class MobEffectAtlasSlicerConverter extends Converter { +public class MobEffectAtlasSlicerConverter1_14 extends Converter { private final int from; - public MobEffectAtlasSlicerConverter(PackConverter packConverter, int from) { + public MobEffectAtlasSlicerConverter1_14(PackConverter packConverter, int from) { super(packConverter); this.from = from; } @@ -49,7 +50,7 @@ public void convert(Pack pack) throws IOException { JsonObject effectJson = JsonUtil.readJsonResource(gson, "/forwards/mob_effect.json", JsonObject.class); if (effectJson != null) { Slice slice = Slice.parse(effectJson); - Slicer.runSlicer(gson, slice, texturesPath, new GuiSlicerConverter.GuiPredicateRunnable(), from, false); + Slicer.runSlicer(gson, slice, texturesPath, new GuiSlicerConverter1_20_2.GuiPredicateRunnable(), from, false); } } } \ No newline at end of file diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/PaintingSlicerConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_14/textures/PaintingSlicerConverter1_14_4.java similarity index 89% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/PaintingSlicerConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_14/textures/PaintingSlicerConverter1_14_4.java index a653e915..28b1d123 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/PaintingSlicerConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_14/textures/PaintingSlicerConverter1_14_4.java @@ -1,4 +1,4 @@ -package com.agentdid127.resourcepack.forwards.impl.textures.slicer; +package com.agentdid127.resourcepack.forwards.impl.v1_14.textures; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; @@ -14,8 +14,8 @@ import java.io.IOException; import java.nio.file.Path; -public class PaintingSlicerConverter extends Converter { - public PaintingSlicerConverter(PackConverter packConverter) { +public class PaintingSlicerConverter1_14_4 extends Converter { + public PaintingSlicerConverter1_14_4(PackConverter packConverter) { super(packConverter); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ChestConverter1_15.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_15/textures/ChestConverter1_15.java similarity index 98% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ChestConverter1_15.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_15/textures/ChestConverter1_15.java index d8cd8702..4fa1d055 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ChestConverter1_15.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_15/textures/ChestConverter1_15.java @@ -1,4 +1,4 @@ -package com.agentdid127.resourcepack.forwards.impl.textures; +package com.agentdid127.resourcepack.forwards.impl.v1_15.textures; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/EnchantConverter1_15.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_15/textures/EnchantConverter1_15.java similarity index 95% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/EnchantConverter1_15.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_15/textures/EnchantConverter1_15.java index e467685f..70688a0b 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/EnchantConverter1_15.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_15/textures/EnchantConverter1_15.java @@ -1,4 +1,4 @@ -package com.agentdid127.resourcepack.forwards.impl.textures; +package com.agentdid127.resourcepack.forwards.impl.v1_15.textures; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/AtlasConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_19/AtlasConverter1_19_3.java similarity index 94% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/AtlasConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_19/AtlasConverter1_19_3.java index fa014bee..940294ed 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/AtlasConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_19/AtlasConverter1_19_3.java @@ -1,4 +1,4 @@ -package com.agentdid127.resourcepack.forwards.impl; +package com.agentdid127.resourcepack.forwards.impl.v1_19; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; @@ -16,11 +16,11 @@ import java.nio.file.Path; import java.util.Objects; -public class AtlasConverter extends Converter { +public class AtlasConverter1_19_3 extends Converter { JsonObject out = new JsonObject(); JsonArray sources = new JsonArray(); - public AtlasConverter(PackConverter packConverter) { + public AtlasConverter1_19_3(PackConverter packConverter) { super(packConverter); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_19/EnchantPathConverter1_19_4.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_19/EnchantPathConverter1_19_4.java new file mode 100644 index 00000000..479bcca5 --- /dev/null +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_19/EnchantPathConverter1_19_4.java @@ -0,0 +1,41 @@ +package com.agentdid127.resourcepack.forwards.impl.v1_19; + +import com.agentdid127.resourcepack.library.Converter; +import com.agentdid127.resourcepack.library.PackConverter; +import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +public class EnchantPathConverter1_19_4 extends Converter { + public EnchantPathConverter1_19_4(PackConverter packConverter) { + super(packConverter); + } + + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from <= Util.getVersionProtocol(gson, "1.19.3") && to >= Util.getVersionProtocol(gson, "1.19.4"); + } + + @Override + public void convert(Pack pack) throws IOException { + Path miscPath = pack.getWorkingPath().resolve("assets/minecraft/textures/misc".replace("/", File.separator)); + Path enchantedItemGlintPath = miscPath.resolve("enchanted_item_glint.png"); + if (miscPath.resolve("enchanted_item_glint.png").toFile().exists()) { + Files.copy(enchantedItemGlintPath, miscPath.resolve("enchanted_glint_entity.png")); + Files.copy(enchantedItemGlintPath, miscPath.resolve("enchanted_glint_item.png")); + Files.delete(enchantedItemGlintPath); + } + + Path enchantedItemGlintMetaPath = miscPath.resolve("enchanted_item_glint.png.mcmeta"); + if (enchantedItemGlintMetaPath.toFile().exists()) { + Files.copy(enchantedItemGlintMetaPath, miscPath.resolve("enchanted_glint_entity.png.mcmeta")); + Files.copy(enchantedItemGlintMetaPath, miscPath.resolve("enchanted_glint_item.png.mcmeta")); + Files.delete(enchantedItemGlintMetaPath); + } + } +} diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/CreativeTabsConverter1_19_3.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_19/textures/CreativeTabsConverter1_19_3.java similarity index 97% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/CreativeTabsConverter1_19_3.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_19/textures/CreativeTabsConverter1_19_3.java index d0dcce1b..455f04a7 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/CreativeTabsConverter1_19_3.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_19/textures/CreativeTabsConverter1_19_3.java @@ -1,4 +1,4 @@ -package com.agentdid127.resourcepack.forwards.impl.textures; +package com.agentdid127.resourcepack.forwards.impl.v1_19.textures; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/creator/WidgetSlidersCreator.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_19/textures/WidgetSlidersCreator1_19_4.java similarity index 88% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/creator/WidgetSlidersCreator.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_19/textures/WidgetSlidersCreator1_19_4.java index 35b31036..e84e7979 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/creator/WidgetSlidersCreator.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_19/textures/WidgetSlidersCreator1_19_4.java @@ -1,4 +1,4 @@ -package com.agentdid127.resourcepack.forwards.impl.textures.creator; +package com.agentdid127.resourcepack.forwards.impl.v1_19.textures; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; @@ -11,8 +11,8 @@ import java.io.IOException; import java.nio.file.Path; -public class WidgetSlidersCreator extends Converter { - public WidgetSlidersCreator(PackConverter packConverter) { +public class WidgetSlidersCreator1_19_4 extends Converter { + public WidgetSlidersCreator1_19_4(PackConverter packConverter) { super(packConverter); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ImageFormatConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/ImageFormatConverter1_20_3.java similarity index 91% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ImageFormatConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/ImageFormatConverter1_20_3.java index d2b27452..81bc57cd 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/ImageFormatConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/ImageFormatConverter1_20_3.java @@ -1,94 +1,94 @@ -package com.agentdid127.resourcepack.forwards.impl; - -import com.agentdid127.resourcepack.library.Converter; -import com.agentdid127.resourcepack.library.PackConverter; -import com.agentdid127.resourcepack.library.pack.Pack; -import com.agentdid127.resourcepack.library.utilities.Util; -import com.google.gson.Gson; - -import javax.imageio.ImageIO; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Objects; - -/** - * Converts Images to only use PNG formats. - */ -public class ImageFormatConverter extends Converter { - private static final String[] types = new String[]{"jpg", "jpeg", "raw", "ico", "bmp"}; - - /** - * constructs a new ImageFormatConverter. - * - * @param packConverter Base PackConverter. - */ - public ImageFormatConverter(PackConverter packConverter) { - super(packConverter); - } - - @Override - public boolean shouldConvert(Gson gson, int from, int to) { - return from <= Util.getVersionProtocol(gson, "1.20.2") && to >= Util.getVersionProtocol(gson, "1.20.3"); - } - - /** - * Converts other types of images to PNG images. - * @param pack Pack to convert - * @throws IOException if the images are of an invalid type, or do not exist. - */ - @Override - public void convert(Pack pack) throws IOException { - // All textures in the game - Path texturesPath = pack.getWorkingPath().resolve(Paths.get("assets", "minecraft", "textures")); - // check for invalid images for all of these types. - for (String type : types) { - findImage(texturesPath, type); - } - } - - /** - * Recursively finds files with {@link Path} path and remaps the files. - * - * @param path Path of directory to find files in. - * @throws IOException If the images are not found, or the remapping fails. - */ - protected void findImage(Path path, String type) throws IOException { - // Find all files in the directory - File directory = path.toFile(); - if (!directory.exists() || !directory.isDirectory()) { - return; - } - - // Check each file - for (File file : Objects.requireNonNull(directory.listFiles())) { - if (file.isDirectory()) - findImage(file.toPath(), type); - else { - if (file.getName().endsWith(type)) { - remapFile(file, type); - } - } - } - } - - /** - * Remaps a single image to a PNG format. - * - * @param file File to remap. - * @param oldFormat Original format of the file. - * @throws IOException If the formatting fails. - */ - protected void remapFile(File file, String oldFormat) throws IOException { - // Get the image - BufferedImage image = ImageIO.read(file); - // Output the correct format - ImageIO.write(image, "png", new File(file.getAbsolutePath().replaceAll(oldFormat, "png"))); - // Delete the old image. - if (file.exists()) { - file.delete(); - } - } -} +package com.agentdid127.resourcepack.forwards.impl.v1_20; + +import com.agentdid127.resourcepack.library.Converter; +import com.agentdid127.resourcepack.library.PackConverter; +import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.Util; +import com.google.gson.Gson; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Objects; + +/** + * Converts Images to only use PNG formats. + */ +public class ImageFormatConverter1_20_3 extends Converter { + private static final String[] types = new String[]{"jpg", "jpeg", "raw", "ico", "bmp"}; + + /** + * constructs a new ImageFormatConverter. + * + * @param packConverter Base PackConverter. + */ + public ImageFormatConverter1_20_3(PackConverter packConverter) { + super(packConverter); + } + + @Override + public boolean shouldConvert(Gson gson, int from, int to) { + return from <= Util.getVersionProtocol(gson, "1.20.2") && to >= Util.getVersionProtocol(gson, "1.20.3"); + } + + /** + * Converts other types of images to PNG images. + * @param pack Pack to convert + * @throws IOException if the images are of an invalid type, or do not exist. + */ + @Override + public void convert(Pack pack) throws IOException { + // All textures in the game + Path texturesPath = pack.getWorkingPath().resolve(Paths.get("assets", "minecraft", "textures")); + // check for invalid images for all of these types. + for (String type : types) { + findImage(texturesPath, type); + } + } + + /** + * Recursively finds files with {@link Path} path and remaps the files. + * + * @param path Path of directory to find files in. + * @throws IOException If the images are not found, or the remapping fails. + */ + protected void findImage(Path path, String type) throws IOException { + // Find all files in the directory + File directory = path.toFile(); + if (!directory.exists() || !directory.isDirectory()) { + return; + } + + // Check each file + for (File file : Objects.requireNonNull(directory.listFiles())) { + if (file.isDirectory()) + findImage(file.toPath(), type); + else { + if (file.getName().endsWith(type)) { + remapFile(file, type); + } + } + } + } + + /** + * Remaps a single image to a PNG format. + * + * @param file File to remap. + * @param oldFormat Original format of the file. + * @throws IOException If the formatting fails. + */ + protected void remapFile(File file, String oldFormat) throws IOException { + // Get the image + BufferedImage image = ImageIO.read(file); + // Output the correct format + ImageIO.write(image, "png", new File(file.getAbsolutePath().replaceAll(oldFormat, "png"))); + // Delete the old image. + if (file.exists()) { + file.delete(); + } + } +} diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/GuiSlicerConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/GuiSlicerConverter1_20_2.java similarity index 94% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/GuiSlicerConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/GuiSlicerConverter1_20_2.java index 4a146582..fdd321d4 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/GuiSlicerConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/GuiSlicerConverter1_20_2.java @@ -1,4 +1,4 @@ -package com.agentdid127.resourcepack.forwards.impl.textures.slicer; +package com.agentdid127.resourcepack.forwards.impl.v1_20.textures; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; @@ -18,10 +18,10 @@ import java.io.IOException; import java.nio.file.Path; -public class GuiSlicerConverter extends Converter { +public class GuiSlicerConverter1_20_2 extends Converter { private final int from; - public GuiSlicerConverter(PackConverter converter, int from) { + public GuiSlicerConverter1_20_2(PackConverter converter, int from) { super(converter); this.from = from; } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/MapIconSlicerConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/MapIconSlicerConverter1_20_5.java similarity index 85% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/MapIconSlicerConverter.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/MapIconSlicerConverter1_20_5.java index 92191b62..57800077 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/slicer/MapIconSlicerConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/MapIconSlicerConverter1_20_5.java @@ -1,4 +1,4 @@ -package com.agentdid127.resourcepack.forwards.impl.textures.slicer; +package com.agentdid127.resourcepack.forwards.impl.v1_20.textures; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; @@ -14,10 +14,10 @@ import java.io.IOException; import java.nio.file.Path; -public class MapIconSlicerConverter extends Converter { +public class MapIconSlicerConverter1_20_5 extends Converter { private final int from; - public MapIconSlicerConverter(PackConverter packConverter, int from) { + public MapIconSlicerConverter1_20_5(PackConverter packConverter, int from) { super(packConverter); this.from = from; } @@ -43,7 +43,7 @@ public void convert(Pack pack) throws IOException { JsonObject mapIconsJson = JsonUtil.readJsonResource(gson, "/forwards/map_icons.json", JsonObject.class); if (mapIconsJson != null) { Slice slice = Slice.parse(mapIconsJson); - Slicer.runSlicer(gson, slice, mapIconsPath, new GuiSlicerConverter.GuiPredicateRunnable(), from, false); + Slicer.runSlicer(gson, slice, mapIconsPath, new GuiSlicerConverter1_20_2.GuiPredicateRunnable(), from, false); } } } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/TitleConverter1_20.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/TitleConverter1_20.java similarity index 96% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/TitleConverter1_20.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/TitleConverter1_20.java index 90883c74..60c1723c 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/TitleConverter1_20.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/TitleConverter1_20.java @@ -1,4 +1,4 @@ -package com.agentdid127.resourcepack.forwards.impl.textures; +package com.agentdid127.resourcepack.forwards.impl.v1_20.textures; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter1_21_2.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_21/textures/ArmorMoverConverter1_21_2.java similarity index 98% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter1_21_2.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_21/textures/ArmorMoverConverter1_21_2.java index 57043d47..b00f7b12 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/ArmorMoverConverter1_21_2.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_21/textures/ArmorMoverConverter1_21_2.java @@ -1,4 +1,4 @@ -package com.agentdid127.resourcepack.forwards.impl.textures; +package com.agentdid127.resourcepack.forwards.impl.v1_21.textures; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/PostEffectShadersConverter1_21_2.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_21/textures/PostEffectShadersConverter1_21_2.java similarity index 98% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/PostEffectShadersConverter1_21_2.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_21/textures/PostEffectShadersConverter1_21_2.java index eecb261f..2176f085 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/PostEffectShadersConverter1_21_2.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_21/textures/PostEffectShadersConverter1_21_2.java @@ -1,4 +1,4 @@ -package com.agentdid127.resourcepack.forwards.impl.textures; +package com.agentdid127.resourcepack.forwards.impl.v1_21.textures; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; @@ -58,6 +58,8 @@ public void convert(Pack pack) throws IOException { // TODO: Move the corresponding program shader from shaders/program to shaders/post Files.move(shadersPostPath, postEffectPath); + // TODO: Determind if legacy post-effect & ignore it/delete it + // Update shaders Logger.addTab(); try (Stream pathStream = Files.list(postEffectPath).filter(file -> file.toString().endsWith(".json"))) { diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/CompassConverter1_9.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_9/textures/CompassConverter1_9.java similarity index 97% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/CompassConverter1_9.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_9/textures/CompassConverter1_9.java index 94b1f7d2..6937ef97 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/CompassConverter1_9.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_9/textures/CompassConverter1_9.java @@ -1,4 +1,4 @@ -package com.agentdid127.resourcepack.forwards.impl.textures; +package com.agentdid127.resourcepack.forwards.impl.v1_9.textures; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/creator/OffHandCreator.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_9/textures/OffHandCreator1_9.java similarity index 93% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/creator/OffHandCreator.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_9/textures/OffHandCreator1_9.java index 05315c9a..ffee996a 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/creator/OffHandCreator.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_9/textures/OffHandCreator1_9.java @@ -1,4 +1,4 @@ -package com.agentdid127.resourcepack.forwards.impl.textures.creator; +package com.agentdid127.resourcepack.forwards.impl.v1_9.textures; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; @@ -11,8 +11,8 @@ import java.io.IOException; import java.nio.file.Path; -public class OffHandCreator extends Converter { - public OffHandCreator(PackConverter packConverter) { +public class OffHandCreator1_9 extends Converter { + public OffHandCreator1_9(PackConverter packConverter) { super(packConverter); } diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/AnimationConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/AnimationConverter.html index 50a4a9fe..74aa9069 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/AnimationConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/AnimationConverter.html @@ -88,7 +88,7 @@

Class AnimationConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.AnimationConverter
+
com.agentdid127.resourcepack.forwards.impl.v1_13.AnimationConverter1_13
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/AtlasConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/AtlasConverter.html index 4fc130e1..1d52f0c1 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/AtlasConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/AtlasConverter.html @@ -88,7 +88,7 @@

Class AtlasConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.AtlasConverter
+
com.agentdid127.resourcepack.forwards.impl.v1_19.AtlasConverter1_19_3
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.html index 7d004f61..e1bda4e1 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/BlockStateConverter.html @@ -88,7 +88,7 @@

Class BlockStateConverter
java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.BlockStateConverter
+
com.agentdid127.resourcepack.forwards.impl.other.BlockStateConverter
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/EnchantPathConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/EnchantPathConverter.html index e958b393..2311970a 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/EnchantPathConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/EnchantPathConverter.html @@ -88,7 +88,7 @@

Class EnchantPathConverter<
java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.EnchantPathConverter
+
com.agentdid127.resourcepack.forwards.impl.v1_19.EnchantPathConverter1_19_4
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/LangConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/LangConverter.html index 6d44176b..84051539 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/LangConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/LangConverter.html @@ -88,7 +88,7 @@

Class LangConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.LangConverter
+
com.agentdid127.resourcepack.forwards.impl.v1_13.LangConverter1_13
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.html index 96266b98..e657bcbe 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/MCPatcherConverter.html @@ -88,7 +88,7 @@

Class MCPatcherConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.MCPatcherConverter
+
com.agentdid127.resourcepack.forwards.impl.v1_13.MCPatcherConverter1_13
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/ModelConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/ModelConverter.html index efbdfb99..b77f5da4 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/ModelConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/ModelConverter.html @@ -88,7 +88,7 @@

Class ModelConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.ModelConverter
+
com.agentdid127.resourcepack.forwards.impl.other.ModelConverter
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/NameConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/NameConverter.html index 8cb3da8a..728d5c34 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/NameConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/NameConverter.html @@ -88,7 +88,7 @@

Class NameConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.NameConverter
+
com.agentdid127.resourcepack.forwards.impl.other.NameConverter
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.html index a1d7cd56..2a7ab6a8 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/PackMetaConverter.html @@ -88,7 +88,7 @@

Class PackMetaConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.PackMetaConverter
+
com.agentdid127.resourcepack.forwards.impl.other.PackMetaConverter
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/ParticleConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/ParticleConverter.html index 046fe78b..c7254133 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/ParticleConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/ParticleConverter.html @@ -88,7 +88,7 @@

Class ParticleConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.ParticleConverter
+
com.agentdid127.resourcepack.forwards.impl.other.ParticleConverter1_18
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/SoundsConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/SoundsConverter.html index dc26b026..8a308bad 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/SoundsConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/SoundsConverter.html @@ -88,7 +88,7 @@

Class SoundsConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.SoundsConverter
+
com.agentdid127.resourcepack.forwards.impl.v1_13.SoundsConverter1_13
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/SpacesConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/SpacesConverter.html index d031414c..35fbbd43 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/SpacesConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/SpacesConverter.html @@ -88,7 +88,7 @@

Class SpacesConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.SpacesConverter
+
com.agentdid127.resourcepack.forwards.impl.other.SpacesConverter1_11
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/ChestConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/ChestConverter.html index 291c3f94..f66b1671 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/ChestConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/ChestConverter.html @@ -88,7 +88,7 @@

Class ChestConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.ChestConverter1_15
+
com.agentdid127.resourcepack.forwards.impl.v1_15.textures.ChestConverter1_15
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/CompassConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/CompassConverter.html index 37e1522c..7ab0cc3f 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/CompassConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/CompassConverter.html @@ -88,7 +88,7 @@

Class CompassConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.CompassConverter1_9
+
com.agentdid127.resourcepack.forwards.impl.v1_9.textures.CompassConverter1_9
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/CreativeTabsConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/CreativeTabsConverter.html index fb196734..37b1203d 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/CreativeTabsConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/CreativeTabsConverter.html @@ -88,7 +88,7 @@

Class CreativeTabsConverte
java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.CreativeTabsConverter1_19_3
+
com.agentdid127.resourcepack.forwards.impl.v1_19.textures.CreativeTabsConverter1_19_3
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/EnchantConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/EnchantConverter.html index 154dce6e..d60e3b26 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/EnchantConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/EnchantConverter.html @@ -88,7 +88,7 @@

Class EnchantConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.EnchantConverter1_15
+
com.agentdid127.resourcepack.forwards.impl.v1_15.textures.EnchantConverter1_15
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter.html index 06a49478..b34e3834 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/MapIconConverter.html @@ -88,7 +88,7 @@

Class MapIconConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.MapIconConverter1_13
+
com.agentdid127.resourcepack.forwards.impl.v1_13.textures.MapIconConverter1_13
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/MobEffectAtlasConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/MobEffectAtlasConverter.html index 796a75c5..45124b97 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/MobEffectAtlasConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/MobEffectAtlasConverter.html @@ -88,7 +88,7 @@

Class MobEffectAtlasConv
java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.slicer.MobEffectAtlasSlicerConverter
+
com.agentdid127.resourcepack.forwards.impl.v1_14.textures.MobEffectAtlasSlicerConverter1_14
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/OffHandCreator.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/OffHandCreator.html index 56b5c00b..6f37a0e9 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/OffHandCreator.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/OffHandCreator.html @@ -88,7 +88,7 @@

Class OffHandCreator

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.creator.OffHandCreator
+
com.agentdid127.resourcepack.forwards.impl.v1_9.textures.OffHandCreator1_9
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/PaintingConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/PaintingConverter.html index 6c460875..cf2e2b60 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/PaintingConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/PaintingConverter.html @@ -88,7 +88,7 @@

Class PaintingConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.slicer.PaintingSlicerConverter
+
com.agentdid127.resourcepack.forwards.impl.v1_14.textures.PaintingSlicerConverter1_14_4
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.html index 229327e3..fd7353ee 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/ParticleTextureConverter.html @@ -88,7 +88,7 @@

Class ParticleTextureCo
java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.slicer.ParticlesSlicerConverter
+
com.agentdid127.resourcepack.forwards.impl.textures.ParticlesSlicerConverter
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.PredicateRunnable.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.PredicateRunnable.html index dbfec8b8..0b3459a9 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.PredicateRunnable.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.PredicateRunnable.html @@ -87,7 +87,7 @@

Class SlicerConverter.PredicateRunnable

java.lang.Object -
com.agentdid127.resourcepack.forwards.impl.textures.slicer.GuiSlicerConverter.PredicateRunnable
+
com.agentdid127.resourcepack.forwards.impl.v1_20.textures.GuiSlicerConverter1_20_2.PredicateRunnable
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.html index 4d348f09..4a8b7bc0 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlicerConverter.html @@ -88,7 +88,7 @@

Class SlicerConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.slicer.GuiSlicerConverter
+
com.agentdid127.resourcepack.forwards.impl.v1_20.textures.GuiSlicerConverter1_20_2
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlidersCreator.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlidersCreator.html index b4e1b404..19d70d30 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlidersCreator.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/SlidersCreator.html @@ -88,7 +88,7 @@

Class SlidersCreator

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.creator.WidgetSlidersCreator
+
com.agentdid127.resourcepack.forwards.impl.v1_19.textures.WidgetSlidersCreator1_19_4
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/TitleConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/TitleConverter.html index 2527c03c..5f209080 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/TitleConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/TitleConverter.html @@ -88,7 +88,7 @@

Class TitleConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.TitleConverter1_20
+
com.agentdid127.resourcepack.forwards.impl.v1_20.textures.TitleConverter1_20
diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/textures/WaterConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/textures/WaterConverter.html index 5e375f30..80714d3e 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/textures/WaterConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/textures/WaterConverter.html @@ -88,7 +88,7 @@

Class WaterConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.textures.WaterConverter1_13
+
com.agentdid127.resourcepack.forwards.impl.v1_13.textures.WaterConverter1_13
diff --git a/docs/deprecated-list.html b/docs/deprecated-list.html index 3892d3d6..51856e13 100644 --- a/docs/deprecated-list.html +++ b/docs/deprecated-list.html @@ -64,7 +64,7 @@

Contents

Description
- +
From 3a1874379e684a037077169b2855ccc35c9002ab Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Mon, 10 Feb 2025 14:51:48 -0500 Subject: [PATCH 44/54] Implement TODO#3 in PostEffectShadersConverter1_21_2 --- .../forwards/ForwardsPackConverter.java | 2 +- .../forwards/impl/other/NameConverter.java | 2 +- .../impl/other/PackMetaConverter.java | 4 +- ...11.java => RemoveSpacesConverter1_11.java} | 4 +- .../PostEffectShadersConverter1_21_2.java | 51 ++++++++++++++----- .../v1_9/textures/CompassConverter1_9.java | 39 +++++++------- .../forwards/impl/SpacesConverter.html | 2 +- .../resourcepack/library/pack/Pack.java | 30 +++++------ .../resourcepack/library/pack/ZipPack.java | 5 +- .../library/utilities/JsonUtil.java | 14 +++-- 10 files changed, 87 insertions(+), 66 deletions(-) rename conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/{SpacesConverter1_11.java => RemoveSpacesConverter1_11.java} (95%) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java index e363940d..cc62f30a 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/ForwardsPackConverter.java @@ -61,7 +61,7 @@ private void setupConverters(String light) { this.registerConverter(new PackMetaConverter(this, from, to)); this.registerConverter(new CompassConverter1_9(this, to)); this.registerConverter(new OffHandCreator1_9(this)); - this.registerConverter(new SpacesConverter1_11(this)); + this.registerConverter(new RemoveSpacesConverter1_11(this)); this.registerConverter(new ModelConverter(this, light, from, to)); this.registerConverter(new SoundsConverter1_13(this)); this.registerConverter(new AnimationConverter1_13(this)); diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/NameConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/NameConverter.java index 04c64df5..1e5c1d15 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/NameConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/NameConverter.java @@ -20,8 +20,8 @@ import java.util.stream.Stream; public class NameConverter extends Converter { - private final int to; private final int from; + private final int to; private final Mapping entityMapping; diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/PackMetaConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/PackMetaConverter.java index a55bc02c..364a2dd3 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/PackMetaConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/PackMetaConverter.java @@ -13,8 +13,8 @@ // Reference: https://minecraft.wiki/w/Pack_format public class PackMetaConverter extends Converter { - private final int to; private final int from; + private final int to; public PackMetaConverter(PackConverter packConverter, int from, int to) { super(packConverter); @@ -68,7 +68,7 @@ public void convert(Pack pack) throws IOException { } packObject.addProperty("pack_format", versionInt); - if (from < Util.getVersionProtocol(packConverter.getGson(), "1.20.2") + if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.20.1") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.20.2")) { JsonObject fromVersion = Util.getVersionObjectByProtocol(packConverter.getGson(), from); JsonObject toVersion = Util.getVersionObjectByProtocol(packConverter.getGson(), to); diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/SpacesConverter1_11.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/RemoveSpacesConverter1_11.java similarity index 95% rename from conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/SpacesConverter1_11.java rename to conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/RemoveSpacesConverter1_11.java index e8f17e05..0bc86095 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/SpacesConverter1_11.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/RemoveSpacesConverter1_11.java @@ -14,8 +14,8 @@ import java.nio.file.Paths; import java.util.Objects; -public class SpacesConverter1_11 extends Converter { - public SpacesConverter1_11(PackConverter packConverter) { +public class RemoveSpacesConverter1_11 extends Converter { + public RemoveSpacesConverter1_11(PackConverter packConverter) { super(packConverter); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_21/textures/PostEffectShadersConverter1_21_2.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_21/textures/PostEffectShadersConverter1_21_2.java index 2176f085..29857164 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_21/textures/PostEffectShadersConverter1_21_2.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_21/textures/PostEffectShadersConverter1_21_2.java @@ -12,7 +12,9 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -40,30 +42,26 @@ public boolean shouldConvert(Gson gson, int from, int to) { @Override public void convert(Pack pack) throws IOException { Path minecraftPath = pack.getWorkingPath().resolve("assets/minecraft".replace("/", File.separator)); - if (!minecraftPath.toFile().exists()) { - return; - } - - // Move shaders - Path shadersPostPath = minecraftPath.resolve("shaders/post".replace("/", File.separator)); + Path shadersPath = minecraftPath.resolve("shaders"); + Path shadersPostPath = shadersPath.resolve("post"); if (!shadersPostPath.toFile().exists()) { return; } + Logger.addTab(); Path postEffectPath = minecraftPath.resolve("post_effect"); if (postEffectPath.toFile().exists()) { + // TODO: Should we merge directories? postEffectPath.toFile().delete(); } - - // TODO: Move the corresponding program shader from shaders/program to shaders/post Files.move(shadersPostPath, postEffectPath); - // TODO: Determind if legacy post-effect & ignore it/delete it - // Update shaders - Logger.addTab(); + // TODO: Determind if legacy post-effect & ignore it/delete it + List postShaders = new ArrayList<>(); try (Stream pathStream = Files.list(postEffectPath).filter(file -> file.toString().endsWith(".json"))) { pathStream.forEach(file -> { + postShaders.add(file.getFileName()); try { JsonObject json = JsonUtil.readJson(packConverter.getGson(), file); @@ -97,14 +95,39 @@ public void convert(Pack pack) throws IOException { } JsonUtil.writeJson(this.packConverter.getGson(), file, json); - Logger.debug("Saving updated post-effect shader \"" + file.toString() + "\""); + Logger.debug("Saving updated post-effect shader \"" + file + "\""); } catch (Exception e) { - Logger.debug("Failed to update post-effect shader \"" + file.toString() + "\": " + e.getMessage()); + Logger.debug("Failed to update post-effect shader \"" + file + "\": " + e.getMessage()); } }); } catch (Exception e) { - Logger.debug("Failed to update shader, unable to open file stream"); + Logger.debug("Failed to update shader, unable to open file stream."); } + + Path shadersProgramPath = shadersPath.resolve("program"); + if (!shadersProgramPath.toFile().exists()) { + return; + } + + // TODO: Could be just all ".json" in "shaders/program"? + postShaders.forEach(postShaderPath -> { + Path programShaderPath = shadersProgramPath.resolve(postShaderPath); + if (!programShaderPath.toFile().exists()) { + return; + } + + if (!shadersPostPath.toFile().exists()) { + shadersPostPath.toFile().mkdirs(); + } + + try { + Logger.debug("Moved post-effect program shader \"" + programShaderPath + "\" to post folder."); + Files.move(programShaderPath, shadersPostPath.resolve(postShaderPath)); + } catch (IOException e) { + Logger.debug("Failed to move post-effect program shader to post folder."); + } + }); + Logger.subTab(); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_9/textures/CompassConverter1_9.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_9/textures/CompassConverter1_9.java index 6937ef97..333e6c38 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_9/textures/CompassConverter1_9.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_9/textures/CompassConverter1_9.java @@ -14,7 +14,6 @@ public class CompassConverter1_9 extends Converter { private final int to; - private Path items; public CompassConverter1_9(PackConverter packConverter, int to) { super(packConverter); @@ -28,33 +27,31 @@ public boolean shouldConvert(Gson gson, int from, int to) { @Override public void convert(Pack pack) throws IOException { - String itemsT = "items"; - if (to > Util.getVersionProtocol(packConverter.getGson(), "1.13")) - itemsT = "item"; - Path compassPath = pack.getWorkingPath() - .resolve(("assets/minecraft/textures/" + itemsT + "/compass.png").replace("/", File.separator)); - items = compassPath.getParent(); + String itemsT = to >= Util.getVersionProtocol(packConverter.getGson(), "1.13") ? "item" : "items"; + Path compassPath = pack.getWorkingPath().resolve(("assets/minecraft/textures/" + itemsT + "/compass.png").replace("/", File.separator)); + Path items = compassPath.getParent(); if (compassPath.toFile().exists()) { ImageConverter imageConverter = new ImageConverter(16, 512, compassPath); - if (!imageConverter.fileIsPowerOfTwo()) - return; - - for (int i = 0; i < 32; i++) { - int h = i * 16; - String it = String.valueOf(i); - if (i < 10) - it = "0" + it; - compass(0, h, 16, h + 16, "compass_" + it, imageConverter); + if (imageConverter.fileIsPowerOfTwo()) { + for (int i = 0; i < 32; i++) { + int h = i * 16; + String it = String.valueOf(i); + if (i < 10) { + it = "0" + it; + } + compass(items, 0, h, 16, 16, "compass_" + it, imageConverter); + } + + if (items.resolve("compass.png.mcmeta").toFile().exists()) { + Files.delete(items.resolve("compass.png.mcmeta")); + } } - - if (items.resolve("compass.png.mcmeta").toFile().exists()) - Files.delete(items.resolve("compass.png.mcmeta")); } } - private void compass(int x, int y, int x2, int y2, String name, ImageConverter imageConverter) throws IOException { + private void compass(Path items, int x, int y, int width, int height, String name, ImageConverter imageConverter) throws IOException { imageConverter.newImage(16, 16); - imageConverter.subImage(x, y, x2, y2, 0, 0); + imageConverter.subImage(x, y, x + width, y + height, 0, 0); imageConverter.store(items.resolve(name + ".png")); } } diff --git a/docs/com/agentdid127/resourcepack/forwards/impl/SpacesConverter.html b/docs/com/agentdid127/resourcepack/forwards/impl/SpacesConverter.html index 35fbbd43..1f9e0b0e 100644 --- a/docs/com/agentdid127/resourcepack/forwards/impl/SpacesConverter.html +++ b/docs/com/agentdid127/resourcepack/forwards/impl/SpacesConverter.html @@ -88,7 +88,7 @@

Class SpacesConverter

java.lang.Object
com.agentdid127.resourcepack.library.Converter -
com.agentdid127.resourcepack.forwards.impl.other.SpacesConverter1_11
+
com.agentdid127.resourcepack.forwards.impl.other.RemoveSpacesConverter1_11
diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/pack/Pack.java b/library/src/main/java/com/agentdid127/resourcepack/library/pack/Pack.java index f3aa2a3e..938fcee0 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/pack/Pack.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/pack/Pack.java @@ -24,16 +24,19 @@ public Handler createHandler() { /** * Checks the type of pack it is. - * + * * @param path Pack Path * @return The Pack information */ public static Pack parse(Path path) { - if (!path.toString().contains(CONVERTED_SUFFIX)) - if (path.toFile().isDirectory() && path.resolve("pack.mcmeta").toFile().exists()) + if (!path.toString().contains(CONVERTED_SUFFIX)) { + if (path.toFile().isDirectory() && path.resolve("pack.mcmeta").toFile().exists()) { return new Pack(path); - else if (path.toString().endsWith(".zip")) + } else if (path.toString().endsWith(".zip")) { return new ZipPack(path); + } + } + return null; } @@ -55,9 +58,7 @@ public String getFileName() { @Override public String toString() { - return "ResourcePack{" + - "path=" + path + - '}'; + return "ResourcePack{path=" + path + "}"; } public static class Handler { @@ -69,7 +70,7 @@ public Handler(Pack pack) { /** * Deletes existing conversions and sets up pack for conversion - * + * * @throws IOException Issues with conversion */ public void setup() throws IOException { @@ -80,17 +81,16 @@ public void setup() throws IOException { Logger.log("Copying existing pack"); FileUtil.copyDirectory(pack.getOriginalPath(), pack.getWorkingPath()); - bomRemover(pack.getWorkingPath()); } static void bomRemover(Path workingPath) throws IOException { - BomDetector bom = new BomDetector( - workingPath.toString(), - ".txt", ".json", ".mcmeta", ".properties", ".lang"); + BomDetector bom = new BomDetector(workingPath.toString(), ".txt", ".json", ".mcmeta", ".properties", ".lang"); int count = bom.findBOMs().size(); - if (count > 0) + if (count > 0) { Logger.debug("Removing BOMs from " + count + " files."); + } + bom.removeBOMs(); } @@ -99,9 +99,7 @@ public void finish() throws IOException { @Override public String toString() { - return "Handler{" + - "pack=" + pack + - '}'; + return "Handler{pack=" + pack + "}"; } } } diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/pack/ZipPack.java b/library/src/main/java/com/agentdid127/resourcepack/library/pack/ZipPack.java index 673ad0cc..46755d0c 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/pack/ZipPack.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/pack/ZipPack.java @@ -3,7 +3,6 @@ import com.agentdid127.resourcepack.library.utilities.FileUtil; import com.agentdid127.resourcepack.library.utilities.Logger; import com.agentdid127.resourcepack.library.utilities.Util; - import net.lingala.zip4j.ZipFile; import net.lingala.zip4j.exception.ZipException; import net.lingala.zip4j.model.ZipParameters; @@ -37,7 +36,7 @@ public Path getConvertedZipPath() { /** * Removes Existing Conversions and starts new one - * + * * @throws IOException Any issue with loading the pack, or deleting previous * packs */ @@ -69,7 +68,7 @@ public void setup() throws IOException { /** * Runs after program is finished. Zips directory. - * + * * @throws IOException Any IO exception */ @Override diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/JsonUtil.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/JsonUtil.java index 033a2f73..789f111d 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/JsonUtil.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/JsonUtil.java @@ -74,11 +74,13 @@ public static boolean isJson(Gson gson, String Json) { public static T readJson(Gson gson, Path path, Class clazz) throws IOException { String json = Util.readFromFile(path); - if (!isJson(gson, json)) + if (isJson(gson, json)) { + JsonReader reader = new JsonReader(new StringReader(json)); + reader.setStrictness(Strictness.LENIENT); + return gson.fromJson(reader, clazz); + } else { return null; - JsonReader reader = new JsonReader(new StringReader(json)); - reader.setStrictness(Strictness.LENIENT); - return gson.fromJson(reader, clazz); + } } public static JsonObject readJson(Gson gson, Path path) throws IOException { @@ -87,8 +89,10 @@ public static JsonObject readJson(Gson gson, Path path) throws IOException { public static T readJsonResource(Gson gson, String path, Class clazz) { try (InputStream stream = PackConverter.class.getResourceAsStream(path)) { - if (stream == null) + if (stream == null) { return null; + } + try (InputStreamReader streamReader = new InputStreamReader(stream)) { return gson.fromJson(streamReader, clazz); } From 0629685ea4e8967d4cbd22dc86f5ccc95889c124 Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Mon, 10 Feb 2025 17:42:24 -0500 Subject: [PATCH 45/54] Work on GUI-refresh --- .../com/agentdid127/resourcepack/Main.java | 6 +- .../com/agentdid127/resourcepack/GUI.form | 86 ------- .../com/agentdid127/resourcepack/GUI.java | 217 +++++++++--------- .../v1_20/ImageFormatConverter1_20_3.java | 8 +- .../textures/GuiSlicerConverter1_20_2.java | 4 - .../MapIconSlicerConverter1_20_5.java | 4 - .../v1_20/textures/TitleConverter1_20.java | 8 - .../resourcepack/library/utilities/Util.java | 21 +- 8 files changed, 132 insertions(+), 222 deletions(-) delete mode 100644 Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.form diff --git a/Applications/Console/src/main/java/com/agentdid127/resourcepack/Main.java b/Applications/Console/src/main/java/com/agentdid127/resourcepack/Main.java index 568147f0..3d4e7736 100644 --- a/Applications/Console/src/main/java/com/agentdid127/resourcepack/Main.java +++ b/Applications/Console/src/main/java/com/agentdid127/resourcepack/Main.java @@ -40,10 +40,10 @@ public static void main(String[] args) throws IOException { int from = Util.getVersionProtocol(gson, optionSet.valueOf(Options.FROM)); int to = Util.getVersionProtocol(gson, optionSet.valueOf(Options.TO)); - if (from > to) { - new BackwardsPackConverter(gson, from, to, inputPath, debug, out).runDir(); - } else { + if (from < to) { new ForwardsPackConverter(gson, from, to, light, inputPath, debug, out).runDir(); + } else { + new BackwardsPackConverter(gson, from, to, inputPath, debug, out).runDir(); } } } \ No newline at end of file diff --git a/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.form b/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.form deleted file mode 100644 index 2f9d6f4e..00000000 --- a/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.form +++ /dev/null @@ -1,86 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java b/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java index ecccd347..a8f84308 100644 --- a/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java +++ b/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java @@ -6,10 +6,10 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.Strictness; +import com.sun.java.swing.plaf.gtk.GTKLookAndFeel; import javax.swing.*; import java.awt.*; -import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; import java.nio.file.Path; @@ -17,151 +17,160 @@ import java.util.Arrays; import java.util.Objects; -public class GUI { - static JFrame frame; - private JPanel panel1; +public class GUI extends JPanel { + private PrintStream out; + private JTextArea outputLogPane; private JComboBox initialVersionBox; - private JComboBox finalVersionBox; - private JTextArea outputArea; + private JComboBox targetVersions; private JCheckBox minifyCheckBox; - private JLabel finalVersionLabel; - private JLabel initialVersionLabel; - private JLabel outputLabel; + private JComboBox lightOptions; private JButton convertButton; - private PrintStream out; - private final Gson gson; - public GUI() { GsonBuilder gsonBuilder = new GsonBuilder().disableHtmlEscaping().setStrictness(Strictness.LENIENT); - this.gson = gsonBuilder.disableHtmlEscaping().create(); - - String[] versions = Util.getSupportedVersions(gson); - for (String item : versions == null ? new String[]{} : versions) { - initialVersionBox.addItem(item); - finalVersionBox.addItem(item); - } - + Gson gson = gsonBuilder.disableHtmlEscaping().create(); + setupGUI(gson); + Arrays.stream((new String[]{"none", "front", "side"})).forEach(lightOptions::addItem); convertButton.addActionListener(e -> { out = redirectSystemStreams(); + String light = Objects.requireNonNull(lightOptions.getSelectedItem()).toString(); int from = Util.getVersionProtocol(gson, Objects.requireNonNull(initialVersionBox.getSelectedItem()).toString()); - int to = Util.getVersionProtocol(gson, Objects.requireNonNull(finalVersionBox.getSelectedItem()).toString()); - String light = "none"; + int to = Util.getVersionProtocol(gson, Objects.requireNonNull(targetVersions.getSelectedItem()).toString()); boolean minify = minifyCheckBox.isSelected(); new Thread(() -> { - convertButton.setVisible(false); + convertButton.setEnabled(false); try { - Gson gson = this.gson; + Gson packGson = gson; if (!minify) { - gson = gsonBuilder.setPrettyPrinting().create(); + packGson = gson.newBuilder().setPrettyPrinting().create(); } Path dotPath = Paths.get("./"); - if (from > to) { - new BackwardsPackConverter(gson, from, to, dotPath, false, out).runDir(); + if (from < to) { + new ForwardsPackConverter(packGson, from, to, light, dotPath, true, out).runDir(); } else { - new ForwardsPackConverter(gson, from, to, light, dotPath, false, out).runDir(); + new BackwardsPackConverter(packGson, from, to, dotPath, true, out).runDir(); } } catch (Exception exception) { out.println(Arrays.toString(exception.getStackTrace())); } - convertButton.setVisible(true); + convertButton.setEnabled(true); }).start(); }); } public static void main(String[] args) { - frame = new JFrame("Resource Pack Converter"); - frame.setContentPane(new GUI().panel1); + JFrame frame = new JFrame("RPC - Resource Pack Converter"); + frame.setContentPane(new GUI()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + try { + UIManager.setLookAndFeel(new GTKLookAndFeel()); + } catch (Exception ignored) { + System.err.println("GTK look not supported, ignoring."); + } + + frame.setFocusable(true); + Dimension dimensions = new Dimension(854, 480); + frame.setMaximumSize(dimensions); + frame.setMinimumSize(dimensions); + frame.setPreferredSize(dimensions); + frame.setLocationRelativeTo(null); // Centers window on screen frame.pack(); frame.setVisible(true); } - private void updateTextArea(final String text) { - outputArea.append(text); + private void setupGUI(Gson gson) { + { + final JPanel panel = new JPanel(); + final JScrollPane scrollPane = new JScrollPane(); + this.outputLogPane = new JTextArea(); + this.outputLogPane.setColumns(60); + this.outputLogPane.setRows(20); + this.outputLogPane.setText(""); + this.outputLogPane.setEditable(false); + scrollPane.setViewportView(this.outputLogPane); + panel.add(scrollPane); + this.add(panel); + } + + { + final JPanel menuBar = new JPanel(); + // Initial Version + JLabel initialVersionLabel = new JLabel(); + initialVersionLabel.setText("Initial Version"); + menuBar.add(initialVersionLabel); + + this.initialVersionBox = new JComboBox<>(); + initialVersionLabel.setLabelFor(this.initialVersionBox); + menuBar.add(this.initialVersionBox); + + // Target Version + JLabel targetVersionsLabel = new JLabel(); + targetVersionsLabel.setText("Final Version"); + menuBar.add(targetVersionsLabel); + + this.targetVersions = new JComboBox<>(); + targetVersionsLabel.setLabelFor(targetVersions); + menuBar.add(this.targetVersions); + + // Add items to both ^ + String[] versions = Util.getSupportedVersions(gson); + if (versions == null) { + throw new RuntimeException("Failed to get supported version, application possibly corrupt!"); + } + + if (versions.length > 0) { + for (String version : versions) { + initialVersionBox.addItem(version); + targetVersions.addItem(version); + } + targetVersions.setSelectedIndex(targetVersions.getItemCount() - 1); + } + + // Minify Checkbox + JLabel minifyCheckboxLabel = new JLabel(); + minifyCheckboxLabel.setText("Minify"); + menuBar.add(minifyCheckboxLabel); + + this.minifyCheckBox = new JCheckBox(); + minifyCheckboxLabel.setLabelFor(this.minifyCheckBox); + menuBar.add(this.minifyCheckBox); + + // Item Lighting Options + JLabel lightOptionsLabel = new JLabel(); + lightOptionsLabel.setText("Item Lighting"); + menuBar.add(lightOptionsLabel); + + this.lightOptions = new JComboBox<>(); + lightOptionsLabel.setLabelFor(this.lightOptions); + menuBar.add(this.lightOptions); + + // Convert Button + this.convertButton = new JButton(); + this.convertButton.setText("Convert"); + menuBar.add(this.convertButton); + + this.add(menuBar); + } } - // Followings are The Methods that do the Redirect, you can simply Ignore them. private PrintStream redirectSystemStreams() { - OutputStream out2 = new OutputStream() { + return new PrintStream(new OutputStream() { @Override - public void write(int b) throws IOException { - updateTextArea(String.valueOf((char) b)); + public void write(int b) { + outputLogPane.append(String.valueOf((char) b)); } @Override - public void write(byte[] b, int off, int len) throws IOException { - updateTextArea(new String(b, off, len)); + public void write(byte[] b, int off, int len) { + outputLogPane.append(new String(b, off, len)); } @Override - public void write(byte[] b) throws IOException { + public void write(byte[] b) { write(b, 0, b.length); } - }; - - return new PrintStream(out2); - } - - { - // GUI initializer generated by IntelliJ IDEA GUI Designer - // >>> IMPORTANT!! <<< - // DO NOT EDIT OR ADD ANY CODE HERE! - $$$setupUI$$$(); - } - - /** - * Method generated by IntelliJ IDEA GUI Designer - * >>> IMPORTANT!! <<< - * DO NOT edit this method OR call it in your code! - * - * @noinspection ALL - */ - private void $$$setupUI$$$() { - panel1 = new JPanel(); - panel1.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5)); - panel1.setFocusable(true); - panel1.setMaximumSize(new Dimension(700, 375)); - panel1.setMinimumSize(new Dimension(700, 375)); - panel1.setPreferredSize(new Dimension(700, 375)); - final JPanel panel2 = new JPanel(); - panel2.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5)); - panel1.add(panel2); - initialVersionBox = new JComboBox(); - panel2.add(initialVersionBox); - initialVersionLabel = new JLabel(); - initialVersionLabel.setText("Initial Version"); - panel2.add(initialVersionLabel); - finalVersionBox = new JComboBox(); - panel2.add(finalVersionBox); - finalVersionLabel = new JLabel(); - finalVersionLabel.setText("Final Version"); - panel2.add(finalVersionLabel); - minifyCheckBox = new JCheckBox(); - minifyCheckBox.setText("Minify"); - panel2.add(minifyCheckBox); - final JPanel panel3 = new JPanel(); - panel3.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5)); - panel1.add(panel3); - outputLabel = new JLabel(); - outputLabel.setText("Output"); - panel3.add(outputLabel); - final JScrollPane scrollPane1 = new JScrollPane(); - panel3.add(scrollPane1); - outputArea = new JTextArea(); - outputArea.setColumns(60); - outputArea.setRows(15); - outputArea.setText(""); - scrollPane1.setViewportView(outputArea); - convertButton = new JButton(); - convertButton.setActionCommand("Convert"); - convertButton.setLabel("Convert"); - convertButton.setText("Convert"); - panel1.add(convertButton); - } - - public JComponent $$$getRootComponent$$$() { - return panel1; + }); } } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/ImageFormatConverter1_20_3.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/ImageFormatConverter1_20_3.java index 81bc57cd..ee8347ea 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/ImageFormatConverter1_20_3.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/ImageFormatConverter1_20_3.java @@ -64,12 +64,10 @@ protected void findImage(Path path, String type) throws IOException { // Check each file for (File file : Objects.requireNonNull(directory.listFiles())) { - if (file.isDirectory()) + if (file.isDirectory()) { findImage(file.toPath(), type); - else { - if (file.getName().endsWith(type)) { - remapFile(file, type); - } + } else if (file.getName().endsWith(type)) { + remapFile(file, type); } } } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/GuiSlicerConverter1_20_2.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/GuiSlicerConverter1_20_2.java index fdd321d4..3db9f106 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/GuiSlicerConverter1_20_2.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/GuiSlicerConverter1_20_2.java @@ -34,10 +34,6 @@ public boolean shouldConvert(Gson gson, int from, int to) { @Override public void convert(Pack pack) throws IOException { Path texturesPath = pack.getWorkingPath().resolve("assets/minecraft/textures".replace("/", File.separator)); - if (!texturesPath.toFile().exists()) { - return; - } - Path guiPath = texturesPath.resolve("gui"); if (!guiPath.toFile().exists()) { return; // No need to do any slicing. diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/MapIconSlicerConverter1_20_5.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/MapIconSlicerConverter1_20_5.java index 57800077..1b87ecdf 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/MapIconSlicerConverter1_20_5.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/MapIconSlicerConverter1_20_5.java @@ -30,10 +30,6 @@ public boolean shouldConvert(Gson gson, int from, int to) { @Override public void convert(Pack pack) throws IOException { Path texturesPath = pack.getWorkingPath().resolve("assets/minecraft/textures".replace("/", File.separator)); - if (!texturesPath.toFile().exists()) { - return; - } - Path mapIconsPath = texturesPath.resolve("map/".replace("/", File.separator)); if (!mapIconsPath.toFile().exists()) { return; diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/TitleConverter1_20.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/TitleConverter1_20.java index 60c1723c..b915965b 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/TitleConverter1_20.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/TitleConverter1_20.java @@ -24,15 +24,7 @@ public boolean shouldConvert(Gson gson, int from, int to) { @Override public void convert(Pack pack) throws IOException { Path texturesPath = pack.getWorkingPath().resolve("assets/minecraft/textures".replace("/", File.separator)); - if (!texturesPath.toFile().exists()) { - return; - } - Path titleFolderPath = texturesPath.resolve("gui/title".replace("/", File.separator)); - if (!titleFolderPath.toFile().exists()) { - return; - } - Path minecraftTilePath = titleFolderPath.resolve("minecraft.png"); if (!minecraftTilePath.toFile().exists()) { return; diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Util.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Util.java index 6cbfd9ec..6727692c 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Util.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Util.java @@ -88,7 +88,11 @@ public static JsonObject getVersionObjectByProtocol(Gson gson, int protocol) { */ public static JsonObject getVersionObject(Gson gson, String version) { JsonObject protocols = JsonUtil.readJsonResource(gson, "/protocol.json"); - return protocols == null ? null : protocols.getAsJsonObject(version); + if (protocols != null) { + return protocols.getAsJsonObject(version); + } else { + return null; + } } /** @@ -100,7 +104,11 @@ public static JsonObject getVersionObject(Gson gson, String version) { */ public static int getVersionProtocol(Gson gson, String version) { JsonObject versionObj = getVersionObject(gson, version); - return versionObj == null ? 0 : versionObj.get("protocol_version").getAsInt(); + if (versionObj != null) { + return versionObj.get("protocol_version").getAsInt(); + } else { + return 0; + } } public static int getLatestProtocol(Gson gson) { @@ -127,13 +135,10 @@ public static int getLatestProtocol(Gson gson) { */ public static String[] getSupportedVersions(Gson gson) { JsonObject protocols = JsonUtil.readJsonResource(gson, "/protocol.json"); - if (protocols == null) { - return null; + if (protocols != null) { + return protocols.entrySet().stream().map(Map.Entry::getKey).toArray(String[]::new); } else { - return protocols.entrySet() - .stream() - .map(Map.Entry::getKey) - .toArray(String[]::new); + return null; } } From 65ca75e098869dda0715f4745f910fa1790e654d Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Mon, 10 Feb 2025 17:47:07 -0500 Subject: [PATCH 46/54] More GUI reworking --- .../com/agentdid127/resourcepack/GUI.java | 177 +++++++++--------- 1 file changed, 86 insertions(+), 91 deletions(-) diff --git a/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java b/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java index a8f84308..610d4bb2 100644 --- a/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java +++ b/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java @@ -18,31 +18,98 @@ import java.util.Objects; public class GUI extends JPanel { + private static final Gson GSON = new GsonBuilder().disableHtmlEscaping().setStrictness(Strictness.LENIENT).disableHtmlEscaping().create(); + private PrintStream out; - private JTextArea outputLogPane; - private JComboBox initialVersionBox; - private JComboBox targetVersions; - private JCheckBox minifyCheckBox; - private JComboBox lightOptions; - private JButton convertButton; + private final JTextArea outputLogPane; + private final JComboBox initialVersionBox; + private final JComboBox targetVersions; + private final JCheckBox minifyCheckBox; + private final JComboBox lightOptions; + private final JButton convertButton; public GUI() { - GsonBuilder gsonBuilder = new GsonBuilder().disableHtmlEscaping().setStrictness(Strictness.LENIENT); - Gson gson = gsonBuilder.disableHtmlEscaping().create(); - setupGUI(gson); + // Log Output Panel + final JPanel logPanel = new JPanel(); + final JScrollPane scrollPane = new JScrollPane(); + this.outputLogPane = new JTextArea(); + this.outputLogPane.setColumns(60); + this.outputLogPane.setRows(20); + this.outputLogPane.setText(""); + this.outputLogPane.setEditable(false); + scrollPane.setViewportView(this.outputLogPane); + logPanel.add(scrollPane); + this.add(logPanel); + + // Menubar Panel + final JPanel menuBarPanel = new JPanel(); + // Initial Version + JLabel initialVersionLabel = new JLabel(); + initialVersionLabel.setText("Initial Version"); + menuBarPanel.add(initialVersionLabel); + + this.initialVersionBox = new JComboBox<>(); + initialVersionLabel.setLabelFor(this.initialVersionBox); + menuBarPanel.add(this.initialVersionBox); + + // Target Version + JLabel targetVersionsLabel = new JLabel(); + targetVersionsLabel.setText("Final Version"); + menuBarPanel.add(targetVersionsLabel); + + this.targetVersions = new JComboBox<>(); + targetVersionsLabel.setLabelFor(targetVersions); + menuBarPanel.add(this.targetVersions); + + // Add items to both ^ + String[] versions = Util.getSupportedVersions(GSON); + if (versions == null) { + throw new RuntimeException("Failed to get supported version, application possibly corrupt!"); + } + + if (versions.length > 0) { + for (String version : versions) { + initialVersionBox.addItem(version); + targetVersions.addItem(version); + } + targetVersions.setSelectedIndex(targetVersions.getItemCount() - 1); + } + + // Minify Checkbox + JLabel minifyCheckboxLabel = new JLabel(); + minifyCheckboxLabel.setText("Minify"); + menuBarPanel.add(minifyCheckboxLabel); + + this.minifyCheckBox = new JCheckBox(); + minifyCheckboxLabel.setLabelFor(this.minifyCheckBox); + menuBarPanel.add(this.minifyCheckBox); + + // Item Lighting Options + JLabel lightOptionsLabel = new JLabel(); + lightOptionsLabel.setText("Item Lighting"); + menuBarPanel.add(lightOptionsLabel); + + this.lightOptions = new JComboBox<>(); + lightOptionsLabel.setLabelFor(this.lightOptions); + menuBarPanel.add(this.lightOptions); + Arrays.stream((new String[]{"none", "front", "side"})).forEach(lightOptions::addItem); - convertButton.addActionListener(e -> { + + // Convert Button + this.convertButton = new JButton(); + this.convertButton.setText("Convert"); + this.convertButton.addActionListener(e -> { out = redirectSystemStreams(); String light = Objects.requireNonNull(lightOptions.getSelectedItem()).toString(); - int from = Util.getVersionProtocol(gson, Objects.requireNonNull(initialVersionBox.getSelectedItem()).toString()); - int to = Util.getVersionProtocol(gson, Objects.requireNonNull(targetVersions.getSelectedItem()).toString()); + int from = Util.getVersionProtocol(GSON, Objects.requireNonNull(initialVersionBox.getSelectedItem()).toString()); + int to = Util.getVersionProtocol(GSON, Objects.requireNonNull(targetVersions.getSelectedItem()).toString()); boolean minify = minifyCheckBox.isSelected(); new Thread(() -> { convertButton.setEnabled(false); try { - Gson packGson = gson; + Gson packGson = GSON; if (!minify) { - packGson = gson.newBuilder().setPrettyPrinting().create(); + packGson = packGson.newBuilder().setPrettyPrinting().create(); } Path dotPath = Paths.get("./"); @@ -57,6 +124,9 @@ public GUI() { convertButton.setEnabled(true); }).start(); }); + menuBarPanel.add(this.convertButton); + + this.add(menuBarPanel); } public static void main(String[] args) { @@ -70,91 +140,16 @@ public static void main(String[] args) { System.err.println("GTK look not supported, ignoring."); } - frame.setFocusable(true); Dimension dimensions = new Dimension(854, 480); - frame.setMaximumSize(dimensions); frame.setMinimumSize(dimensions); frame.setPreferredSize(dimensions); + frame.setFocusable(true); + frame.setResizable(false); frame.setLocationRelativeTo(null); // Centers window on screen frame.pack(); frame.setVisible(true); } - private void setupGUI(Gson gson) { - { - final JPanel panel = new JPanel(); - final JScrollPane scrollPane = new JScrollPane(); - this.outputLogPane = new JTextArea(); - this.outputLogPane.setColumns(60); - this.outputLogPane.setRows(20); - this.outputLogPane.setText(""); - this.outputLogPane.setEditable(false); - scrollPane.setViewportView(this.outputLogPane); - panel.add(scrollPane); - this.add(panel); - } - - { - final JPanel menuBar = new JPanel(); - // Initial Version - JLabel initialVersionLabel = new JLabel(); - initialVersionLabel.setText("Initial Version"); - menuBar.add(initialVersionLabel); - - this.initialVersionBox = new JComboBox<>(); - initialVersionLabel.setLabelFor(this.initialVersionBox); - menuBar.add(this.initialVersionBox); - - // Target Version - JLabel targetVersionsLabel = new JLabel(); - targetVersionsLabel.setText("Final Version"); - menuBar.add(targetVersionsLabel); - - this.targetVersions = new JComboBox<>(); - targetVersionsLabel.setLabelFor(targetVersions); - menuBar.add(this.targetVersions); - - // Add items to both ^ - String[] versions = Util.getSupportedVersions(gson); - if (versions == null) { - throw new RuntimeException("Failed to get supported version, application possibly corrupt!"); - } - - if (versions.length > 0) { - for (String version : versions) { - initialVersionBox.addItem(version); - targetVersions.addItem(version); - } - targetVersions.setSelectedIndex(targetVersions.getItemCount() - 1); - } - - // Minify Checkbox - JLabel minifyCheckboxLabel = new JLabel(); - minifyCheckboxLabel.setText("Minify"); - menuBar.add(minifyCheckboxLabel); - - this.minifyCheckBox = new JCheckBox(); - minifyCheckboxLabel.setLabelFor(this.minifyCheckBox); - menuBar.add(this.minifyCheckBox); - - // Item Lighting Options - JLabel lightOptionsLabel = new JLabel(); - lightOptionsLabel.setText("Item Lighting"); - menuBar.add(lightOptionsLabel); - - this.lightOptions = new JComboBox<>(); - lightOptionsLabel.setLabelFor(this.lightOptions); - menuBar.add(this.lightOptions); - - // Convert Button - this.convertButton = new JButton(); - this.convertButton.setText("Convert"); - menuBar.add(this.convertButton); - - this.add(menuBar); - } - } - private PrintStream redirectSystemStreams() { return new PrintStream(new OutputStream() { @Override From 7f40eeea8df5530d5d416bfab783167b4f7b6817 Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Mon, 10 Feb 2025 19:42:52 -0500 Subject: [PATCH 47/54] Make output log auto-scroll in GUI --- .../Gui/src/main/java/com/agentdid127/resourcepack/GUI.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java b/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java index 610d4bb2..47addb0f 100644 --- a/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java +++ b/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java @@ -9,6 +9,7 @@ import com.sun.java.swing.plaf.gtk.GTKLookAndFeel; import javax.swing.*; +import javax.swing.text.DefaultCaret; import java.awt.*; import java.io.OutputStream; import java.io.PrintStream; @@ -37,6 +38,7 @@ public GUI() { this.outputLogPane.setRows(20); this.outputLogPane.setText(""); this.outputLogPane.setEditable(false); + ((DefaultCaret) this.outputLogPane.getCaret()).setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); scrollPane.setViewportView(this.outputLogPane); logPanel.add(scrollPane); this.add(logPanel); From 170fe05be290ad690502b9d11fc70714d3157c5a Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Mon, 10 Feb 2025 19:47:41 -0500 Subject: [PATCH 48/54] Fix run error --- .../Gui/src/main/java/com/agentdid127/resourcepack/GUI.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java b/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java index 47addb0f..e550c344 100644 --- a/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java +++ b/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java @@ -6,7 +6,6 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.Strictness; -import com.sun.java.swing.plaf.gtk.GTKLookAndFeel; import javax.swing.*; import javax.swing.text.DefaultCaret; @@ -137,7 +136,7 @@ public static void main(String[] args) { frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); try { - UIManager.setLookAndFeel(new GTKLookAndFeel()); + UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); } catch (Exception ignored) { System.err.println("GTK look not supported, ignoring."); } From 540fb71a41d0b3ddc6e3859aa291a012e6b5c012 Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Mon, 10 Feb 2025 19:54:58 -0500 Subject: [PATCH 49/54] Add finished message & rename text in GUI --- .../com/agentdid127/resourcepack/GUI.java | 22 +++++++++---------- .../resourcepack/library/pack/ZipPack.java | 1 + 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java b/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java index e550c344..8add09d7 100644 --- a/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java +++ b/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java @@ -22,7 +22,7 @@ public class GUI extends JPanel { private PrintStream out; private final JTextArea outputLogPane; - private final JComboBox initialVersionBox; + private final JComboBox baseVersions; private final JComboBox targetVersions; private final JCheckBox minifyCheckBox; private final JComboBox lightOptions; @@ -44,18 +44,18 @@ public GUI() { // Menubar Panel final JPanel menuBarPanel = new JPanel(); - // Initial Version - JLabel initialVersionLabel = new JLabel(); - initialVersionLabel.setText("Initial Version"); - menuBarPanel.add(initialVersionLabel); + // Base Version + JLabel baseVersionLabel = new JLabel(); + baseVersionLabel.setText("Base Version"); + menuBarPanel.add(baseVersionLabel); - this.initialVersionBox = new JComboBox<>(); - initialVersionLabel.setLabelFor(this.initialVersionBox); - menuBarPanel.add(this.initialVersionBox); + this.baseVersions = new JComboBox<>(); + baseVersionLabel.setLabelFor(this.baseVersions); + menuBarPanel.add(this.baseVersions); // Target Version JLabel targetVersionsLabel = new JLabel(); - targetVersionsLabel.setText("Final Version"); + targetVersionsLabel.setText("Target Version"); menuBarPanel.add(targetVersionsLabel); this.targetVersions = new JComboBox<>(); @@ -70,7 +70,7 @@ public GUI() { if (versions.length > 0) { for (String version : versions) { - initialVersionBox.addItem(version); + baseVersions.addItem(version); targetVersions.addItem(version); } targetVersions.setSelectedIndex(targetVersions.getItemCount() - 1); @@ -102,7 +102,7 @@ public GUI() { this.convertButton.addActionListener(e -> { out = redirectSystemStreams(); String light = Objects.requireNonNull(lightOptions.getSelectedItem()).toString(); - int from = Util.getVersionProtocol(GSON, Objects.requireNonNull(initialVersionBox.getSelectedItem()).toString()); + int from = Util.getVersionProtocol(GSON, Objects.requireNonNull(baseVersions.getSelectedItem()).toString()); int to = Util.getVersionProtocol(GSON, Objects.requireNonNull(targetVersions.getSelectedItem()).toString()); boolean minify = minifyCheckBox.isSelected(); new Thread(() -> { diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/pack/ZipPack.java b/library/src/main/java/com/agentdid127/resourcepack/library/pack/ZipPack.java index 46755d0c..34e91d72 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/pack/ZipPack.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/pack/ZipPack.java @@ -86,6 +86,7 @@ public void finish() throws IOException { Logger.log("Deleting working directory"); FileUtil.deleteDirectoryAndContents(pack.getWorkingPath()); + Logger.log("Finished!"); } @Override From c0d10f347a4d9f18b3d7e7d30bf1d76316922d2c Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Tue, 11 Feb 2025 01:47:15 -0500 Subject: [PATCH 50/54] Some changes, I forgor --- .../com/agentdid127/resourcepack/GUI.java | 7 ++--- .../textures/ParticlesSlicerConverter.java | 2 +- .../MobEffectAtlasSlicerConverter1_14.java | 7 +---- .../PaintingSlicerConverter1_14_4.java | 7 +---- .../textures/GuiSlicerConverter1_20_2.java | 11 ++++++-- .../MapIconSlicerConverter1_20_5.java | 3 +-- .../resourcepack/library/pack/ZipPack.java | 4 +-- .../utilities/slicing/PredicateRunnable.java | 3 +-- .../library/utilities/slicing/Slicer.java | 26 +++++-------------- 9 files changed, 25 insertions(+), 45 deletions(-) diff --git a/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java b/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java index 8add09d7..a66d52fa 100644 --- a/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java +++ b/Applications/Gui/src/main/java/com/agentdid127/resourcepack/GUI.java @@ -48,7 +48,6 @@ public GUI() { JLabel baseVersionLabel = new JLabel(); baseVersionLabel.setText("Base Version"); menuBarPanel.add(baseVersionLabel); - this.baseVersions = new JComboBox<>(); baseVersionLabel.setLabelFor(this.baseVersions); menuBarPanel.add(this.baseVersions); @@ -57,7 +56,6 @@ public GUI() { JLabel targetVersionsLabel = new JLabel(); targetVersionsLabel.setText("Target Version"); menuBarPanel.add(targetVersionsLabel); - this.targetVersions = new JComboBox<>(); targetVersionsLabel.setLabelFor(targetVersions); menuBarPanel.add(this.targetVersions); @@ -66,13 +64,12 @@ public GUI() { String[] versions = Util.getSupportedVersions(GSON); if (versions == null) { throw new RuntimeException("Failed to get supported version, application possibly corrupt!"); - } - - if (versions.length > 0) { + } else if (versions.length > 0) { for (String version : versions) { baseVersions.addItem(version); targetVersions.addItem(version); } + targetVersions.setSelectedIndex(targetVersions.getItemCount() - 1); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/textures/ParticlesSlicerConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/textures/ParticlesSlicerConverter.java index 22c161df..1aae5750 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/textures/ParticlesSlicerConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/textures/ParticlesSlicerConverter.java @@ -72,7 +72,7 @@ public void convert(Pack pack) throws IOException { if (from <= Util.getVersionProtocol(gson, "1.13.2") && to >= Util.getVersionProtocol(gson, "1.14")) { - Slicer.runSlicer(gson, slice, particlePath, new GuiSlicerConverter1_20_2.GuiPredicateRunnable(), from, false); + Slicer.run(gson, slice, particlePath, new GuiSlicerConverter1_20_2.GuiPredicateRunnable(gson), from, false); Path entityPath = texturesPath.resolve("entity"); Path newFishingHookPath = entityPath.resolve("fishing_hook.png"); if (newFishingHookPath.toFile().exists()) { diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_14/textures/MobEffectAtlasSlicerConverter1_14.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_14/textures/MobEffectAtlasSlicerConverter1_14.java index 709508fb..2de236f6 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_14/textures/MobEffectAtlasSlicerConverter1_14.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_14/textures/MobEffectAtlasSlicerConverter1_14.java @@ -37,10 +37,6 @@ public boolean shouldConvert(Gson gson, int from, int to) { @Override public void convert(Pack pack) throws IOException { Path texturesPath = pack.getWorkingPath().resolve("assets/minecraft/textures".replace("/", File.separator)); - if (!texturesPath.toFile().exists()) { - return; - } - Path inventoryPath = texturesPath.resolve("gui/container/inventory.png".replace("/", File.separator)); if (!inventoryPath.toFile().exists()) { return; @@ -49,8 +45,7 @@ public void convert(Pack pack) throws IOException { Gson gson = packConverter.getGson(); JsonObject effectJson = JsonUtil.readJsonResource(gson, "/forwards/mob_effect.json", JsonObject.class); if (effectJson != null) { - Slice slice = Slice.parse(effectJson); - Slicer.runSlicer(gson, slice, texturesPath, new GuiSlicerConverter1_20_2.GuiPredicateRunnable(), from, false); + Slicer.run(gson, Slice.parse(effectJson), texturesPath, new GuiSlicerConverter1_20_2.GuiPredicateRunnable(gson), from, false); } } } \ No newline at end of file diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_14/textures/PaintingSlicerConverter1_14_4.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_14/textures/PaintingSlicerConverter1_14_4.java index 28b1d123..ceeb600f 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_14/textures/PaintingSlicerConverter1_14_4.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_14/textures/PaintingSlicerConverter1_14_4.java @@ -34,10 +34,6 @@ public boolean shouldConvert(Gson gson, int from, int to) { @Override public void convert(Pack pack) throws IOException { Path texturesPath = pack.getWorkingPath().resolve("assets/minecraft/textures".replace("/", File.separator)); - if (!texturesPath.toFile().exists()) { - return; - } - Path paintingPath = texturesPath.resolve("painting"); if (!paintingPath.toFile().exists()) { return; @@ -46,8 +42,7 @@ public void convert(Pack pack) throws IOException { Gson gson = packConverter.getGson(); JsonObject effectJson = JsonUtil.readJsonResource(gson, "/forwards/paintings_kristoffer_zetterstrand.json", JsonObject.class); if (effectJson != null) { - Slice slice = Slice.parse(effectJson); - Slicer.runSlicer(gson, slice, paintingPath, (gson1, from, predicate) -> true, -1, false); + Slicer.run(gson, Slice.parse(effectJson), paintingPath, (from, predicate) -> true, -1, false); } } } \ No newline at end of file diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/GuiSlicerConverter1_20_2.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/GuiSlicerConverter1_20_2.java index 3db9f106..4fc687ef 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/GuiSlicerConverter1_20_2.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/GuiSlicerConverter1_20_2.java @@ -49,14 +49,21 @@ public void convert(Pack pack) throws IOException { if (array != null) { Logger.addTab(); for (Slice slice : Slice.parseArray(array)) { - Slicer.runSlicer(gson, slice, guiPath, new GuiPredicateRunnable(), from, true); + Slicer.run(gson, slice, guiPath, new GuiPredicateRunnable(gson), from, true); } Logger.subTab(); } } public static class GuiPredicateRunnable implements PredicateRunnable { - public boolean run(Gson gson, int from, JsonObject predicate) { + private final Gson gson; + + public GuiPredicateRunnable(Gson gson) { + this.gson = gson; + } + + @Override + public boolean run(int from, JsonObject predicate) { if (predicate.has("protocol")) { JsonObject protocol = predicate.getAsJsonObject("protocol"); diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/MapIconSlicerConverter1_20_5.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/MapIconSlicerConverter1_20_5.java index 1b87ecdf..96e89d30 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/MapIconSlicerConverter1_20_5.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_20/textures/MapIconSlicerConverter1_20_5.java @@ -38,8 +38,7 @@ public void convert(Pack pack) throws IOException { Gson gson = packConverter.getGson(); JsonObject mapIconsJson = JsonUtil.readJsonResource(gson, "/forwards/map_icons.json", JsonObject.class); if (mapIconsJson != null) { - Slice slice = Slice.parse(mapIconsJson); - Slicer.runSlicer(gson, slice, mapIconsPath, new GuiSlicerConverter1_20_2.GuiPredicateRunnable(), from, false); + Slicer.run(gson, Slice.parse(mapIconsJson), mapIconsPath, new GuiSlicerConverter1_20_2.GuiPredicateRunnable(gson), from, false); } } } diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/pack/ZipPack.java b/library/src/main/java/com/agentdid127/resourcepack/library/pack/ZipPack.java index 34e91d72..40688214 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/pack/ZipPack.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/pack/ZipPack.java @@ -74,7 +74,7 @@ public void setup() throws IOException { @Override public void finish() throws IOException { try { - Logger.log("Zipping working directory"); + Logger.debug("Zipping working directory"); ZipFile zipFile = new ZipFile(getConvertedZipPath().toFile()); ZipParameters parameters = new ZipParameters(); parameters.setIncludeRootFolder(false); @@ -84,7 +84,7 @@ public void finish() throws IOException { Util.propagate(e); } - Logger.log("Deleting working directory"); + Logger.debug("Deleting working directory"); FileUtil.deleteDirectoryAndContents(pack.getWorkingPath()); Logger.log("Finished!"); } diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/PredicateRunnable.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/PredicateRunnable.java index 66053e69..e1d08388 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/PredicateRunnable.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/PredicateRunnable.java @@ -1,8 +1,7 @@ package com.agentdid127.resourcepack.library.utilities.slicing; -import com.google.gson.Gson; import com.google.gson.JsonObject; public interface PredicateRunnable { - boolean run(Gson gson, int from, JsonObject predicate); + boolean run(int from, JsonObject predicate); } diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/Slicer.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/Slicer.java index b886b4a8..e1b7e68c 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/Slicer.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/slicing/Slicer.java @@ -11,8 +11,8 @@ import java.nio.file.Path; public class Slicer { - public static void runSlicer(Gson gson, Slice slice, Path root, /* nullable */ PredicateRunnable predicateRunnable, int from, boolean has_metadata) throws IOException { - if (predicateRunnable != null && !predicateRunnable.run(gson, from, slice.getPredicate())) { + public static void run(Gson gson, Slice slice, Path root, /* nullable */ PredicateRunnable predicateRunnable, int from, boolean has_metadata) throws IOException { + if (predicateRunnable != null && !predicateRunnable.run(from, slice.getPredicate())) { return; } @@ -40,25 +40,15 @@ public static void runSlicer(Gson gson, Slice slice, Path root, /* nullable */ P } FileUtil.ensureParentExists(texturePath); - if (predicateRunnable != null && !predicateRunnable.run(gson, from, texture.getPredicate())) { + if (predicateRunnable != null && !predicateRunnable.run(from, texture.getPredicate())) { continue; } try { Box box = texture.getBox(); - converter.saveSlice( - box.getX(), - box.getY(), - box.getWidth(), - box.getHeight(), - texturePath); - + converter.saveSlice(box.getX(), box.getY(), box.getWidth(), box.getHeight(), texturePath); if (texture.shouldRemove()) { - converter.fillEmpty( - box.getX(), - box.getY(), - box.getWidth(), - box.getHeight()); + converter.fillEmpty(box.getX(), box.getY(), box.getWidth(), box.getHeight()); } if (has_metadata) { @@ -69,10 +59,8 @@ public static void runSlicer(Gson gson, Slice slice, Path root, /* nullable */ P } } } catch (Exception exception) { - Logger.log("Failed to slice texture '" + texture.getPath() + "' (error='" - + exception.getLocalizedMessage() + "')"); - Logger.log(" - box: (x=" + texture.getBox().getX() + ", y=" + texture.getBox().getY() + ", width=" - + texture.getBox().getWidth() + ", height=" + texture.getBox().getHeight() + ")"); + Logger.log("Failed to slice texture '" + texture.getPath() + "' (error='" + exception.getLocalizedMessage() + "')"); + Logger.log(" - box: (x=" + texture.getBox().getX() + ", y=" + texture.getBox().getY() + ", width=" + texture.getBox().getWidth() + ", height=" + texture.getBox().getHeight() + ")"); } } From 3222e51dbcf62105bade6f9e6bfbb6edaed9468b Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Wed, 12 Feb 2025 17:51:38 -0500 Subject: [PATCH 51/54] Make Image Colorzing Accurate --- .../impl/textures/WaterConverter.java | 6 ++--- .../v1_15/textures/EnchantConverter1_15.java | 2 +- .../library/utilities/ImageConverter.java | 25 ++++++------------- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/WaterConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/WaterConverter.java index 885302cf..748abfc7 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/WaterConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/WaterConverter.java @@ -27,8 +27,8 @@ public void convert(Pack pack) throws IOException { Path blocksFolder = pack.getWorkingPath().resolve("assets/minecraft/textures/blocks".replace("/", File.separator)); if (blocksFolder.toFile().exists()) { colorize(blocksFolder.resolve("water_flow.png"), 32, 1024); - colorize(blocksFolder.resolve("water_still.png"), 32, 1024); - colorize(blocksFolder.resolve("water_overlay.png"), 32, 32); + colorize(blocksFolder.resolve("water_still.png"), 16, 512); + colorize(blocksFolder.resolve("water_overlay.png"), 16, 16); } } @@ -37,7 +37,7 @@ private void colorize(Path path, int w, int h) throws IOException { ImageConverter imageConverter = new ImageConverter(w, h, path); if (imageConverter.fileIsPowerOfTwo()) { imageConverter.newImage(w, h); - imageConverter.colorize(new Color(45, 63, 244, 170)); + imageConverter.colorizeGrayscale(new Color(45, 63, 244)); imageConverter.store(); } } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_15/textures/EnchantConverter1_15.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_15/textures/EnchantConverter1_15.java index 70688a0b..cb7ea660 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_15/textures/EnchantConverter1_15.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_15/textures/EnchantConverter1_15.java @@ -32,7 +32,7 @@ public void convert(Pack pack) throws IOException { ImageConverter imageConverter = new ImageConverter(64, 64, itemGlintPath); if (imageConverter.fileIsPowerOfTwo()) { imageConverter.newImage(64, 64); - imageConverter.colorize(new Color(94, 9, 178, 120)); + imageConverter.colorizeGrayscale(new Color(128, 64, 204)); imageConverter.store(); } } diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/ImageConverter.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/ImageConverter.java index 8d84bd0c..6fc0f316 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/ImageConverter.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/ImageConverter.java @@ -236,34 +236,23 @@ public void subImageSized(int x, int y, int width, int height) { subImage(x, y, x + width, y + height, 0, 0); } - /** - * Recolor the entire image. - * - * @param color - */ - public void colorize(Color color) { - g2d.setPaint(color); - g2d.drawImage(image, 0, 0, null); - g2d.fillRect(0, 0, newImage.getWidth(), newImage.getHeight()); - } - /** * Recolor the grayscale image. * * @param color */ - public void colorizeClipped(Color color) { + public void colorizeGrayscale(Color color) { this.newImage(this.getWidth(), this.getHeight()); this.g2d.drawImage(this.image, 0, 0, null); for (int y = 0; y < this.getHeight(); y++) { for (int x = 0; x < this.getWidth(); x++) { - int imageRGBA = newImage.getRGB(x, y); - int alpha = (imageRGBA >> 24) & 0xFF; + int rgba = this.newImage.getRGB(x, y); + int alpha = (rgba >> 24) & 0xFF; if (alpha == 0) { continue; } - int grayscaleValue = (imageRGBA >> 16) & 0xFF; + int grayscaleValue = (rgba >> 16) & 0xFF; int red = (grayscaleValue * color.getRed()) / 255; int green = (grayscaleValue * color.getGreen()) / 255; int blue = (grayscaleValue * color.getBlue()) / 255; @@ -276,8 +265,8 @@ public void colorizeClipped(Color color) { * Grayscale the image using the NTSC grayscale formula */ public void grayscale() { - BufferedImage gray = new BufferedImage(newImage.getWidth(), newImage.getHeight(), BufferedImage.TYPE_INT_ARGB); - gray.createGraphics().drawImage(image, 0, 0, null); + BufferedImage gray = new BufferedImage(this.newImage.getWidth(), this.newImage.getHeight(), BufferedImage.TYPE_INT_ARGB); + gray.createGraphics().drawImage(this.image, 0, 0, null); for (int y = 0; y < gray.getHeight(); y++) { for (int x = 0; x < gray.getWidth(); x++) { int rgba = gray.getRGB(x, y); @@ -289,7 +278,7 @@ public void grayscale() { gray.setRGB(x, y, (alpha << 24) | (average << 16) | (average << 8) | average); } } - newImage = gray; + this.newImage = gray; } /** From 6d8154d597afebf9bce9b955b427ec71cf8584f3 Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Wed, 12 Feb 2025 19:41:48 -0500 Subject: [PATCH 52/54] Fix sizing issue with colorizeGrayscale --- .../resourcepack/backwards/impl/textures/WaterConverter.java | 1 - .../forwards/impl/v1_15/textures/EnchantConverter1_15.java | 1 - .../resourcepack/library/utilities/ImageConverter.java | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/WaterConverter.java b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/WaterConverter.java index 748abfc7..32ffee4c 100644 --- a/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/WaterConverter.java +++ b/conversions/Backwards/src/main/java/com/agentdid127/resourcepack/backwards/impl/textures/WaterConverter.java @@ -36,7 +36,6 @@ private void colorize(Path path, int w, int h) throws IOException { if (path.toFile().exists()) { ImageConverter imageConverter = new ImageConverter(w, h, path); if (imageConverter.fileIsPowerOfTwo()) { - imageConverter.newImage(w, h); imageConverter.colorizeGrayscale(new Color(45, 63, 244)); imageConverter.store(); } diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_15/textures/EnchantConverter1_15.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_15/textures/EnchantConverter1_15.java index cb7ea660..d2e42892 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_15/textures/EnchantConverter1_15.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/v1_15/textures/EnchantConverter1_15.java @@ -31,7 +31,6 @@ public void convert(Pack pack) throws IOException { ImageConverter imageConverter = new ImageConverter(64, 64, itemGlintPath); if (imageConverter.fileIsPowerOfTwo()) { - imageConverter.newImage(64, 64); imageConverter.colorizeGrayscale(new Color(128, 64, 204)); imageConverter.store(); } diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/ImageConverter.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/ImageConverter.java index 6fc0f316..eb808a31 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/ImageConverter.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/ImageConverter.java @@ -242,7 +242,7 @@ public void subImageSized(int x, int y, int width, int height) { * @param color */ public void colorizeGrayscale(Color color) { - this.newImage(this.getWidth(), this.getHeight()); + this.newImage(this.defaultW, this.defaultH); this.g2d.drawImage(this.image, 0, 0, null); for (int y = 0; y < this.getHeight(); y++) { for (int x = 0; x < this.getWidth(); x++) { From f5d1ea00a59c949246c7bc36ca3422dccde36cc8 Mon Sep 17 00:00:00 2001 From: Cory Borek Date: Fri, 23 May 2025 21:32:07 -0400 Subject: [PATCH 53/54] add custommodeldata migration --- .../forwards/impl/other/ModelConverter.java | 157 ++++++++++++++++++ 1 file changed, 157 insertions(+) diff --git a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/ModelConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/ModelConverter.java index 5ed6ce31..f930faf5 100644 --- a/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/ModelConverter.java +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/other/ModelConverter.java @@ -1,5 +1,6 @@ package com.agentdid127.resourcepack.forwards.impl.other; +import com.agentdid127.resourcepack.forwards.ForwardsPackConverter; import com.agentdid127.resourcepack.library.Converter; import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.pack.Pack; @@ -24,11 +25,14 @@ public class ModelConverter extends Converter { private final int to; protected String light = "none"; + private Pack pack; + public ModelConverter(PackConverter packConverter, String light, int from, int to) { super(packConverter); this.light = light; this.from = from; this.to = to; + pack = null; } @Override @@ -44,6 +48,7 @@ public boolean shouldConvert(Gson gson, int from, int to) { */ @Override public void convert(Pack pack) throws IOException { + this.pack = pack; Path models = pack.getWorkingPath().resolve("assets/minecraft/models".replace("/", File.separator)); if (models.toFile().exists()) { Logger.addTab(); @@ -280,6 +285,28 @@ protected void remapModelJson(Path rootPath, Path model) throws IOException { } } + + // New Override System for 1.21.4+ + if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.21.4") + && from < Util.getVersionProtocol(packConverter.getGson(), "1.21.4")) { + + // Check for new overrides + if (jsonObject.has("overrides")) { + JsonArray overridesArray = jsonObject.get("overrides").getAsJsonArray(); + + // Convert damages, and model data + if (isDamageModel(overridesArray)) { + createDamageModel(overridesArray, model); + } else if (isCustomModelData(overridesArray)) { + createCustomModelData(overridesArray, model); + } + + // remove old damages + jsonObject.remove("overrides"); + } + } + + if (!JsonUtil.readJson(packConverter.getGson(), model).equals(jsonObject)) { Logger.debug("Updating Model: " + model.getFileName()); JsonUtil.writeJson(packConverter.getGson(), model, jsonObject); @@ -291,6 +318,136 @@ protected void remapModelJson(Path rootPath, Path model) throws IOException { } } + /** + * Creates a Damage-based item in the new directory for 1.21.4+ + * + * @param overrides overrides system from old model + * @param original original model file + * @throws IOException if we can't save the new file. + */ + private void createDamageModel(JsonArray overrides, Path original) throws IOException { + if (pack == null) return; + Path itemsPath = pack.getWorkingPath().resolve("assets/minecraft/items"); + if (!itemsPath.toFile().exists()) { + itemsPath.toFile().mkdirs(); + } + + JsonObject out = new JsonObject(); + JsonObject model = new JsonObject(); + model.addProperty("type", "range_dispatch"); + model.addProperty("property", "damage"); + + JsonObject fallback = new JsonObject(); + fallback.addProperty("type", "model"); + + fallback.addProperty("model", original.toFile().getAbsolutePath().replace(pack.getWorkingPath().resolve("assets/minecraft/models").toFile().getAbsolutePath() + "/", "").replace(".json", "")); + model.add("fallback", fallback); + + + // iterate through old override entries, and migrate to new file. + JsonArray entries = new JsonArray(); + for (JsonElement override : overrides) { + JsonObject entry = new JsonObject(); + if (override.isJsonObject()) { + double damage = override.getAsJsonObject().get("predicate").getAsJsonObject().get("damage").getAsDouble(); + String entryModel = override.getAsJsonObject().get("model").getAsString(); + + entry.addProperty("threshold", damage); + JsonObject modelEntry = new JsonObject(); + modelEntry.addProperty("model", entryModel); + modelEntry.addProperty("type", "model"); + entry.add("model", modelEntry); + entries.add(entry); + } + } + + model.add("entries", entries); + out.add("model", model); + + JsonUtil.writeJson(packConverter.getGson(), itemsPath.resolve(original.toFile().getName()), out); + } + + + /** + * Creates a Custom Model Data based item in the 1.21.4+ format. + * + * @param overrides old overrides + * @param original original model file path + * @throws IOException if we can't save the new file. + */ + private void createCustomModelData(JsonArray overrides, Path original) throws IOException { + if (pack == null) return; + Path itemsPath = pack.getWorkingPath().resolve("assets/minecraft/items"); + if (!itemsPath.toFile().exists()) { + itemsPath.toFile().mkdirs(); + } + + JsonObject out = new JsonObject(); + JsonObject model = new JsonObject(); + model.addProperty("type", "range_dispatch"); + model.addProperty("property", "custom_model_data"); + + JsonObject fallback = new JsonObject(); + fallback.addProperty("type", "model"); + fallback.addProperty("model", original.toFile().getAbsolutePath().replace(pack.getWorkingPath().resolve("assets/minecraft/models").toFile().getAbsolutePath() + "/", "").replace(".json", "")); + model.add("fallback", fallback); + + JsonArray entries = new JsonArray(); + for (JsonElement override : overrides) { + JsonObject entry = new JsonObject(); + if (override.isJsonObject()) { + long customModelData = override.getAsJsonObject().get("predicate").getAsJsonObject().get("custom_model_data").getAsLong(); + String entryModel = override.getAsJsonObject().get("model").getAsString(); + + entry.addProperty("threshold", customModelData); + JsonObject modelEntry = new JsonObject(); + modelEntry.addProperty("model", entryModel); + modelEntry.addProperty("type", "model"); + entry.add("model", modelEntry); + entries.add(entry); + } + } + model.add("entries", entries); + out.add("model", model); + + JsonUtil.writeJson(packConverter.getGson(), itemsPath.resolve(original.toFile().getName()), out); + } + + /** + * Checks if overrides is damage-based + * + * @param overrides old overrides model + * @return {@code true} if it is a damage-based model + */ + private boolean isDamageModel(JsonArray overrides) { + for (JsonElement override : overrides) { + if (override instanceof JsonObject && override.getAsJsonObject().has("predicate")) { + JsonObject predicate = override.getAsJsonObject().get("predicate").getAsJsonObject(); + if (predicate.has("damage") && !predicate.has("custom_model_data")) { + return true; + } + } + } + return false; + } + + /** + * Checks if overrides is CustomModelData-based + * + * @param overrides old overrides model + * @return {@code true} if it is a CustomModelData-based model + */ + private boolean isCustomModelData(JsonArray overrides) { + for (JsonElement override : overrides) { + if (override instanceof JsonObject && override.getAsJsonObject().has("predicate")) { + JsonObject predicate = override.getAsJsonObject().get("predicate").getAsJsonObject(); + if (!predicate.has("damage") && predicate.has("custom_model_data")) { + return true; + } + } + } + return false; + } /** * Gets parent object and sets a new one * From 47b9d585a7cc4920c8e60de781a78f139cf88a31 Mon Sep 17 00:00:00 2001 From: lowercasebtw Date: Fri, 27 Jun 2025 22:04:26 -0400 Subject: [PATCH 54/54] Update to 1.21.5/6/7 --- library/src/main/resources/protocol.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/library/src/main/resources/protocol.json b/library/src/main/resources/protocol.json index 4944f2c5..1c48eea3 100644 --- a/library/src/main/resources/protocol.json +++ b/library/src/main/resources/protocol.json @@ -338,5 +338,17 @@ "1.21.4": { "protocol_version": 769, "pack_format": 46 + }, + "1.21.5": { + "protocol_version": 770, + "pack_format": 55 + }, + "1.21.6": { + "protocol_version": 771, + "pack_format": 63 + }, + "1.21.7": { + "protocol_version": 772, + "pack_format": 64 } } \ No newline at end of file