Removed clouds

This commit is contained in:
coolGi2007
2022-02-05 09:41:53 +00:00
parent dda3c7636b
commit 213d70f2d1
9 changed files with 14 additions and 906 deletions
@@ -27,7 +27,6 @@ import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton;
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton.IClient.IAdvanced.*;
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton.IClient.IGraphics.*;
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton.IClient.IWorldGenerator;
import net.minecraft.client.renderer.DimensionSpecialEffects;
/**
* This handles any configuration the user has access to.
@@ -85,9 +84,6 @@ public class Config extends ConfigGui
@ConfigAnnotations.ScreenEntry
public static FogQuality fogQuality;
@ConfigAnnotations.ScreenEntry
public static CloudQuality cloudQuality;
@ConfigAnnotations.ScreenEntry
public static AdvancedGraphics advancedGraphics;
@@ -149,34 +145,7 @@ public class Config extends ConfigGui
public static boolean disableVanillaFog = IFogQuality.DISABLE_VANILLA_FOG_DEFAULT;
}
public static class CloudQuality
{
@ConfigAnnotations.Comment
public static ConfigAnnotations.Comment cloudWarning;
@ConfigAnnotations.FileComment
public static String _customClouds = ICloudQuality.CUSTOM_CLOUDS_DESC;
@ConfigAnnotations.Entry
public static boolean customClouds = ICloudQuality.CUSTOM_CLOUDS_DEFAULT;
@ConfigAnnotations.FileComment
public static String _coolClouds = ICloudQuality.COOL_CLOUDS_DESC;
@ConfigAnnotations.Entry
public static boolean coolClouds = ICloudQuality.COOL_CLOUDS_DEFAULT;
@ConfigAnnotations.FileComment
public static String _extendClouds = ICloudQuality.EXTEND_CLOUDS_DESC;
@ConfigAnnotations.Entry
public static boolean extendClouds = ICloudQuality.EXTEND_CLOUDS_DEFAULT;
@ConfigAnnotations.FileComment
public static String _cloudHeight = ICloudQuality.CLOUD_HEIGHT_DESC;
@ConfigAnnotations.Entry
public static double cloudHeight = DimensionSpecialEffects.OverworldEffects.CLOUD_LEVEL;
}
public static class AdvancedGraphics
{
@ConfigAnnotations.FileComment
@@ -1,22 +0,0 @@
package com.seibel.lod.common.clouds;
import org.lwjgl.system.MemoryUtil;
import java.nio.FloatBuffer;
//I'm not sure if there is a better place to put these, if there is feel free to move them.
/**
* This exists because creating a new Floatbuffer every tick to simply store floats seems to be a bad idea.
*/
public class CloudBufferSingleton
{
public static final CloudBufferSingleton INSTANCE = new CloudBufferSingleton();
public FloatBuffer customBuffer = MemoryUtil.memAllocFloat(16);
public FloatBuffer mcBuffer = MemoryUtil.memAllocFloat(16);
public CloudBufferSingleton(){
}
}
@@ -1,84 +0,0 @@
package com.seibel.lod.common.clouds;
import com.mojang.blaze3d.platform.NativeImage;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.levelgen.LegacyRandomSource;
import net.minecraft.world.level.levelgen.synth.SimplexNoise;
import java.util.*;
public class CloudTexture {
public List<PixelCoordinate> pixels = new LinkedList<PixelCoordinate>() {};
public SimplexNoise noise;
public DynamicTexture cloudsTexture;
public ResourceLocation resourceLocation;
public double cloudiness;
public CloudTexture(ResourceLocation resourceLocation) {
this.resourceLocation = resourceLocation;
}
public void updateImage() {
// Comment to not update the sky
// SkyCoverGenerators.cloudySkyUpdate(random, this.noise, this.cloudsTexture.getPixels(), pixels, this.cloudiness);
}
public void updatePixels() {
pixels.removeIf(pixel -> !fadePixel(Objects.requireNonNull(this.cloudsTexture.getPixels()), pixel.posX, pixel.posZ, pixel.fading));
this.cloudsTexture.upload();
}
public boolean fadePixel(NativeImage image, int x, int z, boolean fading) {
int color = image.getPixelRGBA(x, z);
int alpha = (color >> 24) & 0xFF;
//int alpha = image.getLuminanceOrAlpha(x, z) + 128;
if (fading) alpha -= 5;
else alpha += 5;
int newColor = alpha << 24 | 255 << 16 | 255 << 8 | 255;
//int newColor = NativeImage.combine(alpha, 255, 255, 255);
image.setPixelRGBA(x, z, newColor);
if (alpha <= 0) {
image.setPixelRGBA(x, z, 0);
return false;
} else return alpha < 255;
}
public void setTexture(DynamicTexture texture) {
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(SkyCoverGenerators.CLOUD_TEXTURE.getWidth(), SkyCoverGenerators.CLOUD_TEXTURE.getHeight(), false);
// Switch these out to clear sky
// Never comment both or something weird will happen
SkyCoverGenerators.normalSkyGenerator(image);
return new DynamicTexture(image);
}
public static class PixelCoordinate {
public int posX;
public int posZ;
public boolean fading;
public PixelCoordinate(int posX, int posZ, boolean fading) {
this.posX = posX;
this.posZ = posZ;
this.fading = fading;
}
}
}
@@ -1,56 +0,0 @@
package com.seibel.lod.common.clouds;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation;
import java.util.LinkedList;
import java.util.List;
public final class NoiseCloudHandler {
public static List<CloudTexture> cloudTextures = new LinkedList<CloudTexture>() {};
private static long cloudIdx = -1;
private static long timeIdx = -1;
private static long lastTime = -1;
public static void update() {
Minecraft client = Minecraft.getInstance();
assert client.level != null;
long time = client.level.getGameTime();
if (time > lastTime) {
lastTime = time;
updateSkyCover(time);
long update = time / 600;
if (update > timeIdx) {
timeIdx = update;
for (CloudTexture cloudTexture : cloudTextures) {
if (cloudTexture.cloudsTexture.getPixels() != null) {
cloudTexture.updateImage();
}
}
}
for (CloudTexture cloudTexture : cloudTextures) {
if (cloudTexture.cloudsTexture.getPixels() != null) {
cloudTexture.updatePixels();
}
}
}
}
public static void updateSkyCover(long time) {
long idx = time / 12000;
if (idx > cloudIdx) {
cloudIdx = idx;
}
}
public static void initCloudTextures(ResourceLocation defaultCloud) {
CloudTexture defaultCloudTexture = new CloudTexture(defaultCloud);
cloudTextures.add(defaultCloudTexture);
}
}
@@ -1,102 +0,0 @@
package com.seibel.lod.common.clouds;
import com.mojang.blaze3d.platform.NativeImage;
import com.seibel.lod.core.ModInfo;
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/
/** Generates clear sky */
public static void clearSkyGenerator(NativeImage image) {
for (int x = 0; x < image.getWidth(); x++) {
for (int z = 0; z < image.getHeight(); z++) {
image.setPixelRGBA(x, z, 0);
}
}
}
/** 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) & 0x0000ff) > 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);
if (noiseSampler.getValue(x / 16.0, 0, z / 16.0) * 2.5 >= cloudiness || image.getPixelRGBA(x, z) != 0) {
if ((int) (noiseSampler.getValue(x / 16.0, 0, z / 16.0) * 2.5) != 0) {
image.setPixelRGBA(x, z, 0);
}
}
}
}
}
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++) {
int x = random.nextInt(256);
int z = random.nextInt(256);
if (!updatingPixel(x, z, pixels)) {
if (noiseSampler.getValue(x / 16.0, 0, z / 16.0) * 2.5 < cloudiness && image.getPixelRGBA(x, z) == 0) {
if ((int) (noiseSampler.getValue(x / 16.0, 0, z / 16.0) * 2.5) != 0) {
pixels.add(new CloudTexture.PixelCoordinate(x, z, true));
} else {
pixels.add(new CloudTexture.PixelCoordinate(x, z, false));
}
} else {
pixels.add(new CloudTexture.PixelCoordinate(x, z, false));
}
}
}
}
public static boolean updatingPixel(int x, int z, List<CloudTexture.PixelCoordinate> pixels) {
for (CloudTexture.PixelCoordinate pixel : pixels) {
if (pixel.posX == x && pixel.posZ == z) {
return true;
}
}
return false;
}
*/
}
@@ -81,7 +81,6 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
{
public final IQuality quality;
public final IFogQuality fogQuality;
public final ICloudQuality cloudQuality;
public final IAdvancedGraphics advancedGraphics;
@@ -98,12 +97,6 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
return fogQuality;
}
@Override
public ICloudQuality cloudQuality()
{
return cloudQuality;
}
@Override
public IAdvancedGraphics advancedGraphics()
{
@@ -115,7 +108,6 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
{
quality = new Quality();
fogQuality = new FogQuality();
cloudQuality = new CloudQuality();
advancedGraphics = new AdvancedGraphics();
}
@@ -255,61 +247,6 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton
}
public static class CloudQuality implements ICloudQuality
{
@Override
public boolean getCustomClouds()
{
return Config.Client.Graphics.CloudQuality.customClouds;
}
@Override
public void setCustomClouds(boolean newCustomClouds)
{
ConfigGui.editSingleOption.getEntry("client.graphics.cloudQuality.customClouds").value = newCustomClouds;
ConfigGui.editSingleOption.saveOption("client.graphics.cloudQuality.customClouds");
}
@Override
public boolean getCoolClouds()
{
return Config.Client.Graphics.CloudQuality.coolClouds;
}
@Override
public void setCoolClouds(boolean newCoolClouds)
{
ConfigGui.editSingleOption.getEntry("client.graphics.cloudQuality.coolClouds").value = newCoolClouds;
ConfigGui.editSingleOption.saveOption("client.graphics.cloudQuality.coolClouds");
}
@Override
public boolean getExtendClouds()
{
return Config.Client.Graphics.CloudQuality.extendClouds;
}
@Override
public void setExtendClouds(boolean newExtendClouds)
{
ConfigGui.editSingleOption.getEntry("client.graphics.cloudQuality.extendClouds").value = newExtendClouds;
ConfigGui.editSingleOption.saveOption("client.graphics.cloudQuality.extendClouds");
}
@Override
public double getCloudHeight()
{
return Config.Client.Graphics.CloudQuality.cloudHeight;
}
@Override
public void setCloudHeight(double newCloudHeight)
{
ConfigGui.editSingleOption.getEntry("client.graphics.cloudQuality.cloudHeight").value = newCloudHeight;
ConfigGui.editSingleOption.saveOption("client.graphics.cloudQuality.cloudHeight");
}
}
public static class AdvancedGraphics implements IAdvancedGraphics
{
@Override
+1 -1
Submodule core updated: 069978ee1d...09b2d952b6
@@ -19,40 +19,18 @@
package com.seibel.lod.fabric.mixins;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix4f;
import com.seibel.lod.common.clouds.CloudBufferSingleton;
import com.seibel.lod.common.clouds.CloudTexture;
import com.seibel.lod.common.clouds.NoiseCloudHandler;
import com.seibel.lod.common.wrappers.McObjectConverter;
import com.seibel.lod.core.util.LodUtil;
import com.seibel.lod.core.util.SingletonHandler;
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton;
import com.seibel.lod.core.wrapperInterfaces.modAccessor.IModChecker;
import com.seibel.lod.core.api.ClientApi;
import com.seibel.lod.core.objects.math.Mat4f;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.RenderType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.seibel.lod.core.api.ClientApi;
import com.seibel.lod.core.objects.math.Mat4f;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
import net.minecraft.client.CloudStatus;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.*;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.*;
import java.nio.FloatBuffer;
import java.util.Random;
/**
* This class is used to mix in my rendering code
* before Minecraft starts rendering blocks.
@@ -69,18 +47,6 @@ import java.util.Random;
@Mixin(LevelRenderer.class)
public class MixinWorldRenderer
{
@Final @Shadow private static ResourceLocation CLOUDS_LOCATION;
@Shadow private final int ticks;
@Final @Shadow @NotNull private final Minecraft minecraft;
@Shadow private int prevCloudX;
@Shadow private int prevCloudY;
@Shadow private int prevCloudZ;
@Shadow @NotNull private Vec3 prevCloudColor;
@Shadow @NotNull private CloudStatus prevCloudsType;
@Shadow private boolean generateClouds;
@Shadow @NotNull private VertexBuffer cloudBuffer;
@Unique private boolean initializedClouds = false;
private static float previousPartialTicks = 0;
public MixinWorldRenderer() {
@@ -89,21 +55,6 @@ public class MixinWorldRenderer
@Inject(method = "renderClouds", at = @At("HEAD"), cancellable = true)
public void renderClouds(PoseStack poseStack, Matrix4f projectionMatrix, float tickDelta, double cameraX, double cameraY, double cameraZ, CallbackInfo ci) {
ILodConfigWrapperSingleton CONFIG = SingletonHandler.get(ILodConfigWrapperSingleton.class);
if (CONFIG.client().graphics().cloudQuality().getCustomClouds()) {
TextureManager textureManager = Minecraft.getInstance().getTextureManager();
registerClouds(textureManager);
// Only use when needed since it causes lag
// NoiseCloudHandler.update();
if (minecraft.level.dimension() == ClientLevel.OVERWORLD) {
CloudTexture cloudTexture = NoiseCloudHandler.cloudTextures.get(NoiseCloudHandler.cloudTextures.size() - 1);
renderCloudLayer(poseStack, projectionMatrix, tickDelta, cameraX, cameraY, cameraZ, (float) (CONFIG.client().graphics().cloudQuality().getCloudHeight() + 0.01 /* Make clouds a bit higher so it dosnt do janky stuff */), 1, 1, cloudTexture.resourceLocation);
}
ci.cancel();
}
// get the partial ticks since renderChunkLayer doesn't
// have access to them
previousPartialTicks = tickDelta;
@@ -122,222 +73,4 @@ public class MixinWorldRenderer
ClientApi.INSTANCE.renderLods(mcModelViewMatrix, mcProjectionMatrix, previousPartialTicks);
}
}
// TODO: Move these outside of the mixin
// When moved out then put credit to https://github.com/misterslime/fabulousclouds-fabric
private void registerClouds(TextureManager textureManager) {
if (!this.initializedClouds) {
Random random = new Random();
NoiseCloudHandler.initCloudTextures(CLOUDS_LOCATION);
for(CloudTexture cloudTexture : NoiseCloudHandler.cloudTextures) {
cloudTexture.initNoise(random);
DynamicTexture texture = cloudTexture.getNativeImage();
textureManager.register(cloudTexture.resourceLocation, texture);
cloudTexture.setTexture(texture);
}
this.initializedClouds = true;
}
}
private void renderCloudLayer(PoseStack poseStack, Matrix4f projectionMatrix, float tickDelta, double cameraX, double cameraY, double cameraZ, float cloudHeight, float cloudScale, float speedMod, ResourceLocation resourceLocation) {
RenderSystem.disableCull();
RenderSystem.enableBlend();
RenderSystem.enableDepthTest();
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
RenderSystem.depthMask(true);
float scale = 12.0F * cloudScale;
double speed = ((this.ticks + tickDelta) * (0.03F * speedMod));
double posX = (cameraX + speed) / scale;
double posY = (cloudHeight - (float) cameraY) / cloudScale;
double posZ = cameraZ / scale + 0.33000001311302185D;
posX -= Math.floor(posX / 2048.0D) * 2048;
posZ -= Math.floor(posZ / 2048.0D) * 2048;
float adjustedX = (float) (posX - (double) Math.floor(posX));
float adjustedY = (float) (posY / 4.0D - (double) Math.floor(posY / 4.0D)) * 4.0F;
float adjustedZ = (float) (posZ - (double) Math.floor(posZ));
Vec3 cloudColor = minecraft.level.getCloudColor(tickDelta);
int floorX = (int) Math.floor(posX);
int floorY = (int) Math.floor(posY / 4.0D);
int floorZ = (int) Math.floor(posZ);
if (floorX != this.prevCloudX || floorY != this.prevCloudY || floorZ != this.prevCloudZ || this.minecraft.options.getCloudsType() != this.prevCloudsType || this.prevCloudColor.distanceToSqr(cloudColor) > 2.0E-4D) {
this.prevCloudX = floorX;
this.prevCloudY = floorY;
this.prevCloudZ = floorZ;
this.prevCloudColor = cloudColor;
this.prevCloudsType = this.minecraft.options.getCloudsType();
this.generateClouds = true;
}
RenderSystem.setShader(GameRenderer::getPositionTexColorNormalShader);
//Setup custom projection matrix and override minecraft's.
//create needed objects
ILodConfigWrapperSingleton CONFIG = SingletonHandler.get(ILodConfigWrapperSingleton.class);
FloatBuffer customBuffer = CloudBufferSingleton.INSTANCE.customBuffer;
FloatBuffer mcBuffer = CloudBufferSingleton.INSTANCE.mcBuffer;
//create clip values.
//far clip is our clip plane value
float farClip = (CONFIG.client().graphics().quality().getLodChunkRenderDistance() * LodUtil.CHUNK_WIDTH) * LodUtil.CHUNK_WIDTH / 2;
//near clip is mc clip plane value
float nearClip = 0.05f;
float matNearClip = -((farClip + nearClip) / (farClip - nearClip));
float matFarClip = -((2 * farClip * nearClip) / (farClip - nearClip));
//store ProjectionMatrix values to buffers
projectionMatrix.store(customBuffer);
projectionMatrix.store(mcBuffer);
//change values on our custom buffer
customBuffer.put(10, matNearClip);
customBuffer.put(14, matFarClip);
//load values from our buffer to the projection matrix
projectionMatrix.load(customBuffer);
if (this.generateClouds) {
this.generateClouds = false;
Tesselator tessellator = Tesselator.getInstance();
BufferBuilder bufferBuilder = tessellator.getBuilder();
if (this.cloudBuffer != null) this.cloudBuffer.close();
this.cloudBuffer = new VertexBuffer();
this.buildCloudLayer(bufferBuilder, posX, posY, posZ, cloudScale, cloudColor);
bufferBuilder.end();
this.cloudBuffer.upload(bufferBuilder);
}
if (SingletonHandler.get(IModChecker.class).isModLoaded("immersive_portals")) {
RenderSystem.setShaderTexture(0, CLOUDS_LOCATION);
} else {
RenderSystem.setShaderTexture(0, resourceLocation);
}
FogRenderer.levelFogColor();
poseStack.pushPose();
poseStack.scale(scale, cloudScale, scale);
poseStack.translate(-adjustedX, adjustedY, -adjustedZ);
if (this.cloudBuffer != null) {
int cloudMainIndex = this.prevCloudsType == CloudStatus.FANCY ? 0 : 1;
for (int cloudIndex = 1; cloudMainIndex <= cloudIndex; ++cloudMainIndex) {
if (cloudMainIndex == 0) {
RenderSystem.colorMask(false, false, false, false);
} else {
RenderSystem.colorMask(true, true, true, true);
}
ShaderInstance shader = RenderSystem.getShader();
this.cloudBuffer.drawWithShader(poseStack.last().pose(), projectionMatrix, shader);
}
}
//reset the projection matrix to original values
projectionMatrix.load(mcBuffer);
poseStack.popPose();
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.enableCull();
RenderSystem.disableBlend();
}
private void buildCloudLayer(BufferBuilder bufferBuilder, double cloudX, double cloudY, double cloudZ, float scale, Vec3 color) {
float lowpFracAccur = (float) Math.pow(2.0, -8);
float mediumpFracAccur = (float) Math.pow(2.0, -10);
float viewDistance = 8;
float cloudThickness = 4.0f;
float adjustedCloudX = (float)Math.floor(cloudX) * lowpFracAccur;
float adjustedCloudZ = (float)Math.floor(cloudZ) * lowpFracAccur;
float redTop = (float)color.x;
float greenTop = (float)color.y;
float blueTop = (float)color.z;
float redEW = redTop * 0.9f;
float greenEW = greenTop * 0.9f;
float blueEW = blueTop * 0.9f;
float redBottom = redTop * 0.7f;
float greenBottom = greenTop * 0.7f;
float blueBottom = blueTop * 0.7f;
float redNS = redTop * 0.8f;
float greenNS = greenTop * 0.8f;
float blueNS = blueTop * 0.8f;
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR_NORMAL);
float adjustedCloudY = (float) Math.floor(cloudY / cloudThickness) * cloudThickness;
// Where the actual rendering happens
ILodConfigWrapperSingleton CONFIG = SingletonHandler.get(ILodConfigWrapperSingleton.class);
if (this.prevCloudsType == CloudStatus.FANCY) {
int scaledViewDistance = (int) (((CONFIG.client().graphics().cloudQuality().getExtendClouds() ? CONFIG.client().graphics().quality().getLodChunkRenderDistance() : minecraft.options.renderDistance) / 2) / scale) / 2;
for (int x = -scaledViewDistance - 1; x <= scaledViewDistance; ++x) {
for (int z = -scaledViewDistance - 1; z <= scaledViewDistance; ++z) {
int n3;
float scaledX = x * viewDistance;
float scaledZ = z * viewDistance;
if (adjustedCloudY >= -4.0f) {
// Render cloud bottom
bufferBuilder.vertex(scaledX + 0.0f, adjustedCloudY + 0.0f, scaledZ + 8.0f).uv((scaledX + 0.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + 8.0f) * lowpFracAccur + adjustedCloudZ).color(redBottom, greenBottom, blueBottom, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
bufferBuilder.vertex(scaledX + 8.0f, adjustedCloudY + 0.0f, scaledZ + 8.0f).uv((scaledX + 8.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + 8.0f) * lowpFracAccur + adjustedCloudZ).color(redBottom, greenBottom, blueBottom, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
bufferBuilder.vertex(scaledX + 8.0f, adjustedCloudY + 0.0f, scaledZ + 0.0f).uv((scaledX + 8.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + 0.0f) * lowpFracAccur + adjustedCloudZ).color(redBottom, greenBottom, blueBottom, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
bufferBuilder.vertex(scaledX + 0.0f, adjustedCloudY + 0.0f, scaledZ + 0.0f).uv((scaledX + 0.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + 0.0f) * lowpFracAccur + adjustedCloudZ).color(redBottom, greenBottom, blueBottom, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
}
if (adjustedCloudY < 0.0f) {
// Render cloud top
bufferBuilder.vertex(scaledX + 0.0f, adjustedCloudY + cloudThickness - mediumpFracAccur, scaledZ + 8.0f).uv((scaledX + 0.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + 8.0f) * lowpFracAccur + adjustedCloudZ).color(redTop, greenTop, blueTop, 0.8f).normal(0.0f, 1.0f, 0.0f).endVertex();
bufferBuilder.vertex(scaledX + 8.0f, adjustedCloudY + cloudThickness - mediumpFracAccur, scaledZ + 8.0f).uv((scaledX + 8.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + 8.0f) * lowpFracAccur + adjustedCloudZ).color(redTop, greenTop, blueTop, 0.8f).normal(0.0f, 1.0f, 0.0f).endVertex();
bufferBuilder.vertex(scaledX + 8.0f, adjustedCloudY + cloudThickness - mediumpFracAccur, scaledZ + 0.0f).uv((scaledX + 8.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + 0.0f) * lowpFracAccur + adjustedCloudZ).color(redTop, greenTop, blueTop, 0.8f).normal(0.0f, 1.0f, 0.0f).endVertex();
bufferBuilder.vertex(scaledX + 0.0f, adjustedCloudY + cloudThickness - mediumpFracAccur, scaledZ + 0.0f).uv((scaledX + 0.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + 0.0f) * lowpFracAccur + adjustedCloudZ).color(redTop, greenTop, blueTop, 0.8f).normal(0.0f, 1.0f, 0.0f).endVertex();
}
if (x > -1) {
for (n3 = 0; n3 < 8; ++n3) {
bufferBuilder.vertex(scaledX + (float)n3 + 0.0f, adjustedCloudY + 0.0f, scaledZ + 8.0f).uv((scaledX + (float)n3 + 0.5f) * lowpFracAccur + adjustedCloudX, (scaledZ + 8.0f) * lowpFracAccur + adjustedCloudZ).color(redEW, greenEW, blueEW, 0.8f).normal(-1.0f, 0.0f, 0.0f).endVertex();
bufferBuilder.vertex(scaledX + (float)n3 + 0.0f, adjustedCloudY + cloudThickness, scaledZ + 8.0f).uv((scaledX + (float)n3 + 0.5f) * lowpFracAccur + adjustedCloudX, (scaledZ + 8.0f) * lowpFracAccur + adjustedCloudZ).color(redEW, greenEW, blueEW, 0.8f).normal(-1.0f, 0.0f, 0.0f).endVertex();
bufferBuilder.vertex(scaledX + (float)n3 + 0.0f, adjustedCloudY + cloudThickness, scaledZ + 0.0f).uv((scaledX + (float)n3 + 0.5f) * lowpFracAccur + adjustedCloudX, (scaledZ + 0.0f) * lowpFracAccur + adjustedCloudZ).color(redEW, greenEW, blueEW, 0.8f).normal(-1.0f, 0.0f, 0.0f).endVertex();
bufferBuilder.vertex(scaledX + (float)n3 + 0.0f, adjustedCloudY + 0.0f, scaledZ + 0.0f).uv((scaledX + (float)n3 + 0.5f) * lowpFracAccur + adjustedCloudX, (scaledZ + 0.0f) * lowpFracAccur + adjustedCloudZ).color(redEW, greenEW, blueEW, 0.8f).normal(-1.0f, 0.0f, 0.0f).endVertex();
}
}
if (x <= 0) { // FIX.ME is doing to big of an area
for (n3 = 0; n3 < 8; ++n3) {
bufferBuilder.vertex(scaledX + (float)n3 + 1.0f - mediumpFracAccur, adjustedCloudY + 0.0f, scaledZ + 8.0f).uv((scaledX + (float)n3 + 0.5f) * lowpFracAccur + adjustedCloudX, (scaledZ + 8.0f) * lowpFracAccur + adjustedCloudZ).color(redEW, greenEW, blueEW, 0.8f).normal(1.0f, 0.0f, 0.0f).endVertex();
bufferBuilder.vertex(scaledX + (float)n3 + 1.0f - mediumpFracAccur, adjustedCloudY + cloudThickness, scaledZ + 8.0f).uv((scaledX + (float)n3 + 0.5f) * lowpFracAccur + adjustedCloudX, (scaledZ + 8.0f) * lowpFracAccur + adjustedCloudZ).color(redEW, greenEW, blueEW, 0.8f).normal(1.0f, 0.0f, 0.0f).endVertex();
bufferBuilder.vertex(scaledX + (float)n3 + 1.0f - mediumpFracAccur, adjustedCloudY + cloudThickness, scaledZ + 0.0f).uv((scaledX + (float)n3 + 0.5f) * lowpFracAccur + adjustedCloudX, (scaledZ + 0.0f) * lowpFracAccur + adjustedCloudZ).color(redEW, greenEW, blueEW, 0.8f).normal(1.0f, 0.0f, 0.0f).endVertex();
bufferBuilder.vertex(scaledX + (float)n3 + 1.0f - mediumpFracAccur, adjustedCloudY + 0.0f, scaledZ + 0.0f).uv((scaledX + (float)n3 + 0.5f) * lowpFracAccur + adjustedCloudX, (scaledZ + 0.0f) * lowpFracAccur + adjustedCloudZ).color(redEW, greenEW, blueEW, 0.8f).normal(1.0f, 0.0f, 0.0f).endVertex();
}
}
if (z > -1) {
for (n3 = 0; n3 < 8; ++n3) {
bufferBuilder.vertex(scaledX + 0.0f, adjustedCloudY + cloudThickness, scaledZ + (float)n3 + 0.0f).uv((scaledX + 0.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + (float)n3 + 0.5f) * lowpFracAccur + adjustedCloudZ).color(redNS, greenNS, blueNS, 0.8f).normal(0.0f, 0.0f, -1.0f).endVertex();
bufferBuilder.vertex(scaledX + 8.0f, adjustedCloudY + cloudThickness, scaledZ + (float)n3 + 0.0f).uv((scaledX + 8.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + (float)n3 + 0.5f) * lowpFracAccur + adjustedCloudZ).color(redNS, greenNS, blueNS, 0.8f).normal(0.0f, 0.0f, -1.0f).endVertex();
bufferBuilder.vertex(scaledX + 8.0f, adjustedCloudY + 0.0f, scaledZ + (float)n3 + 0.0f).uv((scaledX + 8.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + (float)n3 + 0.5f) * lowpFracAccur + adjustedCloudZ).color(redNS, greenNS, blueNS, 0.8f).normal(0.0f, 0.0f, -1.0f).endVertex();
bufferBuilder.vertex(scaledX + 0.0f, adjustedCloudY + 0.0f, scaledZ + (float)n3 + 0.0f).uv((scaledX + 0.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + (float)n3 + 0.5f) * lowpFracAccur + adjustedCloudZ).color(redNS, greenNS, blueNS, 0.8f).normal(0.0f, 0.0f, -1.0f).endVertex();
}
}
if (z < 1) { // FIX.ME is doing to big of an area
for (n3 = 0; n3 < 8; ++n3) {
bufferBuilder.vertex(scaledX + 0.0f, adjustedCloudY + cloudThickness, scaledZ + (float) n3 + 1.0f - mediumpFracAccur).uv((scaledX + 0.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + (float) n3 + 0.5f) * lowpFracAccur + adjustedCloudZ).color(redNS, greenNS, blueNS, 0.8f).normal(0.0f, 0.0f, 1.0f).endVertex();
bufferBuilder.vertex(scaledX + 8.0f, adjustedCloudY + cloudThickness, scaledZ + (float) n3 + 1.0f - mediumpFracAccur).uv((scaledX + 8.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + (float) n3 + 0.5f) * lowpFracAccur + adjustedCloudZ).color(redNS, greenNS, blueNS, 0.8f).normal(0.0f, 0.0f, 1.0f).endVertex();
bufferBuilder.vertex(scaledX + 8.0f, adjustedCloudY + 0.0f, scaledZ + (float) n3 + 1.0f - mediumpFracAccur).uv((scaledX + 8.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + (float) n3 + 0.5f) * lowpFracAccur + adjustedCloudZ).color(redNS, greenNS, blueNS, 0.8f).normal(0.0f, 0.0f, 1.0f).endVertex();
bufferBuilder.vertex(scaledX + 0.0f, adjustedCloudY + 0.0f, scaledZ + (float) n3 + 1.0f - mediumpFracAccur).uv((scaledX + 0.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + (float) n3 + 0.5f) * lowpFracAccur + adjustedCloudZ).color(redNS, greenNS, blueNS, 0.8f).normal(0.0f, 0.0f, 1.0f).endVertex();
}
}
}
}
} else {
int scaledRenderDistance = (int) ((CONFIG.client().graphics().cloudQuality().getExtendClouds() ? CONFIG.client().graphics().quality().getLodChunkRenderDistance() : minecraft.options.renderDistance) / scale);
for (int x = -scaledRenderDistance; x < scaledRenderDistance; x += scaledRenderDistance) {
for (int z = -scaledRenderDistance; z < scaledRenderDistance; z += scaledRenderDistance) {
bufferBuilder.vertex(x, adjustedCloudY, z + scaledRenderDistance).uv((float)x * lowpFracAccur + adjustedCloudX, (float)(z + scaledRenderDistance) * lowpFracAccur + adjustedCloudZ).color(redTop, greenTop, blueTop, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
bufferBuilder.vertex(x + scaledRenderDistance, adjustedCloudY, z + scaledRenderDistance).uv((float)(x + scaledRenderDistance) * lowpFracAccur + adjustedCloudX, (float)(z + scaledRenderDistance) * lowpFracAccur + adjustedCloudZ).color(redTop, greenTop, blueTop, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
bufferBuilder.vertex(x + scaledRenderDistance, adjustedCloudY, z).uv((float)(x + scaledRenderDistance) * lowpFracAccur + adjustedCloudX, (float)z * lowpFracAccur + adjustedCloudZ).color(redTop, greenTop, blueTop, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
bufferBuilder.vertex(x, adjustedCloudY, z).uv((float)x * lowpFracAccur + adjustedCloudX, (float)z * lowpFracAccur + adjustedCloudZ).color(redTop, greenTop, blueTop, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
}
}
}
}
}
@@ -19,40 +19,18 @@
package com.seibel.lod.forge.mixins;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix4f;
import com.seibel.lod.common.clouds.CloudBufferSingleton;
import com.seibel.lod.common.clouds.CloudTexture;
import com.seibel.lod.common.clouds.NoiseCloudHandler;
import com.seibel.lod.common.wrappers.McObjectConverter;
import com.seibel.lod.core.util.LodUtil;
import com.seibel.lod.core.util.SingletonHandler;
import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton;
import com.seibel.lod.core.wrapperInterfaces.modAccessor.IModChecker;
import com.seibel.lod.core.api.ClientApi;
import com.seibel.lod.core.objects.math.Mat4f;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.RenderType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.seibel.lod.core.api.ClientApi;
import com.seibel.lod.core.objects.math.Mat4f;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
import net.minecraft.client.CloudStatus;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.*;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.*;
import java.nio.FloatBuffer;
import java.util.Random;
/**
* This class is used to mix in my rendering code
* before Minecraft starts rendering blocks.
@@ -69,18 +47,6 @@ import java.util.Random;
@Mixin(LevelRenderer.class)
public class MixinWorldRenderer
{
@Final @Shadow private static ResourceLocation CLOUDS_LOCATION;
@Shadow private final int ticks;
@Final @Shadow @NotNull private final Minecraft minecraft;
@Shadow private int prevCloudX;
@Shadow private int prevCloudY;
@Shadow private int prevCloudZ;
@Shadow @NotNull private Vec3 prevCloudColor;
@Shadow @NotNull private CloudStatus prevCloudsType;
@Shadow private boolean generateClouds;
@Shadow @NotNull private VertexBuffer cloudBuffer;
@Unique private boolean initializedClouds = false;
private static float previousPartialTicks = 0;
public MixinWorldRenderer() {
@@ -89,21 +55,6 @@ public class MixinWorldRenderer
@Inject(method = "renderClouds", at = @At("HEAD"), cancellable = true)
public void renderClouds(PoseStack poseStack, Matrix4f projectionMatrix, float tickDelta, double cameraX, double cameraY, double cameraZ, CallbackInfo ci) {
ILodConfigWrapperSingleton CONFIG = SingletonHandler.get(ILodConfigWrapperSingleton.class);
if (CONFIG.client().graphics().cloudQuality().getCustomClouds()) {
TextureManager textureManager = Minecraft.getInstance().getTextureManager();
registerClouds(textureManager);
// Only use when needed since it causes lag
// NoiseCloudHandler.update();
if (minecraft.level.dimension() == ClientLevel.OVERWORLD) {
CloudTexture cloudTexture = NoiseCloudHandler.cloudTextures.get(NoiseCloudHandler.cloudTextures.size() - 1);
renderCloudLayer(poseStack, projectionMatrix, tickDelta, cameraX, cameraY, cameraZ, (float) (CONFIG.client().graphics().cloudQuality().getCloudHeight() + 0.01 /* Make clouds a bit higher so it dosnt do janky stuff */), 1, 1, cloudTexture.resourceLocation);
}
ci.cancel();
}
// get the partial ticks since renderChunkLayer doesn't
// have access to them
previousPartialTicks = tickDelta;
@@ -122,222 +73,4 @@ public class MixinWorldRenderer
ClientApi.INSTANCE.renderLods(mcModelViewMatrix, mcProjectionMatrix, previousPartialTicks);
}
}
// TODO: Move these outside of the mixin
// When moved out then put credit to https://github.com/misterslime/fabulousclouds-fabric
private void registerClouds(TextureManager textureManager) {
if (!this.initializedClouds) {
Random random = new Random();
NoiseCloudHandler.initCloudTextures(CLOUDS_LOCATION);
for(CloudTexture cloudTexture : NoiseCloudHandler.cloudTextures) {
cloudTexture.initNoise(random);
DynamicTexture texture = cloudTexture.getNativeImage();
textureManager.register(cloudTexture.resourceLocation, texture);
cloudTexture.setTexture(texture);
}
this.initializedClouds = true;
}
}
private void renderCloudLayer(PoseStack poseStack, Matrix4f projectionMatrix, float tickDelta, double cameraX, double cameraY, double cameraZ, float cloudHeight, float cloudScale, float speedMod, ResourceLocation resourceLocation) {
RenderSystem.disableCull();
RenderSystem.enableBlend();
RenderSystem.enableDepthTest();
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
RenderSystem.depthMask(true);
float scale = 12.0F * cloudScale;
double speed = ((this.ticks + tickDelta) * (0.03F * speedMod));
double posX = (cameraX + speed) / scale;
double posY = (cloudHeight - (float) cameraY) / cloudScale;
double posZ = cameraZ / scale + 0.33000001311302185D;
posX -= Math.floor(posX / 2048.0D) * 2048;
posZ -= Math.floor(posZ / 2048.0D) * 2048;
float adjustedX = (float) (posX - (double) Math.floor(posX));
float adjustedY = (float) (posY / 4.0D - (double) Math.floor(posY / 4.0D)) * 4.0F;
float adjustedZ = (float) (posZ - (double) Math.floor(posZ));
Vec3 cloudColor = minecraft.level.getCloudColor(tickDelta);
int floorX = (int) Math.floor(posX);
int floorY = (int) Math.floor(posY / 4.0D);
int floorZ = (int) Math.floor(posZ);
if (floorX != this.prevCloudX || floorY != this.prevCloudY || floorZ != this.prevCloudZ || this.minecraft.options.getCloudsType() != this.prevCloudsType || this.prevCloudColor.distanceToSqr(cloudColor) > 2.0E-4D) {
this.prevCloudX = floorX;
this.prevCloudY = floorY;
this.prevCloudZ = floorZ;
this.prevCloudColor = cloudColor;
this.prevCloudsType = this.minecraft.options.getCloudsType();
this.generateClouds = true;
}
RenderSystem.setShader(GameRenderer::getPositionTexColorNormalShader);
//Setup custom projection matrix and override minecraft's.
//create needed objects
ILodConfigWrapperSingleton CONFIG = SingletonHandler.get(ILodConfigWrapperSingleton.class);
FloatBuffer customBuffer = CloudBufferSingleton.INSTANCE.customBuffer;
FloatBuffer mcBuffer = CloudBufferSingleton.INSTANCE.mcBuffer;
//create clip values.
//far clip is our clip plane value
float farClip = (CONFIG.client().graphics().quality().getLodChunkRenderDistance() * LodUtil.CHUNK_WIDTH) * LodUtil.CHUNK_WIDTH / 2;
//near clip is mc clip plane value
float nearClip = 0.05f;
float matNearClip = -((farClip + nearClip) / (farClip - nearClip));
float matFarClip = -((2 * farClip * nearClip) / (farClip - nearClip));
//store ProjectionMatrix values to buffers
projectionMatrix.store(customBuffer);
projectionMatrix.store(mcBuffer);
//change values on our custom buffer
customBuffer.put(10, matNearClip);
customBuffer.put(14, matFarClip);
//load values from our buffer to the projection matrix
projectionMatrix.load(customBuffer);
if (this.generateClouds) {
this.generateClouds = false;
Tesselator tessellator = Tesselator.getInstance();
BufferBuilder bufferBuilder = tessellator.getBuilder();
if (this.cloudBuffer != null) this.cloudBuffer.close();
this.cloudBuffer = new VertexBuffer();
this.buildCloudLayer(bufferBuilder, posX, posY, posZ, cloudScale, cloudColor);
bufferBuilder.end();
this.cloudBuffer.upload(bufferBuilder);
}
if (SingletonHandler.get(IModChecker.class).isModLoaded("immersive_portals")) {
RenderSystem.setShaderTexture(0, CLOUDS_LOCATION);
} else {
RenderSystem.setShaderTexture(0, resourceLocation);
}
FogRenderer.levelFogColor();
poseStack.pushPose();
poseStack.scale(scale, cloudScale, scale);
poseStack.translate(-adjustedX, adjustedY, -adjustedZ);
if (this.cloudBuffer != null) {
int cloudMainIndex = this.prevCloudsType == CloudStatus.FANCY ? 0 : 1;
for (int cloudIndex = 1; cloudMainIndex <= cloudIndex; ++cloudMainIndex) {
if (cloudMainIndex == 0) {
RenderSystem.colorMask(false, false, false, false);
} else {
RenderSystem.colorMask(true, true, true, true);
}
ShaderInstance shader = RenderSystem.getShader();
this.cloudBuffer.drawWithShader(poseStack.last().pose(), projectionMatrix, shader);
}
}
//reset the projection matrix to original values
projectionMatrix.load(mcBuffer);
poseStack.popPose();
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.enableCull();
RenderSystem.disableBlend();
}
private void buildCloudLayer(BufferBuilder bufferBuilder, double cloudX, double cloudY, double cloudZ, float scale, Vec3 color) {
float lowpFracAccur = (float) Math.pow(2.0, -8);
float mediumpFracAccur = (float) Math.pow(2.0, -10);
float viewDistance = 8;
float cloudThickness = 4.0f;
float adjustedCloudX = (float)Math.floor(cloudX) * lowpFracAccur;
float adjustedCloudZ = (float)Math.floor(cloudZ) * lowpFracAccur;
float redTop = (float)color.x;
float greenTop = (float)color.y;
float blueTop = (float)color.z;
float redEW = redTop * 0.9f;
float greenEW = greenTop * 0.9f;
float blueEW = blueTop * 0.9f;
float redBottom = redTop * 0.7f;
float greenBottom = greenTop * 0.7f;
float blueBottom = blueTop * 0.7f;
float redNS = redTop * 0.8f;
float greenNS = greenTop * 0.8f;
float blueNS = blueTop * 0.8f;
bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR_NORMAL);
float adjustedCloudY = (float) Math.floor(cloudY / cloudThickness) * cloudThickness;
// Where the actual rendering happens
ILodConfigWrapperSingleton CONFIG = SingletonHandler.get(ILodConfigWrapperSingleton.class);
if (this.prevCloudsType == CloudStatus.FANCY) {
int scaledViewDistance = (int) (((CONFIG.client().graphics().cloudQuality().getExtendClouds() ? CONFIG.client().graphics().quality().getLodChunkRenderDistance() : minecraft.options.renderDistance) / 2) / scale) / 2;
for (int x = -scaledViewDistance - 1; x <= scaledViewDistance; ++x) {
for (int z = -scaledViewDistance - 1; z <= scaledViewDistance; ++z) {
int n3;
float scaledX = x * viewDistance;
float scaledZ = z * viewDistance;
if (adjustedCloudY >= -4.0f) {
// Render cloud bottom
bufferBuilder.vertex(scaledX + 0.0f, adjustedCloudY + 0.0f, scaledZ + 8.0f).uv((scaledX + 0.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + 8.0f) * lowpFracAccur + adjustedCloudZ).color(redBottom, greenBottom, blueBottom, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
bufferBuilder.vertex(scaledX + 8.0f, adjustedCloudY + 0.0f, scaledZ + 8.0f).uv((scaledX + 8.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + 8.0f) * lowpFracAccur + adjustedCloudZ).color(redBottom, greenBottom, blueBottom, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
bufferBuilder.vertex(scaledX + 8.0f, adjustedCloudY + 0.0f, scaledZ + 0.0f).uv((scaledX + 8.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + 0.0f) * lowpFracAccur + adjustedCloudZ).color(redBottom, greenBottom, blueBottom, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
bufferBuilder.vertex(scaledX + 0.0f, adjustedCloudY + 0.0f, scaledZ + 0.0f).uv((scaledX + 0.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + 0.0f) * lowpFracAccur + adjustedCloudZ).color(redBottom, greenBottom, blueBottom, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
}
if (adjustedCloudY < 0.0f) {
// Render cloud top
bufferBuilder.vertex(scaledX + 0.0f, adjustedCloudY + cloudThickness - mediumpFracAccur, scaledZ + 8.0f).uv((scaledX + 0.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + 8.0f) * lowpFracAccur + adjustedCloudZ).color(redTop, greenTop, blueTop, 0.8f).normal(0.0f, 1.0f, 0.0f).endVertex();
bufferBuilder.vertex(scaledX + 8.0f, adjustedCloudY + cloudThickness - mediumpFracAccur, scaledZ + 8.0f).uv((scaledX + 8.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + 8.0f) * lowpFracAccur + adjustedCloudZ).color(redTop, greenTop, blueTop, 0.8f).normal(0.0f, 1.0f, 0.0f).endVertex();
bufferBuilder.vertex(scaledX + 8.0f, adjustedCloudY + cloudThickness - mediumpFracAccur, scaledZ + 0.0f).uv((scaledX + 8.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + 0.0f) * lowpFracAccur + adjustedCloudZ).color(redTop, greenTop, blueTop, 0.8f).normal(0.0f, 1.0f, 0.0f).endVertex();
bufferBuilder.vertex(scaledX + 0.0f, adjustedCloudY + cloudThickness - mediumpFracAccur, scaledZ + 0.0f).uv((scaledX + 0.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + 0.0f) * lowpFracAccur + adjustedCloudZ).color(redTop, greenTop, blueTop, 0.8f).normal(0.0f, 1.0f, 0.0f).endVertex();
}
if (x > -1) {
for (n3 = 0; n3 < 8; ++n3) {
bufferBuilder.vertex(scaledX + (float)n3 + 0.0f, adjustedCloudY + 0.0f, scaledZ + 8.0f).uv((scaledX + (float)n3 + 0.5f) * lowpFracAccur + adjustedCloudX, (scaledZ + 8.0f) * lowpFracAccur + adjustedCloudZ).color(redEW, greenEW, blueEW, 0.8f).normal(-1.0f, 0.0f, 0.0f).endVertex();
bufferBuilder.vertex(scaledX + (float)n3 + 0.0f, adjustedCloudY + cloudThickness, scaledZ + 8.0f).uv((scaledX + (float)n3 + 0.5f) * lowpFracAccur + adjustedCloudX, (scaledZ + 8.0f) * lowpFracAccur + adjustedCloudZ).color(redEW, greenEW, blueEW, 0.8f).normal(-1.0f, 0.0f, 0.0f).endVertex();
bufferBuilder.vertex(scaledX + (float)n3 + 0.0f, adjustedCloudY + cloudThickness, scaledZ + 0.0f).uv((scaledX + (float)n3 + 0.5f) * lowpFracAccur + adjustedCloudX, (scaledZ + 0.0f) * lowpFracAccur + adjustedCloudZ).color(redEW, greenEW, blueEW, 0.8f).normal(-1.0f, 0.0f, 0.0f).endVertex();
bufferBuilder.vertex(scaledX + (float)n3 + 0.0f, adjustedCloudY + 0.0f, scaledZ + 0.0f).uv((scaledX + (float)n3 + 0.5f) * lowpFracAccur + adjustedCloudX, (scaledZ + 0.0f) * lowpFracAccur + adjustedCloudZ).color(redEW, greenEW, blueEW, 0.8f).normal(-1.0f, 0.0f, 0.0f).endVertex();
}
}
if (x <= 0) { // FIX.ME is doing to big of an area
for (n3 = 0; n3 < 8; ++n3) {
bufferBuilder.vertex(scaledX + (float)n3 + 1.0f - mediumpFracAccur, adjustedCloudY + 0.0f, scaledZ + 8.0f).uv((scaledX + (float)n3 + 0.5f) * lowpFracAccur + adjustedCloudX, (scaledZ + 8.0f) * lowpFracAccur + adjustedCloudZ).color(redEW, greenEW, blueEW, 0.8f).normal(1.0f, 0.0f, 0.0f).endVertex();
bufferBuilder.vertex(scaledX + (float)n3 + 1.0f - mediumpFracAccur, adjustedCloudY + cloudThickness, scaledZ + 8.0f).uv((scaledX + (float)n3 + 0.5f) * lowpFracAccur + adjustedCloudX, (scaledZ + 8.0f) * lowpFracAccur + adjustedCloudZ).color(redEW, greenEW, blueEW, 0.8f).normal(1.0f, 0.0f, 0.0f).endVertex();
bufferBuilder.vertex(scaledX + (float)n3 + 1.0f - mediumpFracAccur, adjustedCloudY + cloudThickness, scaledZ + 0.0f).uv((scaledX + (float)n3 + 0.5f) * lowpFracAccur + adjustedCloudX, (scaledZ + 0.0f) * lowpFracAccur + adjustedCloudZ).color(redEW, greenEW, blueEW, 0.8f).normal(1.0f, 0.0f, 0.0f).endVertex();
bufferBuilder.vertex(scaledX + (float)n3 + 1.0f - mediumpFracAccur, adjustedCloudY + 0.0f, scaledZ + 0.0f).uv((scaledX + (float)n3 + 0.5f) * lowpFracAccur + adjustedCloudX, (scaledZ + 0.0f) * lowpFracAccur + adjustedCloudZ).color(redEW, greenEW, blueEW, 0.8f).normal(1.0f, 0.0f, 0.0f).endVertex();
}
}
if (z > -1) {
for (n3 = 0; n3 < 8; ++n3) {
bufferBuilder.vertex(scaledX + 0.0f, adjustedCloudY + cloudThickness, scaledZ + (float)n3 + 0.0f).uv((scaledX + 0.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + (float)n3 + 0.5f) * lowpFracAccur + adjustedCloudZ).color(redNS, greenNS, blueNS, 0.8f).normal(0.0f, 0.0f, -1.0f).endVertex();
bufferBuilder.vertex(scaledX + 8.0f, adjustedCloudY + cloudThickness, scaledZ + (float)n3 + 0.0f).uv((scaledX + 8.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + (float)n3 + 0.5f) * lowpFracAccur + adjustedCloudZ).color(redNS, greenNS, blueNS, 0.8f).normal(0.0f, 0.0f, -1.0f).endVertex();
bufferBuilder.vertex(scaledX + 8.0f, adjustedCloudY + 0.0f, scaledZ + (float)n3 + 0.0f).uv((scaledX + 8.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + (float)n3 + 0.5f) * lowpFracAccur + adjustedCloudZ).color(redNS, greenNS, blueNS, 0.8f).normal(0.0f, 0.0f, -1.0f).endVertex();
bufferBuilder.vertex(scaledX + 0.0f, adjustedCloudY + 0.0f, scaledZ + (float)n3 + 0.0f).uv((scaledX + 0.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + (float)n3 + 0.5f) * lowpFracAccur + adjustedCloudZ).color(redNS, greenNS, blueNS, 0.8f).normal(0.0f, 0.0f, -1.0f).endVertex();
}
}
if (z < 1) { // FIX.ME is doing to big of an area
for (n3 = 0; n3 < 8; ++n3) {
bufferBuilder.vertex(scaledX + 0.0f, adjustedCloudY + cloudThickness, scaledZ + (float) n3 + 1.0f - mediumpFracAccur).uv((scaledX + 0.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + (float) n3 + 0.5f) * lowpFracAccur + adjustedCloudZ).color(redNS, greenNS, blueNS, 0.8f).normal(0.0f, 0.0f, 1.0f).endVertex();
bufferBuilder.vertex(scaledX + 8.0f, adjustedCloudY + cloudThickness, scaledZ + (float) n3 + 1.0f - mediumpFracAccur).uv((scaledX + 8.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + (float) n3 + 0.5f) * lowpFracAccur + adjustedCloudZ).color(redNS, greenNS, blueNS, 0.8f).normal(0.0f, 0.0f, 1.0f).endVertex();
bufferBuilder.vertex(scaledX + 8.0f, adjustedCloudY + 0.0f, scaledZ + (float) n3 + 1.0f - mediumpFracAccur).uv((scaledX + 8.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + (float) n3 + 0.5f) * lowpFracAccur + adjustedCloudZ).color(redNS, greenNS, blueNS, 0.8f).normal(0.0f, 0.0f, 1.0f).endVertex();
bufferBuilder.vertex(scaledX + 0.0f, adjustedCloudY + 0.0f, scaledZ + (float) n3 + 1.0f - mediumpFracAccur).uv((scaledX + 0.0f) * lowpFracAccur + adjustedCloudX, (scaledZ + (float) n3 + 0.5f) * lowpFracAccur + adjustedCloudZ).color(redNS, greenNS, blueNS, 0.8f).normal(0.0f, 0.0f, 1.0f).endVertex();
}
}
}
}
} else {
int scaledRenderDistance = (int) ((CONFIG.client().graphics().cloudQuality().getExtendClouds() ? CONFIG.client().graphics().quality().getLodChunkRenderDistance() : minecraft.options.renderDistance) / scale);
for (int x = -scaledRenderDistance; x < scaledRenderDistance; x += scaledRenderDistance) {
for (int z = -scaledRenderDistance; z < scaledRenderDistance; z += scaledRenderDistance) {
bufferBuilder.vertex(x, adjustedCloudY, z + scaledRenderDistance).uv((float)x * lowpFracAccur + adjustedCloudX, (float)(z + scaledRenderDistance) * lowpFracAccur + adjustedCloudZ).color(redTop, greenTop, blueTop, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
bufferBuilder.vertex(x + scaledRenderDistance, adjustedCloudY, z + scaledRenderDistance).uv((float)(x + scaledRenderDistance) * lowpFracAccur + adjustedCloudX, (float)(z + scaledRenderDistance) * lowpFracAccur + adjustedCloudZ).color(redTop, greenTop, blueTop, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
bufferBuilder.vertex(x + scaledRenderDistance, adjustedCloudY, z).uv((float)(x + scaledRenderDistance) * lowpFracAccur + adjustedCloudX, (float)z * lowpFracAccur + adjustedCloudZ).color(redTop, greenTop, blueTop, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
bufferBuilder.vertex(x, adjustedCloudY, z).uv((float)x * lowpFracAccur + adjustedCloudX, (float)z * lowpFracAccur + adjustedCloudZ).color(redTop, greenTop, blueTop, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
}
}
}
}
}