From 1da987d594fe90ecace11d50aba7e279dc151eef Mon Sep 17 00:00:00 2001 From: Jordan Date: Thu, 16 Jun 2022 15:23:52 +0100 Subject: [PATCH] Fix PNGWriter exporting blank PNGs (#1807) * Fix horrendous variable assignment in PNGWriter - Fixes #1679 * More detailed information on PNG format * Avoid a larger number of blocks that do nto have a color assigned in TextureUtil * Don't error in PNGWriter if biomes aren't saved to clipboard and grass is present --- .../clipboard/io/schematic/PNGWriter.java | 20 +++++++++---------- .../clipboard/io/BuiltInClipboardFormat.java | 3 ++- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/clipboard/io/schematic/PNGWriter.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/clipboard/io/schematic/PNGWriter.java index 92be10e66..b5cbc7fb2 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/clipboard/io/schematic/PNGWriter.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/clipboard/io/schematic/PNGWriter.java @@ -7,6 +7,7 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; +import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -68,14 +69,10 @@ public class PNGWriter implements ClipboardWriter { boolean fill = length * 4 < imageSize && width * 4 < imageSize; - MutableBlockVector3 mutable; - MutableBlockVector3 mutableTop; - MutableBlockVector3 mutableRight; - MutableBlockVector3 mutableLeft; - mutable = mutableTop = mutableRight = mutableLeft = new MutableBlockVector3(0, 0, 0); -// Vector mutableTop = new Vector(0, 0, 0); -// Vector mutableRight = new Vector(0, 0, 0); -// Vector mutableLeft = new Vector(0, 0, 0); + MutableBlockVector3 mutable = new MutableBlockVector3(0, 0, 0); + MutableBlockVector3 mutableTop = new MutableBlockVector3(0, 0, 0); + MutableBlockVector3 mutableRight = new MutableBlockVector3(0, 0, 0); + MutableBlockVector3 mutableLeft = new MutableBlockVector3(0, 0, 0); BlockVector3 min = clipboard.getMinimumPoint(); int y0 = min.getBlockY(); @@ -100,7 +97,7 @@ public class PNGWriter implements ClipboardWriter { for (int y = y0; y < y0 + height; y++) { mutable.mutY(y); BlockState block = clipboard.getBlock(mutable); - if (block.getBlockType().getMaterial().isAir()) { + if (!block.getBlockType().getMaterial().isSolid() || block.getBlockType().getMaterial().isTranslucent()) { continue; } mutableTop.mutY(y + 1); @@ -141,8 +138,9 @@ public class PNGWriter implements ClipboardWriter { BlockType type = block.getBlockType(); int color; - if (type == BlockTypes.GRASS_BLOCK) { - color = tu.getColor(clipboard.getBiome(mutable)); + BiomeType biome; + if (type == BlockTypes.GRASS_BLOCK && (biome = clipboard.getBiome(mutable)) != null) { + color = tu.getColor(biome); } else { color = tu.getColor(type); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/BuiltInClipboardFormat.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/BuiltInClipboardFormat.java index 2b06c31ea..5aafa220e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/BuiltInClipboardFormat.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/BuiltInClipboardFormat.java @@ -239,7 +239,8 @@ public enum BuiltInClipboardFormat implements ClipboardFormat { }, /** - * Isometric PNG writer. + * Isometric PNG writer. Only supports solid, full-cube blocks and creates a view of the clipboard looking FROM the south + * east of the clipboard */ PNG("png", "image") { @Override