mirror of
https://github.com/JonasunderscoreJones/nicer-skies.git
synced 2025-10-23 03:39:18 +02:00
new: nebula strength config option + fixed config screen
This commit is contained in:
parent
b2493144ee
commit
df3e886bcc
5 changed files with 59 additions and 9 deletions
|
@ -1,12 +1,12 @@
|
||||||
package codes.ztereohype.example.config;
|
package codes.ztereohype.example.config;
|
||||||
|
|
||||||
public class 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.tweakedLigthmap = tweakedLigthmap;
|
||||||
this.twinklingStars = twinklingStars;
|
this.twinklingStars = twinklingStars;
|
||||||
this.nebulas = nebulas;
|
this.nebulas = nebulas;
|
||||||
|
|
||||||
this.nebulaConfig = new NebulaConfig(nebulaType);
|
this.nebulaConfig = new NebulaConfig(nebulaType, nebulaStrength);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean tweakedLigthmap;
|
private boolean tweakedLigthmap;
|
||||||
|
@ -44,11 +44,13 @@ public class Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class NebulaConfig {
|
public static final class NebulaConfig {
|
||||||
public NebulaConfig(String nebulaType) {
|
public NebulaConfig(String nebulaType, float nebulaStrength) {
|
||||||
this.nebulaType = nebulaType;
|
this.nebulaType = nebulaType;
|
||||||
|
this.nebulaStrength = nebulaStrength;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String nebulaType;
|
private String nebulaType;
|
||||||
|
private float nebulaStrength;
|
||||||
|
|
||||||
public String getNebulaType() {
|
public String getNebulaType() {
|
||||||
return this.nebulaType;
|
return this.nebulaType;
|
||||||
|
@ -57,6 +59,14 @@ public class Config {
|
||||||
public void setNebulaType(String nebulaType) {
|
public void setNebulaType(String nebulaType) {
|
||||||
this.nebulaType = nebulaType;
|
this.nebulaType = nebulaType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getNebulaStrength() {
|
||||||
|
return this.nebulaStrength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNebulaStrength(float nebulaStrength) {
|
||||||
|
this.nebulaStrength = nebulaStrength;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -65,7 +75,7 @@ public class Config {
|
||||||
"tweakedLigthmap=" + tweakedLigthmap +
|
"tweakedLigthmap=" + tweakedLigthmap +
|
||||||
", twinklingStars=" + twinklingStars +
|
", twinklingStars=" + twinklingStars +
|
||||||
", nebulas=" + nebulas +
|
", nebulas=" + nebulas +
|
||||||
", nebulaConfig type=" + nebulaConfig.getNebulaType() +
|
", nebulaConfig=" + nebulaConfig +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.logging.LogManager;
|
|
||||||
|
|
||||||
public class ConfigManager {
|
public class ConfigManager {
|
||||||
private static final Gson gson = new Gson();
|
private static final Gson gson = new Gson();
|
||||||
|
@ -20,7 +19,7 @@ public class ConfigManager {
|
||||||
file.getParentFile().mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
|
|
||||||
config = new Config(false, true, true, "rainbow");
|
config = new Config(false, true, true, "rainbow", 1f);
|
||||||
|
|
||||||
gson.toJson(config, new FileWriter(file));
|
gson.toJson(config, new FileWriter(file));
|
||||||
} else {
|
} else {
|
||||||
|
@ -33,7 +32,7 @@ public class ConfigManager {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// todo setup logger properly
|
// todo setup logger properly
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
config = new Config(false, true, true, "rainbow");
|
config = new Config(false, true, true, "rainbow", 1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ConfigManager(config, file);
|
return new ConfigManager(config, file);
|
||||||
|
@ -61,6 +60,10 @@ public class ConfigManager {
|
||||||
return NebulaType.getFromString(config.getNebulaConfig().getNebulaType());
|
return NebulaType.getFromString(config.getNebulaConfig().getNebulaType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getNebulaStrength() {
|
||||||
|
return config.getNebulaConfig().getNebulaStrength();
|
||||||
|
}
|
||||||
|
|
||||||
public void setLightmapTweaked(boolean tweaked) {
|
public void setLightmapTweaked(boolean tweaked) {
|
||||||
config.setTweakedLigthmap(tweaked);
|
config.setTweakedLigthmap(tweaked);
|
||||||
save(file);
|
save(file);
|
||||||
|
@ -81,6 +84,11 @@ public class ConfigManager {
|
||||||
save(file);
|
save(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setNebulaStrength(float strength) {
|
||||||
|
config.getNebulaConfig().setNebulaStrength(strength);
|
||||||
|
save(file);
|
||||||
|
}
|
||||||
|
|
||||||
public void save(File file) {
|
public void save(File file) {
|
||||||
try (FileWriter writer = new FileWriter(file)) {
|
try (FileWriter writer = new FileWriter(file)) {
|
||||||
writer.write(gson.toJson(config));
|
writer.write(gson.toJson(config));
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package codes.ztereohype.example.config;
|
package codes.ztereohype.example.config;
|
||||||
|
|
||||||
public enum NebulaType {
|
public enum NebulaType {
|
||||||
RAINBOW("rainbow");
|
RAINBOW("Rainbow");
|
||||||
|
|
||||||
private final String type;
|
private final String type;
|
||||||
|
|
||||||
|
|
|
@ -2,16 +2,20 @@ package codes.ztereohype.example.gui;
|
||||||
|
|
||||||
import codes.ztereohype.example.NicerSkies;
|
import codes.ztereohype.example.NicerSkies;
|
||||||
import codes.ztereohype.example.config.ConfigManager;
|
import codes.ztereohype.example.config.ConfigManager;
|
||||||
|
import codes.ztereohype.example.config.NebulaType;
|
||||||
import codes.ztereohype.example.gui.widget.Separator;
|
import codes.ztereohype.example.gui.widget.Separator;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import net.minecraft.client.Minecraft;
|
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.Checkbox;
|
||||||
|
import net.minecraft.client.gui.components.CycleButton;
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
|
||||||
public class ConfigScreen extends Screen {
|
public class ConfigScreen extends Screen {
|
||||||
private Screen lastScreen;
|
private Screen lastScreen;
|
||||||
private ConfigManager cm = NicerSkies.config;
|
private ConfigManager cm = NicerSkies.config;
|
||||||
|
|
||||||
protected ConfigScreen(Screen lastScreen) {
|
protected ConfigScreen(Screen lastScreen) {
|
||||||
super(Component.literal("Nicer Skies Config"));
|
super(Component.literal("Nicer Skies Config"));
|
||||||
this.lastScreen = lastScreen;
|
this.lastScreen = lastScreen;
|
||||||
|
@ -26,6 +30,7 @@ public class ConfigScreen extends Screen {
|
||||||
cm.setNebulas(!cm.getNebulas());
|
cm.setNebulas(!cm.getNebulas());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
addRenderableWidget(new Checkbox(20, 90, 20, 20, Component.literal("Twinlke Stars"), cm.getTwinklingStars()) {
|
addRenderableWidget(new Checkbox(20, 90, 20, 20, Component.literal("Twinlke Stars"), cm.getTwinklingStars()) {
|
||||||
@Override
|
@Override
|
||||||
public void onPress() {
|
public void onPress() {
|
||||||
|
@ -33,16 +38,41 @@ public class ConfigScreen extends Screen {
|
||||||
cm.setTwinklingStars(!cm.getTwinklingStars());
|
cm.setTwinklingStars(!cm.getTwinklingStars());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
addRenderableWidget(new Checkbox(20, 120, 20, 20, Component.literal("Custom Lightmap"), cm.getLightmapTweaked()) {
|
addRenderableWidget(new Checkbox(20, 120, 20, 20, Component.literal("Custom Lightmap"), cm.getLightmapTweaked()) {
|
||||||
@Override
|
@Override
|
||||||
public void onPress() {
|
public void onPress() {
|
||||||
super.onPress();
|
super.onPress();
|
||||||
cm.setLightmapTweaked(!cm.getLightmapTweaked());
|
cm.setLightmapTweaked(!cm.getLightmapTweaked());
|
||||||
|
Minecraft.getInstance().gameRenderer.lightTexture().tick();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
addRenderableOnly(new Separator(this.width / 2, 30, this.height - 40));
|
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
|
@Override
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package codes.ztereohype.example.sky.nebula;
|
package codes.ztereohype.example.sky.nebula;
|
||||||
|
|
||||||
|
import codes.ztereohype.example.NicerSkies;
|
||||||
import com.mojang.blaze3d.platform.NativeImage;
|
import com.mojang.blaze3d.platform.NativeImage;
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import com.mojang.blaze3d.vertex.*;
|
import com.mojang.blaze3d.vertex.*;
|
||||||
|
@ -24,6 +25,7 @@ public class Skybox {
|
||||||
public void render(PoseStack poseStack, Matrix4f projectionMatrix) {
|
public void render(PoseStack poseStack, Matrix4f projectionMatrix) {
|
||||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||||
RenderSystem.setShaderTexture(0, skyTexture.getId());
|
RenderSystem.setShaderTexture(0, skyTexture.getId());
|
||||||
|
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, NicerSkies.config.getNebulaStrength());
|
||||||
|
|
||||||
this.skyboxBuffer.bind();
|
this.skyboxBuffer.bind();
|
||||||
this.skyboxBuffer.drawWithShader(poseStack.last().pose(), projectionMatrix, GameRenderer.getPositionTexShader());
|
this.skyboxBuffer.drawWithShader(poseStack.last().pose(), projectionMatrix, GameRenderer.getPositionTexShader());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue