mirror of
https://github.com/GeyserMC/Rainbow.git
synced 2025-12-19 14:59:16 +00:00
Export generated pack into ZIP-file
This commit is contained in:
@@ -14,9 +14,14 @@ import org.joml.Vector3f;
|
|||||||
import org.joml.Vector3fc;
|
import org.joml.Vector3fc;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.FileSystem;
|
||||||
|
import java.nio.file.FileSystems;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class CodecUtil {
|
public class CodecUtil {
|
||||||
// It's fine to cast to mutable here since codecs won't change the data
|
// It's fine to cast to mutable here since codecs won't change the data
|
||||||
@@ -64,6 +69,28 @@ public class CodecUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void tryZipDirectory(Path directory, Path output) throws IOException {
|
||||||
|
try (FileSystem zip = FileSystems.newFileSystem(output, Map.of("create", "true"))) {
|
||||||
|
try (Stream<Path> paths = Files.walk(directory)) {
|
||||||
|
paths.forEach(path -> {
|
||||||
|
try {
|
||||||
|
Path inZip = zip.getPath(String.valueOf(directory.relativize(path)));
|
||||||
|
if (Files.isDirectory(path)) {
|
||||||
|
Files.createDirectories(inZip);
|
||||||
|
} else {
|
||||||
|
Files.copy(path, inZip, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
}
|
||||||
|
} catch (IOException exception) {
|
||||||
|
Rainbow.LOGGER.warn("Failed to copy contents from {} to ZIP-file {}!", path, output, exception);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (IOException exception) {
|
||||||
|
Rainbow.LOGGER.warn("Failed to write ZIP-file {}!", output, exception);
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void ensureDirectoryExists(Path directory) throws IOException {
|
public static void ensureDirectoryExists(Path directory) throws IOException {
|
||||||
if (!Files.isDirectory(directory)) {
|
if (!Files.isDirectory(directory)) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import net.minecraft.world.item.ItemStack;
|
|||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.geysermc.rainbow.CodecUtil;
|
import org.geysermc.rainbow.CodecUtil;
|
||||||
import org.geysermc.rainbow.PackConstants;
|
import org.geysermc.rainbow.PackConstants;
|
||||||
|
import org.geysermc.rainbow.Rainbow;
|
||||||
import org.geysermc.rainbow.mapping.BedrockItemMapper;
|
import org.geysermc.rainbow.mapping.BedrockItemMapper;
|
||||||
import org.geysermc.rainbow.mapping.geyser.GeyserMappings;
|
import org.geysermc.rainbow.mapping.geyser.GeyserMappings;
|
||||||
import org.geysermc.rainbow.mixin.SplashRendererAccessor;
|
import org.geysermc.rainbow.mixin.SplashRendererAccessor;
|
||||||
@@ -38,7 +39,7 @@ public class BedrockPack {
|
|||||||
"meow", "we'll be done here soon™", "got anything else to say?", "we're done now!", "this will be fixed by v6053", "expect it to be done within 180 business days!");
|
"meow", "we'll be done here soon™", "got anything else to say?", "we're done now!", "this will be fixed by v6053", "expect it to be done within 180 business days!");
|
||||||
private static final RandomSource RANDOM = RandomSource.create();
|
private static final RandomSource RANDOM = RandomSource.create();
|
||||||
|
|
||||||
private static final Path EXPORT_DIRECTORY = FabricLoader.getInstance().getGameDir().resolve("rainbow");
|
private static final Path EXPORT_DIRECTORY = FabricLoader.getInstance().getGameDir().resolve(Rainbow.MOD_ID);
|
||||||
private static final Path PACK_DIRECTORY = Path.of("pack");
|
private static final Path PACK_DIRECTORY = Path.of("pack");
|
||||||
private static final Path ATTACHABLES_DIRECTORY = Path.of("attachables");
|
private static final Path ATTACHABLES_DIRECTORY = Path.of("attachables");
|
||||||
private static final Path GEOMETRY_DIRECTORY = Path.of("models/entity");
|
private static final Path GEOMETRY_DIRECTORY = Path.of("models/entity");
|
||||||
@@ -48,6 +49,7 @@ public class BedrockPack {
|
|||||||
private static final Path MANIFEST_FILE = Path.of("manifest.json");
|
private static final Path MANIFEST_FILE = Path.of("manifest.json");
|
||||||
private static final Path ITEM_ATLAS_FILE = Path.of("textures/item_texture.json");
|
private static final Path ITEM_ATLAS_FILE = Path.of("textures/item_texture.json");
|
||||||
|
|
||||||
|
private static final Path PACK_ZIP_FILE = Path.of("pack.zip");
|
||||||
private static final Path REPORT_FILE = Path.of("report.txt");
|
private static final Path REPORT_FILE = Path.of("report.txt");
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
@@ -155,6 +157,12 @@ public class BedrockPack {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
CodecUtil.tryZipDirectory(packPath, exportPath.resolve(PACK_ZIP_FILE));
|
||||||
|
} catch (IOException exception) {
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Files.writeString(exportPath.resolve(REPORT_FILE), createPackSummary());
|
Files.writeString(exportPath.resolve(REPORT_FILE), createPackSummary());
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
|
|||||||
Reference in New Issue
Block a user