Files
src
build.gradle
gradle.properties
README.md
settings.gradle
Code
6 286
src/client/java/com/kodari/fakerenderdistance/FakeRenderDistanceClient.java
package com.kodari.fakerenderdistance;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.Random;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderContext;
import net.fabricmc.fabric.api.client.rendering.v1.world.WorldRenderEvents;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.RenderLayers;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
public final class FakeRenderDistanceClient implements ClientModInitializer {
private static final float MIN_DRAW_DISTANCE = 160.0f;
private static final float MIN_DRAW_DISTANCE_SQUARED = MIN_DRAW_DISTANCE * MIN_DRAW_DISTANCE;
private static final Island[] ISLANDS = createIslands();
private static boolean enabled = true;
@Override
public void onInitializeClient() {
loadConfig();
WorldRenderEvents.END_MAIN.register(FakeRenderDistanceClient::renderIslands);
}
private static void loadConfig() {
Path path = FabricLoader.getInstance().getConfigDir().resolve("fakerenderdistance.properties");
Properties properties = new Properties();
try {
Files.createDirectories(path.getParent());
if (Files.exists(path)) {
try (InputStream input = Files.newInputStream(path)) {
properties.load(input);
}
} else {
properties.setProperty("enabled", "true");
try (OutputStream output = Files.newOutputStream(path)) {
properties.store(output, "FakeRenderDistance configuration");
}
}
enabled = Boolean.parseBoolean(properties.getProperty("enabled", "true").trim());
} catch (IOException ignored) {
enabled = true;
}
}
private static void renderIslands(WorldRenderContext context) {
if (!enabled) {
return;
}
MinecraftClient client = MinecraftClient.getInstance();
if (client.world == null || client.player == null || !client.world.getRegistryKey().equals(World.END)) {
return;
}
Camera camera = client.gameRenderer.getCamera();
Vec3d cameraPosition = camera.getCameraPos();
float cameraX = (float) cameraPosition.x;
float cameraY = (float) cameraPosition.y;
float cameraZ = (float) cameraPosition.z;
MatrixStack.Entry matrix = context.matrices().peek();
VertexConsumer vertices = context.consumers().getBuffer(RenderLayers.debugQuads());
for (Island island : ISLANDS) {
float dx = island.centerX - cameraX;
float dz = island.centerZ - cameraZ;
if (dx * dx + dz * dz >= MIN_DRAW_DISTANCE_SQUARED) {
island.draw(vertices, matrix, cameraX, cameraY, cameraZ);
}
}
}
private static Island[] createIslands() {
int[] ringRadii = {240, 380, 570, 800, 1070, 1400, 1780};
int[] islandCounts = {12, 16, 20, 24, 28, 32, 36};
Random random = new Random(0x454e44524f434bL);
List<Island> islands = new ArrayList<>(168);
for (int ring = 0; ring < ringRadii.length; ring++) {
int count = islandCounts[ring];
double angleOffset = random.nextDouble() * Math.PI * 2.0;
for (int index = 0; index < count; index++) {
double angle = angleOffset + Math.PI * 2.0 * index / count + (random.nextDouble() - 0.5) * 0.14;
float radius = ringRadii[ring] + (random.nextFloat() - 0.5f) * 70.0f;
float centerX = (float) Math.cos(angle) * radius;
float centerZ = (float) Math.sin(angle) * radius;
float centerY = 48.0f + random.nextFloat() * 42.0f;
float radiusX = 24.0f + random.nextFloat() * 30.0f;
float radiusZ = radiusX * (0.65f + random.nextFloat() * 0.7f);
int sides = 6 + random.nextInt(4);
float rotation = random.nextFloat() * (float) (Math.PI * 2.0);
islands.add(new Island(centerX, centerY, centerZ, radiusX, radiusZ, sides, rotation, random));
}
}
return islands.toArray(Island[]::new);
}
private static void vertex(VertexConsumer vertices, MatrixStack.Entry matrix, float x, float y, float z, int red, int green, int blue) {
vertices.vertex(matrix, x, y, z).color(red, green, blue, 255);
}
private static final class Island {
private final float centerX;
private final float centerY;
private final float centerZ;
private final float[] topX;
private final float[] topY;
private final float[] topZ;
private final float[] bottomX;
private final float[] bottomY;
private final float[] bottomZ;
private final int red;
private final int green;
private final int blue;
private Island(float centerX, float centerY, float centerZ, float radiusX, float radiusZ, int sides, float rotation, Random random) {
this.centerX = centerX;
this.centerY = centerY;
this.centerZ = centerZ;
this.topX = new float[sides];
this.topY = new float[sides];
this.topZ = new float[sides];
this.bottomX = new float[sides];
this.bottomY = new float[sides];
this.bottomZ = new float[sides];
this.red = 102 + random.nextInt(28);
this.green = 91 + random.nextInt(25);
this.blue = 123 + random.nextInt(32);
float undersideY = centerY - 18.0f - random.nextFloat() * 30.0f;
for (int i = 0; i < sides; i++) {
float angle = rotation + (float) (Math.PI * 2.0 * i / sides);
float shape = 0.72f + random.nextFloat() * 0.48f;
float xOffset = (float) Math.cos(angle) * radiusX * shape;
float zOffset = (float) Math.sin(angle) * radiusZ * shape;
this.topX[i] = centerX + xOffset;
this.topY[i] = centerY + (random.nextFloat() - 0.5f) * 3.5f;
this.topZ[i] = centerZ + zOffset;
float undersideScale = 0.22f + random.nextFloat() * 0.2f;
this.bottomX[i] = centerX + xOffset * undersideScale;
this.bottomY[i] = undersideY + random.nextFloat() * 4.0f;
this.bottomZ[i] = centerZ + zOffset * undersideScale;
}
}
private void draw(VertexConsumer vertices, MatrixStack.Entry matrix, float cameraX, float cameraY, float cameraZ) {
float relativeCenterX = centerX - cameraX;
float relativeCenterY = centerY - cameraY;
float relativeCenterZ = centerZ - cameraZ;
for (int i = 0; i < topX.length; i++) {
int next = (i + 1) % topX.length;
int topShade = i % 3 == 0 ? 8 : 0;
vertex(vertices, matrix, relativeCenterX, relativeCenterY, relativeCenterZ, red + topShade, green + topShade, blue + topShade);
vertex(vertices, matrix, topX[i] - cameraX, topY[i] - cameraY, topZ[i] - cameraZ, red + topShade, green + topShade, blue + topShade);
vertex(vertices, matrix, topX[next] - cameraX, topY[next] - cameraY, topZ[next] - cameraZ, red + topShade, green + topShade, blue + topShade);
vertex(vertices, matrix, topX[next] - cameraX, topY[next] - cameraY, topZ[next] - cameraZ, red + topShade, green + topShade, blue + topShade);
int sideShade = i % 2 == 0 ? 0 : 8;
int sideRed = Math.max(0, red - 39 + sideShade);
int sideGreen = Math.max(0, green - 37 + sideShade);
int sideBlue = Math.max(0, blue - 34 + sideShade);
vertex(vertices, matrix, topX[i] - cameraX, topY[i] - cameraY, topZ[i] - cameraZ, sideRed, sideGreen, sideBlue);
vertex(vertices, matrix, topX[next] - cameraX, topY[next] - cameraY, topZ[next] - cameraZ, sideRed, sideGreen, sideBlue);
vertex(vertices, matrix, bottomX[next] - cameraX, bottomY[next] - cameraY, bottomZ[next] - cameraZ, sideRed, sideGreen, sideBlue);
vertex(vertices, matrix, bottomX[i] - cameraX, bottomY[i] - cameraY, bottomZ[i] - cameraZ, sideRed, sideGreen, sideBlue);
}
}
}
}