mirror of
https://github.com/JonasunderscoreJones/nicer-skies.git
synced 2025-10-22 19:29:18 +02:00
misc code cleanups
This commit is contained in:
parent
29f30fb53a
commit
296315aa2a
4 changed files with 31 additions and 45 deletions
|
@ -1,9 +1,7 @@
|
|||
package codes.ztereohype.nicerskies.gui.widget;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.components.Renderable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Separator implements Renderable {
|
||||
private final int x;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package codes.ztereohype.nicerskies.sky;
|
||||
|
||||
import codes.ztereohype.nicerskies.NicerSkies;
|
||||
import codes.ztereohype.nicerskies.config.ConfigManager;
|
||||
import codes.ztereohype.nicerskies.config.Config;
|
||||
import codes.ztereohype.nicerskies.core.Gradient;
|
||||
import codes.ztereohype.nicerskies.mixin.LevelRendererAccessor;
|
||||
import codes.ztereohype.nicerskies.mixin.LevelRendererInvoker;
|
||||
|
@ -15,35 +15,41 @@ import net.minecraft.world.level.levelgen.synth.PerlinNoise;
|
|||
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@Getter
|
||||
public class SkyManager {
|
||||
private @Getter Starbox starbox;
|
||||
private @Getter Skybox skybox;
|
||||
private Starbox starbox;
|
||||
private Skybox skybox;
|
||||
|
||||
private final Gradient starGradient = new Gradient();
|
||||
private final Gradient nebulaGradient = new Gradient();
|
||||
private final Gradient starGradient = new Gradient() {{
|
||||
add(0.0f, 255, 179, 97);
|
||||
add(0.2f, 255, 249, 253);
|
||||
add(1.0f, 175, 199, 255);
|
||||
}};
|
||||
|
||||
public void generateSky(long seed, boolean starsEnabled, boolean nebulaEnabled) {
|
||||
ConfigManager cm = NicerSkies.config;
|
||||
private final Gradient nebulaGradient = new Gradient() {{
|
||||
add(0.2f, 41, 83, 146);
|
||||
add(0.5f, 120, 47, 93);
|
||||
add(0.7f, 209, 58, 103);
|
||||
add(0.8f, 255, 160, 123);
|
||||
add(1.0f, 253, 194, 220);
|
||||
}};
|
||||
|
||||
nebulaGradient.clear();
|
||||
starGradient.clear();
|
||||
|
||||
buildGradients();
|
||||
public void generateSky(long seed) {
|
||||
Config cm = NicerSkies.getInstance().getConfig();
|
||||
|
||||
RandomSource randomSource = RandomSource.create(seed);
|
||||
|
||||
if (nebulaEnabled) {
|
||||
if (cm.areNebulasEnabled()) {
|
||||
PerlinNoise perlinNoise = PerlinNoise.create(randomSource.fork(), IntStream.of(1, 2, 3, 4, 5, 6, 7));
|
||||
NebulaSkyboxPainter painter = new NebulaSkyboxPainter(perlinNoise, nebulaGradient, cm.getNebulaNoiseScale(), cm.getNebulaNoiseAmount(), cm.getNebulaBaseColourAmount());
|
||||
this.skybox = new Skybox(painter);
|
||||
}
|
||||
|
||||
if (starsEnabled) {
|
||||
if (cm.areTwinlkingStarsEnabled()) {
|
||||
LevelRendererAccessor levelRenderer = (LevelRendererAccessor) Minecraft.getInstance().levelRenderer;
|
||||
starbox = new Starbox(randomSource, starGradient, levelRenderer.nicerSkies_getStarBuffer());
|
||||
tick(levelRenderer.nicerSkies_getTicks());
|
||||
} else {
|
||||
|
||||
((LevelRendererInvoker)Minecraft.getInstance().levelRenderer).nicerSkies_generateSky();
|
||||
}
|
||||
}
|
||||
|
@ -53,16 +59,4 @@ public class SkyManager {
|
|||
this.starbox.updateStars(ticks);
|
||||
}
|
||||
}
|
||||
|
||||
public void buildGradients() {
|
||||
starGradient.add(0.0f, 255, 179, 97);
|
||||
starGradient.add(0.2f, 255, 249, 253);
|
||||
starGradient.add(1.0f, 175, 199, 255);
|
||||
|
||||
nebulaGradient.add(0.2f, 41, 83, 146);
|
||||
nebulaGradient.add(0.5f, 120, 47, 93);
|
||||
nebulaGradient.add(0.7f, 209, 58, 103);
|
||||
nebulaGradient.add(0.8f, 255, 160, 123);
|
||||
nebulaGradient.add(1.0f, 253, 194, 220);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,17 +117,5 @@ public class Star {
|
|||
bufferBuilder.vertex(xCoord + ae4 * longitudeSin - firstVertexDistance * longitudeCos, yCoord + fourthVertexDistance * latitudeSin, zCoord + firstVertexDistance * longitudeSin + ae4 * longitudeCos)
|
||||
.color(r, g, b, 255)
|
||||
.endVertex();
|
||||
// // 1
|
||||
// bufferBuilder.vertex(xCoord + ae2 * longitudeSin - thirdVertexDistance * longitudeCos, yCoord + secondVertexDistance * latitudeSin, zCoord + thirdVertexDistance * longitudeSin + ae2 * longitudeCos)
|
||||
// .color(r, g, b, 255)
|
||||
// .endVertex();
|
||||
// // 2
|
||||
// bufferBuilder.vertex(xCoord + ae3 * longitudeSin - fourthVertexDistance * longitudeCos, yCoord + thirdVertexDistance * latitudeSin, zCoord + fourthVertexDistance * longitudeSin + ae3 * longitudeCos)
|
||||
// .color(r, g, b, 255)
|
||||
// .endVertex();
|
||||
// // 3
|
||||
// bufferBuilder.vertex(xCoord + ae4 * longitudeSin - firstVertexDistance * longitudeCos, yCoord + fourthVertexDistance * latitudeSin, zCoord + firstVertexDistance * longitudeSin + ae4 * longitudeCos)
|
||||
// .color(r, g, b, 255)
|
||||
// .endVertex();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,22 @@
|
|||
package codes.ztereohype.nicerskies.sky.star;
|
||||
|
||||
import codes.ztereohype.nicerskies.core.Gradient;
|
||||
import com.mojang.blaze3d.vertex.*;
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import com.mojang.blaze3d.vertex.Tesselator;
|
||||
import com.mojang.blaze3d.vertex.VertexBuffer;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.levelgen.synth.ImprovedNoise;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class Starbox {
|
||||
private static final BufferBuilder STAR_BUFFER_BUILDER = Tesselator.getInstance().getBuilder();
|
||||
|
||||
private final int stars = 1500;
|
||||
|
||||
private final ArrayList<Star> starList = new ArrayList<>();
|
||||
private final List<Star> starList = new ArrayList<>();
|
||||
private final VertexBuffer starBuffer;
|
||||
|
||||
public Starbox(RandomSource randomSource, Gradient starGradient, VertexBuffer starBuffer) {
|
||||
|
@ -25,7 +29,8 @@ public class Starbox {
|
|||
|
||||
ImprovedNoise noise = new ImprovedNoise(randomSource);
|
||||
|
||||
for (int i = 0; i < this.stars; ++i) {
|
||||
int stars = 1500;
|
||||
for (int i = 0; i < stars; ++i) {
|
||||
float randX = randomSource.nextFloat() * 2.0F - 1.0F;
|
||||
float randY = randomSource.nextFloat() * 2.0F - 1.0F;
|
||||
float randZ = randomSource.nextFloat() * 2.0F - 1.0F;
|
||||
|
@ -46,6 +51,7 @@ public class Starbox {
|
|||
}
|
||||
|
||||
public void updateStars(int ticks) {
|
||||
// todo: make a fast path for when sodium is installed (vertexbufferwriter), or just make our own.
|
||||
STAR_BUFFER_BUILDER.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||
|
||||
for (Star star : starList) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue