Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.13 anvil #128

Merged
merged 89 commits into from
Feb 17, 2020
Merged
Changes from 1 commit
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
44f6a26
Added TAG_Long_Array
mmdanggg2 Sep 30, 2018
38b8932
Started on reading new format, displaying something...
mmdanggg2 Oct 1, 2018
e40411b
Now using BitSet to access the long array as a sequence of bits.
mmdanggg2 Oct 1, 2018
53596d6
Fix bits per block calculation
mmdanggg2 Oct 1, 2018
64f3a85
Converted block ID's to use Strings
mmdanggg2 Oct 4, 2018
23f6c92
Fix preview drawing
mmdanggg2 Oct 4, 2018
f75d2b6
Slightly fixed liquid rendering
mmdanggg2 Oct 4, 2018
d4d7f70
Added barrier blocks
mmdanggg2 Oct 5, 2018
ae93207
Make sure string comparisons use .equals as == is not reliable for st…
mmdanggg2 Oct 5, 2018
20f2f14
Converted most of blocks.conf (Thanks Arbiter617)
mmdanggg2 Oct 5, 2018
c4daeff
1.13 has changed texture locations, added new texsplit conf
mmdanggg2 Oct 5, 2018
968879d
Added Path model
mmdanggg2 Oct 6, 2018
d2e7783
Merge branch 'master' into 1.13Anvil
mmdanggg2 Oct 6, 2018
180b1ac
Updated texsplit_1.13.conf properly (Thanks again Arbiter617!)
mmdanggg2 Oct 6, 2018
da1c998
More block updates
mmdanggg2 Oct 7, 2018
69f3a82
Changed data values to be a HashMap of state values from their proper…
mmdanggg2 Oct 8, 2018
5224348
Fixed ladders and hopefully stairs
mmdanggg2 Oct 8, 2018
ba4a9e4
removed Quartz (same as logs)
mmdanggg2 Oct 8, 2018
e66c0c9
Updated more blocks models. (Thanks Arbiter617!)
mmdanggg2 Oct 9, 2018
c7bab54
More block fixes (Arbiter617)
mmdanggg2 Oct 9, 2018
b61645d
Fixed banners!
mmdanggg2 Oct 10, 2018
00b0762
More block updates (Arbiter617)
mmdanggg2 Oct 10, 2018
ae79206
More blocks added & fixed (Arbiter617)
mmdanggg2 Oct 14, 2018
9021a0c
Fixed Mesh block models
mmdanggg2 Oct 14, 2018
92aa0a5
Block updates (Arbiter617)
mmdanggg2 Oct 17, 2018
9105a2b
Mesh models can now have their materials overridden
mmdanggg2 Oct 24, 2018
e09fed0
Fix build errors
mmdanggg2 Oct 24, 2018
71369d5
added Chorus plant (Arbiter617)
mmdanggg2 Nov 8, 2018
0fbf149
New blocks and fixes (Arbiter617)
mmdanggg2 Nov 13, 2018
dcc4223
Added flowerpots with potted plants.
mmdanggg2 Nov 15, 2018
6edb89c
Added Transform toString, helps with debug.
mmdanggg2 Nov 15, 2018
4b957af
Added dragon head and others (Arbiter617)
mmdanggg2 Nov 18, 2018
30c99ab
Fixed waterlogged blocks
mmdanggg2 Nov 17, 2018
de6fb52
Export time changed to debug log
mmdanggg2 Nov 17, 2018
8eb9e67
Fixed banner material export
mmdanggg2 Nov 18, 2018
605e8b3
Fix dragon heads & chorus flower (Arbiter617)
mmdanggg2 Nov 19, 2018
df0d949
Fix panes and added connected hopper (Arbiter617)
mmdanggg2 Jan 5, 2019
c5f715c
Fixed locked repeaters
mmdanggg2 Jan 5, 2019
d1f48c3
Fix < 1.13 chunk crash
mmdanggg2 Jan 6, 2019
73f3ea1
Fix dark_oak_fence_gate texture
mmdanggg2 Jan 6, 2019
0675ad8
Fix torch flame particle
mmdanggg2 Jan 6, 2019
7b88ad7
Added to credits.
mmdanggg2 Jan 6, 2019
3d16b0b
Bumped version
mmdanggg2 Jan 6, 2019
b54804a
Revamped the update system to use GitHub releases.
mmdanggg2 Jan 7, 2019
22ab6ea
gitignore blockselection.dat
mmdanggg2 Jan 7, 2019
bb451bb
Fixed underwater plants and bubble columns not integrating with water…
mmdanggg2 Jan 17, 2019
691a343
Fixed Prismarine occlusions
mmdanggg2 Jan 19, 2019
36b7825
Named viewer and memory monitor threads
mmdanggg2 Jan 19, 2019
1df3e81
Version 102
mmdanggg2 Jan 20, 2019
47e0b17
Again changed block data, now uses the BlockData class.
mmdanggg2 Jan 23, 2019
d82d2ad
Version 103
mmdanggg2 Feb 3, 2019
e86ed0f
Fix dark oak using 'big' oak texture names
mmdanggg2 Apr 6, 2019
0693b87
Fix Nether portals & End portal frames
mmdanggg2 Apr 7, 2019
3ecc7d5
Version 104
mmdanggg2 Apr 7, 2019
c7cabd9
Added fire blockstates
mmdanggg2 Apr 14, 2019
e7e8445
1.6 resource format up to 1.12 not 1.13
mmdanggg2 Apr 17, 2019
1e0b5a0
Added CUSTOM occlusion for more complicated blocks
mmdanggg2 May 13, 2019
967eee0
Much better chunk format detection.
mmdanggg2 May 14, 2019
a44a8e6
Fix Chunk not adding id to BlockData
mmdanggg2 May 16, 2019
a4a4b97
Added custom slab occlusion
mmdanggg2 May 20, 2019
11d6f52
Correct spelling of neighbour
mmdanggg2 May 21, 2019
de69a07
Change Transform to use double, helps with issues with blocks on 0 co…
mmdanggg2 May 27, 2019
f979760
Stairs now have custom occlusion
mmdanggg2 May 27, 2019
7603518
Version 105
mmdanggg2 May 27, 2019
9a55699
Fix straight stairs occluding other stairs facing the same way when i…
mmdanggg2 Jun 2, 2019
c77be8a
Version 106
mmdanggg2 Jun 2, 2019
d33e76a
Added CubeFacing for blocks that use the facing property
mmdanggg2 Jul 11, 2019
22b448c
Merging
Arbiter617 Jul 11, 2019
af523fc
Fixed CubeFacing occlusion
mmdanggg2 Jul 13, 2019
2a2e80a
Merge branch '1.13Anvil' of https://github.com/jmc2obj/j-mc-2-obj int…
Arbiter617 Jul 13, 2019
99b303e
Added 1.14 new blocks
Arbiter617 Jul 14, 2019
740a246
Added missing files
Arbiter617 Jul 14, 2019
ec4f1d2
Merge pull request #120 from Arbiter617/1.13Anvil
mmdanggg2 Jul 15, 2019
4097fab
code cleanup
mmdanggg2 Jul 16, 2019
eaa5a8d
Made normal and specular export optional, speeds up export when not u…
mmdanggg2 Jul 16, 2019
dc1cff5
Fixed texsplit to work with new particle and painting folder structure
Arbiter617 Jul 16, 2019
e52acfd
Added new potted plants
mmdanggg2 Jul 16, 2019
4357e29
Removed level .dat logging from console window
mmdanggg2 Jul 16, 2019
d7c5c5f
Fixed barrel occulsion & sweet_berry_bush model
mmdanggg2 Jul 18, 2019
ae6f201
Merge remote-tracking branch 'remotes/Arbiter617/1.13Anvil' into 1.13…
mmdanggg2 Jul 18, 2019
68655e3
Fix mossy cobblestone material
mmdanggg2 Jul 19, 2019
9206df9
Version 107
mmdanggg2 Jul 19, 2019
7ce836d
Allow selecting .jar files as custom resource packs
mmdanggg2 Aug 12, 2019
3c836e3
Split texture exporting to a separate command --tex_export
mmdanggg2 Aug 14, 2019
6cd8ccb
Optimized texture exporting
TheDuckCow Aug 17, 2019
7a6b4e2
Removing a debug line I added before while exploring early
TheDuckCow Aug 17, 2019
da96712
Move Load button from button bar to save selection bar
opl- Sep 28, 2019
e89fe7d
Merge pull request #124 from TheDuckCow/1.13Anvil
danijel3 Oct 22, 2019
52f02d0
Merge pull request #126 from opl-/better-world-choice-ui
danijel3 Oct 22, 2019
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
Prev Previous commit
Next Next commit
Optimized texture exporting
Textures are exported faster now due to 1) only exporting norm or spec maps if the file is known to exist in the zip file ahead of time (a memory copy of the zip contents is checked for once inistead of multiple times, 2) by switching to directly loading the asset from the zip file instead of iterating over files in the zip until a path matches, and 3) by skipping (sooner) image sets where the default diffuse image is not present at all, whereas before if there was an error in loading the default diffuse image, it will still attempt to continue with the following operations.
  • Loading branch information
TheDuckCow committed Aug 17, 2019
commit 6cd8ccbc0f958a795c5259b30f90e530b7e27470
112 changes: 69 additions & 43 deletions src/org/jmc/TextureExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipFile;

import javax.imageio.ImageIO;
import javax.xml.xpath.XPath;
Expand Down Expand Up @@ -64,24 +67,42 @@ private static BufferedImage loadImageFromFile(File file) throws IOException {
return ImageIO.read(file);
}

private static BufferedImage loadImageFromZip(File zipfile, String imagePath) throws IOException {
private static List<String> loadImageListFromZip(File zipfile) throws IOException {
ZipInputStream zis = null;
ZipEntry entry = null;
Log.debug("\tStarted zip LIST stream");
List<String> texlist = new ArrayList<String>();
try {
zis = new ZipInputStream(new FileInputStream(zipfile));

ZipEntry entry = null;
while ((entry = zis.getNextEntry()) != null)
if (!entry.isDirectory() && entry.getName().equals(imagePath))
break;
if (!entry.isDirectory()){
texlist.add(entry.getName());
}
} finally {
if (zis != null)
zis.close();
}
return texlist;
}

if (entry == null)
private static BufferedImage loadImageFromZip(File zipfile, String imagePath) throws IOException {
InputStream zis = null;
ZipFile zf = null;
BufferedImage result = null;
try {
zf = new ZipFile(zipfile);
ZipEntry entry = null;
entry = zf.getEntry(imagePath);
if (entry.getName() == null)
throw new IOException("Couldn't find " + imagePath + " in " + zipfile.getName());

BufferedImage result = ImageIO.read(zis);
return result;
zis = zf.getInputStream(entry);
result = ImageIO.read(zis);
} finally {
if (zf != null)
zf.close();
if (zis != null)
zis.close();
return result;
}
}

Expand Down Expand Up @@ -177,7 +198,7 @@ private static BufferedImage scaleImage(BufferedImage img, double factor) {
/**
* Looks inside the given zip file to determine the format of the texture
* pack.
*
*
* @param zipfile
* @return Constant indicating texture pack format.
* @throws IOException
Expand All @@ -195,6 +216,7 @@ private static int detectTexturePackFormat(File zipfile) throws IOException {
ZipEntry entry = null;
while ((entry = zis.getNextEntry()) != null) {
String entryName = entry.getName();
Log.debug(entryName + " found in resource pack");
if (entryName.startsWith("assets/minecraft/textures/block"))
found1_13AssetsDir = true;
else if (entryName.startsWith("assets/minecraft/textures/blocks"))
Expand All @@ -205,9 +227,9 @@ else if (entryName.equals("terrain.png"))
foundTerrainPng = true;
}

return found1_13AssetsDir ? FORMAT_1_13 :
found1_6AssetsDir ? FORMAT_1_6 :
foundBlocksDir ? FORMAT_1_5 :
return found1_13AssetsDir ? FORMAT_1_13 :
found1_6AssetsDir ? FORMAT_1_6 :
foundBlocksDir ? FORMAT_1_5 :
foundTerrainPng ? FORMAT_PRE_1_5 :
FORMAT_INVALID;
} finally {
Expand All @@ -220,7 +242,7 @@ else if (entryName.equals("terrain.png"))
* Reads the configuration file "texsplit.conf". Private method to retrieve
* textures from a texturepack in a list. This was extracted into a separate
* method so it can be reused between the split and merge methods.
*
*
* @param texturePack
* @param scale
* @param progress
Expand Down Expand Up @@ -275,6 +297,9 @@ private static List<Texture> getTextures(File texturePack, double scale, Progres
Document doc = Xml.loadDocument(confFile);
XPath xpath = XPathFactory.newInstance().newXPath();

// create a memory copy of zip file names, to avoid duplicate zipstreams
List<String> texlist = loadImageListFromZip(zipfile);

NodeList fileNodes = (NodeList) xpath.evaluate("/texsplit/file", doc, XPathConstants.NODESET);
for (int i = 0; i < fileNodes.getLength(); i++) {
Node fileNode = fileNodes.item(i);
Expand All @@ -287,11 +312,11 @@ private static List<Texture> getTextures(File texturePack, double scale, Progres
throw new Exception("In " + confFilePath + ": 'file' tag is missing required attribute 'name'.");

BufferedImage image = null;

try {
image = loadImage(zipfile, source, fileName);
} catch (Exception e) {
Log.info("Error loading image: " + e.getMessage());
Log.info("Error loading image (" + fileName + "): "+ e.getMessage());
continue;
}

int width = image.getWidth() / Integer.parseInt(cols, 10);
Expand All @@ -307,7 +332,7 @@ private static List<Texture> getTextures(File texturePack, double scale, Progres
String repeating_str = Xml.getAttribute(texNode, "repeating");
if (repeating_str != null)
repeating = repeating_str.toLowerCase().equals("true");

boolean luma = false;
String luma_str = Xml.getAttribute(texNode, "luma");
if (luma_str != null)
Expand Down Expand Up @@ -355,13 +380,13 @@ private static List<Texture> getTextures(File texturePack, double scale, Progres
else {
Log.debug("Creating Texture for: " + texName);
Texture texture2 = new Texture(texName, texture, repeating, luma);

if (diffuse) {
Log.debug("Writing Diffuse Texture: " + texName);
ImageIO.write(texture2.image, "png", new File(destination, texture2.name + ".png"));
}
if (alphas) {

if (alphas){
try {
convertToAlpha(texture2.image);
Log.debug("Writing Alpha Texture: " + texture2.name + "_a.png");
Expand All @@ -370,13 +395,13 @@ private static List<Texture> getTextures(File texturePack, double scale, Progres
Log.info("Cannot save alpha for: " + texture2.name + " (" + e.getMessage() + ")");
}
}
if (exportNormal) {

if (exportNormal && texlist.contains(fileName.replace(".png", "_n.png"))) {
try {
Log.debug("Trying normal map");

BufferedImage imageN = loadImage(zipfile, source, fileName.replace(".png", "_n.png"));

Log.debug("Found Normal. Creating Buffered Texture.");
BufferedImage textureN = new BufferedImage(width, height, imageN.getType());
imageN.getSubimage(colPos * width, rowPos * height, width, height).copyData(textureN.getRaster());
Expand All @@ -387,23 +412,23 @@ private static List<Texture> getTextures(File texturePack, double scale, Progres
Log.info("Cannot scale image: " + texName + "_n (" + e.getMessage() + ")");
}
}

Log.debug("Creating Normal Texture. " + texName + "_n");
Texture texture2N = new Texture(texName + "_n", textureN, repeating, false);
Log.debug("Writing Normal Texture. " + texture2N.name);
ImageIO.write(texture2N.image, "png", new File(destination, texture2N.name + ".png"));

} catch (Exception e) {
Log.info("Error loading normal texture: " + e.getMessage());
}
}
if (exportSpecular) {

if (exportSpecular && texlist.contains(fileName.replace(".png", "_s.png"))) {
try {
Log.debug("Trying specular map");

BufferedImage imageS = loadImage(zipfile, source, fileName.replace(".png", "_s.png"));

Log.debug("Found Specular. Creating Buffered Texture.");
BufferedImage textureS = new BufferedImage(width, height, imageS.getType());
imageS.getSubimage(colPos * width, rowPos * height, width, height).copyData(textureS.getRaster());
Expand All @@ -418,20 +443,20 @@ private static List<Texture> getTextures(File texturePack, double scale, Progres
Texture texture2S = new Texture(texName + "_s", textureS, repeating, false);
Log.debug("Writing Specular Texture. " + texture2S.name);
ImageIO.write(texture2S.image, "png", new File(destination, texture2S.name + ".png"));

} catch (Exception e) {
Log.info("Error loading specular image: " + e.getMessage());
}
}

}

}

if (progress != null)
progress.setProgress((i + 1) / (float) fileNodes.getLength());
}

if(merging)
return ret;
else
Expand All @@ -446,17 +471,17 @@ else if (source.equalsIgnoreCase("distr"))
image = loadImageFromFile(new File(Filesystem.getDatafilesDir(), fileName));
else
image = loadImageFromFile(new File(fileName));

if (image.getType() != BufferedImage.TYPE_4BYTE_ABGR)
image = convertImageType(image);

return image;
}

/**
* Reads a Minecraft texture pack and splits the individual block textures
* into .png images.
*
*
* @param destination
* Directory to place the output files.
* @param texturePack
Expand Down Expand Up @@ -490,7 +515,8 @@ public static void splitTextures(File destination, File texturePack, double scal
throw new RuntimeException("Cannot create texture directory!");
}

/* List<Texture> textures = */getTextures(texturePack, scale, progress, diffuse, alphas, false, normals, specular, destination);
/* List<Texture> textures = */
getTextures(texturePack, scale, progress, diffuse, alphas, false, normals, specular, destination);

// float texnum = textures.size();
// float count = 0;
Expand All @@ -517,7 +543,7 @@ public static void splitTextures(File destination, File texturePack, double scal
* Reads a Minecraft texture pack and splits the individual block textures
* into separate images then merges them into a single file containing all
* the textures.
*
*
* @param destination
* Directory to place the output files. They will be called
* "texture.png" and "texture_a.png"
Expand All @@ -526,8 +552,8 @@ public static void splitTextures(File destination, File texturePack, double scal
* default textures.
* @param scale
* Scaling to apply to textures.
* @param diffuse
* Whether to export separate diffuse maps.
* @param diffuse
* Whether to export separate diffuse maps.
* @param alphas
* Whether to export separate alpha masks.
* @param normals
Expand Down Expand Up @@ -629,7 +655,7 @@ public static void mergeTextures(File destination, File texturePack, double scal

BufferedImage textureimage = new BufferedImage(wmax, hmax, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D gtex = textureimage.createGraphics();

BufferedImage lumaimage = new BufferedImage(wmax, hmax, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D gtexluma = lumaimage.createGraphics();

Expand All @@ -646,7 +672,7 @@ public static void mergeTextures(File destination, File texturePack, double scal
int sy = rect.y + y * rect.height;
gtex.drawImage(texture.image, sx, sy, sx + rect.width, sy + rect.height, 0, 0, rect.width,
rect.height, null);

if(lumas)
if(texture.luma)
gtexluma.drawImage(texture.image, sx, sy, sx + rect.width, sy + rect.height, 0, 0, rect.width,
Expand All @@ -668,7 +694,7 @@ public static void mergeTextures(File destination, File texturePack, double scal
ImageIO.write(textureimage, "png", new File(destination, "texture.png"));
if(lumas)
ImageIO.write(lumaimage, "png", new File(destination, "texture_luma.png"));

if (alphas) {
try {
convertToAlpha(textureimage);
Expand Down