neww: wip config sstufff

This commit is contained in:
ZtereoHYPE 2022-11-14 23:01:41 +01:00
parent 7de8129fb7
commit a421a55cf7
10 changed files with 250 additions and 11 deletions

View file

@ -1,12 +1,20 @@
package codes.ztereohype.example;
import codes.ztereohype.example.config.ConfigManager;
import codes.ztereohype.example.sky.SkyManager;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.impl.game.minecraft.launchwrapper.FabricClientTweaker;
import java.io.File;
public class NicerSkies implements ModInitializer {
public static boolean toggle = true;
public static ConfigManager config = ConfigManager.fromFile(new File(FabricLoader.getInstance()
.getConfigDir()
.toFile(), "nicerskies.json"));
public static SkyManager skyManager = new SkyManager();
@Override
public void onInitialize() {}
public void onInitialize() {
}
}

View file

@ -0,0 +1,71 @@
package codes.ztereohype.example.config;
public class Config {
public Config(boolean tweakedLigthmap, boolean twinklingStars, boolean nebulas, String nebulaType) {
this.tweakedLigthmap = tweakedLigthmap;
this.twinklingStars = twinklingStars;
this.nebulas = nebulas;
this.nebulaConfig = new NebulaConfig(nebulaType);
}
private boolean tweakedLigthmap;
private boolean twinklingStars;
private boolean nebulas;
private final NebulaConfig nebulaConfig;
public boolean isTweakedLigthmap() {
return this.tweakedLigthmap;
}
public boolean isTwinklingStars() {
return this.twinklingStars;
}
public boolean isNebulas() {
return this.nebulas;
}
public NebulaConfig getNebulaConfig() {
return this.nebulaConfig;
}
public void setTweakedLigthmap(boolean tweakedLigthmap) {
this.tweakedLigthmap = tweakedLigthmap;
}
public void setTwinklingStars(boolean twinklingStars) {
this.twinklingStars = twinklingStars;
}
public void setNebulas(boolean nebulas) {
this.nebulas = nebulas;
}
public static final class NebulaConfig {
public NebulaConfig(String nebulaType) {
this.nebulaType = nebulaType;
}
private String nebulaType;
public String getNebulaType() {
return this.nebulaType;
}
public void setNebulaType(String nebulaType) {
this.nebulaType = nebulaType;
}
}
@Override
public String toString() {
return "Config{" +
"tweakedLigthmap=" + tweakedLigthmap +
", twinklingStars=" + twinklingStars +
", nebulas=" + nebulas +
", nebulaConfig type=" + nebulaConfig.getNebulaType() +
'}';
}
}

View file

@ -0,0 +1,94 @@
package codes.ztereohype.example.config;
import com.google.gson.Gson;
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();
private final Config config;
private final File file;
public static ConfigManager fromFile(File file) {
Config config;
try {
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
config = new Config(false, true, true, "rainbow");
gson.toJson(config, new FileWriter(file));
} else {
config = gson.fromJson(new FileReader(file), Config.class);
if (config == null) {
throw new IOException("Failed to read config file");
}
}
} catch (IOException e) {
// todo setup logger properly
e.printStackTrace();
config = new Config(false, true, true, "rainbow");
}
return new ConfigManager(config, file);
}
private ConfigManager(Config config, File file) {
this.config = config;
this.file = file;
save(file);
}
public boolean getLightmapTweaked() {
return config.isTweakedLigthmap();
}
public boolean getTwinklingStars() {
return config.isTwinklingStars();
}
public boolean getNebulas() {
return config.isNebulas();
}
public NebulaType getNebulaType() {
return NebulaType.getFromString(config.getNebulaConfig().getNebulaType());
}
public void setLightmapTweaked(boolean tweaked) {
config.setTweakedLigthmap(tweaked);
save(file);
}
public void setTwinklingStars(boolean twinkling) {
config.setTwinklingStars(twinkling);
save(file);
}
public void setNebulas(boolean nebulas) {
config.setNebulas(nebulas);
save(file);
}
public void setNebulaType(NebulaType type) {
config.getNebulaConfig().setNebulaType(type.getTypeString());
save(file);
}
public void save(File file) {
try (FileWriter writer = new FileWriter(file)) {
writer.write(gson.toJson(config));
// System.out.println("Saved config " + );
} catch (IOException e) {
e.printStackTrace();
// todo setup logger properly
// LogManager.getLogManager().getLogger("NicerSkies").warning("Failed to save config file!");
}
}
}

View file

@ -0,0 +1,25 @@
package codes.ztereohype.example.config;
public enum NebulaType {
RAINBOW("rainbow");
private final String type;
NebulaType(String type) {
this.type = type;
}
public String getTypeString() {
return type;
}
// bad?
public static NebulaType getFromString(String type) {
for (NebulaType nebulaType : NebulaType.values()) {
if (nebulaType.getTypeString().equals(type)) {
return nebulaType;
}
}
return null;
}
}

View file

@ -0,0 +1,31 @@
package codes.ztereohype.example.gui;
import codes.ztereohype.example.config.Config;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import java.lang.reflect.Field;
public class ConfigScreen extends Screen {
private Screen lastScreen;
protected ConfigScreen(Screen lastScreen) {
super(Component.literal("Nicer Skies Config"));
this.lastScreen = lastScreen;
}
@Override
public void init() {
Field[] fields = Config.class.getFields();
for (int i = 0; i < fields.length; i++) {
int finalI = i;
addRenderableWidget(new Button(0, 0, 100, 20, Component.literal(fields[i].getName()), (button) -> {
try {
fields[finalI].setBoolean(null, !fields[finalI].getBoolean(null));
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}));
}
}
}

View file

@ -29,7 +29,7 @@ public abstract class MixinStarRendering {
@Inject(at = @At("HEAD"), method = "createStars", cancellable = true)
private void generateStars(CallbackInfo ci) {
NicerSkies.skyManager.generateSky(321L);
NicerSkies.skyManager.generateSky(212421L);
starBuffer = new VertexBuffer();
NicerSkies.skyManager.tick(ticks, starBuffer);
ci.cancel();

View file

@ -13,8 +13,8 @@ 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(321L);
NicerSkies.toggle = !NicerSkies.toggle;
NicerSkies.skyManager.generateSky(15156);
// NicerSkies.toggle = !NicerSkies.toggle;
}
}
}

View file

@ -45,10 +45,14 @@ public class SkyManager {
starGradient.add(0.2f, 255, 249, 253);
starGradient.add(1.0f, 175, 199, 255);
// nebulaGradient.add(0.21f, 255, 0, 0);
nebulaGradient.add(0.2f, 41, 98, 146);
// nebulaGradient.add(0.2f, 0, 0, 0);
nebulaGradient.add(0.5f, 120, 59, 93);
nebulaGradient.add(0.7f, 209, 72, 103);
nebulaGradient.add(0.8f, 255, 200, 123);
// nebulaGradient.add(1.0f, 30, 20, 20);
nebulaGradient.add(1.0f, 253, 243, 220);
// starryGradient.add(0.0f, 128, 128, 200);

View file

@ -46,18 +46,24 @@ public class NebulaSkyboxPainter extends SkyboxPainter {
int baseG = (int) ((y/2 + 0.5) * 127);
int baseR = (int) ((z/2 + 0.5) * 127);
int alpha = (int)(Mth.clamp((noiseValue * (1 / BASE_NOISE_AMOUNT) - (1 / BASE_NOISE_AMOUNT - 1)) * 255, 20, 254.99f)); // otherwise death occurs
// double noiseAmount = (Mth.clamp((noiseValue * (1 / BASE_NOISE_AMOUNT) - (1 / BASE_NOISE_AMOUNT - 1)) * 255, 0, 255)); // otherwise death occurs
//
// int alpha = (int) Mth.clamp((int)noiseAmount - subtractionValue * 128, 50, 255);
alpha = (int) Mth.clamp(alpha - subtractionValue * 128, 50, 255);
double nebulaFactor = (Mth.clamp((noiseValue * (1D / BASE_NOISE_AMOUNT) - (1D / BASE_NOISE_AMOUNT - 1)), 0.01, 0.9999));
double nebulaFactor = (Mth.clamp((noiseValue * (1D / BASE_NOISE_AMOUNT) - (1D / BASE_NOISE_AMOUNT - 1)), 0, 0.99));
Color nebula = nebulaGradient.getAt(nebulaFactor);
double bgFactor = Mth.clamp(Math.log10(-nebulaFactor + 1) + 1, 0, 1);
int r = Mth.clamp((int) ((nebulaFactor * nebula.getRed()) + baseR * bgFactor) - (int)(ds[0] * nebulaFactor * 127), 0, 255);
int g = Mth.clamp((int) ((nebulaFactor * nebula.getGreen()) + baseG * bgFactor) - (int)(ds[1] * nebulaFactor * 64), 0, 255);
int g = Mth.clamp((int) ((nebulaFactor * nebula.getGreen()) + baseG * bgFactor) - (int)(ds[1] * nebulaFactor * 63), 0, 255);
int b = Mth.clamp((int) ((nebulaFactor * nebula.getBlue()) + baseB * bgFactor) - (int)(ds[2] * nebulaFactor * 127), 0, 255);
// int r = Mth.clamp((int) (baseR * bgFactor), 0, 255);
// int g = Mth.clamp((int) (baseG * bgFactor), 0, 255);
// int b = Mth.clamp((int) (baseB * bgFactor), 0, 255);
int alpha = Mth.clamp((int)((1 - bgFactor) * 255), 50, 255);
return FastColor.ARGB32.color(alpha, b, g, r);
}
}

View file

@ -9,7 +9,7 @@ import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.texture.DynamicTexture;
public class Skybox {
public static final int RESOLUTION = 256;
public static final int RESOLUTION = 512;
private final DynamicTexture skyTexture = new DynamicTexture(RESOLUTION * 4, RESOLUTION * 4, false);