Skip to content

Commit

Permalink
simplify.
Browse files Browse the repository at this point in the history
  • Loading branch information
portlek committed Jun 24, 2024
1 parent 7b40af2 commit 708da26
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 29 deletions.
28 changes: 4 additions & 24 deletions generator/src/main/java/net/infumia/pack/PackWriter.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
package net.infumia.pack;

import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.zip.ZipOutputStream;
import team.unnamed.creative.ResourcePack;
import team.unnamed.creative.serialize.ResourcePackWriter;
import team.unnamed.creative.serialize.minecraft.fs.FileTreeWriter;
import team.unnamed.creative.serialize.minecraft.MinecraftResourcePackWriter;

final class PackWriter {

Expand All @@ -20,28 +13,15 @@ final class PackWriter {
}

PackGeneratedContext write(final PackGeneratorContext context) {
final ResourcePackWriter<FileTreeWriter> writer = this.settings.writer();
final MinecraftResourcePackWriter writer = this.settings.writer();
final Path outputDirectory = context.outputDirectory();
final ResourcePack resourcePack = context.resourcePack();
if (outputDirectory != null) {
writer.write(FileTreeWriter.directory(outputDirectory.toFile()), resourcePack);
writer.writeToDirectory(outputDirectory.toFile(), resourcePack);
}
final Path outputFile = context.outputFile();
if (outputFile != null) {
try (
final ZipOutputStream outputStream = new ZipOutputStream(
new BufferedOutputStream(Files.newOutputStream(outputFile))
)
) {
writer.write(FileTreeWriter.zip(outputStream), resourcePack);
} catch (final FileNotFoundException e) {
throw new IllegalStateException(
"Failed to write resource pack to zip file: File not found: " + outputFile,
e
);
} catch (final IOException e) {
throw new UncheckedIOException(e);
}
writer.writeToZipFile(outputFile, resourcePack);
}
return new PackGeneratedContext(resourcePack, context.pack(), outputDirectory, outputFile);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package net.infumia.pack;

import team.unnamed.creative.serialize.ResourcePackWriter;
import team.unnamed.creative.serialize.minecraft.fs.FileTreeWriter;
import team.unnamed.creative.serialize.minecraft.MinecraftResourcePackWriter;

/**
* Settings for writing a resource pack.
*/
public final class PackWriterSettings {

private final ResourcePackWriter<FileTreeWriter> writer;
private final MinecraftResourcePackWriter writer;

/**
* Ctor.
*
* @param writer the resource pack writer. Cannot be null.
*/
public PackWriterSettings(final ResourcePackWriter<FileTreeWriter> writer) {
public PackWriterSettings(final MinecraftResourcePackWriter writer) {
this.writer = writer;
}

Expand All @@ -24,7 +23,7 @@ public PackWriterSettings(final ResourcePackWriter<FileTreeWriter> writer) {
*
* @return the resource pack writer.
*/
public ResourcePackWriter<FileTreeWriter> writer() {
public MinecraftResourcePackWriter writer() {
return this.writer;
}
}

0 comments on commit 708da26

Please sign in to comment.