From f2d3761a95007d6e5298b2cf040ca86f4b1daa25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZX=E5=A4=8F=E5=A4=9C=E4=B9=8B=E9=A3=8E?= Date: Tue, 7 Jan 2025 19:09:12 +0800 Subject: [PATCH 01/25] =?UTF-8?q?=E5=BA=94=E8=AF=A5=E6=80=BB=E6=98=AF?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=20UTF-8=20=E7=BC=96=E7=A0=81=E4=BB=A5?= =?UTF-8?q?=E4=BF=9D=E8=AF=81=E5=86=85=E5=AE=B9=E7=BC=96=E7=A0=81=E7=BB=9F?= =?UTF-8?q?=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/tacz/guns/resource/PackConvertor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/tacz/guns/resource/PackConvertor.java b/src/main/java/com/tacz/guns/resource/PackConvertor.java index 9e4cd3703..0f5e6b512 100644 --- a/src/main/java/com/tacz/guns/resource/PackConvertor.java +++ b/src/main/java/com/tacz/guns/resource/PackConvertor.java @@ -159,7 +159,7 @@ private boolean parseRecipe(ZipOutputStream newZip, ZipEntry entry, ZipFile oldP if (object != null) { object.addProperty("type", "tacz:gun_smith_table_crafting"); newZip.putNextEntry(new ZipEntry(newPath)); - newZip.write(GSON.toJson(object).getBytes()); + newZip.write(GSON.toJson(object).getBytes(StandardCharsets.UTF_8)); newZip.closeEntry(); } } catch (JsonParseException e) { @@ -311,7 +311,7 @@ private void addMeta(ZipOutputStream newZip) throws IOException { newZip.putNextEntry(entry); PackMeta meta = new PackMeta(namespace, null); - newZip.write(GSON.toJson(meta).getBytes()); + newZip.write(GSON.toJson(meta).getBytes(StandardCharsets.UTF_8)); newZip.closeEntry(); } From b632b54eb45317064df4e7ad57013e85706f6e38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZX=E5=A4=8F=E5=A4=9C=E4=B9=8B=E9=A3=8E?= Date: Tue, 7 Jan 2025 19:28:27 +0800 Subject: [PATCH 02/25] =?UTF-8?q?=E7=8E=B0=E5=9C=A8=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E8=BD=AC=E6=8D=A2=E6=96=87=E4=BB=B6=E5=A4=B9?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E7=9A=84=E6=9E=AA=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tacz/guns/resource/PackConvertor.java | 52 +++-- .../guns/resource/convert/ConverterUtils.java | 37 +++ .../guns/resource/convert/PackConverter.java | 7 + .../convert/folder/EmptyFolderRemover.java | 27 +++ .../guns/resource/convert/folder/FileOp.java | 18 ++ .../convert/folder/FolderEntryVisitor.java | 19 ++ .../convert/folder/FolderPackConverter.java | 217 ++++++++++++++++++ .../com/tacz/guns/util/ThrowingRunnable.java | 5 + 8 files changed, 361 insertions(+), 21 deletions(-) create mode 100644 src/main/java/com/tacz/guns/resource/convert/ConverterUtils.java create mode 100644 src/main/java/com/tacz/guns/resource/convert/PackConverter.java create mode 100644 src/main/java/com/tacz/guns/resource/convert/folder/EmptyFolderRemover.java create mode 100644 src/main/java/com/tacz/guns/resource/convert/folder/FileOp.java create mode 100644 src/main/java/com/tacz/guns/resource/convert/folder/FolderEntryVisitor.java create mode 100644 src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java create mode 100644 src/main/java/com/tacz/guns/util/ThrowingRunnable.java diff --git a/src/main/java/com/tacz/guns/resource/PackConvertor.java b/src/main/java/com/tacz/guns/resource/PackConvertor.java index 0f5e6b512..6d7cd8c92 100644 --- a/src/main/java/com/tacz/guns/resource/PackConvertor.java +++ b/src/main/java/com/tacz/guns/resource/PackConvertor.java @@ -3,6 +3,8 @@ import com.google.gson.*; import com.tacz.guns.GunMod; import com.tacz.guns.client.resource.pojo.PackInfo; +import com.tacz.guns.resource.convert.folder.FolderPackConverter; +import com.tacz.guns.util.ThrowingRunnable; import net.minecraft.commands.CommandSourceStack; import net.minecraft.network.chat.Component; import net.minecraftforge.fml.loading.FMLPaths; @@ -59,33 +61,41 @@ public static void convert(CommandSourceStack source) { msg(source, Component.translatable("message.tacz.converter.start")); GunMod.LOGGER.info("Start converting legacy packs..."); for (File file : files) { + ThrowingRunnable conversionOp; if (file.isFile() && file.getName().endsWith(".zip")) { PackConvertor.LegacyPack pack = fromZipFile(file); - if (pack != null) { - msg(source, Component.translatable("message.tacz.converter.pack.start", file.getName())); - GunMod.LOGGER.info("Attempt to converting legacy pack: {}", file.getName()); - try { - pack.convert(); - } catch (FileAlreadyExistsException e) { - msg(source, Component.translatable("message.tacz.converter.pack.exist")); - GunMod.LOGGER.warn("Target file already exists: {}", file.getName()); - skip++; - continue; - } catch (Exception e){ - msg(source, Component.translatable("message.tacz.converter.pack.failed", file.getName())); - GunMod.LOGGER.error("Failed to convert legacy pack: {}", file.getName(), e); - error++; - continue; - } - cnt++; - msg(source, Component.translatable("message.tacz.converter.pack.finish", file.getName())); - GunMod.LOGGER.info("Legacy pack converted: {}", file.getName()); + if (pack == null) { + GunMod.LOGGER.warn("Skip ZIP archive which is not a gun pack: {}", file.getName()); + skip++; + continue; + } else { + conversionOp = pack::convert; } + } else if (file.isDirectory()) { + conversionOp = () -> FolderPackConverter.INSTANCE.convert(file); } else { - msg(source, Component.translatable("message.tacz.converter.pack.folder", file.getName())); - GunMod.LOGGER.warn("Skip folder: {}", file.getName()); + GunMod.LOGGER.warn("Skip non-pack: {}", file.getName()); skip++; + continue; } + msg(source, Component.translatable("message.tacz.converter.pack.start", file.getName())); + GunMod.LOGGER.info("Attempt to converting legacy pack: {}", file.getName()); + try { + conversionOp.run(); + } catch (FileAlreadyExistsException e) { + msg(source, Component.translatable("message.tacz.converter.pack.exist")); + GunMod.LOGGER.warn("Target file already exists: {}", file.getName()); + skip++; + continue; + } catch (Exception e) { + msg(source, Component.translatable("message.tacz.converter.pack.failed", file.getName())); + GunMod.LOGGER.error("Failed to convert legacy pack: {}", file.getName(), e); + error++; + continue; + } + cnt++; + msg(source, Component.translatable("message.tacz.converter.pack.finish", file.getName())); + GunMod.LOGGER.info("Legacy pack converted: {} (Is folder: {})", file.getName(), file.isDirectory()); } } watch.stop(); diff --git a/src/main/java/com/tacz/guns/resource/convert/ConverterUtils.java b/src/main/java/com/tacz/guns/resource/convert/ConverterUtils.java new file mode 100644 index 000000000..7f355f66e --- /dev/null +++ b/src/main/java/com/tacz/guns/resource/convert/ConverterUtils.java @@ -0,0 +1,37 @@ +package com.tacz.guns.resource.convert; + +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.PackType; +import org.jetbrains.annotations.Nullable; + +import java.io.File; + +public final class ConverterUtils { + + public static String relativePath(File base, File sub) { + return base.toPath().relativize(sub.toPath()).toString(); + } + + @Nullable + public static ResourceLocation parseEntryName(File baseDir, File file) { + String relativePath = relativePath(baseDir, file); + int i = relativePath.indexOf('/'); + if (i != -1) { + String namespace = relativePath.substring(0, i); + String entryName = relativePath.substring(i + 1); + return new ResourceLocation(namespace, entryName); + } + return null; + } + + public static String toFilePath(String namespace, String path, PackType folderType) { + return folderType.getDirectory() + File.separator + namespace + File.separator + path; + } + + public static String toFilePath(ResourceLocation resourceLocation, PackType folderType) { + return toFilePath(resourceLocation.getNamespace(), resourceLocation.getPath(), folderType); + } + + private ConverterUtils() { + } +} diff --git a/src/main/java/com/tacz/guns/resource/convert/PackConverter.java b/src/main/java/com/tacz/guns/resource/convert/PackConverter.java new file mode 100644 index 000000000..53b947a37 --- /dev/null +++ b/src/main/java/com/tacz/guns/resource/convert/PackConverter.java @@ -0,0 +1,7 @@ +package com.tacz.guns.resource.convert; + +import java.io.IOException; + +public interface PackConverter { + boolean convert(T pack) throws IOException; +} diff --git a/src/main/java/com/tacz/guns/resource/convert/folder/EmptyFolderRemover.java b/src/main/java/com/tacz/guns/resource/convert/folder/EmptyFolderRemover.java new file mode 100644 index 000000000..7c0875273 --- /dev/null +++ b/src/main/java/com/tacz/guns/resource/convert/folder/EmptyFolderRemover.java @@ -0,0 +1,27 @@ +package com.tacz.guns.resource.convert.folder; + +import java.io.IOException; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; + +import static org.apache.commons.io.file.PathUtils.isEmptyDirectory; + +public final class EmptyFolderRemover extends SimpleFileVisitor { + private final Path baseDir; + + public EmptyFolderRemover(Path baseDir) { + this.baseDir = baseDir; + } + + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { + if (!baseDir.equals(dir) && isEmptyDirectory(dir)) { + Files.delete(dir); + return FileVisitResult.SKIP_SUBTREE; + } + return FileVisitResult.CONTINUE; + } +} diff --git a/src/main/java/com/tacz/guns/resource/convert/folder/FileOp.java b/src/main/java/com/tacz/guns/resource/convert/folder/FileOp.java new file mode 100644 index 000000000..77ee5ef9b --- /dev/null +++ b/src/main/java/com/tacz/guns/resource/convert/folder/FileOp.java @@ -0,0 +1,18 @@ +package com.tacz.guns.resource.convert.folder; + +import net.minecraft.resources.ResourceLocation; + +import java.io.File; +import java.io.IOException; + +public interface FileOp { + boolean run(File baseDir, File file, ResourceLocation fileResourceLocation) throws IOException; + + default FileOp andThen(FileOp op) { + return (baseDir, file, fileResourceLocation) -> { + boolean self = FileOp.this.run(baseDir, file, fileResourceLocation); + boolean after = op.run(baseDir, file, fileResourceLocation); + return self && after; + }; + } +} diff --git a/src/main/java/com/tacz/guns/resource/convert/folder/FolderEntryVisitor.java b/src/main/java/com/tacz/guns/resource/convert/folder/FolderEntryVisitor.java new file mode 100644 index 000000000..35a950ffb --- /dev/null +++ b/src/main/java/com/tacz/guns/resource/convert/folder/FolderEntryVisitor.java @@ -0,0 +1,19 @@ +package com.tacz.guns.resource.convert.folder; + +import org.jetbrains.annotations.Nullable; + +import java.io.File; +import java.io.IOException; +import java.nio.file.FileVisitResult; + +public interface FolderEntryVisitor { + default boolean visitFile(File baseDir, File subFile) throws IOException { + return true; + } + + // return null if you can't handle the given directory + @Nullable + default FileVisitResult visitDirectory(File baseDir, File subFolder) throws IOException { + return null; + } +} diff --git a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java new file mode 100644 index 000000000..d4ea4d673 --- /dev/null +++ b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java @@ -0,0 +1,217 @@ +package com.tacz.guns.resource.convert.folder; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.tacz.guns.GunMod; +import com.tacz.guns.client.resource.pojo.PackInfo; +import com.tacz.guns.resource.PackMeta; +import com.tacz.guns.resource.convert.PackConverter; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.PackType; +import org.jetbrains.annotations.Nullable; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Function; + +import static com.tacz.guns.resource.PackConvertor.GSON; +import static com.tacz.guns.resource.convert.ConverterUtils.*; + +public enum FolderPackConverter implements PackConverter { + INSTANCE + ; + private final List processors = new ArrayList<>(); + + { + processors.add(createFileRenamer("info.json", "pack_info.json", PackType.CLIENT_RESOURCES)); + processors.add(createFolderRenamer("tags", "tacz_tags", PackType.SERVER_DATA)); + processors.add(createFolderMover("player_animator", PackType.CLIENT_RESOURCES)); + processors.add(createFolderRenamer("sounds", "tacz_sounds", PackType.SERVER_DATA)); + processors.add(createFolderMover("textures", PackType.CLIENT_RESOURCES)); + processors.add(createFolderMover("animations", PackType.CLIENT_RESOURCES)); + processors.add(createFolderMover("lang", PackType.CLIENT_RESOURCES)); + processors.add(createFolderRenamer("models", "geo_models", PackType.CLIENT_RESOURCES)); + processors.add(createFolderMover("display", PackType.CLIENT_RESOURCES)); + processors.add(createFolderMover("index", PackType.SERVER_DATA)); + processors.add(createFolderMover("data", PackType.SERVER_DATA)); + processors.add(createCategoryFileVisitor("recipes", + createJsonFileOperator(json -> { + JsonObject object = json.getAsJsonObject(); + if (!object.has("type")) { + object.addProperty("type", "tacz:gun_smith_table_crafting"); + return object; + } + return null; + }).andThen((baseDir, file, fileResourceLocation) -> move(baseDir, file, fileResourceLocation, PackType.SERVER_DATA)))); + } + + // return false if the given file does not represent a legacy pack + // return true even if conversion failed + @Override + public boolean convert(File baseDir) throws IOException { + if (!baseDir.isDirectory()) { + return false; + } + File[] subFiles = Objects.requireNonNullElseGet(baseDir.listFiles(), () -> new File[0]); + if (subFiles.length == 0) { + return false; + } + String namespace = null; + for (File subFile : subFiles) { + if (subFile.isDirectory()) { + File legacyPackFile = new File(subFile, "pack.json"); + if (legacyPackFile.isFile()) { + BufferedReader reader = Files.newBufferedReader(legacyPackFile.toPath(), StandardCharsets.UTF_8); + PackInfo legacyPackInfo = GSON.fromJson(reader, PackInfo.class); + if (legacyPackInfo != null) { + namespace = relativePath(baseDir, subFile); + break; + } + } + } + } + if (namespace == null) { + return false; + } + Path baseDirAsPath = baseDir.toPath(); + AtomicBoolean failed = new AtomicBoolean(); + Files.walkFileTree(baseDirAsPath, new SimpleFileVisitor<>() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + for (FolderEntryVisitor visitor : processors) { + if (visitor.visitFile(baseDir, file.toFile())) { + break; // a visitor handled this file, go next + } + } + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { + if (!baseDirAsPath.equals(dir)) { // always visit the root directory! + for (FolderEntryVisitor visitor : processors) { + FileVisitResult result = visitor.visitDirectory(baseDir, dir.toFile()); + if (result != null) { + return result; + } + } + } + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(Path file, IOException exc) { + GunMod.LOGGER.error("Error visiting old pack file", exc); + failed.set(true); + return FileVisitResult.TERMINATE; + } + }); + if (!failed.get()) { + Files.walkFileTree(baseDirAsPath, new EmptyFolderRemover(baseDirAsPath)); + PackMeta newPackMeta = new PackMeta(namespace, null); + String newPackMetaAsJson = GSON.toJson(newPackMeta); + Path newPackMetaPath = baseDirAsPath.resolve("gunpack.meta.json"); + Files.writeString(newPackMetaPath, newPackMetaAsJson, StandardCharsets.UTF_8); + } + return true; + } + + private static FolderEntryVisitor createFileRenamer(String oldPath, String newPath, PackType newFolderType) { + return new FolderEntryVisitor() { + @Override + public boolean visitFile(File baseDir, File subFile) { + ResourceLocation entry = parseEntryName(baseDir, subFile); + if (entry != null) { + String path = entry.getPath(); + if (path.equals(oldPath)) { + String namespace = entry.getNamespace(); + String newRelativePath = toFilePath(namespace, newPath, newFolderType); + File newFile = new File(baseDir, newRelativePath); + newFile.getParentFile().mkdirs(); + return subFile.renameTo(newFile); + } + } + return false; + } + }; + } + + private static FolderEntryVisitor createFolderRenamer(String oldPath, String newPath, PackType folderType) { + return new FolderEntryVisitor() { + @Override + public @Nullable FileVisitResult visitDirectory(File baseDir, File subFolder) { + ResourceLocation entry = parseEntryName(baseDir, subFolder); + if (entry != null) { + String path = entry.getPath(); + if (path.equals(oldPath)) { + String namespace = entry.getNamespace(); + String newRelativePath = toFilePath(namespace, newPath, folderType); + File newFile = new File(baseDir, newRelativePath); + newFile.getParentFile().mkdirs(); + subFolder.renameTo(newFile); + return FileVisitResult.SKIP_SUBTREE; + } + } + return null; + } + }; + } + + private static FolderEntryVisitor createFolderMover(String path, PackType folderType) { + return createFolderRenamer(path, path, folderType); + } + + private static FolderEntryVisitor createCategoryFileVisitor(String category, FileOp fileOperator) { + String categoryPlusSlash = category + "/"; + return new FolderEntryVisitor() { + @Override + public boolean visitFile(File baseDir, File subFile) throws IOException { + ResourceLocation entry = parseEntryName(baseDir, subFile); + if (entry != null) { + String path = entry.getPath(); + if (path.startsWith(categoryPlusSlash)) { + return fileOperator.run(baseDir, subFile, entry); + } + } + return false; + } + }; + } + + private static FileOp createJsonFileOperator(Function jsonOperator) { + return (baseDir, file, fileResourceLocation) -> { + if (file.getName().endsWith(".json")) { + Path asPath = file.toPath(); + BufferedReader reader = Files.newBufferedReader(asPath, StandardCharsets.UTF_8); + JsonElement oldJson = JsonParser.parseReader(reader); + JsonElement newJson = jsonOperator.apply(oldJson); + if (newJson != null) { + BufferedWriter writer = Files.newBufferedWriter(asPath, StandardCharsets.UTF_8); + GSON.toJson(newJson, writer); + return true; + } + } + return false; + }; + } + + private static boolean move(File baseDir, File file, ResourceLocation location, PackType folderType) { + String newPath = toFilePath(location, folderType); + File newFile = new File(baseDir, newPath); + newFile.getParentFile().mkdirs(); + return file.renameTo(newFile); + } +} diff --git a/src/main/java/com/tacz/guns/util/ThrowingRunnable.java b/src/main/java/com/tacz/guns/util/ThrowingRunnable.java new file mode 100644 index 000000000..4880a0332 --- /dev/null +++ b/src/main/java/com/tacz/guns/util/ThrowingRunnable.java @@ -0,0 +1,5 @@ +package com.tacz.guns.util; + +public interface ThrowingRunnable { + void run() throws T; +} From 54da5669ac69101db83516ab240ebb9d375b0c37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZX=E5=A4=8F=E5=A4=9C=E4=B9=8B=E9=A3=8E?= Date: Tue, 7 Jan 2025 19:52:15 +0800 Subject: [PATCH 03/25] =?UTF-8?q?=E5=9C=A8=E6=96=87=E4=BB=B6=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E5=99=A8=E4=B8=8A=E6=B7=BB=E5=8A=A0=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../convert/folder/FolderPackConverter.java | 51 +++++++++++++++---- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java index d4ea4d673..deabcc428 100644 --- a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java +++ b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java @@ -91,8 +91,11 @@ public boolean convert(File baseDir) throws IOException { Files.walkFileTree(baseDirAsPath, new SimpleFileVisitor<>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + GunMod.LOGGER.debug("Visiting old pack file {}", file); for (FolderEntryVisitor visitor : processors) { + GunMod.LOGGER.debug("Trying to run visitFile from {}", visitor); if (visitor.visitFile(baseDir, file.toFile())) { + GunMod.LOGGER.debug("File handled, skipping remaining visitors"); break; // a visitor handled this file, go next } } @@ -101,10 +104,13 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { + GunMod.LOGGER.debug("Visiting old pack directory {}", dir); if (!baseDirAsPath.equals(dir)) { // always visit the root directory! for (FolderEntryVisitor visitor : processors) { + GunMod.LOGGER.debug("Trying to run visitDirectory from {}", visitor); FileVisitResult result = visitor.visitDirectory(baseDir, dir.toFile()); if (result != null) { + GunMod.LOGGER.debug("Folder handled with result {}", result); return result; } } @@ -146,6 +152,11 @@ public boolean visitFile(File baseDir, File subFile) { } return false; } + + @Override + public String toString() { + return "file renamer " + oldPath + " -> " + newPath + " (in " + newFolderType.getDirectory() + ")"; + } }; } @@ -167,6 +178,11 @@ private static FolderEntryVisitor createFolderRenamer(String oldPath, String new } return null; } + + @Override + public String toString() { + return "folder renamer " + oldPath + " -> " + newPath + " (in " + folderType.getDirectory() + ")"; + } }; } @@ -188,23 +204,36 @@ public boolean visitFile(File baseDir, File subFile) throws IOException { } return false; } + + @Override + public String toString() { + return "category file visitor (category " + category + ", file operator " + fileOperator + ")"; + } }; } private static FileOp createJsonFileOperator(Function jsonOperator) { - return (baseDir, file, fileResourceLocation) -> { - if (file.getName().endsWith(".json")) { - Path asPath = file.toPath(); - BufferedReader reader = Files.newBufferedReader(asPath, StandardCharsets.UTF_8); - JsonElement oldJson = JsonParser.parseReader(reader); - JsonElement newJson = jsonOperator.apply(oldJson); - if (newJson != null) { - BufferedWriter writer = Files.newBufferedWriter(asPath, StandardCharsets.UTF_8); - GSON.toJson(newJson, writer); - return true; + return new FileOp() { + @Override + public boolean run(File baseDir, File file, ResourceLocation fileResourceLocation) throws IOException { + if (file.getName().endsWith(".json")) { + Path asPath = file.toPath(); + BufferedReader reader = Files.newBufferedReader(asPath, StandardCharsets.UTF_8); + JsonElement oldJson = JsonParser.parseReader(reader); + JsonElement newJson = jsonOperator.apply(oldJson); + if (newJson != null) { + BufferedWriter writer = Files.newBufferedWriter(asPath, StandardCharsets.UTF_8); + GSON.toJson(newJson, writer); + return true; + } } + return false; + } + + @Override + public String toString() { + return "json file modifier"; } - return false; }; } From be3938dcfabbb7ea7809038346fd02d0118f1e18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZX=E5=A4=8F=E5=A4=9C=E4=B9=8B=E9=A3=8E?= Date: Tue, 7 Jan 2025 20:05:48 +0800 Subject: [PATCH 04/25] =?UTF-8?q?=E5=BA=94=E8=AF=A5=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E6=8C=87=E5=AE=9A=E7=9A=84=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E5=88=86=E9=9A=94=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/tacz/guns/resource/convert/ConverterUtils.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/tacz/guns/resource/convert/ConverterUtils.java b/src/main/java/com/tacz/guns/resource/convert/ConverterUtils.java index 7f355f66e..ed8aafe1c 100644 --- a/src/main/java/com/tacz/guns/resource/convert/ConverterUtils.java +++ b/src/main/java/com/tacz/guns/resource/convert/ConverterUtils.java @@ -15,10 +15,10 @@ public static String relativePath(File base, File sub) { @Nullable public static ResourceLocation parseEntryName(File baseDir, File file) { String relativePath = relativePath(baseDir, file); - int i = relativePath.indexOf('/'); + int i = relativePath.indexOf(File.separatorChar); if (i != -1) { String namespace = relativePath.substring(0, i); - String entryName = relativePath.substring(i + 1); + String entryName = relativePath.substring(i + 1).replace(File.separatorChar, '/'); return new ResourceLocation(namespace, entryName); } return null; From c6d140c198733d8383e620551f36da2acc69ac09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZX=E5=A4=8F=E5=A4=9C=E4=B9=8B=E9=A3=8E?= Date: Tue, 7 Jan 2025 20:12:14 +0800 Subject: [PATCH 05/25] =?UTF-8?q?visitFile=20=E9=BB=98=E8=AE=A4=E5=BA=94?= =?UTF-8?q?=E8=AF=A5=E8=BF=94=E5=9B=9E=20false?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tacz/guns/resource/convert/folder/FolderEntryVisitor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/tacz/guns/resource/convert/folder/FolderEntryVisitor.java b/src/main/java/com/tacz/guns/resource/convert/folder/FolderEntryVisitor.java index 35a950ffb..76b6596d9 100644 --- a/src/main/java/com/tacz/guns/resource/convert/folder/FolderEntryVisitor.java +++ b/src/main/java/com/tacz/guns/resource/convert/folder/FolderEntryVisitor.java @@ -8,7 +8,7 @@ public interface FolderEntryVisitor { default boolean visitFile(File baseDir, File subFile) throws IOException { - return true; + return false; } // return null if you can't handle the given directory From 89f2fd00068372005b8d18854382f0ce2d508086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZX=E5=A4=8F=E5=A4=9C=E4=B9=8B=E9=A3=8E?= Date: Tue, 7 Jan 2025 20:37:40 +0800 Subject: [PATCH 06/25] =?UTF-8?q?display,=20index,=20data=20=E5=B1=9E?= =?UTF-8?q?=E4=BA=8E=E5=AD=90=E7=9B=AE=E5=BD=95=EF=BC=8C=E5=8D=95=E7=8B=AC?= =?UTF-8?q?=E8=AE=A8=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../convert/folder/FolderPackConverter.java | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java index deabcc428..dad9ab26b 100644 --- a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java +++ b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java @@ -44,9 +44,9 @@ public enum FolderPackConverter implements PackConverter { processors.add(createFolderMover("animations", PackType.CLIENT_RESOURCES)); processors.add(createFolderMover("lang", PackType.CLIENT_RESOURCES)); processors.add(createFolderRenamer("models", "geo_models", PackType.CLIENT_RESOURCES)); - processors.add(createFolderMover("display", PackType.CLIENT_RESOURCES)); - processors.add(createFolderMover("index", PackType.SERVER_DATA)); - processors.add(createFolderMover("data", PackType.SERVER_DATA)); + processors.add(createSubFolderMover("display", PackType.CLIENT_RESOURCES)); + processors.add(createSubFolderMover("index", PackType.SERVER_DATA)); + processors.add(createSubFolderMover("data", PackType.SERVER_DATA)); processors.add(createCategoryFileVisitor("recipes", createJsonFileOperator(json -> { JsonObject object = json.getAsJsonObject(); @@ -186,6 +186,35 @@ public String toString() { }; } + private static FolderEntryVisitor createSubFolderMover(String path, PackType folderType) { + return new FolderEntryVisitor() { + @Override + public @Nullable FileVisitResult visitDirectory(File baseDir, File subFolder) { + ResourceLocation entry = parseEntryName(baseDir, subFolder); + if (entry != null) { + String path = entry.getPath(); + int i = path.indexOf('/'); + if (i != -1) { + String subPath = path.substring(i + 1); + if (subPath.equals(path)) { + String newRelativePath = toFilePath(entry, folderType); + File newFile = new File(baseDir, newRelativePath); + newFile.getParentFile().mkdirs(); + subFolder.renameTo(newFile); + return FileVisitResult.SKIP_SUBTREE; + } + } + } + return null; + } + + @Override + public String toString() { + return "sub folder mover " + path + " to " + folderType.getDirectory(); + } + }; + } + private static FolderEntryVisitor createFolderMover(String path, PackType folderType) { return createFolderRenamer(path, path, folderType); } From 2dc11b316724b512bacf9841c616992e3b247c23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZX=E5=A4=8F=E5=A4=9C=E4=B9=8B=E9=A3=8E?= Date: Tue, 7 Jan 2025 20:41:15 +0800 Subject: [PATCH 07/25] =?UTF-8?q?=E6=96=B0=E7=9A=84=E5=AD=90=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E6=A0=BC=E5=BC=8F=E9=A2=A0=E5=80=92=E4=BA=86=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9=E5=90=8D=E7=A7=B0=E7=9A=84=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../guns/resource/convert/folder/FolderPackConverter.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java index dad9ab26b..a3aa7ca19 100644 --- a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java +++ b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java @@ -197,7 +197,9 @@ private static FolderEntryVisitor createSubFolderMover(String path, PackType fol if (i != -1) { String subPath = path.substring(i + 1); if (subPath.equals(path)) { - String newRelativePath = toFilePath(entry, folderType); + String parentPath = path.substring(0, i); + String namespace = entry.getNamespace(); + String newRelativePath = toFilePath(namespace, path + "/" + parentPath, folderType); File newFile = new File(baseDir, newRelativePath); newFile.getParentFile().mkdirs(); subFolder.renameTo(newFile); From 5e0d11a404a31b295a925dd29a98dc78578a298a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZX=E5=A4=8F=E5=A4=9C=E4=B9=8B=E9=A3=8E?= Date: Tue, 7 Jan 2025 20:50:32 +0800 Subject: [PATCH 08/25] =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E6=AD=A7=E4=B9=89=E5=BC=95=E8=B5=B7=E7=9A=84=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../guns/resource/convert/folder/FolderPackConverter.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java index a3aa7ca19..7349bd455 100644 --- a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java +++ b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java @@ -192,12 +192,12 @@ private static FolderEntryVisitor createSubFolderMover(String path, PackType fol public @Nullable FileVisitResult visitDirectory(File baseDir, File subFolder) { ResourceLocation entry = parseEntryName(baseDir, subFolder); if (entry != null) { - String path = entry.getPath(); - int i = path.indexOf('/'); + String entryPath = entry.getPath(); + int i = entryPath.indexOf('/'); if (i != -1) { - String subPath = path.substring(i + 1); + String subPath = entryPath.substring(i + 1); if (subPath.equals(path)) { - String parentPath = path.substring(0, i); + String parentPath = entryPath.substring(0, i); String namespace = entry.getNamespace(); String newRelativePath = toFilePath(namespace, path + "/" + parentPath, folderType); File newFile = new File(baseDir, newRelativePath); From 9d277c719146655f17b88d1199bf48790931ae62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZX=E5=A4=8F=E5=A4=9C=E4=B9=8B=E9=A3=8E?= Date: Tue, 7 Jan 2025 21:00:15 +0800 Subject: [PATCH 09/25] =?UTF-8?q?=E6=97=A7=E6=9E=AA=E5=8C=85=E7=9A=84?= =?UTF-8?q?=E5=85=83=E6=95=B0=E6=8D=AE=E6=96=87=E4=BB=B6=E6=98=AF=20pack.j?= =?UTF-8?q?son=20=E8=80=8C=E4=B8=8D=E6=98=AF=20info.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tacz/guns/resource/convert/folder/FolderPackConverter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java index 7349bd455..b15d9b680 100644 --- a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java +++ b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java @@ -36,7 +36,7 @@ public enum FolderPackConverter implements PackConverter { private final List processors = new ArrayList<>(); { - processors.add(createFileRenamer("info.json", "pack_info.json", PackType.CLIENT_RESOURCES)); + processors.add(createFileRenamer("pack.json", "pack_info.json", PackType.CLIENT_RESOURCES)); processors.add(createFolderRenamer("tags", "tacz_tags", PackType.SERVER_DATA)); processors.add(createFolderMover("player_animator", PackType.CLIENT_RESOURCES)); processors.add(createFolderRenamer("sounds", "tacz_sounds", PackType.SERVER_DATA)); From 49936bc58dab19eee7b92e8502bccfa46b0d37fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZX=E5=A4=8F=E5=A4=9C=E4=B9=8B=E9=A3=8E?= Date: Tue, 7 Jan 2025 21:07:38 +0800 Subject: [PATCH 10/25] =?UTF-8?q?=E5=85=88=E5=A4=8D=E5=88=B6=EF=BC=8C?= =?UTF-8?q?=E5=86=8D=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../convert/folder/FolderPackConverter.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java index b15d9b680..fc962ed14 100644 --- a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java +++ b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java @@ -9,6 +9,8 @@ import com.tacz.guns.resource.convert.PackConverter; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.PackType; +import net.minecraftforge.fml.loading.FMLPaths; +import org.apache.commons.io.FileUtils; import org.jetbrains.annotations.Nullable; import java.io.BufferedReader; @@ -86,15 +88,18 @@ public boolean convert(File baseDir) throws IOException { if (namespace == null) { return false; } - Path baseDirAsPath = baseDir.toPath(); + Path resourcePacksPath = FMLPaths.GAMEDIR.get().resolve("tacz"); + Path newPath = resourcePacksPath.resolve(baseDir.getName()); + File newPathAsFile = newPath.toFile(); + FileUtils.copyDirectory(baseDir, newPathAsFile); AtomicBoolean failed = new AtomicBoolean(); - Files.walkFileTree(baseDirAsPath, new SimpleFileVisitor<>() { + Files.walkFileTree(newPath, new SimpleFileVisitor<>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { GunMod.LOGGER.debug("Visiting old pack file {}", file); for (FolderEntryVisitor visitor : processors) { GunMod.LOGGER.debug("Trying to run visitFile from {}", visitor); - if (visitor.visitFile(baseDir, file.toFile())) { + if (visitor.visitFile(newPathAsFile, file.toFile())) { GunMod.LOGGER.debug("File handled, skipping remaining visitors"); break; // a visitor handled this file, go next } @@ -105,10 +110,10 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { GunMod.LOGGER.debug("Visiting old pack directory {}", dir); - if (!baseDirAsPath.equals(dir)) { // always visit the root directory! + if (!newPath.equals(dir)) { // always visit the root directory! for (FolderEntryVisitor visitor : processors) { GunMod.LOGGER.debug("Trying to run visitDirectory from {}", visitor); - FileVisitResult result = visitor.visitDirectory(baseDir, dir.toFile()); + FileVisitResult result = visitor.visitDirectory(newPathAsFile, dir.toFile()); if (result != null) { GunMod.LOGGER.debug("Folder handled with result {}", result); return result; @@ -126,10 +131,10 @@ public FileVisitResult visitFileFailed(Path file, IOException exc) { } }); if (!failed.get()) { - Files.walkFileTree(baseDirAsPath, new EmptyFolderRemover(baseDirAsPath)); + Files.walkFileTree(newPath, new EmptyFolderRemover(newPath)); PackMeta newPackMeta = new PackMeta(namespace, null); String newPackMetaAsJson = GSON.toJson(newPackMeta); - Path newPackMetaPath = baseDirAsPath.resolve("gunpack.meta.json"); + Path newPackMetaPath = newPath.resolve("gunpack.meta.json"); Files.writeString(newPackMetaPath, newPackMetaAsJson, StandardCharsets.UTF_8); } return true; From 2d49c1079e953008f4a37503c2f236bf3ce14e42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZX=E5=A4=8F=E5=A4=9C=E4=B9=8B=E9=A3=8E?= Date: Tue, 7 Jan 2025 21:40:36 +0800 Subject: [PATCH 11/25] =?UTF-8?q?Writer=20=E6=B2=A1=E6=9C=89=E8=A2=AB=20GS?= =?UTF-8?q?ON=20=E8=87=AA=E5=8A=A8=E5=85=B3=E9=97=AD=EF=BC=8C=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E6=89=8B=E5=8A=A8=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tacz/guns/resource/convert/folder/FolderPackConverter.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java index fc962ed14..af53d9584 100644 --- a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java +++ b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java @@ -78,6 +78,7 @@ public boolean convert(File baseDir) throws IOException { if (legacyPackFile.isFile()) { BufferedReader reader = Files.newBufferedReader(legacyPackFile.toPath(), StandardCharsets.UTF_8); PackInfo legacyPackInfo = GSON.fromJson(reader, PackInfo.class); + reader.close(); if (legacyPackInfo != null) { namespace = relativePath(baseDir, subFile); break; @@ -260,6 +261,7 @@ public boolean run(File baseDir, File file, ResourceLocation fileResourceLocatio if (newJson != null) { BufferedWriter writer = Files.newBufferedWriter(asPath, StandardCharsets.UTF_8); GSON.toJson(newJson, writer); + writer.close(); return true; } } From 57b8b811c18effffe83b6e095e4bc9c82ed5e2de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZX=E5=A4=8F=E5=A4=9C=E4=B9=8B=E9=A3=8E?= Date: Tue, 7 Jan 2025 21:51:25 +0800 Subject: [PATCH 12/25] =?UTF-8?q?=E5=9C=A8=E6=96=B0=E7=9A=84=E5=8C=85?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E5=AD=98=E5=9C=A8=E6=97=B6=E4=B8=8D=E8=A6=81?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../guns/resource/convert/folder/FolderPackConverter.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java index af53d9584..17007d027 100644 --- a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java +++ b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java @@ -18,10 +18,7 @@ import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; +import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.List; @@ -92,6 +89,9 @@ public boolean convert(File baseDir) throws IOException { Path resourcePacksPath = FMLPaths.GAMEDIR.get().resolve("tacz"); Path newPath = resourcePacksPath.resolve(baseDir.getName()); File newPathAsFile = newPath.toFile(); + if (newPathAsFile.isDirectory()) { + throw new FileAlreadyExistsException("New path already exists"); + } FileUtils.copyDirectory(baseDir, newPathAsFile); AtomicBoolean failed = new AtomicBoolean(); Files.walkFileTree(newPath, new SimpleFileVisitor<>() { From e11e6726a73e3f80d6e06a506209424b9de64562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZX=E5=A4=8F=E5=A4=9C=E4=B9=8B=E9=A3=8E?= Date: Tue, 7 Jan 2025 21:53:39 +0800 Subject: [PATCH 13/25] =?UTF-8?q?=E5=9C=A8=E7=A6=BB=E5=BC=80=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9=E6=97=B6=E5=BA=94=E8=AF=A5=E4=B9=9F=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E6=98=AF=E5=90=A6=E4=B8=BA=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resource/convert/folder/EmptyFolderRemover.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/com/tacz/guns/resource/convert/folder/EmptyFolderRemover.java b/src/main/java/com/tacz/guns/resource/convert/folder/EmptyFolderRemover.java index 7c0875273..58e117437 100644 --- a/src/main/java/com/tacz/guns/resource/convert/folder/EmptyFolderRemover.java +++ b/src/main/java/com/tacz/guns/resource/convert/folder/EmptyFolderRemover.java @@ -24,4 +24,15 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th } return FileVisitResult.CONTINUE; } + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + if (exc != null) { + throw exc; + } + if (!baseDir.equals(dir) && isEmptyDirectory(dir)) { + Files.delete(dir); + } + return FileVisitResult.CONTINUE; + } } From 858abc0ff3886351cf1744409a8a9950f25114c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZX=E5=A4=8F=E5=A4=9C=E4=B9=8B=E9=A3=8E?= Date: Tue, 7 Jan 2025 22:16:22 +0800 Subject: [PATCH 14/25] =?UTF-8?q?FileOp.andThen=20=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E4=BA=A7=E7=94=9F=E7=9A=84=E5=AE=9E=E4=BE=8B=E5=BA=94=E8=AF=A5?= =?UTF-8?q?=E4=B9=9F=E6=8F=90=E4=BE=9B=E8=B0=83=E8=AF=95=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../guns/resource/convert/folder/FileOp.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/tacz/guns/resource/convert/folder/FileOp.java b/src/main/java/com/tacz/guns/resource/convert/folder/FileOp.java index 77ee5ef9b..9ab548993 100644 --- a/src/main/java/com/tacz/guns/resource/convert/folder/FileOp.java +++ b/src/main/java/com/tacz/guns/resource/convert/folder/FileOp.java @@ -9,10 +9,18 @@ public interface FileOp { boolean run(File baseDir, File file, ResourceLocation fileResourceLocation) throws IOException; default FileOp andThen(FileOp op) { - return (baseDir, file, fileResourceLocation) -> { - boolean self = FileOp.this.run(baseDir, file, fileResourceLocation); - boolean after = op.run(baseDir, file, fileResourceLocation); - return self && after; + return new FileOp() { + @Override + public boolean run(File baseDir, File file, ResourceLocation fileResourceLocation) throws IOException { + boolean self = FileOp.this.run(baseDir, file, fileResourceLocation); + boolean after = op.run(baseDir, file, fileResourceLocation); + return self && after; + } + + @Override + public String toString() { + return FileOp.this + ", and then " + op.toString(); + } }; } } From 0daa5b4416e03d9ce5a903bb002ef329e2b61022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZX=E5=A4=8F=E5=A4=9C=E4=B9=8B=E9=A3=8E?= Date: Tue, 7 Jan 2025 22:17:35 +0800 Subject: [PATCH 15/25] =?UTF-8?q?=E5=8C=BF=E5=90=8D=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=94=A8=E7=9A=84=20FileOp=20=E5=AE=9E?= =?UTF-8?q?=E4=BE=8B=E5=BA=94=E8=AF=A5=E4=B9=9F=E6=8F=90=E4=BE=9B=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resource/convert/folder/FolderPackConverter.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java index 17007d027..0c3ae6631 100644 --- a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java +++ b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java @@ -54,7 +54,17 @@ public enum FolderPackConverter implements PackConverter { return object; } return null; - }).andThen((baseDir, file, fileResourceLocation) -> move(baseDir, file, fileResourceLocation, PackType.SERVER_DATA)))); + }).andThen(new FileOp() { + @Override + public boolean run(File baseDir, File file, ResourceLocation fileResourceLocation) throws IOException { + return move(baseDir, file, fileResourceLocation, PackType.SERVER_DATA); + } + + @Override + public String toString() { + return "move file to " + PackType.SERVER_DATA.getDirectory(); + } + }))); } // return false if the given file does not represent a legacy pack From 59f3b9f503145640e5b66081243b390b51136428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZX=E5=A4=8F=E5=A4=9C=E4=B9=8B=E9=A3=8E?= Date: Tue, 7 Jan 2025 22:17:56 +0800 Subject: [PATCH 16/25] =?UTF-8?q?=E6=B8=85=E7=90=86=E4=B8=8D=E5=BF=85?= =?UTF-8?q?=E8=A6=81=E7=9A=84=20throws=20=E5=A3=B0=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tacz/guns/resource/convert/folder/FolderPackConverter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java index 0c3ae6631..eadd2babf 100644 --- a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java +++ b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java @@ -56,7 +56,7 @@ public enum FolderPackConverter implements PackConverter { return null; }).andThen(new FileOp() { @Override - public boolean run(File baseDir, File file, ResourceLocation fileResourceLocation) throws IOException { + public boolean run(File baseDir, File file, ResourceLocation fileResourceLocation) { return move(baseDir, file, fileResourceLocation, PackType.SERVER_DATA); } From f1c46d93c38d797166a6e0c2326a8fb4000ae44b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZX=E5=A4=8F=E5=A4=9C=E4=B9=8B=E9=A3=8E?= Date: Wed, 8 Jan 2025 12:32:45 +0800 Subject: [PATCH 17/25] =?UTF-8?q?=E5=AF=B9=E4=BA=8E=E9=9D=9E=E6=9E=AA?= =?UTF-8?q?=E5=8C=85=E5=85=83=E7=B4=A0=EF=BC=8C=E5=8E=9F=E6=A0=B7=E5=A4=8D?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/tacz/guns/resource/PackConvertor.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/tacz/guns/resource/PackConvertor.java b/src/main/java/com/tacz/guns/resource/PackConvertor.java index 6d7cd8c92..8c2bc7a9c 100644 --- a/src/main/java/com/tacz/guns/resource/PackConvertor.java +++ b/src/main/java/com/tacz/guns/resource/PackConvertor.java @@ -355,6 +355,9 @@ public void convert() throws FileAlreadyExistsException { if (parseTags(newZip, entry, oldPack)) continue; if (parseRecipe(newZip, entry, oldPack)) continue; if (parsePackInfo(newZip, entry, oldPack)) continue; + // 如果不是任何 TACZ 枪包元素,按原样复制 + // 这个情况为诸如 LICENSE 文件等文档考虑 + writeEntry(newZip, entry, oldPack, entry.getName()); } } catch (IOException e) { GunMod.LOGGER.warn("Failed to convert pack: {}", file.getName()); From 872141984d68dbb740ab0cab70e781289cfa25d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZX=E5=A4=8F=E5=A4=9C=E4=B9=8B=E9=A3=8E?= Date: Wed, 8 Jan 2025 12:36:45 +0800 Subject: [PATCH 18/25] =?UTF-8?q?=E5=AF=B9=E4=BA=8E=E6=9E=AA=E5=8C=85?= =?UTF-8?q?=E5=86=85=E5=AE=B9=EF=BC=8C=E4=B8=8D=E9=AA=8C=E8=AF=81=E5=85=B6?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E7=9A=84=E6=9C=89=E6=95=88=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../guns/resource/convert/ConverterUtils.java | 7 +++---- .../resource/convert/UnsafeResourceLocation.java | 12 ++++++++++++ .../guns/resource/convert/folder/FileOp.java | 5 +++-- .../convert/folder/FolderPackConverter.java | 16 ++++++++-------- 4 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/tacz/guns/resource/convert/UnsafeResourceLocation.java diff --git a/src/main/java/com/tacz/guns/resource/convert/ConverterUtils.java b/src/main/java/com/tacz/guns/resource/convert/ConverterUtils.java index ed8aafe1c..ae8a49463 100644 --- a/src/main/java/com/tacz/guns/resource/convert/ConverterUtils.java +++ b/src/main/java/com/tacz/guns/resource/convert/ConverterUtils.java @@ -1,6 +1,5 @@ package com.tacz.guns.resource.convert; -import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.PackType; import org.jetbrains.annotations.Nullable; @@ -13,13 +12,13 @@ public static String relativePath(File base, File sub) { } @Nullable - public static ResourceLocation parseEntryName(File baseDir, File file) { + public static UnsafeResourceLocation parseEntryName(File baseDir, File file) { String relativePath = relativePath(baseDir, file); int i = relativePath.indexOf(File.separatorChar); if (i != -1) { String namespace = relativePath.substring(0, i); String entryName = relativePath.substring(i + 1).replace(File.separatorChar, '/'); - return new ResourceLocation(namespace, entryName); + return new UnsafeResourceLocation(namespace, entryName); } return null; } @@ -28,7 +27,7 @@ public static String toFilePath(String namespace, String path, PackType folderTy return folderType.getDirectory() + File.separator + namespace + File.separator + path; } - public static String toFilePath(ResourceLocation resourceLocation, PackType folderType) { + public static String toFilePath(UnsafeResourceLocation resourceLocation, PackType folderType) { return toFilePath(resourceLocation.getNamespace(), resourceLocation.getPath(), folderType); } diff --git a/src/main/java/com/tacz/guns/resource/convert/UnsafeResourceLocation.java b/src/main/java/com/tacz/guns/resource/convert/UnsafeResourceLocation.java new file mode 100644 index 000000000..164b3a982 --- /dev/null +++ b/src/main/java/com/tacz/guns/resource/convert/UnsafeResourceLocation.java @@ -0,0 +1,12 @@ +package com.tacz.guns.resource.convert; + +// 不验证路径是否有效的 ResourceLocation 实现 +public record UnsafeResourceLocation(String namespace, String path) { + public String getNamespace() { + return namespace; + } + + public String getPath() { + return path; + } +} diff --git a/src/main/java/com/tacz/guns/resource/convert/folder/FileOp.java b/src/main/java/com/tacz/guns/resource/convert/folder/FileOp.java index 9ab548993..c11661f12 100644 --- a/src/main/java/com/tacz/guns/resource/convert/folder/FileOp.java +++ b/src/main/java/com/tacz/guns/resource/convert/folder/FileOp.java @@ -1,17 +1,18 @@ package com.tacz.guns.resource.convert.folder; +import com.tacz.guns.resource.convert.UnsafeResourceLocation; import net.minecraft.resources.ResourceLocation; import java.io.File; import java.io.IOException; public interface FileOp { - boolean run(File baseDir, File file, ResourceLocation fileResourceLocation) throws IOException; + boolean run(File baseDir, File file, UnsafeResourceLocation fileResourceLocation) throws IOException; default FileOp andThen(FileOp op) { return new FileOp() { @Override - public boolean run(File baseDir, File file, ResourceLocation fileResourceLocation) throws IOException { + public boolean run(File baseDir, File file, UnsafeResourceLocation fileResourceLocation) throws IOException { boolean self = FileOp.this.run(baseDir, file, fileResourceLocation); boolean after = op.run(baseDir, file, fileResourceLocation); return self && after; diff --git a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java index eadd2babf..49dae9460 100644 --- a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java +++ b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java @@ -7,7 +7,7 @@ import com.tacz.guns.client.resource.pojo.PackInfo; import com.tacz.guns.resource.PackMeta; import com.tacz.guns.resource.convert.PackConverter; -import net.minecraft.resources.ResourceLocation; +import com.tacz.guns.resource.convert.UnsafeResourceLocation; import net.minecraft.server.packs.PackType; import net.minecraftforge.fml.loading.FMLPaths; import org.apache.commons.io.FileUtils; @@ -56,7 +56,7 @@ public enum FolderPackConverter implements PackConverter { return null; }).andThen(new FileOp() { @Override - public boolean run(File baseDir, File file, ResourceLocation fileResourceLocation) { + public boolean run(File baseDir, File file, UnsafeResourceLocation fileResourceLocation) { return move(baseDir, file, fileResourceLocation, PackType.SERVER_DATA); } @@ -155,7 +155,7 @@ private static FolderEntryVisitor createFileRenamer(String oldPath, String newPa return new FolderEntryVisitor() { @Override public boolean visitFile(File baseDir, File subFile) { - ResourceLocation entry = parseEntryName(baseDir, subFile); + UnsafeResourceLocation entry = parseEntryName(baseDir, subFile); if (entry != null) { String path = entry.getPath(); if (path.equals(oldPath)) { @@ -180,7 +180,7 @@ private static FolderEntryVisitor createFolderRenamer(String oldPath, String new return new FolderEntryVisitor() { @Override public @Nullable FileVisitResult visitDirectory(File baseDir, File subFolder) { - ResourceLocation entry = parseEntryName(baseDir, subFolder); + UnsafeResourceLocation entry = parseEntryName(baseDir, subFolder); if (entry != null) { String path = entry.getPath(); if (path.equals(oldPath)) { @@ -206,7 +206,7 @@ private static FolderEntryVisitor createSubFolderMover(String path, PackType fol return new FolderEntryVisitor() { @Override public @Nullable FileVisitResult visitDirectory(File baseDir, File subFolder) { - ResourceLocation entry = parseEntryName(baseDir, subFolder); + UnsafeResourceLocation entry = parseEntryName(baseDir, subFolder); if (entry != null) { String entryPath = entry.getPath(); int i = entryPath.indexOf('/'); @@ -242,7 +242,7 @@ private static FolderEntryVisitor createCategoryFileVisitor(String category, Fil return new FolderEntryVisitor() { @Override public boolean visitFile(File baseDir, File subFile) throws IOException { - ResourceLocation entry = parseEntryName(baseDir, subFile); + UnsafeResourceLocation entry = parseEntryName(baseDir, subFile); if (entry != null) { String path = entry.getPath(); if (path.startsWith(categoryPlusSlash)) { @@ -262,7 +262,7 @@ public String toString() { private static FileOp createJsonFileOperator(Function jsonOperator) { return new FileOp() { @Override - public boolean run(File baseDir, File file, ResourceLocation fileResourceLocation) throws IOException { + public boolean run(File baseDir, File file, UnsafeResourceLocation fileResourceLocation) throws IOException { if (file.getName().endsWith(".json")) { Path asPath = file.toPath(); BufferedReader reader = Files.newBufferedReader(asPath, StandardCharsets.UTF_8); @@ -285,7 +285,7 @@ public String toString() { }; } - private static boolean move(File baseDir, File file, ResourceLocation location, PackType folderType) { + private static boolean move(File baseDir, File file, UnsafeResourceLocation location, PackType folderType) { String newPath = toFilePath(location, folderType); File newFile = new File(baseDir, newPath); newFile.getParentFile().mkdirs(); From 5ea4c3951a8bb1382b1e4ef701a4a172a6fd2558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZX=E5=A4=8F=E5=A4=9C=E4=B9=8B=E9=A3=8E?= Date: Wed, 8 Jan 2025 12:45:02 +0800 Subject: [PATCH 19/25] =?UTF-8?q?=E5=BF=BD=E7=95=A5=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E6=9E=AA=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/tacz/guns/resource/PackConvertor.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/tacz/guns/resource/PackConvertor.java b/src/main/java/com/tacz/guns/resource/PackConvertor.java index 8c2bc7a9c..99dcd9ccf 100644 --- a/src/main/java/com/tacz/guns/resource/PackConvertor.java +++ b/src/main/java/com/tacz/guns/resource/PackConvertor.java @@ -23,6 +23,8 @@ import java.util.zip.ZipFile; import java.util.zip.ZipOutputStream; +import static com.tacz.guns.resource.convert.ConverterUtils.relativePath; + public class PackConvertor { public static final Path FOLDER = Paths.get("config", GunMod.MOD_ID, "custom"); public static final Pattern PACK_INFO_PATTERN = Pattern.compile("^(\\w+)/pack\\.json$"); @@ -61,6 +63,9 @@ public static void convert(CommandSourceStack source) { msg(source, Component.translatable("message.tacz.converter.start")); GunMod.LOGGER.info("Start converting legacy packs..."); for (File file : files) { + if (relativePath(folder, file).equals("tacz_default_gun")) { + continue; + } ThrowingRunnable conversionOp; if (file.isFile() && file.getName().endsWith(".zip")) { PackConvertor.LegacyPack pack = fromZipFile(file); From 71d82f4be103caef378f25ed0c68a07ba93cebe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZX=E5=A4=8F=E5=A4=9C=E4=B9=8B=E9=A3=8E?= Date: Wed, 8 Jan 2025 12:51:45 +0800 Subject: [PATCH 20/25] =?UTF-8?q?=E8=AF=BB=E5=85=A5=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E5=90=8E=E5=BA=94=E8=AF=A5=E5=85=B3=E9=97=AD=20Reader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tacz/guns/resource/convert/folder/FolderPackConverter.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java index 49dae9460..77990a368 100644 --- a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java +++ b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java @@ -267,6 +267,7 @@ public boolean run(File baseDir, File file, UnsafeResourceLocation fileResourceL Path asPath = file.toPath(); BufferedReader reader = Files.newBufferedReader(asPath, StandardCharsets.UTF_8); JsonElement oldJson = JsonParser.parseReader(reader); + reader.close(); JsonElement newJson = jsonOperator.apply(oldJson); if (newJson != null) { BufferedWriter writer = Files.newBufferedWriter(asPath, StandardCharsets.UTF_8); From 2cba691ddd4cf99bf70139a011136cf4926782d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZX=E5=A4=8F=E5=A4=9C=E4=B9=8B=E9=A3=8E?= Date: Wed, 8 Jan 2025 19:25:53 +0800 Subject: [PATCH 21/25] =?UTF-8?q?=E5=85=81=E8=AE=B8=E5=BF=BD=E7=95=A5?= =?UTF-8?q?=E7=89=B9=E5=AE=9A=E6=9E=AA=E5=8C=85=E7=9A=84=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tacz/guns/config/common/OtherConfig.java | 12 ++++++++++++ .../java/com/tacz/guns/resource/PackConvertor.java | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/tacz/guns/config/common/OtherConfig.java b/src/main/java/com/tacz/guns/config/common/OtherConfig.java index 1737247fd..46ef21df8 100644 --- a/src/main/java/com/tacz/guns/config/common/OtherConfig.java +++ b/src/main/java/com/tacz/guns/config/common/OtherConfig.java @@ -1,13 +1,18 @@ package com.tacz.guns.config.common; +import net.minecraft.Util; import net.minecraftforge.common.ForgeConfigSpec; +import java.util.ArrayList; +import java.util.List; + public class OtherConfig { public static ForgeConfigSpec.BooleanValue DEFAULT_PACK_DEBUG; public static ForgeConfigSpec.IntValue TARGET_SOUND_DISTANCE; public static ForgeConfigSpec.DoubleValue SERVER_HITBOX_OFFSET; public static ForgeConfigSpec.BooleanValue SERVER_HITBOX_LATENCY_FIX; public static ForgeConfigSpec.DoubleValue SERVER_HITBOX_LATENCY_MAX_SAVE_MS; + public static ForgeConfigSpec.ConfigValue> PACK_UPGRADE_BLACKLIST; public static void init(ForgeConfigSpec.Builder builder) { builder.push("other"); @@ -19,6 +24,13 @@ public static void init(ForgeConfigSpec.Builder builder) { builder.comment("The farthest sound distance of the target, including minecarts type"); TARGET_SOUND_DISTANCE = builder.defineInRange("TargetSoundDistance", 128, 0, Integer.MAX_VALUE); + builder.comment("The pack names in the list will be ignored during legacy pack upgrade"); + PACK_UPGRADE_BLACKLIST = builder.defineList("PackUpgradeBlackList", Util.make(() -> { + ArrayList list = new ArrayList<>(); + list.add("tacz_default_gun"); + return list; + }), String.class::isInstance); + serverConfig(builder); builder.pop(); diff --git a/src/main/java/com/tacz/guns/resource/PackConvertor.java b/src/main/java/com/tacz/guns/resource/PackConvertor.java index 99dcd9ccf..b20876d02 100644 --- a/src/main/java/com/tacz/guns/resource/PackConvertor.java +++ b/src/main/java/com/tacz/guns/resource/PackConvertor.java @@ -3,6 +3,7 @@ import com.google.gson.*; import com.tacz.guns.GunMod; import com.tacz.guns.client.resource.pojo.PackInfo; +import com.tacz.guns.config.common.OtherConfig; import com.tacz.guns.resource.convert.folder.FolderPackConverter; import com.tacz.guns.util.ThrowingRunnable; import net.minecraft.commands.CommandSourceStack; @@ -63,7 +64,7 @@ public static void convert(CommandSourceStack source) { msg(source, Component.translatable("message.tacz.converter.start")); GunMod.LOGGER.info("Start converting legacy packs..."); for (File file : files) { - if (relativePath(folder, file).equals("tacz_default_gun")) { + if (OtherConfig.PACK_UPGRADE_BLACKLIST.get().contains(relativePath(folder, file))) { continue; } ThrowingRunnable conversionOp; From 4d6edad6627d8db7dbd6fc87185f3ac93f11b40f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZX=E5=A4=8F=E5=A4=9C=E4=B9=8B=E9=A3=8E?= Date: Wed, 8 Jan 2025 19:28:03 +0800 Subject: [PATCH 22/25] =?UTF-8?q?=E7=AE=80=E5=8C=96=E8=AF=AD=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/tacz/guns/config/common/OtherConfig.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/tacz/guns/config/common/OtherConfig.java b/src/main/java/com/tacz/guns/config/common/OtherConfig.java index 46ef21df8..361e036a5 100644 --- a/src/main/java/com/tacz/guns/config/common/OtherConfig.java +++ b/src/main/java/com/tacz/guns/config/common/OtherConfig.java @@ -25,11 +25,9 @@ public static void init(ForgeConfigSpec.Builder builder) { TARGET_SOUND_DISTANCE = builder.defineInRange("TargetSoundDistance", 128, 0, Integer.MAX_VALUE); builder.comment("The pack names in the list will be ignored during legacy pack upgrade"); - PACK_UPGRADE_BLACKLIST = builder.defineList("PackUpgradeBlackList", Util.make(() -> { - ArrayList list = new ArrayList<>(); - list.add("tacz_default_gun"); - return list; - }), String.class::isInstance); + PACK_UPGRADE_BLACKLIST = builder.defineList("PackUpgradeBlackList", + Util.make(new ArrayList<>(), list -> list.add("tacz_default_gun")), + String.class::isInstance); serverConfig(builder); From 69877432d798ff5be7c0dbbe9a364e852ef970f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZX=E5=A4=8F=E5=A4=9C=E4=B9=8B=E9=A3=8E?= Date: Thu, 9 Jan 2025 12:49:04 +0800 Subject: [PATCH 23/25] =?UTF-8?q?=E5=BC=82=E6=AD=A5=E8=BF=90=E8=A1=8C?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=EF=BC=8C=E9=81=BF=E5=85=8D=E9=98=BB=E5=A1=9E?= =?UTF-8?q?=E4=B8=BB=E7=BA=BF=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 过长时间的转换可能会导致像 spark 之类的分析器模组认为 TACZ 存在性能问题 --- src/main/java/com/tacz/guns/command/sub/ConvertCommand.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/tacz/guns/command/sub/ConvertCommand.java b/src/main/java/com/tacz/guns/command/sub/ConvertCommand.java index b087dbc94..14eb3bc94 100644 --- a/src/main/java/com/tacz/guns/command/sub/ConvertCommand.java +++ b/src/main/java/com/tacz/guns/command/sub/ConvertCommand.java @@ -9,6 +9,8 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; +import java.util.concurrent.CompletableFuture; + public class ConvertCommand { private static final String CONVERT_NAME = "convert"; @@ -19,7 +21,9 @@ public static LiteralArgumentBuilder get() { } private static int convert(CommandContext context) { - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> PackConvertor.convert(context.getSource())); + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> CompletableFuture.runAsync( + () -> PackConvertor.convert(context.getSource()) + )); return Command.SINGLE_SUCCESS; } } From 4f26c0ab884d85e7e8d26642700b5bdce26edc36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZX=E5=A4=8F=E5=A4=9C=E4=B9=8B=E9=A3=8E?= Date: Thu, 9 Jan 2025 13:06:51 +0800 Subject: [PATCH 24/25] =?UTF-8?q?=E4=B8=8D=E6=AD=A3=E7=A1=AE=E7=9A=84?= =?UTF-8?q?=E7=9B=B8=E5=AF=B9=E8=B7=AF=E5=BE=84=E8=AE=A1=E7=AE=97=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/tacz/guns/resource/PackConvertor.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/tacz/guns/resource/PackConvertor.java b/src/main/java/com/tacz/guns/resource/PackConvertor.java index b20876d02..f998b549b 100644 --- a/src/main/java/com/tacz/guns/resource/PackConvertor.java +++ b/src/main/java/com/tacz/guns/resource/PackConvertor.java @@ -54,7 +54,8 @@ public static void convert(CommandSourceStack source) { } } - File[] files = FOLDER.toFile().listFiles(); + File legacyPackFolderAsFile = FOLDER.toFile(); + File[] files = legacyPackFolderAsFile.listFiles(); int cnt = 0; int skip = 0; int error = 0; @@ -64,7 +65,7 @@ public static void convert(CommandSourceStack source) { msg(source, Component.translatable("message.tacz.converter.start")); GunMod.LOGGER.info("Start converting legacy packs..."); for (File file : files) { - if (OtherConfig.PACK_UPGRADE_BLACKLIST.get().contains(relativePath(folder, file))) { + if (OtherConfig.PACK_UPGRADE_BLACKLIST.get().contains(relativePath(legacyPackFolderAsFile, file))) { continue; } ThrowingRunnable conversionOp; From 1d0ed19893c3fe82cf78472d3a80c5fa865c9b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZX=E5=A4=8F=E5=A4=9C=E4=B9=8B=E9=A3=8E?= Date: Sat, 11 Jan 2025 12:31:59 +0800 Subject: [PATCH 25/25] =?UTF-8?q?=E9=9F=B3=E6=95=88=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=B9=E8=A2=AB=E9=94=99=E8=AF=AF=E5=9C=B0=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E5=88=B0=E6=95=B0=E6=8D=AE=E6=96=87=E4=BB=B6=E5=A4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tacz/guns/resource/convert/folder/FolderPackConverter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java index 77990a368..90edc3d4d 100644 --- a/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java +++ b/src/main/java/com/tacz/guns/resource/convert/folder/FolderPackConverter.java @@ -38,7 +38,7 @@ public enum FolderPackConverter implements PackConverter { processors.add(createFileRenamer("pack.json", "pack_info.json", PackType.CLIENT_RESOURCES)); processors.add(createFolderRenamer("tags", "tacz_tags", PackType.SERVER_DATA)); processors.add(createFolderMover("player_animator", PackType.CLIENT_RESOURCES)); - processors.add(createFolderRenamer("sounds", "tacz_sounds", PackType.SERVER_DATA)); + processors.add(createFolderRenamer("sounds", "tacz_sounds", PackType.CLIENT_RESOURCES)); processors.add(createFolderMover("textures", PackType.CLIENT_RESOURCES)); processors.add(createFolderMover("animations", PackType.CLIENT_RESOURCES)); processors.add(createFolderMover("lang", PackType.CLIENT_RESOURCES));