From df3e886bcc2fbb8b6a0a5387714f53ac4079a8a5 Mon Sep 17 00:00:00 2001 From: ZtereoHYPE <57519662+ZtereoHYPE@users.noreply.github.com> Date: Mon, 5 Dec 2022 20:36:21 +0100 Subject: [PATCH] new: nebula strength config option + fixed config screen --- .../ztereohype/example/config/Config.java | 18 ++++++++--- .../example/config/ConfigManager.java | 14 ++++++-- .../ztereohype/example/config/NebulaType.java | 2 +- .../ztereohype/example/gui/ConfigScreen.java | 32 ++++++++++++++++++- .../ztereohype/example/sky/nebula/Skybox.java | 2 ++ 5 files changed, 59 insertions(+), 9 deletions(-) diff --git a/src/main/java/codes/ztereohype/example/config/Config.java b/src/main/java/codes/ztereohype/example/config/Config.java index ca2db91..930b0b0 100644 --- a/src/main/java/codes/ztereohype/example/config/Config.java +++ b/src/main/java/codes/ztereohype/example/config/Config.java @@ -1,12 +1,12 @@ package codes.ztereohype.example.config; public class Config { - public Config(boolean tweakedLigthmap, boolean twinklingStars, boolean nebulas, String nebulaType) { + public Config(boolean tweakedLigthmap, boolean twinklingStars, boolean nebulas, String nebulaType, float nebulaStrength) { this.tweakedLigthmap = tweakedLigthmap; this.twinklingStars = twinklingStars; this.nebulas = nebulas; - this.nebulaConfig = new NebulaConfig(nebulaType); + this.nebulaConfig = new NebulaConfig(nebulaType, nebulaStrength); } private boolean tweakedLigthmap; @@ -44,11 +44,13 @@ public class Config { } public static final class NebulaConfig { - public NebulaConfig(String nebulaType) { + public NebulaConfig(String nebulaType, float nebulaStrength) { this.nebulaType = nebulaType; + this.nebulaStrength = nebulaStrength; } private String nebulaType; + private float nebulaStrength; public String getNebulaType() { return this.nebulaType; @@ -57,6 +59,14 @@ public class Config { public void setNebulaType(String nebulaType) { this.nebulaType = nebulaType; } + + public float getNebulaStrength() { + return this.nebulaStrength; + } + + public void setNebulaStrength(float nebulaStrength) { + this.nebulaStrength = nebulaStrength; + } } @Override @@ -65,7 +75,7 @@ public class Config { "tweakedLigthmap=" + tweakedLigthmap + ", twinklingStars=" + twinklingStars + ", nebulas=" + nebulas + - ", nebulaConfig type=" + nebulaConfig.getNebulaType() + + ", nebulaConfig=" + nebulaConfig + '}'; } } diff --git a/src/main/java/codes/ztereohype/example/config/ConfigManager.java b/src/main/java/codes/ztereohype/example/config/ConfigManager.java index 3a1244b..d8c42e5 100644 --- a/src/main/java/codes/ztereohype/example/config/ConfigManager.java +++ b/src/main/java/codes/ztereohype/example/config/ConfigManager.java @@ -6,7 +6,6 @@ import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; -import java.util.logging.LogManager; public class ConfigManager { private static final Gson gson = new Gson(); @@ -20,7 +19,7 @@ public class ConfigManager { file.getParentFile().mkdirs(); file.createNewFile(); - config = new Config(false, true, true, "rainbow"); + config = new Config(false, true, true, "rainbow", 1f); gson.toJson(config, new FileWriter(file)); } else { @@ -33,7 +32,7 @@ public class ConfigManager { } catch (IOException e) { // todo setup logger properly e.printStackTrace(); - config = new Config(false, true, true, "rainbow"); + config = new Config(false, true, true, "rainbow", 1f); } return new ConfigManager(config, file); @@ -61,6 +60,10 @@ public class ConfigManager { return NebulaType.getFromString(config.getNebulaConfig().getNebulaType()); } + public float getNebulaStrength() { + return config.getNebulaConfig().getNebulaStrength(); + } + public void setLightmapTweaked(boolean tweaked) { config.setTweakedLigthmap(tweaked); save(file); @@ -81,6 +84,11 @@ public class ConfigManager { save(file); } + public void setNebulaStrength(float strength) { + config.getNebulaConfig().setNebulaStrength(strength); + save(file); + } + public void save(File file) { try (FileWriter writer = new FileWriter(file)) { writer.write(gson.toJson(config)); diff --git a/src/main/java/codes/ztereohype/example/config/NebulaType.java b/src/main/java/codes/ztereohype/example/config/NebulaType.java index 62f9409..4183d24 100644 --- a/src/main/java/codes/ztereohype/example/config/NebulaType.java +++ b/src/main/java/codes/ztereohype/example/config/NebulaType.java @@ -1,7 +1,7 @@ package codes.ztereohype.example.config; public enum NebulaType { - RAINBOW("rainbow"); + RAINBOW("Rainbow"); private final String type; diff --git a/src/main/java/codes/ztereohype/example/gui/ConfigScreen.java b/src/main/java/codes/ztereohype/example/gui/ConfigScreen.java index 5d6fc61..99f0f74 100644 --- a/src/main/java/codes/ztereohype/example/gui/ConfigScreen.java +++ b/src/main/java/codes/ztereohype/example/gui/ConfigScreen.java @@ -2,16 +2,20 @@ package codes.ztereohype.example.gui; import codes.ztereohype.example.NicerSkies; import codes.ztereohype.example.config.ConfigManager; +import codes.ztereohype.example.config.NebulaType; 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.Checkbox; +import net.minecraft.client.gui.components.CycleButton; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; public class ConfigScreen extends Screen { private Screen lastScreen; private ConfigManager cm = NicerSkies.config; + protected ConfigScreen(Screen lastScreen) { super(Component.literal("Nicer Skies Config")); this.lastScreen = lastScreen; @@ -26,6 +30,7 @@ public class ConfigScreen extends Screen { cm.setNebulas(!cm.getNebulas()); } }); + addRenderableWidget(new Checkbox(20, 90, 20, 20, Component.literal("Twinlke Stars"), cm.getTwinklingStars()) { @Override public void onPress() { @@ -33,16 +38,41 @@ public class ConfigScreen extends Screen { cm.setTwinklingStars(!cm.getTwinklingStars()); } }); + addRenderableWidget(new Checkbox(20, 120, 20, 20, Component.literal("Custom Lightmap"), cm.getLightmapTweaked()) { @Override public void onPress() { super.onPress(); cm.setLightmapTweaked(!cm.getLightmapTweaked()); + Minecraft.getInstance().gameRenderer.lightTexture().tick(); } }); + addRenderableOnly(new Separator(this.width / 2, 30, this.height - 40)); - addRenderableWidget(new Slider) + CycleButton nebulaType = CycleButton.builder((NebulaType value) -> Component.literal(value.getTypeString())) + .withValues(NebulaType.values()) + .withTooltip((type) -> minecraft.font.split(Component.literal("Currently disabled as there's only one type of nebula"), 200)) + .create(this.width / 2 + (this.width / 2 - 150) / 2, 60, 150, 20, Component.literal("Nebula Type"), (button, value) -> { + NicerSkies.config.setNebulaType(value); + }); + if (NebulaType.values().length < 2) + nebulaType.active = false; // deactivate while theres only one! + + addRenderableWidget(nebulaType); + + float strength = cm.getNebulaStrength(); + addRenderableWidget(new AbstractSliderButton(this.width / 2 + (this.width / 2 - 150) / 2, 90, 150, 20, Component.literal("Nebula Strength: " + (int) (strength * 100) + "%"), strength) { + @Override + protected void updateMessage() { + this.setMessage(Component.literal("Nebula Strength: " + (int) (this.value * 100) + "%")); + } + + @Override + protected void applyValue() { + NicerSkies.config.setNebulaStrength((float)this.value); + } + }); } @Override diff --git a/src/main/java/codes/ztereohype/example/sky/nebula/Skybox.java b/src/main/java/codes/ztereohype/example/sky/nebula/Skybox.java index f5ad90b..8660d9c 100644 --- a/src/main/java/codes/ztereohype/example/sky/nebula/Skybox.java +++ b/src/main/java/codes/ztereohype/example/sky/nebula/Skybox.java @@ -1,5 +1,6 @@ package codes.ztereohype.example.sky.nebula; +import codes.ztereohype.example.NicerSkies; import com.mojang.blaze3d.platform.NativeImage; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.*; @@ -24,6 +25,7 @@ public class Skybox { public void render(PoseStack poseStack, Matrix4f projectionMatrix) { RenderSystem.setShader(GameRenderer::getPositionTexShader); RenderSystem.setShaderTexture(0, skyTexture.getId()); + RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, NicerSkies.config.getNebulaStrength()); this.skyboxBuffer.bind(); this.skyboxBuffer.drawWithShader(poseStack.last().pose(), projectionMatrix, GameRenderer.getPositionTexShader());