mirror of
https://github.com/JonasunderscoreJones/nicer-skies.git
synced 2025-10-23 19:49:21 +02:00
new: nebula strength config option + fixed config screen
This commit is contained in:
parent
df3e886bcc
commit
9bcdb6f378
7 changed files with 69 additions and 9 deletions
|
@ -0,0 +1,17 @@
|
|||
package codes.ztereohype.example.core;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class NebulaSeedManager {
|
||||
public static long getSeed() {
|
||||
if (Minecraft.getInstance().hasSingleplayerServer()) {
|
||||
// calculate seed from overworld seed
|
||||
return Objects.hash(Minecraft.getInstance().getSingleplayerServer().getLevel(Level.OVERWORLD).getSeed());
|
||||
} else {
|
||||
return Objects.requireNonNull(Minecraft.getInstance().getCurrentServer()).ip.hashCode();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import codes.ztereohype.example.gui.widget.Separator;
|
|||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.AbstractSliderButton;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.Checkbox;
|
||||
import net.minecraft.client.gui.components.CycleButton;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
|
@ -73,6 +74,15 @@ public class ConfigScreen extends Screen {
|
|||
NicerSkies.config.setNebulaStrength((float)this.value);
|
||||
}
|
||||
});
|
||||
|
||||
//reload nebula button
|
||||
// addRenderableWidget(new Button(this.width / 2 + (this.width / 2 - 150) / 2, 120, 150, 20, Component.literal("Reload Nebula"), (button) -> {
|
||||
// NicerSkies.skyManager.generateSky(NebulaSeedManager.getSeed());
|
||||
// }));
|
||||
|
||||
addRenderableWidget(new Button(this.width / 2 - 100, this.height - 30, 200, 20, Component.literal("Back"), (button) -> {
|
||||
minecraft.setScreen(lastScreen);
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package codes.ztereohype.example.mixin;
|
||||
|
||||
import codes.ztereohype.example.NicerSkies;
|
||||
import codes.ztereohype.example.core.NebulaSeedManager;
|
||||
import net.minecraft.client.Minecraft;
|
||||
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;
|
||||
|
||||
@Mixin(Minecraft.class)
|
||||
public class MinecraftMixin {
|
||||
@Inject(at = @At("TAIL"), method = "setLevel")
|
||||
private void onWorldLoad(CallbackInfo ci) {
|
||||
System.out.println("DONED THE LOADD");
|
||||
NicerSkies.skyManager.generateSky(NebulaSeedManager.getSeed());
|
||||
}
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
package codes.ztereohype.example.mixin;
|
||||
|
||||
import codes.ztereohype.example.NicerSkies;
|
||||
import codes.ztereohype.example.core.NebulaSeedManager;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexBuffer;
|
||||
import com.mojang.blaze3d.vertex.*;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
|
@ -29,9 +29,14 @@ public abstract class MixinStarRendering {
|
|||
|
||||
@Inject(at = @At("HEAD"), method = "createStars", cancellable = true)
|
||||
private void generateStars(CallbackInfo ci) {
|
||||
NicerSkies.skyManager.generateSky(212421L);
|
||||
starBuffer = new VertexBuffer();
|
||||
NicerSkies.skyManager.tick(ticks, starBuffer);
|
||||
|
||||
BufferBuilder builder = Tesselator.getInstance().getBuilder();
|
||||
builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||
|
||||
starBuffer.bind();
|
||||
starBuffer.upload(builder.end());
|
||||
|
||||
ci.cancel();
|
||||
}
|
||||
|
||||
|
@ -57,9 +62,13 @@ public abstract class MixinStarRendering {
|
|||
locals = LocalCapture.CAPTURE_FAILHARD
|
||||
)
|
||||
private void drawSkybox(PoseStack poseStack, Matrix4f projectionMatrix, float partialTick, Camera camera, boolean bl, Runnable skyFogSetup, CallbackInfo ci, FogType fogType, Vec3 vec3, float f, float g, float h, BufferBuilder bufferBuilder, ShaderInstance shaderInstance, float[] fs, float i, Matrix4f matrix4f2, float k, int r, int s, int m, float t, float o, float p, float q) {
|
||||
if (!NicerSkies.config.getNebulas()) return;
|
||||
if (!NicerSkies.config.getNebulas() || !NicerSkies.skyManager.isInitialized()) return;
|
||||
float alpha = 2 * level.getStarBrightness(partialTick) * (1.0F - this.level.getRainLevel(partialTick));
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, alpha);
|
||||
NicerSkies.skyManager.getSkybox().render(poseStack, projectionMatrix);
|
||||
}
|
||||
|
||||
// public void setStarBuffer(VertexBuffer starBuffer) {
|
||||
// this.starBuffer = starBuffer;
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package codes.ztereohype.example.mixin.debug;
|
||||
|
||||
import codes.ztereohype.example.NicerSkies;
|
||||
import codes.ztereohype.example.core.NebulaSeedManager;
|
||||
import net.minecraft.client.KeyboardHandler;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
|
@ -13,7 +14,7 @@ public class MixinKeyboardHandler {
|
|||
private void printKey(long windowPointer, int key, int scanCode, int action, int modifiers, CallbackInfo ci) {
|
||||
// \ key, keydown action
|
||||
if (key == 92 && action == 1) {
|
||||
NicerSkies.skyManager.generateSky(15156);
|
||||
NicerSkies.skyManager.generateSky(NebulaSeedManager.getSeed());
|
||||
// NicerSkies.toggle = !NicerSkies.toggle;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import java.util.stream.IntStream;
|
|||
public class SkyManager {
|
||||
private @Getter Starbox starbox;
|
||||
private @Getter Skybox skybox;
|
||||
private @Getter boolean isInitialized = false;
|
||||
|
||||
private final Gradient starGradient = new Gradient();
|
||||
private final Gradient nebulaGradient = new Gradient();
|
||||
|
@ -25,6 +26,8 @@ public class SkyManager {
|
|||
|
||||
buildGradients();
|
||||
|
||||
System.out.println(seed);
|
||||
|
||||
RandomSource randomSource = RandomSource.create(seed); //todo: world seed/hash server ip
|
||||
|
||||
PerlinNoise perlinNoise = PerlinNoise.create(randomSource, IntStream.of(1, 2, 3, 4, 5));
|
||||
|
@ -38,6 +41,7 @@ public class SkyManager {
|
|||
|
||||
public void tick(int ticks, VertexBuffer starBuffer) {
|
||||
this.starbox.updateStars(ticks, starBuffer);
|
||||
this.isInitialized = true;
|
||||
}
|
||||
|
||||
public void buildGradients() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue