new feature: snowed grass
This commit is contained in:
@@ -74,10 +74,16 @@ public class BetterFoliageClient {
|
|||||||
MinecraftForge.EVENT_BUS.register(new BlockTextureGenerator("bf_shortgrass", new ResourceLocation("betterfoliage", "textures/blocks/missing_leaf.png")) {
|
MinecraftForge.EVENT_BUS.register(new BlockTextureGenerator("bf_shortgrass", new ResourceLocation("betterfoliage", "textures/blocks/missing_leaf.png")) {
|
||||||
@Override
|
@Override
|
||||||
public IResource getResource(ResourceLocation var1) throws IOException {
|
public IResource getResource(ResourceLocation var1) throws IOException {
|
||||||
return new ShortGrassTextureResource(unwrapResource(var1), getMissingResource());
|
return new ShortGrassTextureResource(unwrapResource(var1), false, getMissingResource());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
MinecraftForge.EVENT_BUS.register(new BlockTextureGenerator("bf_shortgrass_snow", new ResourceLocation("betterfoliage", "textures/blocks/missing_leaf.png")) {
|
||||||
|
@Override
|
||||||
|
public IResource getResource(ResourceLocation var1) throws IOException {
|
||||||
|
return new ShortGrassTextureResource(unwrapResource(var1), true, getMissingResource());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
MinecraftForge.EVENT_BUS.register(new BetterFoliageClient());
|
MinecraftForge.EVENT_BUS.register(new BetterFoliageClient());
|
||||||
|
|
||||||
ShadersModIntegration.init();
|
ShadersModIntegration.init();
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ public class RenderBlockAOBase extends RenderBlocks {
|
|||||||
public float red;
|
public float red;
|
||||||
public float green;
|
public float green;
|
||||||
public float blue;
|
public float blue;
|
||||||
|
public void setGray(float value) {
|
||||||
|
red = value; green = value; blue = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected double[] uValues = new double[] {0.0, 16.0, 16.0, 0.0};
|
protected double[] uValues = new double[] {0.0, 16.0, 16.0, 0.0};
|
||||||
|
|||||||
@@ -23,13 +23,15 @@ import cpw.mods.fml.relauncher.SideOnly;
|
|||||||
public class RenderBlockBetterGrass extends RenderBlockAOBase implements IRenderBlockDecorator {
|
public class RenderBlockBetterGrass extends RenderBlockAOBase implements IRenderBlockDecorator {
|
||||||
|
|
||||||
public IconSet grassIcons = new IconSet("bettergrassandleaves", "better_grass_long_%d");
|
public IconSet grassIcons = new IconSet("bettergrassandleaves", "better_grass_long_%d");
|
||||||
|
public IconSet snowGrassIcons = new IconSet("bettergrassandleaves", "better_grass_snowed_%d");
|
||||||
public IconSet myceliumIcons = new IconSet("bettergrassandleaves", "better_mycel_%d");
|
public IconSet myceliumIcons = new IconSet("bettergrassandleaves", "better_mycel_%d");
|
||||||
public IIcon grassGenIcon;
|
public IIcon grassGenIcon;
|
||||||
|
public IIcon snowGrassGenIcon;
|
||||||
|
|
||||||
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
|
public boolean isBlockAccepted(IBlockAccess blockAccess, int x, int y, int z, Block block, int original) {
|
||||||
if (!BetterFoliage.config.grassEnabled) return false;
|
if (!BetterFoliage.config.grassEnabled) return false;
|
||||||
if (!((block instanceof BlockGrass || block == Blocks.mycelium))) return false;
|
if (!((block instanceof BlockGrass || block == Blocks.mycelium))) return false;
|
||||||
if (y == 255 || !blockAccess.isAirBlock(x, y + 1, z)) return false;
|
if (!blockAccess.isAirBlock(x, y + 1, z) && blockAccess.getBlock(x, y + 1, z) != Blocks.snow_layer) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,19 +46,32 @@ public class RenderBlockBetterGrass extends RenderBlockAOBase implements IRender
|
|||||||
|
|
||||||
int variation = getSemiRandomFromPos(x, y, z, 0);
|
int variation = getSemiRandomFromPos(x, y, z, 0);
|
||||||
int heightVariation = getSemiRandomFromPos(x, y, z, 1);
|
int heightVariation = getSemiRandomFromPos(x, y, z, 1);
|
||||||
|
boolean isSnowed = blockAccess.getBlock(x, y + 1, z) == Blocks.snow_layer;
|
||||||
|
|
||||||
IIcon renderIcon = (block == Blocks.mycelium) ?
|
IIcon renderIcon = null;
|
||||||
myceliumIcons.get(variation) :
|
if (block instanceof BlockGrass) {
|
||||||
(BetterFoliage.config.grassUseGenerated ? grassGenIcon : grassIcons.get(variation));
|
if (BetterFoliage.config.grassUseGenerated) {
|
||||||
|
renderIcon = isSnowed ? snowGrassGenIcon : grassGenIcon;
|
||||||
|
} else {
|
||||||
|
renderIcon = isSnowed ? snowGrassIcons.get(variation) : grassIcons.get(variation);
|
||||||
|
}
|
||||||
|
} else if (block == Blocks.mycelium && !isSnowed) {
|
||||||
|
renderIcon = myceliumIcons.get(variation);
|
||||||
|
}
|
||||||
if (renderIcon == null) return true;
|
if (renderIcon == null) return true;
|
||||||
|
|
||||||
double scale = BetterFoliage.config.grassSize.value * 0.5;
|
double scale = BetterFoliage.config.grassSize.value * 0.5;
|
||||||
double halfHeight = 0.5 * (BetterFoliage.config.grassHeightMin.value + pRand[heightVariation] * (BetterFoliage.config.grassHeightMax.value - BetterFoliage.config.grassHeightMin.value));
|
double halfHeight = 0.5 * (BetterFoliage.config.grassHeightMin.value + pRand[heightVariation] * (BetterFoliage.config.grassHeightMax.value - BetterFoliage.config.grassHeightMin.value));
|
||||||
|
|
||||||
|
if (isSnowed) {
|
||||||
|
aoYPXZNN.setGray(0.9f); aoYPXZNP.setGray(0.9f); aoYPXZPN.setGray(0.9f); aoYPXZPP.setGray(0.9f);
|
||||||
|
Tessellator.instance.setColorOpaque(230, 230, 230);
|
||||||
|
}
|
||||||
|
|
||||||
// render short grass
|
// render short grass
|
||||||
ShadersModIntegration.startGrassQuads();
|
ShadersModIntegration.startGrassQuads();
|
||||||
Tessellator.instance.setBrightness(getBrightness(block, x, y + 1, z));
|
Tessellator.instance.setBrightness(getBrightness(block, x, y + 1, z));
|
||||||
renderCrossedSideQuads(new Double3(x + 0.5, y + 1.0 - 0.125 * halfHeight, z + 0.5), ForgeDirection.UP, scale, halfHeight, pRot[variation], BetterFoliage.config.grassHOffset.value, renderIcon, 0, false);
|
renderCrossedSideQuads(new Double3(x + 0.5, y + 1.0 + (isSnowed ? 0.0625 : 0.0), z + 0.5), ForgeDirection.UP, scale, halfHeight, pRot[variation], BetterFoliage.config.grassHOffset.value, renderIcon, 0, false);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -66,9 +81,12 @@ public class RenderBlockBetterGrass extends RenderBlockAOBase implements IRender
|
|||||||
if (event.map.getTextureType() != 0) return;
|
if (event.map.getTextureType() != 0) return;
|
||||||
|
|
||||||
grassIcons.registerIcons(event.map);
|
grassIcons.registerIcons(event.map);
|
||||||
|
snowGrassIcons.registerIcons(event.map);
|
||||||
myceliumIcons.registerIcons(event.map);
|
myceliumIcons.registerIcons(event.map);
|
||||||
grassGenIcon = event.map.registerIcon("bf_shortgrass:minecraft:tallgrass");
|
grassGenIcon = event.map.registerIcon("bf_shortgrass:minecraft:tallgrass");
|
||||||
|
snowGrassGenIcon = event.map.registerIcon("bf_shortgrass_snow:minecraft:tallgrass");
|
||||||
BetterFoliage.log.info(String.format("Found %d short grass textures", grassIcons.numLoaded));
|
BetterFoliage.log.info(String.format("Found %d short grass textures", grassIcons.numLoaded));
|
||||||
|
BetterFoliage.log.info(String.format("Found %d snowy grass textures", snowGrassIcons.numLoaded));
|
||||||
BetterFoliage.log.info(String.format("Found %d mycelium textures", myceliumIcons.numLoaded));
|
BetterFoliage.log.info(String.format("Found %d mycelium textures", myceliumIcons.numLoaded));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,8 +23,9 @@ public class ShortGrassTextureResource implements IResource {
|
|||||||
/** Resource to return if generation fails */
|
/** Resource to return if generation fails */
|
||||||
public IResource fallbackResource;
|
public IResource fallbackResource;
|
||||||
|
|
||||||
public ShortGrassTextureResource(ResourceLocation resource, IResource fallbackResource) {
|
public ShortGrassTextureResource(ResourceLocation resource, boolean isSnowed, IResource fallbackResource) {
|
||||||
this.fallbackResource = fallbackResource;
|
this.fallbackResource = fallbackResource;
|
||||||
|
boolean isSpecialTexture = resource.getResourcePath().toLowerCase().endsWith("_n.png") || resource.getResourcePath().toLowerCase().endsWith("_s.png");
|
||||||
|
|
||||||
IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager();
|
IResourceManager resourceManager = Minecraft.getMinecraft().getResourceManager();
|
||||||
try {
|
try {
|
||||||
@@ -37,6 +38,13 @@ public class ShortGrassTextureResource implements IResource {
|
|||||||
Graphics2D graphics = result.createGraphics();
|
Graphics2D graphics = result.createGraphics();
|
||||||
graphics.drawImage(origImage, 0, 3 * origImage.getHeight() / 8, null);
|
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
|
// create PNG image
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
ImageIO.write(result, "PNG", baos);
|
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
|
@Override
|
||||||
public InputStream getInputStream() {
|
public InputStream getInputStream() {
|
||||||
return data != null ? new ByteArrayInputStream(data) : fallbackResource.getInputStream();
|
return data != null ? new ByteArrayInputStream(data) : fallbackResource.getInputStream();
|
||||||
|
|||||||
Reference in New Issue
Block a user