new: nebula strength config option + fixed config screen

This commit is contained in:
ZtereoHYPE 2022-12-05 20:36:21 +01:00
parent b2493144ee
commit df3e886bcc
5 changed files with 59 additions and 9 deletions

View file

@ -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 +
'}';
}
}

View file

@ -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));

View file

@ -1,7 +1,7 @@
package codes.ztereohype.example.config;
public enum NebulaType {
RAINBOW("rainbow");
RAINBOW("Rainbow");
private final String type;

View file

@ -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> 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

View file

@ -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());