Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import com.formdev.flatlaf.intellijthemes.FlatArcDarkIJTheme;
import org.geysermc.pack.converter.PackConverter;
import org.geysermc.pack.converter.converter.Converters;
import org.geysermc.pack.converter.pipeline.AssetConverters;

import java.io.*;
import java.nio.file.Path;
Expand Down Expand Up @@ -77,7 +77,7 @@ public static void main(String[] arguments) throws IOException {
.input(Path.of(inputPath))
.output(Path.of(outputPath))
.packName(packName)
.converters(Converters.defaultConverters(debug))
.converters(AssetConverters.converters(debug))
.convert()
.pack();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import com.twelvemonkeys.image.BufferedImageIcon;
import org.geysermc.pack.converter.PackConverter;
import org.geysermc.pack.converter.converter.Converters;
import org.geysermc.pack.converter.pipeline.AssetConverters;
import org.geysermc.pack.converter.util.ImageUtil;
import org.geysermc.pack.converter.util.ZipUtils;

Expand Down Expand Up @@ -128,7 +128,7 @@ public ThunderGUI(boolean debug) throws IOException {
.output(outputPath)
.packName(packName.getText().isBlank() ? inputPath.getFileName().toString() : packName.getText())
.vanillaPackPath(vanillaPackPath)
.converters(Converters.defaultConverters(this.debugMode.get()))
.converters(AssetConverters.converters(this.debugMode.get()))
.logListener(logListener)
.convert()
.pack();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@

import org.apache.commons.io.file.PathUtils;
import org.geysermc.pack.bedrock.resource.BedrockResourcePack;
import org.geysermc.pack.converter.converter.ActionListener;
import org.geysermc.pack.converter.converter.Converter;
import org.geysermc.pack.converter.data.ConversionData;
import org.geysermc.pack.converter.util.*;
import org.geysermc.pack.converter.pipeline.ConverterPipeline;
import org.geysermc.pack.converter.util.DefaultLogListener;
import org.geysermc.pack.converter.util.LogListener;
import org.geysermc.pack.converter.util.NioDirectoryFileTreeReader;
import org.geysermc.pack.converter.util.VanillaPackProvider;
import org.geysermc.pack.converter.util.ZipUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import team.unnamed.creative.ResourcePack;
Expand All @@ -43,9 +45,8 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.BiConsumer;

/**
Expand All @@ -63,11 +64,9 @@ public final class PackConverter {
private boolean compressed;
private boolean enforcePackCheck = false;

private final Map<Class<?>, List<ActionListener<?>>> actionListeners = new IdentityHashMap<>();

private BiConsumer<ResourcePack, BedrockResourcePack> postProcessor;

private final List<Converter<?>> converters = new ArrayList<>();
private final List<ConverterPipeline<?, ?>> converters = new ArrayList<>();

private Path tmpDir;

Expand Down Expand Up @@ -187,7 +186,7 @@ public PackConverter enforcePackCheck(boolean enforcePackCheck) {
* @param converter the converter to add
* @return this instance
*/
public PackConverter converter(@NotNull Converter<?> converter) {
public PackConverter converter(@NotNull ConverterPipeline<?, ?> converter) {
this.converters.add(converter);
return this;
}
Expand All @@ -198,7 +197,7 @@ public PackConverter converter(@NotNull Converter<?> converter) {
* @param converters the converters to add
* @return this instance
*/
public PackConverter converters(@NotNull List<? extends Converter<?>> converters) {
public PackConverter converters(@NotNull List<? extends ConverterPipeline<?, ?>> converters) {
this.converters.addAll(converters);
return this;
}
Expand Down Expand Up @@ -227,42 +226,6 @@ public PackConverter packageHandler(@NotNull PackageHandler packageHandler) {
return this;
}

/**
* Sets a list of action listeners for a specific conversion data class.
* <p>
* This is particularly useful for external programs that may rely on
* various bits of information from the pack converter at different
* stages.
*
* @param clazz the conversion data class
* @param actionListeners the action listeners
* @return this instance
* @param <T> the conversion data type
*/
public <T extends ConversionData> PackConverter actionListeners(@NotNull Class<T> clazz, @NotNull ActionListener<T>... actionListeners) {
this.actionListeners.put(clazz, List.of(actionListeners));
return this;
}

/**
* Sets the action listeners.
* <p>
* This is particularly useful for external programs that may rely on
* various bits of information from the pack converter at different
* stages.
*
* @param actionListeners the action listeners
* @return this instance
* @param <T> the conversion data type
*/
public <T extends ConversionData> PackConverter actionListeners(@NotNull Map<Class<T>, List<ActionListener<T>>> actionListeners) {
for (Map.Entry<Class<T>, List<ActionListener<T>>> entry : actionListeners.entrySet()) {
this.actionListeners.put(entry.getKey(), (List) entry.getValue());
}

return this;
}

/**
* Sets the post processor for the converted resource pack.
* <p>
Expand Down Expand Up @@ -320,25 +283,10 @@ public PackConverter convert() throws IOException {
ResourcePack vanillaResourcePack = MinecraftResourcePackReader.minecraft().readFromZipFile(vanillaPackPath);
BedrockResourcePack bedrockResourcePack = new BedrockResourcePack(this.tmpDir);

final Converter.ConversionDataCreationContext conversionDataCreationContext = new Converter.ConversionDataCreationContext(
this, logListener, input, this.tmpDir, javaResourcePack, vanillaResourcePack
);

int errors = 0;
for (Converter converter : this.converters) {
ConversionData data = converter.createConversionData(conversionDataCreationContext);
PackConversionContext<?> context = new PackConversionContext<>(data, this, javaResourcePack, bedrockResourcePack, this.logListener);

List<ActionListener<?>> actionListeners = this.actionListeners.getOrDefault(data.getClass(), List.of());
try {
actionListeners.forEach(actionListener -> actionListener.preConvert((PackConversionContext) context));
converter.convert(context);
actionListeners.forEach(actionListener -> actionListener.postConvert((PackConversionContext) context));
} catch (Throwable t) {
this.logListener.error("Error converting pack!", t);
errors++;
}
}
int errors = converters.stream()
.mapToInt(converter -> converter.convert(javaResourcePack, Optional.of(vanillaResourcePack),
bedrockResourcePack, packName(), textureSubdirectory, logListener))
.sum();

if (this.postProcessor != null) {
this.postProcessor.accept(javaResourcePack, bedrockResourcePack);
Expand Down

This file was deleted.

Loading