Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master-1.12' into master-1.14
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Nov 22, 2019
2 parents cd666d3 + 91c226e commit 0ab493f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
12 changes: 12 additions & 0 deletions resources/changelog/1.12.2-1.2.0.txt
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions src/main/java/org/cyclops/iconexporter/GeneralConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<IExportTask> createExportTasks() {
// Initialize our output folder
File baseDir = new File(Minecraft.getInstance().gameDir, "icon-exports-x" + (this.scale * 2));
Expand Down Expand Up @@ -89,13 +99,16 @@ public Queue<IExportTask> 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());
}
});
}
}
Expand Down

0 comments on commit 0ab493f

Please sign in to comment.