Made clouds get from texture rather than use noise

This commit is contained in:
coolGi2007
2022-01-04 07:57:55 +00:00
parent b1a9a8ac8d
commit 66a16ee508
5 changed files with 53 additions and 27 deletions
@@ -101,7 +101,6 @@ public class Config extends ConfigGui
@ConfigAnnotations.Entry(minValue = 2, maxValue = 32)
public static int horizontalScale = IQuality.HORIZONTAL_SCALE_MIN_DEFAULT_MAX.defaultValue;
//@ConfigAnnotations.Category("client.graphics.quality")
@ConfigAnnotations.Entry
public static HorizontalQuality horizontalQuality = IQuality.HORIZONTAL_QUALITY_DEFAULT;
}
@@ -22,12 +22,9 @@ public class CloudTexture {
this.resourceLocation = resourceLocation;
}
public void updateImage(long time) {
Random random = new Random(time);
// Comment to clear sky
SkyCoverGenerators.cloudySkyUpdate(random, this.noise, this.cloudsTexture.getPixels(), pixels, this.cloudiness);
public void updateImage() {
// Comment to not update the sky
// SkyCoverGenerators.cloudySkyUpdate(random, this.noise, this.cloudsTexture.getPixels(), pixels, this.cloudiness);
}
public void updatePixels() {
@@ -58,22 +55,18 @@ public class CloudTexture {
this.cloudsTexture = texture;
}
/** Generates the noise at the start of the game */
public void initNoise(Random random) {
// this.noise = new SimplexNoise(new WorldgenRandom(random.nextLong()));
this.noise = new SimplexNoise(new LegacyRandomSource(random.nextLong()));
}
public DynamicTexture getNativeImage() {
NativeImage image = new NativeImage(256, 256, false);
Random random = new Random();
this.cloudiness = random.nextDouble();
NativeImage image = new NativeImage(SkyCoverGenerators.CLOUD_TEXTURE.getWidth(), SkyCoverGenerators.CLOUD_TEXTURE.getHeight(), false);
// Switch these out to clear sky
// Never comment both or something weird will happen
// SkyCoverGenerators.clearSkyGenerator(this.noise, image, this.cloudiness);
SkyCoverGenerators.cloudySkyGenerator(this.noise, image, this.cloudiness);
SkyCoverGenerators.normalSkyGenerator(image);
return new DynamicTexture(image);
}
@@ -27,7 +27,7 @@ public final class NoiseCloudHandler {
timeIdx = update;
for (CloudTexture cloudTexture : cloudTextures) {
if (cloudTexture.cloudsTexture.getPixels() != null) {
cloudTexture.updateImage(time);
cloudTexture.updateImage();
}
}
}
@@ -1,29 +1,62 @@
package com.seibel.lod.common.clouds;
import com.mojang.blaze3d.platform.NativeImage;
import net.minecraft.world.level.levelgen.synth.SimplexNoise;
import com.seibel.lod.core.ModInfo;
import java.util.List;
import java.util.Random;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
public class SkyCoverGenerators {
public static final int COLOR = NativeImage.combine(255, 255, 255, 255);
public static final BufferedImage CLOUD_TEXTURE = accessFile("/assets/lod/textures/environment/clouds_small.png");
// Where the generator for clouds could be made
// TODO: Try to implement this https://www.reddit.com/r/Minecraft/comments/e7xol/this_is_how_clouds_should_work_gif_simulation/
public static void clearSkyGenerator(SimplexNoise noiseSampler, NativeImage image, double cloudiness) {
for (int x = 0; x < 256; x++) {
for (int z = 0; z < 256; z++) {
if (noiseSampler.getValue(x / 16.0, 0, z / 16.0) * 2.5 < cloudiness || image.getPixelRGBA(x, z) != 0) {
image.setPixelRGBA(x, z, 0);
}
/** Generates clear sky */
public static void clearSkyGenerator(NativeImage image) {
for (int x = 0; x < CLOUD_TEXTURE.getWidth(); x++) {
for (int z = 0; z < CLOUD_TEXTURE.getHeight(); z++) {
image.setPixelRGBA(x, z, 0);
}
}
}
public static void cloudySkyGenerator(SimplexNoise noiseSampler, NativeImage image, double cloudiness) {
/** Generates the sky texture according to the texture */
public static void normalSkyGenerator(NativeImage image) {
for (int x = 0; x < CLOUD_TEXTURE.getWidth(); x++) {
for (int z = 0; z < CLOUD_TEXTURE.getHeight(); z++) {
image.setPixelRGBA(x, z, ((CLOUD_TEXTURE.getRGB(x, z) & 0x000000ff) > 130 ? COLOR : 0));
}
}
}
/** Acsess an image file from the jar */
public static BufferedImage accessFile(String resource) {
// this is the path within the jar file
InputStream input = ModInfo.class.getResourceAsStream(resource);
if (input == null) {
// this is how we load file within editor (eg eclipse)
input = ModInfo.class.getClassLoader().getResourceAsStream(resource);
}
// Turn it into an image
BufferedImage image;
try {
image = ImageIO.read(input);
} catch (Exception e) {
image = null;
}
return image;
}
// Old code
/*
public static void noiseSkyGenerator(SimplexNoise noiseSampler, NativeImage image, double cloudiness) {
for (int x = 0; x < 256; x++) {
for (int z = 0; z < 256; z++) {
image.setPixelRGBA(x, z, COLOR);
@@ -36,7 +69,7 @@ public class SkyCoverGenerators {
}
}
public static void cloudySkyUpdate(Random random, SimplexNoise noiseSampler, NativeImage image, List<CloudTexture.PixelCoordinate> pixels, double cloudiness) {
public static void noiseSkyUpdate(Random random, SimplexNoise noiseSampler, NativeImage image, List<CloudTexture.PixelCoordinate> pixels, double cloudiness) {
int count = random.nextInt(4000) + 4000;
for (int i = 0; i < count; i++) {
@@ -65,4 +98,5 @@ public class SkyCoverGenerators {
}
return false;
}
*/
}
+1 -1
Submodule core updated: 3b475886ef...44bcc5ae01