mirror of
https://github.com/GeyserMC/PackConverter.git
synced 2026-01-06 15:41:51 +00:00
Add support for action listeners
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
package org.geysermc.packconverter.bootstrap;
|
||||
|
||||
import org.geysermc.pack.converter.PackConverter;
|
||||
import org.geysermc.pack.converter.converters.Converters;
|
||||
import org.geysermc.pack.converter.converter.Converters;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -28,13 +28,12 @@ package org.geysermc.pack.converter;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.geysermc.pack.bedrock.resource.BedrockResourcePack;
|
||||
import org.geysermc.pack.converter.converters.Converter;
|
||||
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.DefaultLogListener;
|
||||
import org.geysermc.pack.converter.util.LogListener;
|
||||
import org.geysermc.pack.converter.util.ZipUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import team.unnamed.creative.ResourcePack;
|
||||
import team.unnamed.creative.serialize.minecraft.MinecraftResourcePackReader;
|
||||
@@ -55,6 +54,9 @@ public class PackConverter {
|
||||
private Path input;
|
||||
private Path output;
|
||||
|
||||
private ActionListener actionListener = new ActionListener() {
|
||||
};
|
||||
|
||||
@Getter
|
||||
private final Map<String, Int2ObjectMap<String>> customModelData = new HashMap<>();
|
||||
|
||||
@@ -62,7 +64,7 @@ public class PackConverter {
|
||||
|
||||
private Path tmpDir;
|
||||
|
||||
@Setter
|
||||
private PackageHandler packageHandler = PackageHandler.ZIP;
|
||||
private LogListener logListener = new DefaultLogListener();
|
||||
|
||||
public PackConverter input(@NotNull Path input) {
|
||||
@@ -90,6 +92,16 @@ public class PackConverter {
|
||||
return this;
|
||||
}
|
||||
|
||||
public PackConverter packageHandler(@NotNull PackageHandler packageHandler) {
|
||||
this.packageHandler = packageHandler;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PackConverter actionListener(@NotNull ActionListener actionListener) {
|
||||
this.actionListener = actionListener;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert all resources in the pack using the converters
|
||||
*/
|
||||
@@ -123,7 +135,9 @@ public class PackConverter {
|
||||
PackConversionContext<?> context = new PackConversionContext<>(data, this, javaResourcePack, bedrockResourcePack, this.logListener);
|
||||
|
||||
try {
|
||||
this.actionListener.preConvert(context);
|
||||
converter.convert(context);
|
||||
this.actionListener.postConvert(context);
|
||||
} catch (Throwable t) {
|
||||
this.logListener.error("Error converting pack!", t);
|
||||
errors++;
|
||||
@@ -146,10 +160,8 @@ public class PackConverter {
|
||||
/**
|
||||
* Convert the temporary folder into the output zip
|
||||
*/
|
||||
public void pack() {
|
||||
ZipUtils zipUtils = new ZipUtils(this, this.tmpDir.toFile());
|
||||
zipUtils.generateFileList();
|
||||
zipUtils.zipIt(this.logListener, this.output.toString());
|
||||
public void pack() throws IOException {
|
||||
this.packageHandler.pack(this, this.tmpDir, this.output, this.logListener);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2023 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/PackConverter
|
||||
*
|
||||
*/
|
||||
|
||||
package org.geysermc.pack.converter;
|
||||
|
||||
import org.geysermc.pack.converter.util.LogListener;
|
||||
import org.geysermc.pack.converter.util.ZipUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public interface PackageHandler {
|
||||
PackageHandler ZIP = (converter, path, outputPath, logger) -> {
|
||||
ZipUtils zipUtils = new ZipUtils(converter, path.toFile());
|
||||
zipUtils.generateFileList();
|
||||
zipUtils.zipIt(logger, outputPath.toString());
|
||||
};
|
||||
|
||||
void pack(@NotNull PackConverter converter, @NotNull Path path, @NotNull Path outputPath, @NotNull LogListener logger) throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2023 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/PackConverter
|
||||
*
|
||||
*/
|
||||
|
||||
package org.geysermc.pack.converter.converter;
|
||||
|
||||
import org.geysermc.pack.converter.PackConversionContext;
|
||||
import org.geysermc.pack.converter.data.ConversionData;
|
||||
|
||||
/**
|
||||
* A listener for actions that occur during pack conversion.
|
||||
*/
|
||||
public interface ActionListener {
|
||||
|
||||
default <T extends ConversionData> void preConvert(PackConversionContext<T> context) {
|
||||
}
|
||||
|
||||
default <T extends ConversionData> void postConvert(PackConversionContext<T> context) {
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package org.geysermc.pack.converter.converters;
|
||||
package org.geysermc.pack.converter.converter;
|
||||
|
||||
import org.geysermc.pack.converter.PackConverter;
|
||||
import org.geysermc.pack.converter.data.BaseConversionData;
|
||||
@@ -24,7 +24,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package org.geysermc.pack.converter.converters;
|
||||
package org.geysermc.pack.converter.converter;
|
||||
|
||||
import org.geysermc.pack.converter.PackConversionContext;
|
||||
import org.geysermc.pack.converter.PackConverter;
|
||||
@@ -24,7 +24,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package org.geysermc.pack.converter.converters;
|
||||
package org.geysermc.pack.converter.converter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ServiceLoader;
|
||||
@@ -24,12 +24,12 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package org.geysermc.pack.converter.converters.base;
|
||||
package org.geysermc.pack.converter.converter.base;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import org.geysermc.pack.converter.PackConversionContext;
|
||||
import org.geysermc.pack.converter.converters.BaseConverter;
|
||||
import org.geysermc.pack.converter.converters.Converter;
|
||||
import org.geysermc.pack.converter.converter.BaseConverter;
|
||||
import org.geysermc.pack.converter.converter.Converter;
|
||||
import org.geysermc.pack.converter.data.BaseConversionData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import team.unnamed.creative.base.Writable;
|
||||
@@ -24,15 +24,15 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package org.geysermc.pack.converter.converters.base;
|
||||
package org.geysermc.pack.converter.converter.base;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import org.geysermc.pack.bedrock.resource.Manifest;
|
||||
import org.geysermc.pack.bedrock.resource.manifest.Header;
|
||||
import org.geysermc.pack.bedrock.resource.manifest.Modules;
|
||||
import org.geysermc.pack.converter.PackConversionContext;
|
||||
import org.geysermc.pack.converter.converters.BaseConverter;
|
||||
import org.geysermc.pack.converter.converters.Converter;
|
||||
import org.geysermc.pack.converter.converter.BaseConverter;
|
||||
import org.geysermc.pack.converter.converter.Converter;
|
||||
import org.geysermc.pack.converter.data.BaseConversionData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import team.unnamed.creative.ResourcePack;
|
||||
@@ -24,7 +24,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package org.geysermc.pack.converter.converters.sound;
|
||||
package org.geysermc.pack.converter.converter.sound;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import org.apache.commons.io.file.PathUtils;
|
||||
@@ -32,8 +32,8 @@ import org.geysermc.pack.bedrock.resource.sounds.sounddefinitions.SoundDefinitio
|
||||
import org.geysermc.pack.bedrock.resource.sounds.sounddefinitions.Sounds;
|
||||
import org.geysermc.pack.converter.Constants;
|
||||
import org.geysermc.pack.converter.PackConversionContext;
|
||||
import org.geysermc.pack.converter.converters.BaseConverter;
|
||||
import org.geysermc.pack.converter.converters.Converter;
|
||||
import org.geysermc.pack.converter.converter.BaseConverter;
|
||||
import org.geysermc.pack.converter.converter.Converter;
|
||||
import org.geysermc.pack.converter.data.BaseConversionData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import team.unnamed.creative.sound.Sound;
|
||||
@@ -24,13 +24,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package org.geysermc.pack.converter.converters.texture;
|
||||
package org.geysermc.pack.converter.converter.texture;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import org.geysermc.pack.converter.PackConversionContext;
|
||||
import org.geysermc.pack.converter.converters.BaseConverter;
|
||||
import org.geysermc.pack.converter.converters.Converter;
|
||||
import org.geysermc.pack.converter.data.BaseConversionData;
|
||||
import org.geysermc.pack.converter.PackConverter;
|
||||
import org.geysermc.pack.converter.converter.Converter;
|
||||
import org.geysermc.pack.converter.data.TextureConversionData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import team.unnamed.creative.texture.Texture;
|
||||
|
||||
@@ -43,13 +43,13 @@ import java.util.ServiceLoader;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
@AutoService(Converter.class)
|
||||
public class TextureConverter extends BaseConverter {
|
||||
public class TextureConverter implements Converter<TextureConversionData> {
|
||||
public static final String BEDROCK_TEXTURES_LOCATION = "textures";
|
||||
|
||||
private final List<TextureTransformer> transformers = StreamSupport.stream(ServiceLoader.load(TextureTransformer.class).spliterator(), false).toList();
|
||||
|
||||
@Override
|
||||
public void convert(@NotNull PackConversionContext<BaseConversionData> context) throws Exception {
|
||||
public void convert(@NotNull PackConversionContext<TextureConversionData> context) throws Exception {
|
||||
Collection<Texture> textures = context.javaResourcePack().textures();
|
||||
|
||||
for (Texture texture : textures) {
|
||||
@@ -78,7 +78,14 @@ public class TextureConverter extends BaseConverter {
|
||||
try (OutputStream stream = Files.newOutputStream(textureOutput)) {
|
||||
texture.data().write(stream);
|
||||
}
|
||||
|
||||
context.data().addTransformedTexture(transformedTexture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureConversionData createConversionData(@NotNull PackConverter converter, @NotNull Path inputDirectory, @NotNull Path outputDirectory) {
|
||||
return new TextureConversionData(inputDirectory, outputDirectory);
|
||||
}
|
||||
}
|
||||
@@ -24,10 +24,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package org.geysermc.pack.converter.converters.texture;
|
||||
package org.geysermc.pack.converter.converter.texture;
|
||||
|
||||
import org.geysermc.pack.converter.PackConversionContext;
|
||||
import org.geysermc.pack.converter.data.BaseConversionData;
|
||||
import org.geysermc.pack.converter.data.TextureConversionData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import team.unnamed.creative.texture.Texture;
|
||||
@@ -37,5 +37,5 @@ public interface TextureTransformer {
|
||||
boolean filter(@NotNull Texture texture);
|
||||
|
||||
@Nullable
|
||||
TransformedTexture transform(@NotNull PackConversionContext<BaseConversionData> context, @NotNull TransformedTexture texture);
|
||||
TransformedTexture transform(@NotNull PackConversionContext<TextureConversionData> context, @NotNull TransformedTexture texture);
|
||||
}
|
||||
@@ -24,7 +24,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package org.geysermc.pack.converter.converters.texture;
|
||||
package org.geysermc.pack.converter.converter.texture;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import team.unnamed.creative.texture.Texture;
|
||||
@@ -24,10 +24,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package org.geysermc.pack.converter.converters.texture.transformer.path;
|
||||
package org.geysermc.pack.converter.converter.texture.transformer.path;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import org.geysermc.pack.converter.converters.texture.TextureTransformer;
|
||||
import org.geysermc.pack.converter.converter.texture.TextureTransformer;
|
||||
|
||||
@AutoService(TextureTransformer.class)
|
||||
public class BlockTextureTransformer extends PathTransformer {
|
||||
@@ -24,10 +24,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package org.geysermc.pack.converter.converters.texture.transformer.path;
|
||||
package org.geysermc.pack.converter.converter.texture.transformer.path;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import org.geysermc.pack.converter.converters.texture.TextureTransformer;
|
||||
import org.geysermc.pack.converter.converter.texture.TextureTransformer;
|
||||
|
||||
@AutoService(TextureTransformer.class)
|
||||
public class ItemTextureTransformer extends PathTransformer {
|
||||
@@ -24,13 +24,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package org.geysermc.pack.converter.converters.texture.transformer.path;
|
||||
package org.geysermc.pack.converter.converter.texture.transformer.path;
|
||||
|
||||
import org.geysermc.pack.converter.PackConversionContext;
|
||||
import org.geysermc.pack.converter.converters.texture.TextureConverter;
|
||||
import org.geysermc.pack.converter.converters.texture.TextureTransformer;
|
||||
import org.geysermc.pack.converter.converters.texture.TransformedTexture;
|
||||
import org.geysermc.pack.converter.data.BaseConversionData;
|
||||
import org.geysermc.pack.converter.converter.texture.TextureConverter;
|
||||
import org.geysermc.pack.converter.converter.texture.TextureTransformer;
|
||||
import org.geysermc.pack.converter.converter.texture.TransformedTexture;
|
||||
import org.geysermc.pack.converter.data.TextureConversionData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import team.unnamed.creative.texture.Texture;
|
||||
@@ -52,7 +52,7 @@ public class PathTransformer implements TextureTransformer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable TransformedTexture transform(@NotNull PackConversionContext<BaseConversionData> context, @NotNull TransformedTexture texture) {
|
||||
public @Nullable TransformedTexture transform(@NotNull PackConversionContext<TextureConversionData> context, @NotNull TransformedTexture texture) {
|
||||
String output = texture.texture().key().value();
|
||||
Path outputDir = context.outputDirectory()
|
||||
.resolve(TextureConverter.BEDROCK_TEXTURES_LOCATION)
|
||||
@@ -39,13 +39,15 @@ public class BaseConversionData implements ConversionData {
|
||||
this.outputDirectory = outputDirectory;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public @NotNull Path inputDirectory() {
|
||||
public Path inputDirectory() {
|
||||
return this.inputDirectory;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public @NotNull Path outputDirectory() {
|
||||
public Path outputDirectory() {
|
||||
return this.outputDirectory;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2023 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/PackConverter
|
||||
*
|
||||
*/
|
||||
|
||||
package org.geysermc.pack.converter.data;
|
||||
|
||||
import org.geysermc.pack.converter.converter.texture.TransformedTexture;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TextureConversionData extends BaseConversionData {
|
||||
private final List<TransformedTexture> transformedTextures = new ArrayList<>();
|
||||
|
||||
public TextureConversionData(@NotNull Path inputDirectory, @NotNull Path outputDirectory) {
|
||||
super(inputDirectory, outputDirectory);
|
||||
}
|
||||
|
||||
public void addTransformedTexture(@NotNull TransformedTexture transformedTexture) {
|
||||
this.transformedTextures.add(transformedTexture);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<TransformedTexture> transformedTextures() {
|
||||
return this.transformedTextures;
|
||||
}
|
||||
}
|
||||
@@ -97,7 +97,6 @@ public class ZipUtils {
|
||||
generateFileList(sourceFolder);
|
||||
}
|
||||
|
||||
|
||||
public void generateFileList(File node) {
|
||||
// Add file only
|
||||
if (node.isFile()) {
|
||||
|
||||
Reference in New Issue
Block a user