diff --git a/resources/changelog/1.12.2-1.2.0.txt b/resources/changelog/1.12.2-1.2.0.txt new file mode 100644 index 0000000..f14814f --- /dev/null +++ b/resources/changelog/1.12.2-1.2.0.txt @@ -0,0 +1,12 @@ +As always, don't forget to backup your world before updating! +Requires CyclopsCore version 1.0.6 or higher. + +Additions: +* Add config option to hash NBT tags in filenames + This resolves OS problems with long filenames. + If enabled, NBT tag contents are serialized to + an auxiliary txt file with the same base name. + Closes #5 + +Changes: +* Don't make export stop the export process, Closes #4 diff --git a/src/main/java/org/cyclops/iconexporter/GeneralConfig.java b/src/main/java/org/cyclops/iconexporter/GeneralConfig.java index e2aba9d..3d96e17 100644 --- a/src/main/java/org/cyclops/iconexporter/GeneralConfig.java +++ b/src/main/java/org/cyclops/iconexporter/GeneralConfig.java @@ -29,6 +29,9 @@ public class GeneralConfig extends DummyConfig { @ConfigurableProperty(category = "core", comment = "The default image width in px to render at.", isCommandable = true, configLocation = ModConfig.Type.CLIENT) public static int defaultScale = 32; + @ConfigurableProperty(category = "core", comment = "If the NBT tag should be hashed with MD5 when constructing the file name, and if an auxiliary txt file should be created with the full tag contents.", isCommandable = true) + public static boolean fileNameHashTag = false; + public GeneralConfig() { super(IconExporter._instance, "general"); } diff --git a/src/main/java/org/cyclops/iconexporter/client/gui/ImageExportUtil.java b/src/main/java/org/cyclops/iconexporter/client/gui/ImageExportUtil.java index e9ee417..aca9746 100644 --- a/src/main/java/org/cyclops/iconexporter/client/gui/ImageExportUtil.java +++ b/src/main/java/org/cyclops/iconexporter/client/gui/ImageExportUtil.java @@ -1,10 +1,13 @@ package org.cyclops.iconexporter.client.gui; +import com.google.common.base.Charsets; import com.mojang.blaze3d.platform.GLX; import com.mojang.blaze3d.platform.GlStateManager; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.NativeImage; import net.minecraft.client.shader.Framebuffer; +import net.minecraft.nbt.INBT; +import org.apache.commons.io.FileUtils; import org.apache.logging.log4j.Level; import org.cyclops.iconexporter.IconExporter; import org.lwjgl.system.MemoryUtil; @@ -56,6 +59,23 @@ public static void exportImageFromScreenshot(File dir, String key, int guiWidth, } } + public static void exportNbtFile(File dir, String key, INBT tag) throws IOException { + // Write the file + key = key.replaceAll(":", "__"); + try { + File file = new File(dir, key + ".txt").getCanonicalFile(); + try { + FileUtils.writeStringToFile(file, tag.toString(), Charsets.UTF_8); + } catch (NullPointerException e) { + e.printStackTrace(); + throw new IOException("Error while writing the TXT image " + file); + } + } catch (IOException e) { + IconExporter.clog(Level.ERROR, "Error while writing the TXT image for key " + key); + throw e; + } + } + public static NativeImage getSubImage(NativeImage image, int width, int height) { NativeImage imageNew = new NativeImage(width, height, false); diff --git a/src/main/java/org/cyclops/iconexporter/client/gui/ScreenIconExporter.java b/src/main/java/org/cyclops/iconexporter/client/gui/ScreenIconExporter.java index 4908027..2d13a12 100644 --- a/src/main/java/org/cyclops/iconexporter/client/gui/ScreenIconExporter.java +++ b/src/main/java/org/cyclops/iconexporter/client/gui/ScreenIconExporter.java @@ -7,12 +7,15 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.INBT; import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.TranslationTextComponent; import net.minecraftforge.registries.ForgeRegistries; +import org.apache.commons.codec.digest.DigestUtils; import org.cyclops.cyclopscore.datastructure.Wrapper; import org.cyclops.cyclopscore.helper.Helpers; +import org.cyclops.iconexporter.GeneralConfig; import java.io.File; import java.io.IOException; @@ -54,11 +57,18 @@ public void render(int mouseX, int mouseY, float partialTicks) { } catch (IOException e) { Minecraft.getInstance().player.sendMessage(new TranslationTextComponent("gui.itemexporter.error")); e.printStackTrace(); - Minecraft.getInstance().displayGuiScreen(null); } } } + public String serializeNbtTag(INBT tag) { + if (GeneralConfig.fileNameHashTag) { + return DigestUtils.md5Hex(tag.toString()); + } else { + return tag.toString(); + } + } + public Queue createExportTasks() { // Initialize our output folder File baseDir = new File(Minecraft.getInstance().gameDir, "icon-exports-x" + (this.scale * 2)); @@ -89,13 +99,16 @@ public Queue createExportTasks() { value.fillItemGroup(ItemGroup.SEARCH, subItems); for (ItemStack subItem : subItems) { tasks.set(tasks.get() + 1); - String subKey = key + (subItem.hasTag() ? "__" + subItem.getTag().toString() : ""); + String subKey = key + (subItem.hasTag() ? "__" + serializeNbtTag(subItem.getTag()) : ""); exportTasks.add(() -> { taskProcessed.set(taskProcessed.get() + 1); signalStatus(tasks, taskProcessed); fill(0, 0, this.scale, this.scale, BACKGROUND_COLOR); ItemRenderUtil.renderItem(subItem, this.scale); ImageExportUtil.exportImageFromScreenshot(baseDir, subKey, this.width, this.height, this.scale, BACKGROUND_COLOR_SHIFTED); + if (subItem.hasTag() && GeneralConfig.fileNameHashTag) { + ImageExportUtil.exportNbtFile(baseDir, subKey, subItem.getTag()); + } }); } }