diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index c7925abe..442b043b 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -1,67 +1,67 @@ -# This is a basic workflow to help you get started with Actions - -name: CI - -# Controls when the action will run. Triggers the workflow on push or pull request -# events but only for the master branch -on: - push: - branches: [prerelease ] - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - name: Checkout code - uses: actions/checkout@v2 - - name: Set up Java - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - name: "Get Information" - run: | - echo 'VERSION='$(cat pom.xml | grep "^ .*$" | awk -F'[><]' '{print $3}')'-pre' >> $GITHUB_ENV - echo 'VERSIONID='$(cat pom.xml | grep "^ .*$" | awk -F'[><]' '{print $3}')'' >> $GITHUB_ENV - - name: Create Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token - with: - tag_name: ${{ env.VERSION }} - release_name: Prerelease ${{ env.VERSION }} - body: | - Prerelease Automatically Generated by software... Please change draft to add changelog. - draft: true - prerelease: true - # Runs a single command using the runners shell - - name: Build Software - run: mvn clean install - - # Runs a set of commands using the runners shell - - name: Upload Console Release - id: upload-console-release - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps - asset_path: ./Applications/Console/target/ResourcePackConverter-Console-${{ env.VERSION }}.jar - asset_name: ResourcePackConverter.jar - asset_content_type: application/zip - - name: Upload GUI Release - id: upload-gui-release - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps - asset_path: ./Applications/Gui/target/ResourcePackConverter-Gui-${{ env.VERSION }}.jar - asset_name: ResourcePackConverter-Gui-${{ env.VERSION }}.jar - asset_content_type: application/zip +# This is a basic workflow to help you get started with Actions + +name: CI + +# Controls when the action will run. Triggers the workflow on push or pull request +# events but only for the master branch +on: + push: + branches: [prerelease ] + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - name: Checkout code + uses: actions/checkout@v2 + - name: Set up Java + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: "Get Information" + run: | + echo 'VERSION='$(cat pom.xml | grep "^ .*$" | awk -F'[><]' '{print $3}')'-pre' >> $GITHUB_ENV + echo 'VERSIONID='$(cat pom.xml | grep "^ .*$" | awk -F'[><]' '{print $3}')'' >> $GITHUB_ENV + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token + with: + tag_name: ${{ env.VERSION }} + release_name: Prerelease ${{ env.VERSIONID }} + body: | + Prerelease Automatically Generated by software... Please change draft to add changelog. + draft: true + prerelease: true + # Runs a single command using the runners shell + - name: Build Software + run: mvn clean install + + # Runs a set of commands using the runners shell + - name: Upload Console Release + id: upload-console-release + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps + asset_path: ./Applications/Console/target/ResourcePackConverter-Console-${{ env.VERSIONID }}.jar + asset_name: ResourcePackConverter.jar + asset_content_type: application/zip + - name: Upload GUI Release + id: upload-gui-release + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps + asset_path: ./Applications/Gui/target/ResourcePackConverter-Gui-${{ env.VERSIONID }}.jar + asset_name: ResourcePackConverter-Gui-${{ env.VERSION }}.jar + asset_content_type: application/zip diff --git a/Applications/Console/pom.xml b/Applications/Console/pom.xml index 8e325bd8..a63d637e 100644 --- a/Applications/Console/pom.xml +++ b/Applications/Console/pom.xml @@ -5,7 +5,7 @@ Applications com.agentdid127.resourcepack - 2.2.2 + 2.2.3 4.0.0 diff --git a/Applications/Gui/pom.xml b/Applications/Gui/pom.xml index 2d9b7c77..914955b9 100644 --- a/Applications/Gui/pom.xml +++ b/Applications/Gui/pom.xml @@ -5,7 +5,7 @@ Applications com.agentdid127.resourcepack - 2.2.2 + 2.2.3 4.0.0 diff --git a/Applications/pom.xml b/Applications/pom.xml index 32ff2dce..da810774 100644 --- a/Applications/pom.xml +++ b/Applications/pom.xml @@ -5,7 +5,7 @@ ResourcePackConverter com.agentdid127 - 2.2.2 + 2.2.3 4.0.0 @@ -33,12 +33,12 @@ com.agentdid127.resourcepack Forwards - 2.2.2 + 2.2.3 com.agentdid127.resourcepack Backwards - 2.2.2 + 2.2.3 diff --git a/README.MD b/README.MD index 2b137986..865a2345 100644 --- a/README.MD +++ b/README.MD @@ -2,7 +2,7 @@ [![](https://jitpack.io/v/agentdid127/ResourcePackConverter.svg)](https://jitpack.io/#agentdid127/ResourcePackConverter) -This is my fork of Hypixel's Resource Pack Converter. It updates to any newer version from 1.8.x - 1.17 +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. diff --git a/conversions/Backwards/pom.xml b/conversions/Backwards/pom.xml index 5edc5751..ce96aea5 100644 --- a/conversions/Backwards/pom.xml +++ b/conversions/Backwards/pom.xml @@ -5,7 +5,7 @@ conversions com.agentdid127.resourcepack - 2.2.2 + 2.2.3 4.0.0 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 e937134c..06509c7b 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 @@ -6,6 +6,7 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.Util; import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.Logger; import com.google.gson.GsonBuilder; import java.io.IOException; @@ -17,77 +18,90 @@ public class BackwardsPackConverter extends PackConverter { Path INPUT_DIR; - public BackwardsPackConverter(String from, String to, String light, boolean minify, Path input, boolean debug, PrintStream out) { + public BackwardsPackConverter(String from, String to, String light, boolean minify, Path input, boolean debug, + PrintStream out) { GsonBuilder gsonBuilder = new GsonBuilder().disableHtmlEscaping(); if (!minify) gsonBuilder.setPrettyPrinting(); gson = gsonBuilder.create(); DEBUG = debug; - PackConverter.out = out; + Logger.setStream(out); + Logger.log(from); + Logger.log(to); this.INPUT_DIR = input; - log(from); - log(to); converterRunner(from, to, light); } protected void converterRunner(String from, String to, String light) { // this needs to be run first, other converters might reference new directory // names - this.registerConverter(new NameConverter(this, Util.getVersionProtocol(gson, from), Util.getVersionProtocol(gson, to))); - + this.registerConverter( + new NameConverter(this, Util.getVersionProtocol(gson, from), Util.getVersionProtocol(gson, to))); + this.registerConverter(new PackMetaConverter(this, Util.getVersionProtocol(gson, to))); - - this.registerConverter(new DeleteFileConverter(this, Util.getVersionProtocol(gson, from), Util.getVersionProtocol(gson, to))); + + this.registerConverter( + new DeleteFileConverter(this, Util.getVersionProtocol(gson, from), Util.getVersionProtocol(gson, to))); // TODO: backwards title converter for going from 1.20 to anything below - if (Util.getVersionProtocol(gson, from) >= Util.getVersionProtocol(gson, "1.19.4") && Util.getVersionProtocol(gson, to) < Util.getVersionProtocol(gson, "1.19.4")) + if (Util.getVersionProtocol(gson, from) >= Util.getVersionProtocol(gson, "1.19.4") + && Util.getVersionProtocol(gson, to) < Util.getVersionProtocol(gson, "1.19.4")) this.registerConverter(new EnchantPathConverter(this)); - if (Util.getVersionProtocol(gson, from) > Util.getVersionProtocol(gson, "1.18") && Util.getVersionProtocol(gson, to) <= Util.getVersionProtocol(gson, "1.18")) { + if (Util.getVersionProtocol(gson, from) > Util.getVersionProtocol(gson, "1.18") + && Util.getVersionProtocol(gson, to) <= Util.getVersionProtocol(gson, "1.18")) { this.registerConverter(new ParticleConverter(this)); this.registerConverter(new InventoryConverter(this)); } - if (Util.getVersionProtocol(gson, from) >= Util.getVersionProtocol(gson, "1.13") && Util.getVersionProtocol(gson, to) <= Util.getVersionProtocol(gson, "1.14.4")) + if (Util.getVersionProtocol(gson, from) >= Util.getVersionProtocol(gson, "1.13") + && Util.getVersionProtocol(gson, to) <= Util.getVersionProtocol(gson, "1.14.4")) this.registerConverter(new PaintingConverter(this)); - if (Util.getVersionProtocol(gson, from) > Util.getVersionProtocol(gson, "1.15") && Util.getVersionProtocol(gson, to) <= Util.getVersionProtocol(gson, "1.15")) { + if (Util.getVersionProtocol(gson, from) > Util.getVersionProtocol(gson, "1.15") + && Util.getVersionProtocol(gson, to) <= Util.getVersionProtocol(gson, "1.15")) { this.registerConverter(new EnchantConverter(this)); this.registerConverter(new ChestConverter(this)); } - this.registerConverter(new ParticleTextureConverter(this, Util.getVersionProtocol(gson, from), Util.getVersionProtocol(gson, to))); + this.registerConverter(new ParticleTextureConverter(this, Util.getVersionProtocol(gson, from), + Util.getVersionProtocol(gson, to))); if (Util.getVersionProtocol(gson, to) <= Util.getVersionProtocol(gson, "1.13")) this.registerConverter(new LangConverter(this, from, to)); - if (Util.getVersionProtocol(gson, from) >= Util.getVersionProtocol(gson, "1.12.2") && Util.getVersionProtocol(gson, to) <= Util.getVersionProtocol(gson, "1.13")) { + if (Util.getVersionProtocol(gson, from) >= Util.getVersionProtocol(gson, "1.12.2") + && Util.getVersionProtocol(gson, to) <= Util.getVersionProtocol(gson, "1.13")) { this.registerConverter(new MapIconConverter(this)); this.registerConverter(new MCPatcherConverter(this)); } - this.registerConverter(new BlockStateConverter(this, Util.getVersionProtocol(gson, from), Util.getVersionProtocol(gson, to))); - - this.registerConverter(new ModelConverter(this, light, Util.getVersionProtocol(gson, to), Util.getVersionProtocol(gson, from))); + this.registerConverter( + new BlockStateConverter(this, Util.getVersionProtocol(gson, from), Util.getVersionProtocol(gson, to))); + + this.registerConverter(new ModelConverter(this, light, Util.getVersionProtocol(gson, to), + Util.getVersionProtocol(gson, from))); - if (Util.getVersionProtocol(gson, from) > Util.getVersionProtocol(gson, "1.9") && Util.getVersionProtocol(gson, to) <= Util.getVersionProtocol(gson, "1.9")) - this.registerConverter(new CompassConverter(this, Util.getVersionProtocol(gson, from), Util.getVersionProtocol(gson, to))); + if (Util.getVersionProtocol(gson, from) > Util.getVersionProtocol(gson, "1.9") + && Util.getVersionProtocol(gson, to) <= Util.getVersionProtocol(gson, "1.9")) + this.registerConverter( + new CompassConverter(this, Util.getVersionProtocol(gson, from), Util.getVersionProtocol(gson, to))); } public void runPack(Pack pack) { try { - log("Converting " + pack); + Logger.log("Converting " + pack); pack.getHandler().setup(); - log(" Running Converters"); + Logger.log(" Running Converters"); for (Converter converter : converters.values()) { if (DEBUG) - log(" Running " + converter.getClass().getSimpleName()); + Logger.log(" Running " + converter.getClass().getSimpleName()); converter.convert(pack); } pack.getHandler().finish(); } catch (Throwable t) { - log("Failed to convert!"); + 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 b4214cfc..12058ee3 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 @@ -4,6 +4,7 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.Util; import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.Logger; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -34,7 +35,8 @@ public BlockStateConverter(PackConverter packConverter, int from, int to) { */ @Override public void convert(Pack pack) throws IOException { - Path states = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "blockstates"); + Path states = pack.getWorkingPath() + .resolve("assets" + File.separator + "minecraft" + File.separator + "blockstates"); if (!states.toFile().exists()) return; Files.list(states) @@ -58,7 +60,8 @@ public void convert(Pack pack) throws IOException { 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 (from >= Util.getVersionProtocol(packConverter.getGson(), "1.13") + && to < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { JsonElement normal = variantsObject.get(""); if (normal instanceof JsonObject || normal instanceof JsonArray) { variantsObject.add("normal", normal); @@ -72,9 +75,10 @@ public void convert(Pack pack) throws IOException { updateModelPath(entry); } if (anyChanges) { - Files.write(file, Collections.singleton(packConverter.getGson().toJson(json)), Charset.forName("UTF-8")); - if (packConverter.DEBUG) - PackConverter.log(" Converted " + file.getFileName()); + Files.write(file, Collections.singleton(packConverter.getGson().toJson(json)), + Charset.forName("UTF-8")); + if (PackConverter.DEBUG) + Logger.log(" Converted " + file.getFileName()); } } catch (IOException e) { Util.propagate(e); @@ -94,29 +98,35 @@ 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()); - - if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.19.3") && to < Util.getVersionProtocol(packConverter.getGson(), "1.19.3")) { + 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:", ""); anyChanges = true; } - if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.19") && to < Util.getVersionProtocol(packConverter.getGson(), "1.19")) { + if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.19") + && to < Util.getVersionProtocol(packConverter.getGson(), "1.19")) { val = nameConverter.getBlockMapping19().remap(val); anyChanges = true; } - if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.17") && to < Util.getVersionProtocol(packConverter.getGson(), "1.17")) { + if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.17") + && to < Util.getVersionProtocol(packConverter.getGson(), "1.17")) { val = nameConverter.getBlockMapping17().remap(val); anyChanges = true; } - if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.14") && to < Util.getVersionProtocol(packConverter.getGson(), "1.14")) { + if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.14") + && to < Util.getVersionProtocol(packConverter.getGson(), "1.14")) { val = nameConverter.getNewBlockMapping().remap(val); anyChanges = true; } - if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.13") && to < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { + if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.13") + && to < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { val = nameConverter.getBlockMapping().remap(val); prefix = prefix.replaceAll("block", "blocks"); anyChanges = true; @@ -132,34 +142,40 @@ 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()); - - if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.19.3") && to < Util.getVersionProtocol(packConverter.getGson(), "1.19.3")) { + 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:", ""); anyChanges = true; } - if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.19") && to < Util.getVersionProtocol(packConverter.getGson(), "1.19")) { + if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.19") + && to < Util.getVersionProtocol(packConverter.getGson(), "1.19")) { val = nameConverter.getBlockMapping19().remap(val); anyChanges = true; } - if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.17") && to < Util.getVersionProtocol(packConverter.getGson(), "1.17")) { + if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.17") + && to < Util.getVersionProtocol(packConverter.getGson(), "1.17")) { val = nameConverter.getBlockMapping17().remap(val); anyChanges = true; } - if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.14") && to < Util.getVersionProtocol(packConverter.getGson(), "1.14")) { + if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.14") + && to < Util.getVersionProtocol(packConverter.getGson(), "1.14")) { val = nameConverter.getNewBlockMapping().remap(val); anyChanges = true; } - if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.13") && to < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { + if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.13") + && to < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { val = nameConverter.getBlockMapping().remap(val); prefix = prefix.replaceAll("block", "blocks"); anyChanges = true; } - + 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 2862b59f..cb712442 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 @@ -46,14 +46,16 @@ public void convert(Pack pack) throws IOException { } protected void findFiles(Path path) throws IOException { - File directory = new File(path.toString()); - File[] fList = directory.listFiles(); - for (File file : fList) - if (file.isDirectory()) - findFiles(Paths.get(file.getPath())); - fList = directory.listFiles(); - if (fList.length == 0) - Files.deleteIfExists(directory.toPath()); + if (path.toFile().exists()) { + File directory = new File(path.toString()); + File[] fList = directory.listFiles(); + for (File file : fList) + if (file.isDirectory()) + findFiles(Paths.get(file.getPath())); + fList = directory.listFiles(); + if (fList.length == 0) + Files.deleteIfExists(directory.toPath()); + } } public void deleteBlocks(int version) throws IOException { 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 4c1e50bd..2008cbe5 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 @@ -4,6 +4,7 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.Util; import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.Logger; import com.agentdid127.resourcepack.library.utilities.PropertiesEx; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -43,8 +44,14 @@ public void convert(Pack pack) throws IOException { try (InputStream input = new FileInputStream(model.toString())) { JsonObject object = Util.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 = Util.readJsonResource(packConverter.getGson(), "/backwards/lang.json").getAsJsonObject("1_13"); + 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 = Util.readJsonResource(packConverter.getGson(), "/backwards/lang.json") + .getAsJsonObject("1_13"); object.keySet().forEach(key -> { String value = object.get(key).getAsString(); for (Map.Entry id2 : id.entrySet()) { @@ -55,16 +62,18 @@ public void convert(Pack pack) throws IOException { }); } - if (Util.getVersionProtocol(packConverter.getGson(), version) <= Util.getVersionProtocol(packConverter.getGson(), "1.14")) { - JsonObject id = Util.readJsonResource(packConverter.getGson(), "/backwards/lang.json").getAsJsonObject("1_14"); + if (Util.getVersionProtocol(packConverter.getGson(), version) <= Util + .getVersionProtocol(packConverter.getGson(), "1.14")) { + JsonObject id = Util.readJsonResource(packConverter.getGson(), "/backwards/lang.json") + .getAsJsonObject("1_14"); object.keySet().forEach(key -> { String value = object.get(key).getAsString(); - for (Map.Entry id2 : id.entrySet()) - if (key.equals(id2.getKey())) + for (Map.Entry id2 : id.entrySet()) + if (key.equals(id2.getKey())) out.setProperty(id2.getValue().getAsString(), value); }); } - + input.close(); } catch (FileNotFoundException e) { e.printStackTrace(); @@ -75,8 +84,12 @@ public void convert(Pack pack) throws IOException { try { int modelNoJson = model.getFileName().toString().indexOf(".json"); String file2 = model.getFileName().toString().substring(0, modelNoJson); - PackConverter.log("Saving: " + file2 + ".lang"); - out.store(new FileOutputStream(pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "lang" + File.separator + file2 + ".lang").toFile()), ""); + Logger.log("Saving: " + file2 + ".lang"); + out.store( + new FileOutputStream( + pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + + File.separator + "lang" + File.separator + file2 + ".lang").toFile()), + ""); } catch (IOException e) { e.printStackTrace(); } @@ -84,8 +97,10 @@ public void convert(Pack pack) throws IOException { models.add(model.getFileName().toString()); }); for (int i = 0; i < models.size(); i++) { - PackConverter.log("Deleting: " + pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "lang" + File.separator + models.get(i))); - Files.delete(pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "lang" + File.separator + models.get(i))); + Logger.log("Deleting: " + pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + + File.separator + "lang" + File.separator + models.get(i))); + Files.delete(pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "lang" + + File.separator + models.get(i))); } } } 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 76294697..ccf0d355 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 @@ -4,6 +4,7 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.Util; import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.Logger; import com.agentdid127.resourcepack.library.utilities.PropertiesEx; import com.google.gson.JsonObject; @@ -26,7 +27,8 @@ public MCPatcherConverter(PackConverter packConverter) { */ @Override public void convert(Pack pack) throws IOException { - Path models = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "mcpatcher"); + Path models = pack.getWorkingPath() + .resolve("assets" + File.separator + "minecraft" + File.separator + "mcpatcher"); if (models.toFile().exists()) findFiles(models); // remapModelJson(models.resolve("item")); @@ -63,8 +65,8 @@ 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) - PackConverter.log("Updating:" + model.getFileName()); + if (PackConverter.DEBUG) + Logger.log("Updating:" + model.getFileName()); PropertiesEx prop = new PropertiesEx(); prop.load(input); @@ -75,13 +77,15 @@ protected void remapProperties(Path path) throws IOException { // Updates Item IDs if (prop.containsKey("matchItems")) - prop.setProperty("matchItems", updateID("matchItems", prop, "regular").replaceAll("\"", "")); + 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("\"", "")); + prop.setProperty("matchBlocks", + updateID("matchBlocks", prop, "regular").replaceAll("\"", "")); // Saves File prop.store(output, ""); 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 bcea3b1d..03995b87 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 @@ -4,6 +4,7 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.Util; import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.Logger; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -37,7 +38,8 @@ public ModelConverter(PackConverter packConverter, String lightIn, int versionIn */ @Override public void convert(Pack pack) throws IOException { - Path models = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "models"); + Path models = pack.getWorkingPath() + .resolve("assets" + File.separator + "minecraft" + File.separator + "models"); if (!models.toFile().exists()) return; findFiles(models); @@ -72,29 +74,26 @@ protected void remapModelJson(Path path) throws IOException { Files.list(path).filter(path1 -> path1.toString().endsWith(".json")).forEach(model -> { try { JsonObject jsonObject; - if (Util.readJson(packConverter.getGson(), model) != null && Util.readJson(packConverter.getGson(), model).isJsonObject()) + if (Util.readJson(packConverter.getGson(), model) != null + && Util.readJson(packConverter.getGson(), model).isJsonObject()) jsonObject = Util.readJson(packConverter.getGson(), model); else { - if (packConverter.DEBUG) { - PackConverter.log("Could not convert model: " + model.getFileName()); + if (PackConverter.DEBUG) { + Logger.log("Could not convert model: " + model.getFileName()); if (Util.readJson(packConverter.getGson(), model) == null) - PackConverter.log("Check for Syntax Errors in file."); + Logger.log("Check for Syntax Errors in file."); else - PackConverter.log("File is not JSON Object."); + Logger.log("File is not JSON Object."); } 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? - - // 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); @@ -102,51 +101,60 @@ protected void remapModelJson(Path path) throws IOException { JsonObject textureObject = initialTextureObject.deepCopy(); for (Map.Entry entry : initialTextureObject.entrySet()) { String value = entry.getValue().getAsString(); - PackConverter.log(entry.getKey() + ": " + entry.getValue()); + Logger.log(entry.getKey() + ": " + entry.getValue()); 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:", ""); + 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 = "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("[()]", ""); + 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 = "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())); + 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())); + value = "item/" + + nameConverter.getNewItemMapping().remap(value.substring("item/".length())); // 1.13 Mappings if (version < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { if (value.startsWith("block/")) { - value = "block/" + nameConverter.getBlockMapping().remap(value.substring("block/".length())).toLowerCase().replaceAll("[()]", ""); - PackConverter.log(value.substring("block/".length()).toLowerCase().replaceAll("[()]", "")); - PackConverter.log(nameConverter.getBlockMapping().remap(value.substring("block/".length())).toLowerCase().replaceAll("[()]", "")); - } else if (value.startsWith("item/")) - value = "item/" + nameConverter.getItemMapping().remap(value.substring("item/".length())).toLowerCase().replaceAll("[()]", ""); + value = "block/" + nameConverter.getBlockMapping() + .remap(value.substring("block/".length())).toLowerCase().replaceAll("[()]", ""); + Logger.log( + value.substring("block/".length()).toLowerCase().replaceAll("[()]", "")); + Logger.log( + nameConverter.getBlockMapping().remap(value.substring("block/".length())) + .toLowerCase().replaceAll("[()]", "")); + } else if (value.startsWith("item/")) + value = "item/" + nameConverter.getItemMapping() + .remap(value.substring("item/".length())).toLowerCase().replaceAll("[()]", ""); else value = value.toLowerCase().replaceAll("[()]", ""); } - - if (!textureObject.has(entry.getKey())) textureObject.addProperty(entry.getKey(), value); } @@ -156,7 +164,8 @@ else if (value.startsWith("item/")) } // 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")) { + if (jsonObject.has("display") && from > Util.getVersionProtocol(packConverter.getGson(), "1.8") + && version == Util.getVersionProtocol(packConverter.getGson(), "1.8")) { JsonObject display = jsonObject.getAsJsonObject("display"); if (display.has("firstperson_righthand")) { @@ -190,7 +199,8 @@ else if (value.startsWith("item/")) 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("[()]", "")); + object.addProperty(json.getKey(), + json.getValue().getAsString().replaceAll("[()]", "")); else object.add(json.getKey(), json.getValue()); } @@ -210,32 +220,37 @@ else if (value.startsWith("item/")) parent = parent.replace(" ", "_"); // Get block/item parents renamed - if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.19") && version < Util.getVersionProtocol(packConverter.getGson(), "1.19")) + 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 (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 (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 (from >= Util.getVersionProtocol(packConverter.getGson(), "1.13") + && version < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { if (parent.startsWith("block/")) parent = setParent("blocks/", "/backwards/blocks.json", parent, "1_13"); if (parent.startsWith("item/")) parent = setParent("items/", "/backwards/items.json", parent, "1_13"); } - if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.19.3") && version < Util.getVersionProtocol(packConverter.getGson(), "1.19.3")) + if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.19.3") + && version < Util.getVersionProtocol(packConverter.getGson(), "1.19.3")) parent = parent.replaceAll("minecraft:", ""); jsonObject.addProperty(entry.getKey(), parent); @@ -253,8 +268,9 @@ else if (value.startsWith("item/")) if (!Util.readJson(packConverter.getGson(), model).equals(jsonObject)) { if (packConverter.DEBUG) - PackConverter.log("Updating Model: " + model.getFileName()); - Files.write(model, Collections.singleton(packConverter.getGson().toJson(jsonObject)), Charset.forName("UTF-8")); + Logger.log("Updating Model: " + model.getFileName()); + Files.write(model, Collections.singleton(packConverter.getGson().toJson(jsonObject)), + Charset.forName("UTF-8")); } } catch (IOException e) { throw Util.propagate(e); @@ -274,7 +290,7 @@ protected String setParent(String prefix, String path, String parent, String ite String parent2 = parent.replace(prefix, ""); JsonObject file = Util.readJsonResource(packConverter.getGson(), path).getAsJsonObject(item); if (file == null) { - PackConverter.log("Prefix Failed on: " + parent); + Logger.log("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 296e0198..40e49c94 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 @@ -4,6 +4,7 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.Util; import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.Logger; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -48,14 +49,15 @@ public void convert(Pack pack) throws IOException { Path mc = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft"); // Version is greater than 1.13 - if (to <= Util.getVersionProtocol(packConverter.getGson(), "1.13") && from > Util.getVersionProtocol(packConverter.getGson(), "1.13")) { + if (to <= Util.getVersionProtocol(packConverter.getGson(), "1.13") + && from > Util.getVersionProtocol(packConverter.getGson(), "1.13")) { // OptiFine conversion if (mc.resolve("mcpatcher").toFile().exists()) { - if (packConverter.DEBUG) - PackConverter.log("MCPatcher exists, switching to optifine"); + if (PackConverter.DEBUG) + Logger.log("MCPatcher exists, switching to optifine"); if (mc.resolve("optifine").toFile().exists()) { if (packConverter.DEBUG) - PackConverter.log("OptiFine exists, merging directories"); + Logger.log("OptiFine exists, merging directories"); Util.mergeDirectories(mc.resolve("optifine").toFile(), mc.resolve("mcpatcher").toFile()); } else Files.move(mc.resolve("mcpatcher"), mc.resolve("optifine")); @@ -64,7 +66,8 @@ public void convert(Pack pack) throws IOException { } } - Path models = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "models"); + Path models = pack.getWorkingPath() + .resolve("assets" + File.separator + "minecraft" + File.separator + "models"); if (models.toFile().exists()) { if (to < Util.getVersionProtocol(packConverter.getGson(), "1.19")) renameAll(blockMapping19, ".json", models.resolve("block")); @@ -97,33 +100,46 @@ public void convert(Pack pack) throws IOException { } // Update BlockStates - Path blockStates = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "blockstates"); + Path blockStates = pack.getWorkingPath() + .resolve("assets" + File.separator + "minecraft" + File.separator + "blockstates"); if (blockStates.toFile().exists()) renameAll(blockMapping, ".json", blockStates); // Update textures - Path textures = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "textures"); + Path textures = pack.getWorkingPath() + .resolve("assets" + File.separator + "minecraft" + File.separator + "textures"); if (textures.toFile().exists()) { // 1.19 - if (to < Util.getVersionProtocol(packConverter.getGson(), "1.19") && from >= Util.getVersionProtocol(packConverter.getGson(), "1.19")) + if (to < Util.getVersionProtocol(packConverter.getGson(), "1.19") + && from >= Util.getVersionProtocol(packConverter.getGson(), "1.19")) renameAll(blockMapping19, ".png", textures.resolve("block")); // 1.17 Squid - if (to < Util.getVersionProtocol(packConverter.getGson(), "1.17") && from >= Util.getVersionProtocol(packConverter.getGson(), "1.17")) { + if (to < Util.getVersionProtocol(packConverter.getGson(), "1.17") + && from >= Util.getVersionProtocol(packConverter.getGson(), "1.17")) { renameAll(blockMapping17, ".png", textures.resolve("block")); renameAll(itemMapping17, ".png", textures.resolve("item")); renameAll(blockMapping17, ".png", models.resolve("block")); renameAll(itemMapping17, ".png", models.resolve("item")); - if (textures.resolve("entity" + File.separator + "squid" + File.separator + "squid.png").toFile().exists()) - Files.move(textures.resolve("entity" + File.separator + "squid" + File.separator + "squid.png"), textures.resolve("entity" + File.separator + "squid.png")); - // Files.deleteIfExists(textures.resolve("entity" + File.separator + "squid" + File.separator)); + if (textures.resolve("entity" + File.separator + "squid" + File.separator + "squid.png").toFile() + .exists()) + Files.move(textures.resolve("entity" + File.separator + "squid" + File.separator + "squid.png"), + textures.resolve("entity" + File.separator + "squid.png")); + // Files.deleteIfExists(textures.resolve("entity" + File.separator + "squid" + + // File.separator)); } // 1.16 Iron golems - if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.16") && to < Util.getVersionProtocol(packConverter.getGson(), "1.16")) { - if (textures.resolve("entity" + File.separator + "iron_golem" + File.separator + "iron_golem.png").toFile().exists()) - Files.move(textures.resolve("entity" + File.separator + "iron_golem" + File.separator + "iron_golem.png"), textures.resolve("entity" + File.separator + "iron_golem.png")); - // Files.deleteIfExists(textures.resolve("entity" + File.separator + "iron_golem" + File.separator + "iron_golem.png")); + if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.16") + && to < Util.getVersionProtocol(packConverter.getGson(), "1.16")) { + if (textures.resolve("entity" + File.separator + "iron_golem" + File.separator + "iron_golem.png") + .toFile().exists()) + Files.move( + textures.resolve( + "entity" + File.separator + "iron_golem" + File.separator + "iron_golem.png"), + textures.resolve("entity" + File.separator + "iron_golem.png")); + // Files.deleteIfExists(textures.resolve("entity" + File.separator + + // "iron_golem" + File.separator + "iron_golem.png")); } if (to < Util.getVersionProtocol(packConverter.getGson(), "1.14")) { @@ -138,21 +154,24 @@ public void convert(Pack pack) throws IOException { renameAll(itemMapping, ".png.mcmeta", textures.resolve("item")); } - if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.13") && to < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { + if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.13") + && to < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { renameAll(blockMapping, ".png", textures.resolve("block")); renameAll(blockMapping, ".png.mcmeta", textures.resolve("block")); // 1.13 End Crystals if (textures.resolve("entity" + File.separator + "end_crystal").toFile().exists()) - Files.move(textures.resolve("entity" + File.separator + "end_crystal"), textures.resolve("entity" + File.separator + "endercrystal")); + Files.move(textures.resolve("entity" + File.separator + "end_crystal"), + textures.resolve("entity" + File.separator + "endercrystal")); findEntityFiles(textures.resolve("entity")); } } // Less than 1.12 - if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.12.2") && to < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { + if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.12.2") + && to < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { if (packConverter.DEBUG) - PackConverter.log("Finding files that are greater than 1.12"); + Logger.log("Finding files that are greater than 1.12"); findFiles(mc); } } @@ -191,13 +210,13 @@ protected void findFiles(Path path) throws IOException { if (file.isDirectory()) { if (file.getName().equals("item")) { if (packConverter.DEBUG) - PackConverter.log("Found Items folder, renaming"); + Logger.log("Found Items folder, renaming"); Util.renameFile(path.resolve(file.getName()), file.getName().replaceAll("item", "items")); } if (file.getName().equals("block")) { if (packConverter.DEBUG) - PackConverter.log("Found blocks folder, renaming"); + Logger.log("Found blocks folder, renaming"); Util.renameFile(path.resolve(file.getName()), file.getName().replaceAll("block", "blocks")); } @@ -206,11 +225,11 @@ protected void findFiles(Path path) throws IOException { if (file.getName().contains("(")) Util.renameFile(path.resolve(file.getName()), file.getName().replaceAll("[()]", "")); - + if (!file.getName().equals(file.getName().toLowerCase())) if (packConverter.DEBUG) - PackConverter.log("Renamed: " + file.getName() + "->" + file.getName().toLowerCase()); - + Logger.log("Renamed: " + file.getName() + "->" + file.getName().toLowerCase()); + Util.renameFile(path.resolve(file.getName()), file.getName().toLowerCase()); } } @@ -229,22 +248,24 @@ protected void renameAll(Mapping mapping, String extension, Path path) throws IO // 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" + File.separator + "block"))) { + if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.12.2") + && (path.endsWith("blockstates") || path.endsWith("textures" + File.separator + "block"))) { grasses.stream().forEach(name -> { String newName = mapping.remap(name); Boolean ret = Util.renameFile(Paths.get(path + File.separator + name + extension), newName + extension); if (ret == null) return; - if (ret && packConverter.DEBUG) - PackConverter.log(" Renamed: " + name + extension + "->" + newName + extension); - else if (!ret) + if (ret && packConverter.DEBUG) + Logger.log(" Renamed: " + name + extension + "->" + newName + extension); + else if (!ret) System.err.println(" Failed to rename: " + name + extension + "->" + newName + extension); }); } // remap snow jsons, but not images. - if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.13") && to < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { + if (from >= Util.getVersionProtocol(packConverter.getGson(), "1.13") + && to < Util.getVersionProtocol(packConverter.getGson(), "1.13")) { if (path.resolve("snow.json").toFile().exists()) Util.renameFile(path.resolve("snow" + extension), "snow_layer" + extension); if (path.resolve("snow_block.json").toFile().exists()) @@ -255,20 +276,22 @@ else if (!ret) 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" + File.separator + "block"))) + if (grasses.contains(baseName) + && (path.endsWith("blockstates") || path.endsWith("textures" + File.separator + "block"))) return; - + String newName = mapping.remap(baseName); if (newName != null && !newName.equals(baseName)) { Boolean ret = Util.renameFile(path1, newName + extension); if (ret == null) return; - if (ret && packConverter.DEBUG) - PackConverter - .log(" Renamed: " + path1.getFileName().toString() + "->" + newName + extension); - else if (!ret) + if (ret && packConverter.DEBUG) + Logger.log( + " Renamed: " + path1.getFileName().toString() + "->" + newName + extension); + else if (!ret) System.err.println(" Failed to rename: " + path1.getFileName().toString() + "->" + newName + extension); } @@ -332,9 +355,10 @@ public String remap(String in) { protected class BlockMapping13 extends Mapping { @Override protected void load() { - JsonObject blocks = Util.readJsonResource(packConverter.getGson(), "/backwards/blocks.json").getAsJsonObject("1_13"); - if (blocks != null) - for (Map.Entry entry : blocks.entrySet()) + JsonObject blocks = Util.readJsonResource(packConverter.getGson(), "/backwards/blocks.json") + .getAsJsonObject("1_13"); + if (blocks != null) + for (Map.Entry entry : blocks.entrySet()) this.mapping.put(entry.getKey(), entry.getValue().getAsString()); } } @@ -342,9 +366,10 @@ protected void load() { protected class BlockMapping14 extends Mapping { @Override protected void load() { - JsonObject blocks = Util.readJsonResource(packConverter.getGson(), "/backwards/blocks.json").getAsJsonObject("1_14"); - if (blocks != null) - for (Map.Entry entry : blocks.entrySet()) + JsonObject blocks = Util.readJsonResource(packConverter.getGson(), "/backwards/blocks.json") + .getAsJsonObject("1_14"); + if (blocks != null) + for (Map.Entry entry : blocks.entrySet()) this.mapping.put(entry.getKey(), entry.getValue().getAsString()); } } @@ -352,9 +377,10 @@ protected void load() { protected class BlockMapping17 extends Mapping { @Override protected void load() { - JsonObject blocks = Util.readJsonResource(packConverter.getGson(), "/backwards/blocks.json").getAsJsonObject("1_17"); - if (blocks != null) - for (Map.Entry entry : blocks.entrySet()) + JsonObject blocks = Util.readJsonResource(packConverter.getGson(), "/backwards/blocks.json") + .getAsJsonObject("1_17"); + if (blocks != null) + for (Map.Entry entry : blocks.entrySet()) this.mapping.put(entry.getKey(), entry.getValue().getAsString()); } } @@ -362,9 +388,10 @@ protected void load() { protected class BlockMapping19 extends Mapping { @Override protected void load() { - JsonObject blocks = Util.readJsonResource(packConverter.getGson(), "/backwards/blocks.json").getAsJsonObject("1_19"); - if (blocks != null) - for (Map.Entry entry : blocks.entrySet()) + JsonObject blocks = Util.readJsonResource(packConverter.getGson(), "/backwards/blocks.json") + .getAsJsonObject("1_19"); + if (blocks != null) + for (Map.Entry entry : blocks.entrySet()) this.mapping.put(entry.getKey(), entry.getValue().getAsString()); } } @@ -372,9 +399,10 @@ protected void load() { protected class LangMapping extends Mapping { @Override protected void load() { - JsonObject entities = Util.readJsonResource(packConverter.getGson(), "/backwards/lang.json").getAsJsonObject("1_13"); - if (entities != null) - for (Map.Entry entry : entities.entrySet()) + JsonObject entities = Util.readJsonResource(packConverter.getGson(), "/backwards/lang.json") + .getAsJsonObject("1_13"); + if (entities != null) + for (Map.Entry entry : entities.entrySet()) this.mapping.put(entry.getKey(), entry.getValue().getAsString()); } } @@ -382,9 +410,10 @@ protected void load() { protected class LangMapping14 extends Mapping { @Override protected void load() { - JsonObject entities = Util.readJsonResource(packConverter.getGson(), "/backwards/lang.json").getAsJsonObject("1_14"); - if (entities != null) - for (Map.Entry entry : entities.entrySet()) + JsonObject entities = Util.readJsonResource(packConverter.getGson(), "/backwards/lang.json") + .getAsJsonObject("1_14"); + if (entities != null) + for (Map.Entry entry : entities.entrySet()) this.mapping.put(entry.getKey(), entry.getValue().getAsString()); } } @@ -393,8 +422,8 @@ protected class EntityMapping extends Mapping { @Override protected void load() { JsonObject entities = Util.readJsonResource(packConverter.getGson(), "/backwards/entities.json"); - if (entities != null) - for (Map.Entry entry : entities.entrySet()) + if (entities != null) + for (Map.Entry entry : entities.entrySet()) this.mapping.put(entry.getKey(), entry.getValue().getAsString()); } } @@ -402,9 +431,10 @@ protected void load() { protected class ItemMapping13 extends Mapping { @Override protected void load() { - JsonObject items = Util.readJsonResource(packConverter.getGson(), "/backwards/items.json").getAsJsonObject("1_13"); - if (items != null) - for (Map.Entry entry : items.entrySet()) + JsonObject items = Util.readJsonResource(packConverter.getGson(), "/backwards/items.json") + .getAsJsonObject("1_13"); + if (items != null) + for (Map.Entry entry : items.entrySet()) this.mapping.put(entry.getKey(), entry.getValue().getAsString()); } } @@ -412,9 +442,10 @@ protected void load() { protected class ItemMapping14 extends Mapping { @Override protected void load() { - JsonObject items = Util.readJsonResource(packConverter.getGson(), "/backwards/items.json").getAsJsonObject("1_14"); - if (items != null) - for (Map.Entry entry : items.entrySet()) + JsonObject items = Util.readJsonResource(packConverter.getGson(), "/backwards/items.json") + .getAsJsonObject("1_14"); + if (items != null) + for (Map.Entry entry : items.entrySet()) this.mapping.put(entry.getKey(), entry.getValue().getAsString()); } } @@ -422,9 +453,10 @@ protected void load() { protected class ItemMapping17 extends Mapping { @Override protected void load() { - JsonObject items = Util.readJsonResource(packConverter.getGson(), "/backwards/items.json").getAsJsonObject("1_17"); - if (items != null) - for (Map.Entry entry : items.entrySet()) + JsonObject items = Util.readJsonResource(packConverter.getGson(), "/backwards/items.json") + .getAsJsonObject("1_17"); + if (items != null) + for (Map.Entry entry : items.entrySet()) this.mapping.put(entry.getKey(), entry.getValue().getAsString()); } } 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 f401a7ae..d7a3a5dd 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 @@ -4,6 +4,7 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.Util; import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.Logger; import javax.imageio.ImageIO; import java.awt.*; @@ -39,11 +40,14 @@ public MapIconConverter(PackConverter packConverter) { */ @Override public void convert(Pack pack) throws IOException { - Path imagePath = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "textures" + File.separator + "map" + File.separator + "backwards/map_icons.png"); - if (!imagePath.toFile().exists()) return; + Path imagePath = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + + "textures" + File.separator + "map" + File.separator + "backwards/map_icons.png"); + if (!imagePath.toFile().exists()) + return; BufferedImage newImage = Util.readImageResource("/backwards/map_icons.png"); - if (newImage == null) throw new NullPointerException(); + if (newImage == null) + throw new NullPointerException(); Graphics2D g2d = (Graphics2D) newImage.getGraphics(); BufferedImage image = ImageIO.read(imagePath.toFile()); @@ -52,11 +56,12 @@ public void convert(Pack pack) throws IOException { 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; + if (mapped == null) + continue; int newX = (int) (mapped >> 32); int newY = (int) (long) mapped; - PackConverter.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/Backwards/src/main/resources/backwards/blocks.json b/conversions/Backwards/src/main/resources/backwards/blocks.json index aeac5dfd..706d545f 100644 --- a/conversions/Backwards/src/main/resources/backwards/blocks.json +++ b/conversions/Backwards/src/main/resources/backwards/blocks.json @@ -417,7 +417,6 @@ "cobblestone_stairs": "stone_stairs", "stone_pressure_plate": "stone_pressure_plate_up", "stone_bricks": "stonebrick", - "stone_bricks": "stonebrick_normal", "stone_brick_stairs_inner": "stone_brick_inner_stairs", "stone_brick_stairs_outer": "stone_brick_outer_stairs", "chiseled_stone_bricks": "stonebrick_carved", diff --git a/conversions/Forwards/pom.xml b/conversions/Forwards/pom.xml index b348c72b..35e9f4ba 100644 --- a/conversions/Forwards/pom.xml +++ b/conversions/Forwards/pom.xml @@ -5,7 +5,7 @@ conversions com.agentdid127.resourcepack - 2.2.2 + 2.2.3 4.0.0 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 b744a161..ee0f60ad 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 @@ -5,6 +5,7 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.Util; import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.Logger; import com.agentdid127.resourcepack.forwards.impl.*; import com.google.gson.GsonBuilder; @@ -17,84 +18,108 @@ public class ForwardsPackConverter extends PackConverter { Path INPUT_DIR; - public ForwardsPackConverter(String from, String to, String light, boolean minify, Path input, boolean debug, PrintStream out) { + public ForwardsPackConverter(String from, String to, String light, boolean minify, Path input, boolean debug, + PrintStream out) { GsonBuilder gsonBuilder = new GsonBuilder().disableHtmlEscaping(); if (!minify) gsonBuilder.setPrettyPrinting(); gson = gsonBuilder.create(); DEBUG = debug; - PackConverter.out = out; + Logger.setStream(out); + Logger.log(from); + Logger.log(to); this.INPUT_DIR = input; - log(from); - log(to); converterRunner(from, to, light); } protected void converterRunner(String from, String to, String light) { // this needs to be run first, other converters might reference new directory // names - this.registerConverter(new NameConverter(this, Util.getVersionProtocol(gson, from), Util.getVersionProtocol(gson, to))); + this.registerConverter( + new NameConverter(this, Util.getVersionProtocol(gson, from), Util.getVersionProtocol(gson, to))); this.registerConverter(new PackMetaConverter(this, Util.getVersionProtocol(gson, to))); - if (Util.getVersionProtocol(gson, from) < Util.getVersionProtocol(gson, "1.9") && Util.getVersionProtocol(gson, to) >= Util.getVersionProtocol(gson, "1.9")) - this.registerConverter(new CompassConverter(this, Util.getVersionProtocol(gson, from), Util.getVersionProtocol(gson, to))); + if (Util.getVersionProtocol(gson, from) < Util.getVersionProtocol(gson, "1.9") + && Util.getVersionProtocol(gson, to) >= Util.getVersionProtocol(gson, "1.9")) + this.registerConverter( + new CompassConverter(this, Util.getVersionProtocol(gson, from), Util.getVersionProtocol(gson, to))); - if (Util.getVersionProtocol(gson, from) < Util.getVersionProtocol(gson, "1.11") && Util.getVersionProtocol(gson, to) >= Util.getVersionProtocol(gson, "1.11")) + if (Util.getVersionProtocol(gson, from) < Util.getVersionProtocol(gson, "1.11") + && Util.getVersionProtocol(gson, to) >= Util.getVersionProtocol(gson, "1.11")) this.registerConverter(new SpacesConverter(this)); - this.registerConverter(new ModelConverter(this, light, Util.getVersionProtocol(gson, to), Util.getVersionProtocol(gson, from))); + this.registerConverter(new ModelConverter(this, light, Util.getVersionProtocol(gson, to), + Util.getVersionProtocol(gson, from))); - if (Util.getVersionProtocol(gson, from) <= Util.getVersionProtocol(gson, "1.12.2") && Util.getVersionProtocol(gson, to) >= Util.getVersionProtocol(gson, "1.13")) { + if (Util.getVersionProtocol(gson, from) <= Util.getVersionProtocol(gson, "1.12.2") + && Util.getVersionProtocol(gson, to) >= 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 BlockStateConverter(this, Util.getVersionProtocol(gson, from), Util.getVersionProtocol(gson, to))); + this.registerConverter( + new BlockStateConverter(this, Util.getVersionProtocol(gson, from), Util.getVersionProtocol(gson, to))); if (Util.getVersionProtocol(gson, to) >= Util.getVersionProtocol(gson, "1.13")) this.registerConverter(new LangConverter(this, from, to)); - this.registerConverter(new ParticleTextureConverter(this, Util.getVersionProtocol(gson, from), Util.getVersionProtocol(gson, to))); - - if (Util.getVersionProtocol(gson, from) < Util.getVersionProtocol(gson, "1.15") && Util.getVersionProtocol(gson, to) >= Util.getVersionProtocol(gson, "1.15")) - this.registerConverter(new EnchantConverter(this)); + this.registerConverter(new ParticleTextureConverter(this, Util.getVersionProtocol(gson, from), + Util.getVersionProtocol(gson, to))); this.registerConverter(new ChestConverter(this)); - if (Util.getVersionProtocol(gson, from) <= Util.getVersionProtocol(gson, "1.13") && Util.getVersionProtocol(gson, to) >= Util.getVersionProtocol(gson, "1.14.4")) + if (Util.getVersionProtocol(gson, from) <= Util.getVersionProtocol(gson, "1.13") + && Util.getVersionProtocol(gson, to) >= Util.getVersionProtocol(gson, "1.14.4")) this.registerConverter(new PaintingConverter(this)); - if (Util.getVersionProtocol(gson, from) < Util.getVersionProtocol(gson, "1.18") && Util.getVersionProtocol(gson, to) >= Util.getVersionProtocol(gson, "1.18")) + if (Util.getVersionProtocol(gson, from) <= Util.getVersionProtocol(gson, "1.13.2") + && Util.getVersionProtocol(gson, to) >= Util.getVersionProtocol(gson, "1.14")) + this.registerConverter(new MobEffectAtlasConverter(this)); + + if (Util.getVersionProtocol(gson, from) < Util.getVersionProtocol(gson, "1.15") + && Util.getVersionProtocol(gson, to) >= Util.getVersionProtocol(gson, "1.15")) + this.registerConverter(new EnchantConverter(this)); + + if (Util.getVersionProtocol(gson, from) < Util.getVersionProtocol(gson, "1.18") + && Util.getVersionProtocol(gson, to) >= Util.getVersionProtocol(gson, "1.18")) this.registerConverter(new ParticleConverter(this)); this.registerConverter(new InventoryConverter(this)); - if (Util.getVersionProtocol(gson, from) < Util.getVersionProtocol(gson, "1.19.3") && Util.getVersionProtocol(gson, to) >= Util.getVersionProtocol(gson, "1.19.3")) + if (Util.getVersionProtocol(gson, from) < Util.getVersionProtocol(gson, "1.19.3") + && Util.getVersionProtocol(gson, to) >= Util.getVersionProtocol(gson, "1.19.3")) this.registerConverter(new AtlasConverter(this)); - if (Util.getVersionProtocol(gson, from) < Util.getVersionProtocol(gson, "1.19.4") && Util.getVersionProtocol(gson, to) >= Util.getVersionProtocol(gson, "1.19.4")) + if (Util.getVersionProtocol(gson, from) < Util.getVersionProtocol(gson, "1.19.4") + && Util.getVersionProtocol(gson, to) >= Util.getVersionProtocol(gson, "1.19.4")) this.registerConverter(new EnchantPathConverter(this)); - if (Util.getVersionProtocol(gson, from) <= Util.getVersionProtocol(gson, "1.19.4") && Util.getVersionProtocol(gson, to) >= Util.getVersionProtocol(gson, "1.20")) + if (Util.getVersionProtocol(gson, from) <= Util.getVersionProtocol(gson, "1.19.4") + && Util.getVersionProtocol(gson, to) >= Util.getVersionProtocol(gson, "1.20")) this.registerConverter(new TitleConverter(this)); + + if (Util.getVersionProtocol(gson, from) <= Util.getVersionProtocol(gson, "1.20.1") + && Util.getVersionProtocol(gson, to) >= Util.getVersionProtocol(gson, "1.20.2")) { + // register gui slicer + } } public void runPack(Pack pack) { try { - log("Converting " + pack); + Logger.log("Converting " + pack); pack.getHandler().setup(); - log(" Running Converters"); + Logger.log(" Running Converters"); for (Converter converter : converters.values()) { if (DEBUG) - log(" Running " + converter.getClass().getSimpleName()); + Logger.log(" Running " + converter.getClass().getSimpleName()); converter.convert(pack); } pack.getHandler().finish(); } catch (Throwable t) { - log("Failed to convert!"); + 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 df188329..424ee909 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 @@ -4,6 +4,7 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.Util; import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.Logger; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -21,8 +22,10 @@ public AnimationConverter(PackConverter packConverter) { @Override public void convert(Pack pack) throws IOException { - fixAnimations(pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "textures" + File.separator + "block")); - fixAnimations(pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "textures" + File.separator + "item")); + fixAnimations(pack.getWorkingPath().resolve( + "assets" + File.separator + "minecraft" + File.separator + "textures" + File.separator + "block")); + fixAnimations(pack.getWorkingPath().resolve( + "assets" + File.separator + "minecraft" + File.separator + "textures" + File.separator + "item")); } /** @@ -32,7 +35,8 @@ public void convert(Pack pack) throws IOException { * @throws IOException */ protected void fixAnimations(Path animations) throws IOException { - if (!animations.toFile().exists()) return; + if (!animations.toFile().exists()) + return; Files.list(animations) .filter(file -> file.toString().endsWith(".png.mcmeta")) .forEach(file -> { @@ -54,8 +58,8 @@ protected void fixAnimations(Path animations) throws IOException { if (anyChanges) { Files.write(file, Collections.singleton(packConverter.getGson().toJson(json)), Charset.forName("UTF-8")); - if (packConverter.DEBUG) - PackConverter.log(" Converted " + file.getFileName()); + if (PackConverter.DEBUG) + Logger.log(" Converted " + file.getFileName()); } } catch (IOException e) { Util.propagate(e); 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 9c569ff1..407356ec 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 @@ -16,16 +16,20 @@ public class AtlasConverter extends Converter { JsonObject out = new JsonObject(); JsonArray sources = new JsonArray(); + public AtlasConverter(PackConverter packConverter) { super(packConverter); } @Override public void convert(Pack pack) throws IOException { - Path atlases = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "atlases"); - Path textures = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "textures"); + Path atlases = pack.getWorkingPath() + .resolve("assets" + File.separator + "minecraft" + File.separator + "atlases"); + Path textures = pack.getWorkingPath() + .resolve("assets" + File.separator + "minecraft" + File.separator + "textures"); - if (!atlases.toFile().exists()) atlases.toFile().mkdirs(); + if (!atlases.toFile().exists()) + atlases.toFile().mkdirs(); if (textures.toFile().exists()) { File[] files = textures.toFile().listFiles(); @@ -55,16 +59,16 @@ public void convert(Pack pack) throws IOException { public void findFiles(Path directory, String prefix) { if (directory.toFile().isDirectory()) - for (File file : directory.toFile().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); + for (File file : directory.toFile().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 0ac7ec3e..1fa27fbb 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 @@ -4,6 +4,7 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.Util; import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.Logger; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -34,7 +35,8 @@ public BlockStateConverter(PackConverter packConverter, int from, int to) { */ @Override public void convert(Pack pack) throws IOException { - Path states = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "blockstates"); + Path states = pack.getWorkingPath() + .resolve("assets" + File.separator + "minecraft" + File.separator + "blockstates"); if (!states.toFile().exists()) return; Files.list(states).filter(file -> file.toString().endsWith(".json")).forEach(file -> { @@ -47,7 +49,7 @@ public void convert(Pack pack) throws IOException { if (multipartArray != null) { for (int i = 0; i < multipartArray.size(); i++) { JsonObject multipartObject = multipartArray.get(i).getAsJsonObject(); - for (Map.Entry entry : multipartObject.entrySet()) + for (Map.Entry entry : multipartObject.entrySet()) updateModelPath(entry); } } @@ -56,7 +58,8 @@ public void convert(Pack pack) throws IOException { JsonObject variantsObject = json.getAsJsonObject("variants"); if (variantsObject != null) { // change "normal" key to "" - if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.12.2") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.13")) { + if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.12.2") + && to >= Util.getVersionProtocol(packConverter.getGson(), "1.13")) { JsonElement normal = variantsObject.get("normal"); if (normal instanceof JsonObject || normal instanceof JsonArray) { variantsObject.add("", normal); @@ -66,13 +69,14 @@ 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); } if (anyChanges) { - Files.write(file, Collections.singleton(packConverter.getGson().toJson(json)), Charset.forName("UTF-8")); - if (packConverter.DEBUG) - PackConverter.log(" Converted " + file.getFileName()); + Files.write(file, Collections.singleton(packConverter.getGson().toJson(json)), + Charset.forName("UTF-8")); + if (PackConverter.DEBUG) + Logger.log(" Converted " + file.getFileName()); } } catch (IOException e) { Util.propagate(e); @@ -92,30 +96,36 @@ 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()); - - if (from < Util.getVersionProtocol(packConverter.getGson(), "1.13") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.13")) { + String prefix = value.get("model").getAsString().substring(0, + value.get("model").getAsString().length() - val.length()); + + if (from < Util.getVersionProtocol(packConverter.getGson(), "1.13") + && to >= Util.getVersionProtocol(packConverter.getGson(), "1.13")) { val = nameConverter.getBlockMapping().remap(val); prefix = prefix.replaceAll("blocks", "block"); anyChanges = true; } - if (from < Util.getVersionProtocol(packConverter.getGson(), "1.14") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.14")) { + if (from < Util.getVersionProtocol(packConverter.getGson(), "1.14") + && to >= Util.getVersionProtocol(packConverter.getGson(), "1.14")) { val = nameConverter.getNewBlockMapping().remap(val); anyChanges = true; } - if (from < Util.getVersionProtocol(packConverter.getGson(), "1.17") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.17")) { + if (from < Util.getVersionProtocol(packConverter.getGson(), "1.17") + && to >= Util.getVersionProtocol(packConverter.getGson(), "1.17")) { val = nameConverter.getBlockMapping17().remap(val); anyChanges = true; } - if (from < Util.getVersionProtocol(packConverter.getGson(), "1.19") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.19")) { + if (from < Util.getVersionProtocol(packConverter.getGson(), "1.19") + && to >= Util.getVersionProtocol(packConverter.getGson(), "1.19")) { val = nameConverter.getBlockMapping19().remap(val); anyChanges = true; } - if (from < Util.getVersionProtocol(packConverter.getGson(), "1.19.3") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.19.3")) { + if (from < Util.getVersionProtocol(packConverter.getGson(), "1.19.3") + && to >= Util.getVersionProtocol(packConverter.getGson(), "1.19.3")) { prefix = "minecraft:" + prefix; anyChanges = true; } @@ -130,30 +140,36 @@ 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()); - - if (from < Util.getVersionProtocol(packConverter.getGson(), "1.13") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.13")) { + String prefix = value.get("model").getAsString().substring(0, + value.get("model").getAsString().length() - val.length()); + + if (from < Util.getVersionProtocol(packConverter.getGson(), "1.13") + && to >= Util.getVersionProtocol(packConverter.getGson(), "1.13")) { val = nameConverter.getBlockMapping().remap(val); prefix = prefix.replaceAll("blocks", "block"); anyChanges = true; } - if (from < Util.getVersionProtocol(packConverter.getGson(), "1.14") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.14")) { + if (from < Util.getVersionProtocol(packConverter.getGson(), "1.14") + && to >= Util.getVersionProtocol(packConverter.getGson(), "1.14")) { val = nameConverter.getNewBlockMapping().remap(val); anyChanges = true; } - if (from < Util.getVersionProtocol(packConverter.getGson(), "1.17") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.17")) { + if (from < Util.getVersionProtocol(packConverter.getGson(), "1.17") + && to >= Util.getVersionProtocol(packConverter.getGson(), "1.17")) { val = nameConverter.getBlockMapping17().remap(val); anyChanges = true; } - if (from < Util.getVersionProtocol(packConverter.getGson(), "1.19") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.19")) { + if (from < Util.getVersionProtocol(packConverter.getGson(), "1.19") + && to >= Util.getVersionProtocol(packConverter.getGson(), "1.19")) { val = nameConverter.getBlockMapping19().remap(val); anyChanges = true; } - if (from < Util.getVersionProtocol(packConverter.getGson(), "1.19.3") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.19.3")) { + if (from < Util.getVersionProtocol(packConverter.getGson(), "1.19.3") + && to >= Util.getVersionProtocol(packConverter.getGson(), "1.19.3")) { prefix = "minecraft:" + prefix; anyChanges = true; } 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 ec2753bd..39dba2e3 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 @@ -16,7 +16,8 @@ public EnchantPathConverter(PackConverter packConverter) { @Override public void convert(Pack pack) throws IOException { - Path misc = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "textures" + File.separator + "misc"); + Path misc = pack.getWorkingPath().resolve( + "assets" + File.separator + "minecraft" + File.separator + "textures" + File.separator + "misc"); if (misc.resolve("enchanted_item_glint.png").toFile().exists()) { Files.copy(misc.resolve("enchanted_item_glint.png"), misc.resolve("enchanted_glint_entity.png")); @@ -25,8 +26,10 @@ public void convert(Pack pack) throws IOException { } if (misc.resolve("enchanted_item_glint.png.mcmeta").toFile().exists()) { - Files.copy(misc.resolve("enchanted_item_glint.png.mcmeta"), misc.resolve("enchanted_glint_entity.png.mcmeta")); - Files.copy(misc.resolve("enchanted_item_glint.png.mcmeta"), misc.resolve("enchanted_glint_item.png.mcmeta")); + Files.copy(misc.resolve("enchanted_item_glint.png.mcmeta"), + misc.resolve("enchanted_glint_entity.png.mcmeta")); + Files.copy(misc.resolve("enchanted_item_glint.png.mcmeta"), + misc.resolve("enchanted_glint_item.png.mcmeta")); Files.delete(misc.resolve("enchanted_item_glint.png.mcmeta")); } } 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 c94172c0..e1245989 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 @@ -4,6 +4,7 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.Util; import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.Logger; import com.agentdid127.resourcepack.library.utilities.PropertiesEx; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -61,9 +62,9 @@ public void convert(Pack pack) throws IOException { String key = enums.nextElement(); String value = prop.getProperty(key); for (Map.Entry id2 : id.entrySet()) { - if (key.equals(id2.getKey())) { + if (key.equals(id2.getKey())) out.addProperty(id2.getValue().getAsString(), value); - } else + else out.addProperty(key, value); } } @@ -79,9 +80,9 @@ public void convert(Pack pack) throws IOException { String key = enums.nextElement(); String value = prop.getProperty(key); for (Map.Entry id2 : id.entrySet()) { - if (key.equals(id2.getKey())) { + if (key.equals(id2.getKey())) out.addProperty(id2.getValue().getAsString(), value); - } else + else out.addProperty(key, value); } } @@ -93,10 +94,11 @@ public void convert(Pack pack) throws IOException { } catch (IOException e) { e.printStackTrace(); } + try { int modelNoLang = model.getFileName().toString().indexOf(".lang"); String file2 = model.getFileName().toString().substring(0, modelNoLang); - packConverter.log("Saving: " + file2 + ".json"); + Logger.log("Saving: " + file2 + ".json"); Files.write( pack.getWorkingPath() .resolve("assets" + File.separator + "minecraft" + File.separator + "lang" @@ -106,10 +108,12 @@ public void convert(Pack pack) throws IOException { } catch (IOException e) { e.printStackTrace(); } + models.add(model.getFileName().toString()); }); + for (int i = 0; i < models.size(); i++) { - packConverter.log("Deleting: " + pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + Logger.log("Deleting: " + pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "lang" + File.separator + models.get(i))); Files.delete(pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "lang" + File.separator + models.get(i))); 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 e1ef8ca5..13be14d0 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 @@ -4,6 +4,7 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.Util; import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.Logger; import com.agentdid127.resourcepack.library.utilities.PropertiesEx; import com.google.gson.JsonObject; @@ -26,7 +27,8 @@ public MCPatcherConverter(PackConverter packConverter) { */ @Override public void convert(Pack pack) throws IOException { - Path models = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "optifine"); + Path models = pack.getWorkingPath() + .resolve("assets" + File.separator + "minecraft" + File.separator + "optifine"); if (models.toFile().exists()) findFiles(models); // remapModelJson(models.resolve("item")); @@ -62,8 +64,8 @@ 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) - PackConverter.log("Updating:" + model.getFileName()); + if (PackConverter.DEBUG) + Logger.log("Updating:" + model.getFileName()); PropertiesEx prop = new PropertiesEx(); prop.load(input); @@ -119,7 +121,8 @@ else if (properties.startsWith("textures/items/")) * @return */ protected String updateID(String type, PropertiesEx prop, String selection) { - JsonObject id = Util.readJsonResource(packConverter.getGson(), "/forwards/ids.json").get(selection).getAsJsonObject(); + JsonObject id = Util.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++) 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 e5c10fe5..5526aff3 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 @@ -4,6 +4,7 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.Util; import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.Logger; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -17,11 +18,11 @@ import java.util.Collections; import java.util.Map; - 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; @@ -31,18 +32,22 @@ public ModelConverter(PackConverter packConverter, String lightIn, int 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" + File.separator + "minecraft" +File.separator + "models"); - if (!models.toFile().exists()) return; + Path models = pack.getWorkingPath() + .resolve("assets" + File.separator + "minecraft" + File.separator + "models"); + if (!models.toFile().exists()) + return; findFiles(models); } /** * Recursively finds files with Path path and runs remapModelJson + * * @param path * @throws IOException */ @@ -60,216 +65,247 @@ protected void findFiles(Path path) throws IOException { /** * Updates model Json to newer versions + * * @param path * @throws IOException */ protected void remapModelJson(Path path) throws IOException { - if (!path.toFile().exists()) return; + if (!path.toFile().exists()) + return; - Files.list(path) - .filter(path1 -> path1.toString().endsWith(".json")) - .forEach(model -> { - try { - JsonObject jsonObject; - if (Util.readJson(packConverter.getGson(), model) != null && Util.readJson(packConverter.getGson(), model).isJsonObject()) - jsonObject = Util.readJson(packConverter.getGson(), model); - else { - if (packConverter.DEBUG) { - packConverter.log("Could not convert model: " + model.getFileName()); - if (Util.readJson(packConverter.getGson(), model) == null) - packConverter.log("Check for Syntax Errors in file."); - else packConverter.log("File is not JSON Object."); - } + Files.list(path) + .filter(path1 -> path1.toString().endsWith(".json")) + .forEach(model -> { + try { + JsonObject jsonObject; + if (Util.readJson(packConverter.getGson(), model) != null + && Util.readJson(packConverter.getGson(), model).isJsonObject()) + jsonObject = Util.readJson(packConverter.getGson(), model); + else { + if (packConverter.DEBUG) { + Logger.log("Could not convert model: " + model.getFileName()); + if (Util.readJson(packConverter.getGson(), model) == null) + Logger.log("Check for Syntax Errors in file."); + else + Logger.log("File is not JSON Object."); + } 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(" ", "_"); + // 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.has("textures") && jsonObject.get("textures").isJsonObject()) { - NameConverter nameConverter = packConverter.getConverter(NameConverter.class); + // handle the remapping of textures, for models that use default texture names + jsonObject = packConverter.getGson().fromJson(content, JsonObject.class); + 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.13 Mappings - if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.13")) { - if (value.startsWith("block/")) { - value = "block/" + nameConverter.getBlockMapping().remap(value.substring("block/".length())).toLowerCase().replaceAll("[()]", ""); - packConverter.log(value.substring("block/".length()).toLowerCase().replaceAll("[()]", "")); - packConverter.log(nameConverter.getBlockMapping().remap(value.substring("block/".length())).toLowerCase().replaceAll("[()]", "")); - } else if (value.startsWith("item/")) { - value = "item/" + nameConverter.getItemMapping().remap(value.substring("item/".length())).toLowerCase().replaceAll("[()]", ""); + 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.13 Mappings + if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.13")) { + if (value.startsWith("block/")) { + value = "block/" + nameConverter.getBlockMapping() + .remap(value.substring("block/".length())).toLowerCase() + .replaceAll("[()]", ""); + Logger.log(value.substring("block/".length()).toLowerCase() + .replaceAll("[()]", "")); + Logger.log(nameConverter.getBlockMapping() + .remap(value.substring("block/".length())).toLowerCase() + .replaceAll("[()]", "")); + } else if (value.startsWith("item/")) { + value = "item/" + nameConverter.getItemMapping() + .remap(value.substring("item/".length())).toLowerCase() + .replaceAll("[()]", ""); + } else + value = value.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.getNewBlockMapping().remap(value.substring("block/".length())); + // 1.14 Mappings + if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.14")) { + if (value.startsWith("block/")) { + value = "block/" + nameConverter.getNewBlockMapping() + .remap(value.substring("block/".length())); + } } - } - //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("[()]", ""); + // 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("[()]", ""); } - value = value.toLowerCase().replaceAll("[()]", ""); - } - //1.17 Mappings - if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.19")) { - if (value.startsWith("block/")) { - value = "block/" + nameConverter.getBlockMapping19().remap(value.substring("block/".length())).toLowerCase().replaceAll("[()]", ""); + // 1.17 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("[()]", ""); } - value = value.toLowerCase().replaceAll("[()]", ""); - } - - //Dyes - if (value.startsWith("item/") && value.contains("dye")) { - if (version > Util.getVersionProtocol(packConverter.getGson(), "1.13")) { - value = "item/" + nameConverter.getNewItemMapping().remap(value.substring("item/".length())); + // Dyes + if (value.startsWith("item/") && value.contains("dye")) { + if (version > Util.getVersionProtocol(packConverter.getGson(), "1.13")) { + value = "item/" + nameConverter.getNewItemMapping() + .remap(value.substring("item/".length())); + } } - } - 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 (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); } - if (!textureObject.has(entry.getKey())) textureObject.addProperty(entry.getKey(), value); + jsonObject.remove("textures"); + jsonObject.add("textures", textureObject); } - jsonObject.remove("textures"); - jsonObject.add("textures", textureObject); - } - //fix display settings for packs from 1.8 - if (jsonObject.has("display") && from == Util.getVersionProtocol(packConverter.getGson(), "1.8")) { - JsonObject display = jsonObject.getAsJsonObject("display"); - if (display.has("firstperson")){ - display.add("firstperson_righthand", display.get("firstperson")); - display.remove("firstperson"); + // fix display settings for packs from 1.8 + if (jsonObject.has("display") + && from == Util.getVersionProtocol(packConverter.getGson(), "1.8")) { + JsonObject display = jsonObject.getAsJsonObject("display"); + if (display.has("firstperson")) { + display.add("firstperson_righthand", display.get("firstperson")); + display.remove("firstperson"); + } + if (display.has("thirdperson")) { + display.add("thirdperson_righthand", display.get("thirdperson")); + display.remove("thirdperson"); + } + jsonObject.remove("display"); + jsonObject.add("display", display); } - if (display.has("thirdperson")) { - display.add("thirdperson_righthand", display.get("thirdperson")); - display.remove("thirdperson"); - } - jsonObject.remove("display"); - jsonObject.add("display", display); - } - if (jsonObject.has("overrides")) { - for(Map.Entry entry : jsonObject.entrySet()) { + 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()); + 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); } - overrides2.add(object); + jsonObject.add(entry.getKey(), overrides2); } - 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 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"); + 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"); + } + if (parent.startsWith("item/")) { + parent = setParent("item/", "/forwards/items.json", parent, "1_13"); + } } - 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"); - } - 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"); + 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"); + } + if (parent.startsWith("item/")) { + parent = setParent("item/", "/forwards/items.json", parent, "1_14"); + } } - if (parent.startsWith("item/")) { - parent = setParent("item/", "/forwards/items.json", parent, "1_17"); + 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"); + } + 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 (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 (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 (!Util.readJson(packConverter.getGson(), model).equals(jsonObject)) { + if (packConverter.DEBUG) + Logger.log("Updating Model: " + model.getFileName()); + Files.write(model, Collections.singleton(packConverter.getGson().toJson(jsonObject)), + Charset.forName("UTF-8")); + } + } catch (IOException e) { + throw Util.propagate(e); } - if (!Util.readJson(packConverter.getGson(), model).equals(jsonObject)) { - if (packConverter.DEBUG) packConverter.log("Updating Model: " + model.getFileName()); - Files.write(model, Collections.singleton(packConverter.getGson().toJson(jsonObject)), Charset.forName("UTF-8")); - } - } 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 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 = Util.readJsonResource(packConverter.getGson(), path).getAsJsonObject(item); - if (file != null) { - if (file.has(parent2)) - return prefix + file.get(parent2).getAsString(); - else return parent; - } - else{ - packConverter.log("Prefix Failed on: " + parent); - return ""; + protected String setParent(String prefix, String path, String parent, String item) { + String parent2 = parent.replace(prefix, ""); + JsonObject file = Util.readJsonResource(packConverter.getGson(), path).getAsJsonObject(item); + if (file != null) { + if (file.has(parent2)) + return prefix + file.get(parent2).getAsString(); + else + return parent; + } else { + Logger.log("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 ff053a44..a2d736f2 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 @@ -4,6 +4,7 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.Util; import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.Logger; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -30,6 +31,7 @@ public class NameConverter extends Converter { protected final Mapping entityMapping = new EntityMapping(); protected final Mapping langMapping = new LangMapping(); protected final Mapping langMapping14 = new LangMapping14(); + public NameConverter(PackConverter packConverter, int from, int to) { super(packConverter); this.from = from; @@ -38,15 +40,18 @@ public NameConverter(PackConverter packConverter, int from, int to) { /** * Fixes folder names and file names + * * @param pack Resource Pack * @throws IOException Error handler */ @Override public void convert(Pack pack) throws IOException { Path mc = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft"); - //Less than 1.12 - if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.12.2") && to > Util.getVersionProtocol(packConverter.getGson(), "1.13")) { - if (packConverter.DEBUG) PackConverter.log("Finding files that are less than 1.12"); + // 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"); findFiles(mc); } @@ -54,27 +59,34 @@ public void convert(Pack pack) throws IOException { if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.13")) { // OptiFine conversion if (mc.resolve("mcpatcher").toFile().exists()) { - if (packConverter.DEBUG) PackConverter.log("MCPatcher exists, switching to optifine"); + if (PackConverter.DEBUG) + Logger.log("MCPatcher exists, switching to optifine"); if (mc.resolve("optifine").toFile().exists()) { - if (packConverter.DEBUG) PackConverter.log("OptiFine exists, merging directories"); + if (packConverter.DEBUG) + Logger.log("OptiFine exists, merging directories"); Util.mergeDirectories(mc.resolve("optifine").toFile(), mc.resolve("mcpatcher").toFile()); - } else Files.move(mc.resolve("mcpatcher"), mc.resolve("optifine")); - if (mc.resolve("mcpatcher").toFile().exists()) Util.deleteDirectoryAndContents(mc.resolve("mcpatcher")); + } else + Files.move(mc.resolve("mcpatcher"), mc.resolve("optifine")); + if (mc.resolve("mcpatcher").toFile().exists()) + Util.deleteDirectoryAndContents(mc.resolve("mcpatcher")); } // 1.13 Models - Path models = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "models"); + Path models = pack.getWorkingPath() + .resolve("assets" + File.separator + "minecraft" + File.separator + "models"); if (models.toFile().exists()) { - //1.13 block/item name change + // 1.13 block/item name change if (models.resolve("blocks").toFile().exists()) { - if (models.resolve("block").toFile().exists()) Util.deleteDirectoryAndContents( models.resolve("block")); + if (models.resolve("block").toFile().exists()) + Util.deleteDirectoryAndContents(models.resolve("block")); Files.move(models.resolve("blocks"), models.resolve("block")); } // Update all blocks for 1.13 renameAll(blockMapping, ".json", models.resolve("block")); if (models.resolve("items").toFile().exists()) { - if (models.resolve("item").toFile().exists()) Util.deleteDirectoryAndContents(models.resolve("item")); + if (models.resolve("item").toFile().exists()) + Util.deleteDirectoryAndContents(models.resolve("item")); Files.move(models.resolve("items"), models.resolve("item")); } @@ -84,10 +96,22 @@ public void convert(Pack pack) throws IOException { // Update 1.14 items if (to > Util.getVersionProtocol(packConverter.getGson(), "1.13")) { renameAll(newItemMapping, ".json", models.resolve("item")); - if (!models.resolve("item" + File.separator + "ink_sac.json").toFile().exists() && models.resolve("item" + File.separator + "black_dye.json").toFile().exists()) Files.copy(models.resolve("item" + File.separator + "black_dye.json"), models.resolve("item" + File.separator + "ink_sac.json")); - if (!models.resolve("item" + File.separator + "cocoa_beans.json").toFile().exists() && models.resolve("item" + File.separator + "brown_dye.json").toFile().exists()) Files.copy(models.resolve("item" + File.separator + "brown_dye.json"), models.resolve("item" + File.separator + "cocoa_beans.json")); - if (!models.resolve("item" + File.separator + "bone_meal.json").toFile().exists() && models.resolve("item" + File.separator + "white_dye.json").toFile().exists())Files.copy(models.resolve("item" + File.separator + "white_dye.json"), models.resolve("item" + File.separator + "bone_meal.json")); - if (!models.resolve("item" + File.separator + "lapis_lazuli.json").toFile().exists() && models.resolve("item" + File.separator + "blue_dye.json").toFile().exists())Files.copy(models.resolve("item" + File.separator + "blue_dye.json"), models.resolve("item" + File.separator + "lapis_lazuli.json")); + if (!models.resolve("item" + File.separator + "ink_sac.json").toFile().exists() + && models.resolve("item" + File.separator + "black_dye.json").toFile().exists()) + Files.copy(models.resolve("item" + File.separator + "black_dye.json"), + models.resolve("item" + File.separator + "ink_sac.json")); + if (!models.resolve("item" + File.separator + "cocoa_beans.json").toFile().exists() + && models.resolve("item" + File.separator + "brown_dye.json").toFile().exists()) + Files.copy(models.resolve("item" + File.separator + "brown_dye.json"), + models.resolve("item" + File.separator + "cocoa_beans.json")); + if (!models.resolve("item" + File.separator + "bone_meal.json").toFile().exists() + && models.resolve("item" + File.separator + "white_dye.json").toFile().exists()) + Files.copy(models.resolve("item" + File.separator + "white_dye.json"), + models.resolve("item" + File.separator + "bone_meal.json")); + if (!models.resolve("item" + File.separator + "lapis_lazuli.json").toFile().exists() + && models.resolve("item" + File.separator + "blue_dye.json").toFile().exists()) + Files.copy(models.resolve("item" + File.separator + "blue_dye.json"), + models.resolve("item" + File.separator + "lapis_lazuli.json")); } if (to > Util.getVersionProtocol(packConverter.getGson(), "1.19")) { @@ -96,13 +120,15 @@ public void convert(Pack pack) throws IOException { } // Update BlockStates - Path blockStates = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "blockstates"); - - if (blockStates.toFile().exists()) renameAll(blockMapping, ".json", blockStates); + Path blockStates = pack.getWorkingPath() + .resolve("assets" + File.separator + "minecraft" + File.separator + "blockstates"); + if (blockStates.toFile().exists()) + renameAll(blockMapping, ".json", blockStates); // Update textures - Path textures = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "textures"); + Path textures = pack.getWorkingPath() + .resolve("assets" + File.separator + "minecraft" + File.separator + "textures"); if (textures.toFile().exists()) { if (textures.resolve("blocks").toFile().exists()) Files.move(textures.resolve("blocks"), textures.resolve("block")); @@ -121,20 +147,35 @@ public void convert(Pack pack) throws IOException { if (to > Util.getVersionProtocol(packConverter.getGson(), "1.13.2")) { renameAll(newItemMapping, ".png", textures.resolve("item")); renameAll(newItemMapping, ".png.mcmeta", textures.resolve("item")); - if (!models.resolve("item" + File.separator + "ink_sac.png").toFile().exists() && models.resolve("item" + File.separator + "black_dye.png").toFile().exists()) Files.copy(models.resolve("item" + File.separator + "black_dye.png"), models.resolve("item" + File.separator + "ink_sac.png")); - if (!models.resolve("item" + File.separator + "cocoa_beans.png").toFile().exists() && models.resolve("item" + File.separator + "brown_dye.png").toFile().exists()) Files.copy(models.resolve("item" + File.separator + "brown_dye.png"), models.resolve("item" + File.separator + "cocoa_beans.png")); - if (!models.resolve("item" + File.separator + "bone_meal.png").toFile().exists() && models.resolve("item" + File.separator + "white_dye.png").toFile().exists()) Files.copy(models.resolve("item" + File.separator + "white_dye.png"), models.resolve("item" + File.separator + "bone_meal.png")); - if (!models.resolve("item" + File.separator + "lapis_lazuli.png").toFile().exists() && models.resolve("item" + File.separator + "blue_dye.png").toFile().exists()) Files.copy(models.resolve("item" + File.separator + "blue_dye.png"), models.resolve("item" + File.separator + "lapis_lazuli.png")); + if (!models.resolve("item" + File.separator + "ink_sac.png").toFile().exists() + && models.resolve("item" + File.separator + "black_dye.png").toFile().exists()) + Files.copy(models.resolve("item" + File.separator + "black_dye.png"), + models.resolve("item" + File.separator + "ink_sac.png")); + if (!models.resolve("item" + File.separator + "cocoa_beans.png").toFile().exists() + && models.resolve("item" + File.separator + "brown_dye.png").toFile().exists()) + Files.copy(models.resolve("item" + File.separator + "brown_dye.png"), + models.resolve("item" + File.separator + "cocoa_beans.png")); + if (!models.resolve("item" + File.separator + "bone_meal.png").toFile().exists() + && models.resolve("item" + File.separator + "white_dye.png").toFile().exists()) + Files.copy(models.resolve("item" + File.separator + "white_dye.png"), + models.resolve("item" + File.separator + "bone_meal.png")); + if (!models.resolve("item" + File.separator + "lapis_lazuli.png").toFile().exists() + && models.resolve("item" + File.separator + "blue_dye.png").toFile().exists()) + Files.copy(models.resolve("item" + File.separator + "blue_dye.png"), + models.resolve("item" + File.separator + "lapis_lazuli.png")); } - //1.16 Iron golems - if (from < Util.getVersionProtocol(packConverter.getGson(), "1.15") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.15")) { + // 1.16 Iron golems + if (from < Util.getVersionProtocol(packConverter.getGson(), "1.15") + && to >= Util.getVersionProtocol(packConverter.getGson(), "1.15")) { if (!textures.resolve("entity" + File.separator + "iron_golem").toFile().exists()) textures.resolve("entity" + File.separator + "iron_golem" + File.separator).toFile().mkdir(); if (textures.resolve("entity" + File.separator + "iron_golem.png").toFile().exists()) - Files.move(textures.resolve("entity" + File.separator + "iron_golem.png"), textures.resolve("entity" + File.separator + "iron_golem" + File.separator + "iron_golem.png")); + Files.move(textures.resolve("entity" + File.separator + "iron_golem.png"), textures + .resolve("entity" + File.separator + "iron_golem" + File.separator + "iron_golem.png")); } // 1.17 Squid - if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.17") && from < Util.getVersionProtocol(packConverter.getGson(), "1.17")) { + if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.17") + && from < Util.getVersionProtocol(packConverter.getGson(), "1.17")) { renameAll(blockMapping17, ".png", textures.resolve("block")); renameAll(itemMapping17, ".png", textures.resolve("item")); renameAll(blockMapping17, ".png", models.resolve("block")); @@ -142,16 +183,20 @@ public void convert(Pack pack) throws IOException { if (!textures.resolve("entity" + File.separator + "squid").toFile().exists()) textures.resolve("entity" + File.separator + "squid" + File.separator).toFile().mkdir(); if (textures.resolve("entity" + File.separator + "squid.png").toFile().exists()) - Files.move(textures.resolve("entity" + File.separator + "squid.png"), textures.resolve("entity" + File.separator + "squid" + File.separator + "squid.png")); + Files.move(textures.resolve("entity" + File.separator + "squid.png"), + textures.resolve("entity" + File.separator + "squid" + File.separator + "squid.png")); } - if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.19") && from < Util.getVersionProtocol(packConverter.getGson(),"1.19")) { + if (to >= Util.getVersionProtocol(packConverter.getGson(), "1.19") + && from < Util.getVersionProtocol(packConverter.getGson(), "1.19")) { renameAll(blockMapping19, ".png", textures.resolve("block")); } // 1.13 End Crystals - if (textures.resolve("entity" + File.separator + "endercrystal").toFile().exists() && !textures.resolve("entity" + File.separator + "end_crystal").toFile().exists()) - Files.move(textures.resolve("entity" + File.separator + "endercrystal"), textures.resolve("entity" + File.separator + "end_crystal")); + if (textures.resolve("entity" + File.separator + "endercrystal").toFile().exists() + && !textures.resolve("entity" + File.separator + "end_crystal").toFile().exists()) + Files.move(textures.resolve("entity" + File.separator + "endercrystal"), + textures.resolve("entity" + File.separator + "end_crystal")); findEntityFiles(textures.resolve("entity")); } } @@ -160,6 +205,7 @@ public void convert(Pack pack) throws IOException { /** * Finds files in entity folder + * * @param path * @throws IOException */ @@ -179,6 +225,7 @@ protected void findEntityFiles(Path path) throws IOException { /** * Finds files in folders called + * * @param path * @throws IOException */ @@ -189,18 +236,22 @@ protected void findFiles(Path path) throws IOException { for (File file : fList) { if (file.isDirectory()) { if (file.getName().equals("items")) { - if (packConverter.DEBUG) packConverter.log("Found Items folder, renaming"); + if (packConverter.DEBUG) + Logger.log("Found Items folder, renaming"); Util.renameFile(path.resolve(file.getName()), file.getName().replaceAll("items", "item")); } if (file.getName().equals("blocks")) { - if (packConverter.DEBUG) packConverter.log("Found blocks folder, renaming"); + if (packConverter.DEBUG) + Logger.log("Found blocks folder, renaming"); Util.renameFile(path.resolve(file.getName()), file.getName().replaceAll("blocks", "block")); } findFiles(Paths.get(file.getPath())); } - if (file.getName().contains("(")) Util.renameFile(path.resolve(file.getName()), file.getName().replaceAll("[()]", "")); + if (file.getName().contains("(")) + Util.renameFile(path.resolve(file.getName()), file.getName().replaceAll("[()]", "")); if (!file.getName().equals(file.getName().toLowerCase())) - if (packConverter.DEBUG) packConverter.log("Renamed: " + file.getName() + "->" +file.getName().toLowerCase()); + if (packConverter.DEBUG) + Logger.log("Renamed: " + file.getName() + "->" + file.getName().toLowerCase()); Util.renameFile(path.resolve(file.getName()), file.getName().toLowerCase()); } } @@ -208,6 +259,7 @@ protected void findFiles(Path path) throws IOException { /** * Renames folder + * * @param mapping * @param extension * @param path @@ -222,37 +274,48 @@ protected void renameAll(Mapping mapping, String extension, Path path) throws IO if ((path.endsWith("blockstates") || path.endsWith("textures" + File.separator + "block"))) { grasses.stream().forEach(name -> { String newName = mapping.remap(name); - Boolean ret = Util.renameFile(Paths.get(path + File.separator + name + extension), newName + extension); - if (ret == null) return; + Boolean ret = Util.renameFile(Paths.get(path + File.separator + name + extension), + newName + extension); + if (ret == null) + return; if (ret && packConverter.DEBUG) { - packConverter.log(" Renamed: " + name + extension + "->" + newName + extension); + Logger.log(" Renamed: " + name + extension + "->" + newName + extension); } else if (!ret) { - System.err.println(" Failed to rename: " + name + extension + "->" + newName + extension); + System.err.println( + " Failed to rename: " + name + extension + "->" + newName + extension); } }); } } - //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()) Util.renameFile(path.resolve("snow_layer" + extension), "snow" + extension); + // 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()) + Util.renameFile(path.resolve("snow_layer" + extension), "snow" + extension); } Files.list(path).forEach(path1 -> { - if (!path1.toString().endsWith(extension)) return; + 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" + File.separator + "block"))) { + if (grasses.contains(baseName) + && (path.endsWith("blockstates") || path.endsWith("textures" + File.separator + "block"))) { return; } String newName = mapping.remap(baseName); if (newName != null && !newName.equals(baseName)) { Boolean ret = Util.renameFile(path1, newName + extension); - if (ret == null) return; + if (ret == null) + return; if (ret && packConverter.DEBUG) { - packConverter.log(" Renamed: " + path1.getFileName().toString() + "->" + newName + extension); + Logger.log( + " Renamed: " + path1.getFileName().toString() + "->" + newName + extension); } else if (!ret) { - System.err.println(" Failed to rename: " + path1.getFileName().toString() + "->" + newName + extension); + System.err.println(" Failed to rename: " + path1.getFileName().toString() + "->" + newName + + extension); } } }); @@ -263,7 +326,6 @@ public Mapping getBlockMapping() { return blockMapping; } - public Mapping getItemMapping() { return itemMapping; } @@ -276,20 +338,27 @@ public Mapping getNewItemMapping() { return newItemMapping; } - public Mapping getItemMapping17() {return itemMapping17;} + public Mapping getItemMapping17() { + return itemMapping17; + } - public Mapping getBlockMapping17() {return blockMapping17; } + public Mapping getBlockMapping17() { + return blockMapping17; + } - public Mapping getBlockMapping19() {return blockMapping19; } + public Mapping getBlockMapping19() { + return blockMapping19; + } public Mapping getLangMapping() { return langMapping; } - public Mapping getLangMapping14() {return langMapping14; }; + public Mapping getLangMapping14() { + return langMapping14; + }; protected abstract static class Mapping { - protected final Map mapping = new HashMap<>(); public Mapping() { @@ -307,53 +376,53 @@ public String remap(String in) { } protected class BlockMapping13 extends Mapping { - @Override protected void load() { - JsonObject blocks = Util.readJsonResource(packConverter.getGson(), "/forwards/blocks.json").getAsJsonObject("1_13"); - if (blocks != null) { - for (Map.Entry entry : blocks.entrySet()) { - this.mapping.put(entry.getKey(), entry.getValue().getAsString()); - } + JsonObject blocks = Util.readJsonResource(packConverter.getGson(), "/forwards/blocks.json") + .getAsJsonObject("1_13"); + if (blocks == null) + return; + for (Map.Entry entry : blocks.entrySet()) { + this.mapping.put(entry.getKey(), entry.getValue().getAsString()); } } } protected class BlockMapping14 extends Mapping { - @Override protected void load() { - JsonObject blocks = Util.readJsonResource(packConverter.getGson(), "/forwards/blocks.json").getAsJsonObject("1_14"); - if (blocks != null) { - for (Map.Entry entry : blocks.entrySet()) { - this.mapping.put(entry.getKey(), entry.getValue().getAsString()); - } + JsonObject blocks = Util.readJsonResource(packConverter.getGson(), "/forwards/blocks.json") + .getAsJsonObject("1_14"); + if (blocks == null) + return; + for (Map.Entry entry : blocks.entrySet()) { + this.mapping.put(entry.getKey(), entry.getValue().getAsString()); } } } protected class BlockMapping17 extends Mapping { - @Override protected void load() { - JsonObject blocks = Util.readJsonResource(packConverter.getGson(), "/forwards/blocks.json").getAsJsonObject("1_17"); - if (blocks != null) { - for (Map.Entry entry : blocks.entrySet()) { - this.mapping.put(entry.getKey(), entry.getValue().getAsString()); - } + JsonObject blocks = Util.readJsonResource(packConverter.getGson(), "/forwards/blocks.json") + .getAsJsonObject("1_17"); + if (blocks == null) + return; + for (Map.Entry entry : blocks.entrySet()) { + this.mapping.put(entry.getKey(), entry.getValue().getAsString()); } } } protected class BlockMapping19 extends Mapping { - @Override protected void load() { - JsonObject blocks = Util.readJsonResource(packConverter.getGson(), "/forwards/blocks.json").getAsJsonObject("1_19"); - if (blocks != null) { - for (Map.Entry entry : blocks.entrySet()) { - this.mapping.put(entry.getKey(), entry.getValue().getAsString()); - } + JsonObject blocks = Util.readJsonResource(packConverter.getGson(), "/forwards/blocks.json") + .getAsJsonObject("1_19"); + if (blocks == null) + return; + for (Map.Entry entry : blocks.entrySet()) { + this.mapping.put(entry.getKey(), entry.getValue().getAsString()); } } } @@ -361,11 +430,12 @@ protected void load() { protected class LangMapping extends Mapping { @Override protected void load() { - JsonObject entities = Util.readJsonResource(packConverter.getGson(), "/forwards/lang.json").getAsJsonObject("1_13"); - if (entities != null) { - for (Map.Entry entry : entities.entrySet()) { - this.mapping.put(entry.getKey(), entry.getValue().getAsString()); - } + JsonObject entities = Util.readJsonResource(packConverter.getGson(), "/forwards/lang.json") + .getAsJsonObject("1_13"); + if (entities == null) + return; + for (Map.Entry entry : entities.entrySet()) { + this.mapping.put(entry.getKey(), entry.getValue().getAsString()); } } } @@ -373,11 +443,12 @@ protected void load() { protected class LangMapping14 extends Mapping { @Override protected void load() { - JsonObject entities = Util.readJsonResource(packConverter.getGson(), "/forwards/lang.json").getAsJsonObject("1_14"); - if (entities != null) { - for (Map.Entry entry : entities.entrySet()) { - this.mapping.put(entry.getKey(), entry.getValue().getAsString()); - } + JsonObject entities = Util.readJsonResource(packConverter.getGson(), "/forwards/lang.json") + .getAsJsonObject("1_14"); + if (entities == null) + return; + for (Map.Entry entry : entities.entrySet()) { + this.mapping.put(entry.getKey(), entry.getValue().getAsString()); } } } @@ -386,36 +457,36 @@ protected class EntityMapping extends Mapping { @Override protected void load() { JsonObject entities = Util.readJsonResource(packConverter.getGson(), "/forwards/entities.json"); - if (entities != null) { - for (Map.Entry entry : entities.entrySet()) { - this.mapping.put(entry.getKey(), entry.getValue().getAsString()); - } + if (entities == null) + return; + for (Map.Entry entry : entities.entrySet()) { + this.mapping.put(entry.getKey(), entry.getValue().getAsString()); } } } protected class ItemMapping13 extends Mapping { - @Override protected void load() { - JsonObject items = Util.readJsonResource(packConverter.getGson(), "/forwards/items.json").getAsJsonObject("1_13"); - if (items != null) { - for (Map.Entry entry : items.entrySet()) { - this.mapping.put(entry.getKey(), entry.getValue().getAsString()); - } + JsonObject items = Util.readJsonResource(packConverter.getGson(), "/forwards/items.json") + .getAsJsonObject("1_13"); + if (items == null) + return; + for (Map.Entry entry : items.entrySet()) { + this.mapping.put(entry.getKey(), entry.getValue().getAsString()); } } } protected class ItemMapping14 extends Mapping { - @Override protected void load() { - JsonObject items = Util.readJsonResource(packConverter.getGson(), "/forwards/items.json").getAsJsonObject("1_14"); - if (items != null) { - for (Map.Entry entry : items.entrySet()) { - this.mapping.put(entry.getKey(), entry.getValue().getAsString()); - } + JsonObject items = Util.readJsonResource(packConverter.getGson(), "/forwards/items.json") + .getAsJsonObject("1_14"); + if (items == null) + return; + for (Map.Entry entry : items.entrySet()) { + this.mapping.put(entry.getKey(), entry.getValue().getAsString()); } } } @@ -423,11 +494,12 @@ protected void load() { protected class ItemMapping17 extends Mapping { @Override protected void load() { - JsonObject items = Util.readJsonResource(packConverter.getGson(), "/forwards/items.json").getAsJsonObject("1_17"); - if (items != null) { - for (Map.Entry entry : items.entrySet()) { - this.mapping.put(entry.getKey(), entry.getValue().getAsString()); - } + JsonObject items = Util.readJsonResource(packConverter.getGson(), "/forwards/items.json") + .getAsJsonObject("1_17"); + if (items == null) + return; + for (Map.Entry entry : items.entrySet()) { + this.mapping.put(entry.getKey(), entry.getValue().getAsString()); } } } 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 7c17cb38..9003a11b 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 @@ -34,27 +34,38 @@ public void convert(Pack pack) throws IOException { return; if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.20")) versionInt = 15; - else if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.19.4") && version < Util.getVersionProtocol(packConverter.getGson(), "1.20")) + 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")) + 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")) + 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")) + 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")) + 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")) + 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")) + 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")) + 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")) + 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")) + 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")) + else if (version >= Util.getVersionProtocol(packConverter.getGson(), "1.7.2") + && version < Util.getVersionProtocol(packConverter.getGson(), "1.9")) versionInt = 1; else versionInt = 0; 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 0aec7b65..a21f02fe 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 @@ -20,7 +20,8 @@ public ParticleConverter(PackConverter packConverter) { @Override public void convert(Pack pack) throws IOException { // The directory to convert - particles = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "particles"); + particles = pack.getWorkingPath() + .resolve("assets" + File.separator + "minecraft" + File.separator + "particles"); // Check if the two merged files exist. boolean barrier = false; 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 1fe4323d..16f49183 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 @@ -4,6 +4,7 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.Util; import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.Logger; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -24,13 +25,16 @@ public SoundsConverter(PackConverter packConverter) { /** * Updates Sounds + * * @param pack * @throws IOException */ @Override public void convert(Pack pack) throws IOException { - Path soundsJsonPath = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "sounds.json"); - if (!soundsJsonPath.toFile().exists()) return; + Path soundsJsonPath = pack.getWorkingPath() + .resolve("assets" + File.separator + "minecraft" + File.separator + "sounds.json"); + if (!soundsJsonPath.toFile().exists()) + return; JsonObject sounds = Util.readJson(packConverter.getGson(), soundsJsonPath); JsonObject newSoundsObject = new JsonObject(); @@ -45,18 +49,23 @@ public void convert(Pack pack) throws IOException { 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()); - - Path baseSoundsPath = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "sounds"); + else + throw new IllegalArgumentException( + "Unknown element type: " + jsonElement.getClass().getSimpleName()); + + Path baseSoundsPath = pack.getWorkingPath() + .resolve("assets" + File.separator + "minecraft" + File.separator + "sounds"); Path path = baseSoundsPath.resolve(sound + ".ogg"); if (!Util.fileExistsCorrectCasing(path)) { - String rewrite = path.toFile().getCanonicalPath().substring(baseSoundsPath.toString().length() + 1, path.toFile().getCanonicalPath().length() - 4); - if (packConverter.DEBUG) PackConverter.log(" Rewriting Sound: '" + sound + "' -> '" + rewrite + "'"); + String rewrite = path.toFile().getCanonicalPath().substring( + baseSoundsPath.toString().length() + 1, + path.toFile().getCanonicalPath().length() - 4); + if (packConverter.DEBUG) + Logger.log(" Rewriting Sound: '" + sound + "' -> '" + rewrite + "'"); sound = rewrite; } else { sound = jsonElement.getAsString(); @@ -69,7 +78,7 @@ 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); @@ -81,6 +90,7 @@ else if (jsonElement instanceof JsonPrimitive) } } - Files.write(soundsJsonPath, Collections.singleton(packConverter.getGson().toJson(newSoundsObject)), Charset.forName("UTF-8")); + Files.write(soundsJsonPath, Collections.singleton(packConverter.getGson().toJson(newSoundsObject)), + Charset.forName("UTF-8")); } } 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 37aee81a..56850a8a 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 @@ -4,6 +4,7 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.Util; import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.Logger; import java.io.File; import java.io.IOException; @@ -41,8 +42,8 @@ protected void findFiles(Path path) throws IOException { File[] fList = directory.listFiles(); for (File file : fList) { String dir = fixSpaces(file.toPath()); - if (file.isDirectory()) - findFiles(Paths.get(dir)); + if (file.isDirectory()) + findFiles(Paths.get(dir)); } } } @@ -65,7 +66,7 @@ protected String fixSpaces(Path path) throws IOException { return "null"; if (ret && packConverter.DEBUG) { - PackConverter.log(" Renamed: " + path.getFileName().toString() + "->" + noSpaces); + Logger.log(" Renamed: " + path.getFileName().toString() + "->" + noSpaces); return path.getParent() + File.separator + noSpaces; } else if (!ret) { System.err.println(" Failed to rename: " + path.getFileName().toString() + "->" + noSpaces); 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 e3e9d69e..b0bfa3ab 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 @@ -92,55 +92,56 @@ private void chest(Path imagePath, String 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()) { - ImageConverter normal = new ImageConverter(defaultW, defaultH, imagePath.resolve(name + "_double.png")); - if (!normal.fileIsPowerOfTwo()) return; - - // Left Side - // Body - normal.newImage(64, 64); - normal.subImage(59, 19, 74, 33, 14, 19, true); - normal.subImage(59, 0, 74, 14, 14, 0, true); - normal.subImage(29, 19, 44, 33, 29, 19, true); - normal.subImage(29, 14, 44, 19, 43, 14, 1); - normal.subImage(29, 0, 44, 14, 29, 0, true); - normal.subImage(44, 33, 58, 43, 29, 33, 1); - normal.subImage(29, 33, 44, 43, 43, 33, 1); - normal.subImage(58, 33, 73, 43, 14, 33, 1); - normal.subImage(44, 14, 58, 19, 29, 14, 1); - normal.subImage(58, 14, 73, 19, 14, 14, 1); - - // Latch - normal.subImage(4, 0, 5, 1, 1, 0); - normal.subImage(2, 0, 3, 1, 2, 0); - normal.subImage(2, 1, 5, 5, 1, 1, 1); - - // Stores Image - normal.store(imagePath.resolve(name + "_left.png")); - - // Right Side - // Body - normal.newImage(64, 64); - normal.subImage(44, 0, 59, 14, 14, 0, true); - normal.subImage(14, 0, 29, 14, 29, 0, true); - normal.subImage(14, 19, 29, 33, 29, 19, true); - normal.subImage(0, 14, 14, 19, 0, 14, 1); - normal.subImage(73, 14, 88, 19, 14, 14, 1); - normal.subImage(14, 14, 29, 19, 43, 14, 1); - normal.subImage(44, 19, 59, 33, 14, 19, true); - normal.subImage(14, 33, 29, 43, 43, 33, 1); - normal.subImage(0, 33, 14, 43, 0, 33, 1); - normal.subImage(73, 33, 88, 43, 14, 33, 1); - - // Latch - normal.subImage(3, 0, 4, 1, 1, 0); - normal.subImage(1, 0, 2, 1, 2, 0); - normal.subImage(0, 1, 1, 5, 0, 1, true); - normal.subImage(5, 1, 6, 5, 1, 1, true); - 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().exists()) + return; + ImageConverter normal = new ImageConverter(defaultW, defaultH, imagePath.resolve(name + "_double.png")); + if (!normal.fileIsPowerOfTwo()) + return; + + // Left Side + // Body + normal.newImage(64, 64); + normal.subImage(59, 19, 74, 33, 14, 19, true); + normal.subImage(59, 0, 74, 14, 14, 0, true); + normal.subImage(29, 19, 44, 33, 29, 19, true); + normal.subImage(29, 14, 44, 19, 43, 14, 1); + normal.subImage(29, 0, 44, 14, 29, 0, true); + normal.subImage(44, 33, 58, 43, 29, 33, 1); + normal.subImage(29, 33, 44, 43, 43, 33, 1); + normal.subImage(58, 33, 73, 43, 14, 33, 1); + normal.subImage(44, 14, 58, 19, 29, 14, 1); + normal.subImage(58, 14, 73, 19, 14, 14, 1); + + // Latch + normal.subImage(4, 0, 5, 1, 1, 0); + normal.subImage(2, 0, 3, 1, 2, 0); + normal.subImage(2, 1, 5, 5, 1, 1, 1); + + // Stores Image + normal.store(imagePath.resolve(name + "_left.png")); + + // Right Side + // Body + normal.newImage(64, 64); + normal.subImage(44, 0, 59, 14, 14, 0, true); + normal.subImage(14, 0, 29, 14, 29, 0, true); + normal.subImage(14, 19, 29, 33, 29, 19, true); + normal.subImage(0, 14, 14, 19, 0, 14, 1); + normal.subImage(73, 14, 88, 19, 14, 14, 1); + normal.subImage(14, 14, 29, 19, 43, 14, 1); + normal.subImage(44, 19, 59, 33, 14, 19, true); + normal.subImage(14, 33, 29, 43, 43, 33, 1); + normal.subImage(0, 33, 14, 43, 0, 33, 1); + normal.subImage(73, 33, 88, 43, 14, 33, 1); + + // Latch + normal.subImage(3, 0, 4, 1, 1, 0); + normal.subImage(1, 0, 2, 1, 2, 0); + normal.subImage(0, 1, 1, 5, 0, 1, true); + normal.subImage(5, 1, 6, 5, 1, 1, true); + normal.subImage(1, 1, 2, 5, 3, 1, true); + normal.store(imagePath.resolve(name + "_right.png")); + + imagePath.resolve(name + "_double.png").toFile().delete(); } } 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 3b5d676c..de837d3f 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 @@ -17,11 +17,14 @@ public EnchantConverter(PackConverter packConverter) { @Override public void convert(Pack pack) throws IOException { - Path paintingPath = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "textures" + File.separator + "misc" + File.separator + "enchanted_item_glint.png"); - if (!paintingPath.toFile().exists()) return; + Path paintingPath = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + + "textures" + File.separator + "misc" + File.separator + "enchanted_item_glint.png"); + if (!paintingPath.toFile().exists()) + return; ImageConverter imageConverter = new ImageConverter(64, 64, paintingPath); - if (!imageConverter.fileIsPowerOfTwo()) return; + if (!imageConverter.fileIsPowerOfTwo()) + return; imageConverter.newImage(64, 64); imageConverter.colorize(new Color(94, 9, 178, 120)); 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 a723c81e..12b1782f 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 @@ -16,8 +16,11 @@ public InventoryConverter(PackConverter packConverter) { @Override public void convert(Pack pack) throws IOException { - Path imagePath = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "textures" + File.separator + "gui" + File.separator + "container" + File.separator + "inventory.png"); - if (!imagePath.toFile().exists()) return; + Path imagePath = pack.getWorkingPath() + .resolve("assets" + File.separator + "minecraft" + File.separator + "textures" + File.separator + "gui" + + File.separator + "container" + File.separator + "inventory.png"); + if (!imagePath.toFile().exists()) + return; int defaultW = 256, defaultH = 256; ImageConverter image = new ImageConverter(defaultW, defaultH, imagePath); 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 cab268d7..87e120e0 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 @@ -4,6 +4,7 @@ import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.Util; import com.agentdid127.resourcepack.library.pack.Pack; +import com.agentdid127.resourcepack.library.utilities.Logger; import javax.imageio.ImageIO; import java.awt.*; @@ -39,11 +40,14 @@ public MapIconConverter(PackConverter packConverter) { */ @Override public void convert(Pack pack) throws IOException { - Path imagePath = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "textures" + File.separator + "map" + File.separator + "forwards/map_icons.png"); - if (!imagePath.toFile().exists()) return; + Path imagePath = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + + "textures" + File.separator + "map" + File.separator + "forwards/map_icons.png"); + if (!imagePath.toFile().exists()) + return; BufferedImage newImage = Util.readImageResource("/forwards/map_icons.png"); - if (newImage == null) throw new NullPointerException(); + if (newImage == null) + throw new NullPointerException(); Graphics2D g2d = (Graphics2D) newImage.getGraphics(); BufferedImage image = ImageIO.read(imagePath.toFile()); @@ -52,13 +56,15 @@ public void convert(Pack pack) throws IOException { 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; + if (mapped == null) + continue; int newX = (int) (mapped >> 32); int newY = (int) (long) mapped; - PackConverter.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); + 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/MobEffectAtlasConverter.java b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MobEffectAtlasConverter.java new file mode 100644 index 00000000..43162d80 --- /dev/null +++ b/conversions/Forwards/src/main/java/com/agentdid127/resourcepack/forwards/impl/textures/MobEffectAtlasConverter.java @@ -0,0 +1,156 @@ +package com.agentdid127.resourcepack.forwards.impl.textures; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.util.HashMap; + +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.Logger; + +public class MobEffectAtlasConverter extends Converter { + public static HashMap MOB_EFFECTS = new HashMap(); + static { + // Col #1 + // x: 0, y: 0, id: 0 - speed + MOB_EFFECTS.put(0, "speed.png"); + // x: 1, y: 0, id: 1 - slowness + MOB_EFFECTS.put(1, "slowness.png"); + // x: 2, y: 0, id: 2 - haste + MOB_EFFECTS.put(2, "haste.png"); + // x: 3, y: 0, id: 3 - mining fatigue + MOB_EFFECTS.put(3, "mining_fatigue.png"); + // x: 4, y: 0, id: 4 - strength + MOB_EFFECTS.put(4, "strength.png"); + // x: 5, y: 0, id: 5 - weakness + MOB_EFFECTS.put(5, "weakness.png"); + // x: 6, y: 0, id: 6 - poison + MOB_EFFECTS.put(6, "poison.png"); + // x: 7, y: 0, id: 7 - regeneration + MOB_EFFECTS.put(7, "regeneration.png"); + // x: 8, y: 0, id: 8 - slow falling + MOB_EFFECTS.put(8, "slow_falling.png"); + // x: 9, y: 0, id: 9 - conduit power + MOB_EFFECTS.put(9, "conduit_power.png"); + // x: 10, y: 0, id: 10 - dolphins grace + MOB_EFFECTS.put(10, "dolphins_grace.png"); + // x: 11, y: 0, id: 11 - unknown + + // Col #2 + // x: 0, y: 1, id: 256 - invisibility + MOB_EFFECTS.put(256, "invisibility.png"); + // x: 1, y: 1, id: 257 - hunger + MOB_EFFECTS.put(257, "hunger.png"); + // x: 2, y: 1, id: 258 - jump boost + MOB_EFFECTS.put(258, "jump_boost.png"); + // x: 3, y: 1, id: 259 - nausea + MOB_EFFECTS.put(259, "nausea.png"); + // x: 4, y: 1, id: 260 - night vision + MOB_EFFECTS.put(260, "night_vision.png"); + // x: 5, y: 1, id: 261 - blindness + MOB_EFFECTS.put(261, "blindness.png"); + // x: 6, y: 1, id: 262 - resistance + MOB_EFFECTS.put(262, "resistance.png"); + // x: 7, y: 1, id: 263 - fire resistance + MOB_EFFECTS.put(263, "fire_resistance.png"); + // x: 8, y: 1, id: 264 - unknown + // x: 9, y: 1, id: 265 - unknown + // x: 10, y: 1, id: 266 - unknown + // x: 11, y: 1, id: 267 - unknown + + // Col #3 + // x: 0, y: 2, id: 512 - water breathing + MOB_EFFECTS.put(512, "water_breathing.png"); + // x: 1, y: 2, id: 513 - wither + MOB_EFFECTS.put(513, "wither.png"); + // x: 2, y: 2, id: 514 - absorption + MOB_EFFECTS.put(514, "absorption.png"); + // x: 3, y: 2, id: 515 - levitation + MOB_EFFECTS.put(515, "levitation.png"); + // x: 4, y: 2, id: 516 - glowing + MOB_EFFECTS.put(516, "glowing.png"); + // x: 5, y: 2, id: 517 - luck + MOB_EFFECTS.put(517, "luck.png"); + // x: 6, y: 2, id: 518 - bad luck + MOB_EFFECTS.put(518, "unluck.png"); + // x: 7, y: 2, id: 519 - health boost + MOB_EFFECTS.put(519, "health_boost.png"); + // x: 8, y: 2, id: 520 - unknown + // x: 9, y: 2, id: 521 - unknown + // x: 10, y: 2, id: 522 - unknown + // x: 11, y: 2, id: 523 - unknown + } + + public MobEffectAtlasConverter(PackConverter packConverter) { + super(packConverter); + } + + /** + * Converts inventory.png mob atlas into its own files + * + * @param pack + * @throws IOException + */ + @Override + public void convert(Pack pack) throws IOException { + Path inventoryPath = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + + "textures" + File.separator + "gui" + File.separator + "container" + File.separator + + "inventory.png"); + if (!inventoryPath.toFile().exists()) + return; + + int DWIDTH = 256, DHEIGHT = 256; + ImageConverter inventoryImage = new ImageConverter(DWIDTH, DHEIGHT, inventoryPath); + if (!inventoryImage.fileIsPowerOfTwo() || !inventoryImage.isSquare()) { + Logger.log("Failed to generate mob_effect-atlas, inventory image is not power of 2/is not square!"); + return; + } + + Path mobEffectPath = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + + "textures" + File.separator + "mob_effect"); + if (!mobEffectPath.toFile().exists()) + mobEffectPath.toFile().mkdirs(); + + int iw = 18; // effect width + int ih = 18; // effect height + + int rows = 3; // Default rows + int cols = 12; // Default cols + + int START_HEIGHT = DHEIGHT - 58; // Start heigh + + for (int y = 0; y < rows; ++y) { + for (int x = 0; x < cols; ++x) { + int id = y * 256 + x; // 256 is a hack, idk what else to do + if (!MOB_EFFECTS.containsKey(id)) { + if (PackConverter.DEBUG) + Logger.log("Could not find effect with RPID=" + id); + continue; + } + + String effect_file_name = MOB_EFFECTS.get(id); + if (PackConverter.DEBUG) + Logger.log("Effect: " + effect_file_name); + + int sx = x * iw; + int sy = START_HEIGHT + (y * ih); + + Path imagePath = mobEffectPath.resolve(effect_file_name); + if (!imagePath.toFile().exists()) { + inventoryImage.newImage(iw, ih); + inventoryImage.subImage(sx, sy, sx + iw, sy + ih); + inventoryImage.store(imagePath); + } + + // Logger.log("x: " + x + ", y: " + y + ", id: " + id); + } + } + + inventoryImage.newImage(DWIDTH, DHEIGHT); + inventoryImage.subImage(0, 0, DWIDTH, START_HEIGHT); + inventoryImage.store(inventoryPath); + } +} \ 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/PaintingConverter.java index 7f8e0ba3..4dc2b3bc 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 @@ -22,8 +22,10 @@ public PaintingConverter(PackConverter packConverter) { */ @Override public void convert(Pack pack) throws IOException { - Path paintingPath = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "textures" + File.separator + "painting" + File.separator); - if (!paintingPath.toFile().exists()) return; + Path paintingPath = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + + "textures" + File.separator + "painting" + File.separator); + if (!paintingPath.toFile().exists()) + return; // 16x16 painting(paintingPath, "kebab.png", 0, 0, 1, 1); @@ -73,8 +75,10 @@ public void convert(Pack pack) throws IOException { private void painting(Path paintingPath, String name, int x, int y, int scaleX, int scaleY) throws IOException { int defaultW = 16, defaultH = 16; if (paintingPath.resolve("paintings_kristoffer_zetterstrand.png").toFile().exists()) { - ImageConverter normal = new ImageConverter(256, 256, paintingPath.resolve("paintings_kristoffer_zetterstrand.png")); - if (!normal.fileIsPowerOfTwo()) return; + ImageConverter normal = new ImageConverter(256, 256, + paintingPath.resolve("paintings_kristoffer_zetterstrand.png")); + if (!normal.fileIsPowerOfTwo()) + return; normal.newImage(defaultW * scaleX, defaultH * scaleY); normal.subImage(x, y, x + defaultW * scaleX, y + defaultH * scaleY, 0, 0); normal.store(paintingPath.resolve(name)); 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 834de82e..92346824 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 @@ -27,13 +27,15 @@ public ParticleTextureConverter(PackConverter packConverter, int from, int to) { */ @Override public void convert(Pack pack) throws IOException { - Path imagePath = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "textures" + File.separator + "particle" + File.separator); - if (!imagePath.toFile().exists()) return; - if (!imagePath.resolve("particles.png").toFile().exists()) return; + Path imagePath = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + + "textures" + File.separator + "particle" + File.separator); + if (!imagePath.toFile().exists() || !imagePath.resolve("particles.png").toFile().exists()) + return; int defaultW = 128, defaultH = 128; ImageConverter iconvert = new ImageConverter(defaultW, defaultH, imagePath.resolve("particles.png")); - if (!iconvert.fileIsPowerOfTwo()) return; + if (!iconvert.fileIsPowerOfTwo()) + return; // Particles boolean isLegacy = false; @@ -43,7 +45,8 @@ public void convert(Pack pack) throws IOException { isLegacy = iconvert.store(); } - if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.13.2") && to >= Util.getVersionProtocol(packConverter.getGson(), "1.14")) { + if (from <= Util.getVersionProtocol(packConverter.getGson(), "1.13.2") + && to >= Util.getVersionProtocol(packConverter.getGson(), "1.14")) { defaultW = 256; defaultH = 256; if (!isLegacy) @@ -413,7 +416,8 @@ public void convert(Pack pack) throws IOException { iconvert.newImage(8, 8); iconvert.subImage(8, 16, 16, 24, 0, 0); - iconvert.store(pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "textures" + File.separator + "entity" + File.separator + "fishing_hook.png")); + iconvert.store(pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + + "textures" + File.separator + "entity" + File.separator + "fishing_hook.png")); } } } 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 efdd2c83..e952db0a 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 @@ -22,12 +22,15 @@ public TitleConverter(PackConverter packConverter) { */ @Override public void convert(Pack pack) throws IOException { - Path imagePath = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "textures" + File.separator + "gui" + File.separator + "title" + File.separator + "minecraft.png"); - if (!imagePath.toFile().exists()) return; + Path imagePath = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + + "textures" + File.separator + "gui" + File.separator + "title" + File.separator + "minecraft.png"); + if (!imagePath.toFile().exists()) + return; int oldWidth = 256, oldHeight = 256; ImageConverter image = new ImageConverter(oldWidth, oldHeight, imagePath); - if (!image.isSquare()) return; + if (!image.isSquare()) + return; // Normal Minecraft Title image.newImage(274, 64); diff --git a/conversions/pom.xml b/conversions/pom.xml index 77c08c58..1f5f2544 100644 --- a/conversions/pom.xml +++ b/conversions/pom.xml @@ -5,7 +5,7 @@ ResourcePackConverter com.agentdid127 - 2.2.2 + 2.2.3 4.0.0 @@ -32,7 +32,7 @@ com.agentdid127.resourcepack Library - 2.2.2 + 2.2.3 diff --git a/library/pom.xml b/library/pom.xml index b849b8af..419277c4 100644 --- a/library/pom.xml +++ b/library/pom.xml @@ -10,7 +10,7 @@ com.agentdid127 ResourcePackConverter - 2.2.2 + 2.2.3 ../pom.xml \ No newline at end of file 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 d8fbbc2c..7bcebc1e 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/PackConverter.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/PackConverter.java @@ -2,15 +2,13 @@ import com.google.gson.Gson; -import java.io.PrintStream; import java.util.LinkedHashMap; import java.util.Map; public abstract class PackConverter { protected final Map, Converter> converters = new LinkedHashMap<>(); protected Gson gson; - public boolean DEBUG = true; - protected static PrintStream out; + public static boolean DEBUG = true; /** * Registers Converter. @@ -30,10 +28,6 @@ public T getConverter(Class clazz) { return (T) converters.get(clazz); } - public static void log(String output) { - out.println(output); - } - /** * Gson * diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/Util.java b/library/src/main/java/com/agentdid127/resourcepack/library/Util.java index 71f108cd..e8a46e91 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/Util.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/Util.java @@ -1,5 +1,6 @@ package com.agentdid127.resourcepack.library; +import com.agentdid127.resourcepack.library.utilities.Logger; import com.google.gson.Gson; import com.google.gson.JsonObject; import com.google.gson.stream.JsonReader; @@ -12,6 +13,7 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import java.util.Map; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; @@ -52,7 +54,7 @@ public static void deleteDirectoryAndContents(Path dirPath) throws IOException { // noinspection ResultOfMethodCallIgnored Files.walk(dirPath).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(file -> { file.delete(); - System.out.println(file.getName()); + Logger.log(file.getName()); }); } @@ -126,7 +128,8 @@ public static String getVersionFromProtocol(Gson gson, int protocol) { JsonObject protocols = Util.readJsonResource(gson, "/protocol.json"); if (protocols == null) return null; - List keys = protocols.entrySet().stream().map(i -> i.getKey()).collect(Collectors.toCollection(ArrayList::new)); + List keys = protocols.entrySet().stream().map(i -> i.getKey()) + .collect(Collectors.toCollection(ArrayList::new)); keys.forEach(key -> { if (Integer.parseInt(protocols.get(key).getAsString()) == protocol) version.set(key); @@ -144,11 +147,10 @@ public static String[] getSupportedVersions(Gson gson) { JsonObject protocols = Util.readJsonResource(gson, "/protocol.json"); if (protocols == null) return null; - List keys = protocols.entrySet().stream().map(i -> i.getKey()).collect(Collectors.toCollection(ArrayList::new)); - String[] keys2 = new String[keys.size()]; - for (int i = 0; i < keys.size(); i++) - keys2[i] = keys.get(i); - return keys2; + return protocols.entrySet() + .stream() + .map(Map.Entry::getKey) + .toArray(String[]::new); } public static JsonObject readJson(Gson gson, Path path) throws IOException { @@ -168,7 +170,7 @@ private 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(); @@ -200,24 +202,24 @@ public static Boolean renameFile(Path file, String newName) { public static Boolean mergeDirectories(File dir1, File dir2) throws IOException { if (!dir1.exists() && !dir2.exists()) return null; - + // TODO: another unused variable? String targetDirPath = dir1.getAbsolutePath(); File[] files = dir2.listFiles(); for (File file : files) { if (file.isDirectory()) { - System.out.println(dir1.getAbsolutePath() + File.separator + file.getName()); + Logger.log(dir1.getAbsolutePath() + File.separator + file.getName()); File file3 = new File(dir1.getAbsolutePath() + File.separator + file.getName()); file3.mkdirs(); - System.out.println("Created" + file3.getName()); + Logger.log("Created" + file3.getName()); mergeDirectories(file3, file); } else { - System.out.println(dir1.getAbsolutePath() + File.separator + file.getName()); + Logger.log(dir1.getAbsolutePath() + File.separator + file.getName()); file.renameTo(new File(dir1.getAbsolutePath() + File.separator + file.getName())); } } - if ((dir2.list().length == 0)) + if (dir2.list().length == 0) Files.delete(dir2.toPath()); return true; 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 d1139ce6..2bd11356 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 @@ -1,8 +1,8 @@ package com.agentdid127.resourcepack.library.pack; -import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.Util; import com.agentdid127.resourcepack.library.utilities.BomDetector; +import com.agentdid127.resourcepack.library.utilities.Logger; import java.io.IOException; import java.nio.file.Path; @@ -74,11 +74,11 @@ public Handler(Pack pack) { */ public void setup() throws IOException { if (pack.getWorkingPath().toFile().exists()) { - PackConverter.log(" Deleting existing conversion"); + Logger.log(" Deleting existing conversion"); Util.deleteDirectoryAndContents(pack.getWorkingPath()); } - PackConverter.log(" Copying existing pack"); + Logger.log(" Copying existing pack"); Util.copyDir(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) - PackConverter.log("Removing BOMs from " + count + " files."); + Logger.log("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 7f165c69..9223fa22 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 @@ -1,7 +1,8 @@ package com.agentdid127.resourcepack.library.pack; -import com.agentdid127.resourcepack.library.PackConverter; import com.agentdid127.resourcepack.library.Util; +import com.agentdid127.resourcepack.library.utilities.Logger; + import net.lingala.zip4j.ZipFile; import net.lingala.zip4j.exception.ZipException; import net.lingala.zip4j.model.ZipParameters; @@ -42,13 +43,13 @@ public Path getConvertedZipPath() { @Override public void setup() throws IOException { if (pack.getWorkingPath().toFile().exists()) { - PackConverter.log(" Deleting existing conversion"); + Logger.log(" Deleting existing conversion"); Util.deleteDirectoryAndContents(pack.getWorkingPath()); } Path convertedZipPath = getConvertedZipPath(); if (convertedZipPath.toFile().exists()) { - PackConverter.log(" Deleting existing conversion zip"); + Logger.log(" Deleting existing conversion zip"); convertedZipPath.toFile().delete(); } @@ -73,7 +74,7 @@ public void setup() throws IOException { @Override public void finish() throws IOException { try { - PackConverter.log(" Zipping working directory"); + Logger.log(" Zipping working directory"); ZipFile zipFile = new ZipFile(getConvertedZipPath().toFile()); ZipParameters parameters = new ZipParameters(); parameters.setIncludeRootFolder(false); @@ -82,7 +83,7 @@ public void finish() throws IOException { Util.propagate(e); } - PackConverter.log(" Deleting working directory"); + Logger.log(" Deleting working directory"); Util.deleteDirectoryAndContents(pack.getWorkingPath()); } diff --git a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/BomDetector.java b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/BomDetector.java index 53cd09d5..4275f631 100644 --- a/library/src/main/java/com/agentdid127/resourcepack/library/utilities/BomDetector.java +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/BomDetector.java @@ -51,7 +51,7 @@ public final class BomDetector { public BomDetector(String rootDirectory, String... fileExtensions) { this.rootDir = new File(rootDirectory); this.extensions = Arrays.asList(fileExtensions); - if (!rootDir.exists() || rootDir.isFile()) + if (!rootDir.exists() || rootDir.isFile()) throw new RuntimeException("Root directory not valid."); } @@ -85,10 +85,6 @@ public List removeBOMs() throws IOException { /** Different encodings will have different BOMs. This is for UTF-8. */ private final int[] BYTE_ORDER_MARK = { 239, 187, 191 }; - private static void log(Object thing) { - System.out.println(String.valueOf(thing)); - } - private List findTextFilesBeneath(File startingDir) throws IOException { List result = new ArrayList(); File[] filesAndDirs = startingDir.listFiles(); @@ -125,7 +121,7 @@ private boolean startsWithBOM(File textFile) throws IOException { InputStream input = null; try { input = new FileInputStream(textFile); - for (int index = 0; index < BYTE_ORDER_MARK.length; ++index) + for (int index = 0; index < BYTE_ORDER_MARK.length; ++index) firstFewBytes[index] = input.read(); // read a single byte result = Arrays.equals(firstFewBytes, BYTE_ORDER_MARK); } finally { @@ -147,7 +143,7 @@ private void stripBomFrom(String textFile) throws IOException { while (totalBytesReadIntoMemory < truncatedSize) { int bytesRemaining = (int) truncatedSize - totalBytesReadIntoMemory; int bytesRead = input.read(memory, totalBytesReadIntoMemory, bytesRemaining); - if (bytesRead > 0) + if (bytesRead > 0) totalBytesReadIntoMemory = totalBytesReadIntoMemory + bytesRead; } overwriteWithoutBOM(memory, bomFile); @@ -158,7 +154,8 @@ private void stripBomFrom(String textFile) throws IOException { long finalSize = after.length(); long changeInSize = initialSize - finalSize; if (changeInSize != BYTE_ORDER_MARK.length) { - throw new RuntimeException("Change in file size: " + changeInSize + " Expected change: " + BYTE_ORDER_MARK.length); + throw new RuntimeException( + "Change in file size: " + changeInSize + " Expected change: " + BYTE_ORDER_MARK.length); } } 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 0270a245..d7a0dfc1 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 @@ -1,7 +1,5 @@ package com.agentdid127.resourcepack.library.utilities; -import com.agentdid127.resourcepack.library.PackConverter; - import javax.imageio.ImageIO; import java.awt.*; import java.awt.geom.AffineTransform; @@ -38,8 +36,9 @@ public ImageConverter(int defaultWIn, int defaultHIn, Path locationIn) throws IO wMultiplier = wMultiplier == 0 ? 1 : wMultiplier; hMultiplier = hMultiplier == 0 ? 1 : hMultiplier; } else { - PackConverter.log("File is not a power of 2. Converting image to be so."); - newImage = new BufferedImage((int) Math.ceil(Math.log(image.getWidth()) / Math.log(2)), (int) Math.ceil(Math.log(image.getHeight()) / Math.log(2)), image.getType()); + Logger.log("File is not a power of 2. Converting image to be so."); + newImage = new BufferedImage((int) Math.ceil(Math.log(image.getWidth()) / Math.log(2)), + (int) Math.ceil(Math.log(image.getHeight()) / Math.log(2)), image.getType()); width = (int) Math.ceil(Math.log(image.getWidth()) / Math.log(2)); defaultW = defaultWIn; defaultH = defaultHIn; @@ -74,7 +73,7 @@ public void setImage(int defaultWIn, int defaultHIn) throws IOException { wMultiplier = image.getWidth() / defaultW; hMultiplier = image.getHeight() / defaultH; } else - PackConverter.log("File is not a power of 2"); + Logger.log("File is not a power of 2"); } // Creates a new Image to store @@ -102,6 +101,10 @@ public void subImage(int x, int y, int x2, int y2, int storex, int storey) { g2d.drawImage(part, storex * wMultiplier, storey * hMultiplier, null); } + public void subImage(int x, int y, int x2, int y2) { + subImage(x, y, x2, y2, 0, 0); + } + // Takes a part of an image and flips it either horizontally or vertically public void subImage(int x, int y, int x2, int y2, int storex, int storey, boolean flip) { int x3; @@ -171,7 +174,7 @@ private static BufferedImage createFlipped(BufferedImage image2, boolean flip) { // Transforms the BufferedImage private static BufferedImage createTransformed(BufferedImage image, AffineTransform at) { - BufferedImage newImage = new BufferedImage(image.getWidth(), image.getHeight(),BufferedImage.TYPE_INT_ARGB); + BufferedImage newImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g = newImage.createGraphics(); g.transform(at); g.drawImage(image, 0, 0, null); 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 new file mode 100644 index 00000000..d6b28220 --- /dev/null +++ b/library/src/main/java/com/agentdid127/resourcepack/library/utilities/Logger.java @@ -0,0 +1,19 @@ +package com.agentdid127.resourcepack.library.utilities; + +import java.io.PrintStream; + +public class Logger { + private static PrintStream stream; + + public static void setStream(PrintStream stream) { + Logger.stream = stream; + } + + public static void log(String message) { + stream.println(message); + } + + public static void log(Object thing) { + stream.println(String.valueOf(thing)); + } +} diff --git a/library/src/main/resources/protocol.json b/library/src/main/resources/protocol.json index 7d273076..81238833 100644 --- a/library/src/main/resources/protocol.json +++ b/library/src/main/resources/protocol.json @@ -73,5 +73,8 @@ "1.19.4": "762", "1.20": "763", "1.20.0": "763", - "1.20.1": "763" + "1.20.1": "763", + "1.20.2": "764", + "1.20.3": "765", + "1.20.4": "765" } \ No newline at end of file diff --git a/pom.xml b/pom.xml index 12758f9a..0cd6c578 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.agentdid127 ResourcePackConverter - 2.2.2 + 2.2.3 pom ResourcePackConverter