Skip to content

Commit

Permalink
Support for non-power-of-2 leaf textures
Browse files Browse the repository at this point in the history
  • Loading branch information
octarine-noise committed Sep 21, 2015
1 parent a624285 commit 3ce95b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Expand Up @@ -9,6 +9,7 @@
import mods.betterfoliage.BetterFoliage;
import mods.betterfoliage.client.BetterFoliageClient;
import mods.betterfoliage.client.integration.ShadersModIntegration;
import mods.betterfoliage.client.util.RenderUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.TextureStitchEvent;
Expand Down Expand Up @@ -53,11 +54,11 @@ protected BufferedImage generateLeaf(ResourceLocation originalResource) throws I
if (!ShadersModIntegration.isSpecialTexture(originalResource)) {
// load alpha mask of appropriate size
BufferedImage maskImage = loadLeafMaskImage(defaultMask, size * 2);
int scale = size * 2 / maskImage.getWidth();
if (maskImage == null) maskImage = loadLeafMaskImage(defaultMask, RenderUtils.nextPowerOf2(size * 2));

for (int x = 0; x < genIcon.getWidth(); x++) for (int y = 0; y < genIcon.getHeight(); y++) {
long origPixel = genIcon.getRGB(x, y) & 0xFFFFFFFFl;
long maskPixel = maskImage.getRGB(x / scale, y / scale) & 0xFF000000l | 0x00FFFFFF;
long maskPixel = maskImage.getRGB(x * maskImage.getWidth() / genIcon.getWidth(), y * maskImage.getWidth() / genIcon.getWidth()) & 0xFF000000l | 0x00FFFFFF;
genIcon.setRGB(x, y, (int) (origPixel & maskPixel));
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/mods/betterfoliage/client/util/RenderUtils.java
Expand Up @@ -107,4 +107,8 @@ public static Integer calculateTextureColor(TextureAtlasSprite icon) {
return null;
}
}

public static int nextPowerOf2(int x) {
return 1 << (x == 0 ? 0 : 32 - Integer.numberOfLeadingZeros(x - 1));
}
}

0 comments on commit 3ce95b3

Please sign in to comment.