new feature: snowed grass

This commit is contained in:
octarine-noise
2014-07-28 21:52:23 +02:00
parent 168fad883d
commit 7cdddef1bf
4 changed files with 52 additions and 8 deletions

View File

@@ -23,8 +23,9 @@ public class ShortGrassTextureResource implements IResource {
/** Resource to return if generation fails */
public IResource fallbackResource;
public ShortGrassTextureResource(ResourceLocation resource, IResource fallbackResource) {
public ShortGrassTextureResource(ResourceLocation resource, boolean isSnowed, IResource fallbackResource) {
this.fallbackResource = fallbackResource;
boolean isSpecialTexture = resource.getResourcePath().toLowerCase().endsWith("_n.png") || resource.getResourcePath().toLowerCase().endsWith("_s.png");
IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager();
try {
@@ -37,6 +38,13 @@ public class ShortGrassTextureResource implements IResource {
Graphics2D graphics = result.createGraphics();
graphics.drawImage(origImage, 0, 3 * origImage.getHeight() / 8, null);
// blend with white if snowed
if (isSnowed && !isSpecialTexture) {
for (int x = 0; x < result.getWidth(); x++) for (int y = 0; y < result.getHeight(); y++) {
result.setRGB(x, y, blend(result.getRGB(x, y), 0xFFFFFF, 2, 3));
}
}
// create PNG image
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(result, "PNG", baos);
@@ -47,6 +55,15 @@ public class ShortGrassTextureResource implements IResource {
}
}
protected int blend(int rgbOrig, int rgbBlend, int weightOrig, int weightBlend) {
int r = ((rgbOrig & 0xFF) * weightOrig + (rgbBlend & 0xFF) * weightBlend) / (weightOrig + weightBlend);
int g = (((rgbOrig >> 8) & 0xFF) * weightOrig + ((rgbBlend >> 8) & 0xFF) * weightBlend) / (weightOrig + weightBlend);
int b = (((rgbOrig >> 16) & 0xFF) * weightOrig + ((rgbBlend >> 16) & 0xFF) * weightBlend) / (weightOrig + weightBlend);
int a = (rgbOrig >> 24) & 0xFF;
int result = (int) (a << 24 | b << 16 | g << 8 | r);
return result;
}
@Override
public InputStream getInputStream() {
return data != null ? new ByteArrayInputStream(data) : fallbackResource.getInputStream();