mohamed zenthen

create a minecraft mod that completely changes the sky in overworld even in day and night to a realistic space sky

Kodari AI
KodariOct 30 at 12:30 pm 4
RealisticSpaceSky
A Minecraft Fabric mod that completely replaces the Overworld sky with a realistic space vista, visible both day and night. It renders a deep black space backdrop filled with procedurally generated stars, a visible sun with realistic glow, and a detailed Earth-like planet visible from orbit. The mod overrides vanilla sky rendering to eliminate the blue atmosphere and clouds, providing an immersive outer-space perspective. Includes configurable star density, planet appearance, and optional celestial body positioning to create a truly unique skybox experience for players exploring the Overworld dimension.

Plan:

  1. Replace the Overworld’s vanilla sky pass with a custom space-sky renderer.

  2. Add the Fabric 26.3 mod setup and required resources.

Created a client-only Fabric 26.3 mod that replaces the Overworld sky with a custom 360° space panorama at all times of day and night. The Nether and End skies remain unchanged.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
7 207
src/client/java/com/kodari/spacesky/mixin/SkyRendererMixin.java
package com.kodari.spacesky.mixin;

import com.mojang.blaze3d.pipeline.RenderTarget;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.ByteBufferBuilder;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.MeshData;
import com.mojang.renderpearl.api.buffers.GpuBuffer;
import com.mojang.renderpearl.api.buffers.GpuBufferSlice;
import com.mojang.renderpearl.api.pipeline.PrimitiveTopology;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.client.renderer.SkyRenderer;
import net.minecraft.client.renderer.texture.AbstractTexture;
import net.minecraft.client.renderer.state.level.SkyRenderState;
import net.minecraft.resources.Identifier;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Optional;
import java.util.OptionalDouble;

@Mixin(SkyRenderer.class)
public abstract class SkyRendererMixin {
	@Shadow
	@Final
	private RenderTarget renderTarget;

	@Unique
	private static final Identifier spacesky$textureId = Identifier.fromNamespaceAndPath("spacesky", "textures/environment/space_sky");
	@Unique
	private static final int spacesky$longitudeSegments = 64;
	@Unique
	private static final int spacesky$latitudeSegments = 32;
	@Unique
	private static final int spacesky$indexCount = spacesky$longitudeSegments * spacesky$latitudeSegments * 6;
	@Unique
	private static GpuBuffer spacesky$vertexBuffer;

	@Inject(method = "render", at = @At("HEAD"), cancellable = true)
	private void spacesky$render(GpuBufferSlice skyFog, SkyRenderState state, CallbackInfo callbackInfo) {
		Minecraft minecraft = Minecraft.getInstance();
		if (minecraft.level == null || !minecraft.level.dimension().equals(Level.OVERWORLD)) {
			return;
		}

		callbackInfo.cancel();
		spacesky$ensureVertexBuffer();
		RenderSystem.setShaderFog(skyFog);

		try (var renderPass = RenderSystem.getDevice().createCommandEncoder().createRenderPass(
				() -> "Space sky",
				this.renderTarget.getColorTextureView(),
				Optional.empty(),
				this.renderTarget.getDepthTextureView(),
				OptionalDouble.empty()
		)) {
			RenderSystem.bindDefaultUniforms(renderPass);
			renderPass.setPipeline(RenderSystem.getCompiledPipeline(RenderPipelines.END_SKY));
			renderPass.setUniform("DynamicTransforms", RenderSystem.getDynamicUniforms().writeTransform(RenderSystem.getModelViewMatrixCopy()));

			AbstractTexture texture = minecraft.getTextureManager().getTexture(spacesky$textureId);
			renderPass.setUniform("Sampler0", texture.getTextureView(), texture.getSampler());
			renderPass.setVertexBuffer(0, spacesky$vertexBuffer.slice());

			var indices = RenderSystem.getSequentialBuffer(PrimitiveTopology.QUADS);
			renderPass.setIndexBuffer(indices.getBuffer(spacesky$indexCount), indices.type());
			renderPass.drawIndexed(spacesky$indexCount, 1, 0, 0, 0);
		}
	}

	@Unique
	private static void spacesky$ensureVertexBuffer() {
		if (spacesky$vertexBuffer != null) {
			return;
		}

		try (ByteBufferBuilder byteBufferBuilder = new ByteBufferBuilder(1_048_576)) {
			BufferBuilder builder = new BufferBuilder(byteBufferBuilder, PrimitiveTopology.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
			for (int latitude = 0; latitude < spacesky$latitudeSegments; latitude++) {
				float latitude0 = (float) (-Math.PI / 2.0 + Math.PI * latitude / spacesky$latitudeSegments);
				float latitude1 = (float) (-Math.PI / 2.0 + Math.PI * (latitude + 1) / spacesky$latitudeSegments);
				float v0 = 1.0F - (float) latitude / spacesky$latitudeSegments;
				float v1 = 1.0F - (float) (latitude + 1) / spacesky$latitudeSegments;
				for (int longitude = 0; longitude < spacesky$longitudeSegments; longitude++) {
					float longitude0 = (float) (Math.PI * 2.0 * longitude / spacesky$longitudeSegments);
					float longitude1 = (float) (Math.PI * 2.0 * (longitude + 1) / spacesky$longitudeSegments);
					float u0 = (float) longitude / spacesky$longitudeSegments;
					float u1 = (float) (longitude + 1) / spacesky$longitudeSegments;

					spacesky$addVertex(builder, longitude0, latitude0, u0, v0);
					spacesky$addVertex(builder, longitude0, latitude1, u0, v1);
					spacesky$addVertex(builder, longitude1, latitude1, u1, v1);
					spacesky$addVertex(builder, longitude1, latitude0, u1, v0);
				}
			}

			try (MeshData meshData = builder.buildOrThrow()) {
				spacesky$vertexBuffer = RenderSystem.getDevice().createBuffer(
						() -> "Space sky panorama",
						GpuBuffer.USAGE_VERTEX,
						meshData.vertexBuffer()
				);
			}
		}
	}

	@Unique
	private static void spacesky$addVertex(BufferBuilder builder, float longitude, float latitude, float u, float v) {
		float radius = 100.0F;
		float cosLatitude = (float) Math.cos(latitude);
		float x = radius * cosLatitude * (float) Math.sin(longitude);
		float y = radius * (float) Math.sin(latitude);
		float z = radius * cosLatitude * (float) Math.cos(longitude);
		builder.addVertex(x, y, z).setColor(255, 255, 255, 255).setUv(u, v);
	}
}