Skip to content

Commit 874fbb2

Browse files
committed
Anisotropic Filtering missing texture generator
Closes #24. This code isn't the same as the code used by Minecraft to generate this texture, but the end result is identical.
1 parent 4425423 commit 874fbb2

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

mc-texture-gen-impl/src/main/java/com/github/nerdthened/mctexturegen/generators/AbstractTextureGenerator.java

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public abstract class AbstractTextureGenerator {
2929
/** The size of a standard image in pixels. */
3030
static final int STANDARD_IMAGE_SIZE = 16 * STANDARD_IMAGE_SIZE_MULTIPLIER;
3131

32+
/** Twice the size of a standard image in pixels. */
33+
static final int STANDARD_IMAGE_SIZE_2X = STANDARD_IMAGE_SIZE * 2;
34+
3235
/** A bit mask of the size of a standard image. */
3336
static final int STANDARD_IMAGE_SIZE_BITMASK = STANDARD_IMAGE_SIZE - 1;
3437

mc-texture-gen-impl/src/main/java/com/github/nerdthened/mctexturegen/generators/MissingTextureGenerator.java

+23-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,27 @@ private static TextureGroup missingTextureCheckerboard(String name, int colorOne
4848
return new TextureGroup("Missing_Texture_" + name, missingTexture);
4949
}
5050

51+
/**
52+
* Generates a "checkerboard" texture with the provided colors, with twice the usual image resolution.
53+
*
54+
* @param name the name of the returned texture group
55+
* @param colorOne the first color
56+
* @param colorTwo the second color
57+
* @return the generated "checkerboard" texture
58+
*/
59+
private static TextureGroup missingTextureCheckerboard2x(String name, int colorOne, int colorTwo) {
60+
final BufferedImage missingTexture = new BufferedImage(STANDARD_IMAGE_SIZE_2X, STANDARD_IMAGE_SIZE_2X, BufferedImage.TYPE_INT_RGB);
61+
final int[] textureData = ((DataBufferInt) missingTexture.getRaster().getDataBuffer()).getData();
62+
63+
for (int xPixel = 0; xPixel < STANDARD_IMAGE_SIZE_2X; ++xPixel) {
64+
for (int yPixel = 0; yPixel < STANDARD_IMAGE_SIZE_2X; ++yPixel) {
65+
textureData[xPixel + (yPixel * STANDARD_IMAGE_SIZE_2X)] = (xPixel % STANDARD_IMAGE_SIZE < (STANDARD_IMAGE_SIZE / 2)) ^ (yPixel % STANDARD_IMAGE_SIZE < (STANDARD_IMAGE_SIZE / 2)) ? colorOne : colorTwo;
66+
}
67+
}
68+
69+
return new TextureGroup("Missing_Texture_2x_" + name, missingTexture);
70+
}
71+
5172
/**
5273
* Generates a text-based texture with the provided text.
5374
* The generated TextureGroup is JVM / system dependent:
@@ -135,7 +156,8 @@ public TextureGroup[] getTextureGroups() {
135156
missingTextureText("Java_b1_4_to_13w01b", false, new String[] { "missingtex" }),
136157
missingTextureText("Java_13w02a_to_13w17a", true, new String[] { "missing", "texture"}),
137158
missingTextureCheckerboard("Java_13w18a_to_1_12_2", 0x000000, 0xF800F8),
138-
missingTextureCheckerboard("Java_17w43a_to_current", 0xF800F8, 0x000000)
159+
missingTextureCheckerboard("Java_17w43a_to_current", 0xF800F8, 0x000000),
160+
missingTextureCheckerboard2x("Java_13w38a_to_14w21b", 0x000000, 0xF800F8)
139161
};
140162
}
141163

0 commit comments

Comments
 (0)