diff --git a/src/main/java/com/backsun/lod/LodMain.java b/src/main/java/com/backsun/lod/LodMain.java index ec8974c20..fcdc70246 100644 --- a/src/main/java/com/backsun/lod/LodMain.java +++ b/src/main/java/com/backsun/lod/LodMain.java @@ -34,7 +34,7 @@ public class LodMain private void init(final FMLCommonSetupEvent event) { Minecraft.getInstance().getFramebuffer().enableStencil(); - ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, LodConfig.COMMON_SPEC); + ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, LodConfig.clientSpec); } diff --git a/src/main/java/com/backsun/lod/proxy/ClientProxy.java b/src/main/java/com/backsun/lod/proxy/ClientProxy.java index c424d831f..7ef20c564 100644 --- a/src/main/java/com/backsun/lod/proxy/ClientProxy.java +++ b/src/main/java/com/backsun/lod/proxy/ClientProxy.java @@ -54,7 +54,7 @@ public class ClientProxy RenderGlobalHook.endRenderingStencil(); GL11.glStencilFunc(GL11.GL_EQUAL, 0, 0xFF); - if (LodConfig.COMMON.drawLODs.get()) + if (LodConfig.CLIENT.drawLODs.get()) renderLods(event.getPartialTicks()); GL11.glDisable(GL11.GL_STENCIL_TEST); diff --git a/src/main/java/com/backsun/lod/renderer/LodRenderer.java b/src/main/java/com/backsun/lod/renderer/LodRenderer.java index 066c7bcca..2f188d3b6 100644 --- a/src/main/java/com/backsun/lod/renderer/LodRenderer.java +++ b/src/main/java/com/backsun/lod/renderer/LodRenderer.java @@ -163,7 +163,7 @@ public class LodRenderer if ((int)player.getPosX() / LodChunk.WIDTH != prevChunkX || (int)player.getPosZ() / LodChunk.WIDTH != prevChunkZ || previousChunkRenderDistance != mc.gameSettings.renderDistanceChunks || - prevFogDistance != LodConfig.COMMON.fogDistance.get() || + prevFogDistance != LodConfig.CLIENT.fogDistance.get() || lodDimension != newDimension) { // yes @@ -171,7 +171,7 @@ public class LodRenderer prevChunkX = (int)player.getPosX() / LodChunk.WIDTH; prevChunkZ = (int)player.getPosZ() / LodChunk.WIDTH; - prevFogDistance = LodConfig.COMMON.fogDistance.get(); + prevFogDistance = LodConfig.CLIENT.fogDistance.get(); } else { @@ -189,15 +189,15 @@ public class LodRenderer return; } - if (LodConfig.COMMON.drawCheckerBoard.get()) + if (LodConfig.CLIENT.drawCheckerBoard.get()) { - if (debugging != LodConfig.COMMON.drawCheckerBoard.get()) + if (debugging != LodConfig.CLIENT.drawCheckerBoard.get()) regen = true; debugging = true; } else { - if (debugging != LodConfig.COMMON.drawCheckerBoard.get()) + if (debugging != LodConfig.CLIENT.drawCheckerBoard.get()) regen = true; debugging = false; } @@ -656,7 +656,7 @@ public class LodRenderer // generate our new buildable buffers NearFarBuffer nearFarBuffers = lodBufferBuilder.createBuffers( buildableNearBuffer, buildableFarBuffer, - LodConfig.COMMON.fogDistance.get(), lodArray, colorArray); + LodConfig.CLIENT.fogDistance.get(), lodArray, colorArray); // update our buffers buildableNearBuffer = nearFarBuffers.nearBuffer; @@ -734,12 +734,12 @@ public class LodRenderer { NearFarFogSetting fogSetting = new NearFarFogSetting(); - LodConfig.COMMON.fogDistance.get(); + LodConfig.CLIENT.fogDistance.get(); switch(reflectionHandler.getFogQuality()) { case FANCY: - switch(LodConfig.COMMON.fogDistance.get()) + switch(LodConfig.CLIENT.fogDistance.get()) { case NEAR_AND_FAR: fogSetting.nearFogSetting = FogDistance.NEAR; @@ -764,7 +764,7 @@ public class LodRenderer // and far portion; and fast fog is rendered from the // frustrum's perspective instead of the camera - switch(LodConfig.COMMON.fogDistance.get()) + switch(LodConfig.CLIENT.fogDistance.get()) { case NEAR_AND_FAR: fogSetting.nearFogSetting = FogDistance.NEAR; diff --git a/src/main/java/com/backsun/lod/util/LodConfig.java b/src/main/java/com/backsun/lod/util/LodConfig.java index 02977fcb1..7c4bc5fff 100644 --- a/src/main/java/com/backsun/lod/util/LodConfig.java +++ b/src/main/java/com/backsun/lod/util/LodConfig.java @@ -1,34 +1,30 @@ package com.backsun.lod.util; +import java.nio.file.Path; +import java.nio.file.Paths; + import org.apache.commons.lang3.tuple.Pair; +import org.apache.logging.log4j.LogManager; import com.backsun.lod.ModInfo; import com.backsun.lod.util.enums.FogDistance; +import com.electronwill.nightconfig.core.file.CommentedFileConfig; +import com.electronwill.nightconfig.core.io.WritingMode; import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.config.ModConfig; /** * * @author James Seibel - * @version 02-14-2021 + * @version 02-27-2021 */ @Mod.EventBusSubscriber public class LodConfig { - public static final LodConfig.Common COMMON; - public static final ForgeConfigSpec COMMON_SPEC; - - // create the required variables - static - { - final Pair specPair = new ForgeConfigSpec.Builder().configure(LodConfig.Common::new); - COMMON_SPEC = specPair.getRight(); - COMMON = specPair.getLeft(); - } - - - public static class Common + public static class Client { public ForgeConfigSpec.BooleanValue drawLODs; @@ -37,24 +33,28 @@ public class LodConfig public ForgeConfigSpec.BooleanValue drawCheckerBoard; - Common(ForgeConfigSpec.Builder builder) + Client(ForgeConfigSpec.Builder builder) { - builder.comment(ModInfo.MODNAME + " configuration settings").push("common"); + builder.comment(ModInfo.MODNAME + " configuration settings").push("client"); drawLODs = builder - .comment("If true LODs will be drawn, if false LODs will " - + "not be rendered. However they will " - + "still be generated.") + .comment("If false LODs will not be drawn, \n" + + "however they will still be generated \n" + + "and saved to file for later use.") .define("drawLODs", true); fogDistance = builder - .comment("At what distance should Fog be drawn on the LODs?") + .comment("\n" + + "At what distance should Fog be drawn on the LODs? \n" + + "If fog cuts off ubruptly or you are using Optifine's \"fast\" \n" + + "fog option set this to " + FogDistance.NEAR.toString() + " or " + FogDistance.FAR.toString() + ".") .defineEnum("fogDistance", FogDistance.NEAR_AND_FAR); drawCheckerBoard = builder - .comment("If false the LODs will draw with their normal world colors. " - + "If true they will draw as a black and white checkerboard. " - + "This can be used for debugging or imagining you are playing a " + .comment("\n" + + "If false the LODs will draw with their normal world colors. \n" + + "If true they will draw as a black and white checkerboard. \n" + + "This can be used for debugging or imagining you are playing a \n" + "giant game of chess ;)") .define("drawCheckerBoard", false); @@ -62,4 +62,44 @@ public class LodConfig } } + + + /** + * {@link Path} to the configuration file of this mod + */ + private static final Path CONFIG_PATH = + Paths.get("config", ModInfo.MODID + ".toml"); + + public static final ForgeConfigSpec clientSpec; + public static final Client CLIENT; + static { + final Pair specPair = new ForgeConfigSpec.Builder().configure(Client::new); + clientSpec = specPair.getRight(); + CLIENT = specPair.getLeft(); + + // setup the config file + CommentedFileConfig config = CommentedFileConfig.builder(CONFIG_PATH) + .writingMode(WritingMode.REPLACE) + .build(); + config.load(); + config.save(); + clientSpec.setConfig(config); + } + + + @SubscribeEvent + public static void onLoad(final ModConfig.Loading configEvent) + { + LogManager.getLogger().debug(ModInfo.MODNAME, "Loaded forge config file {}", configEvent.getConfig().getFileName()); + } + + @SubscribeEvent + public static void onFileChange(final ModConfig.Reloading configEvent) + { + LogManager.getLogger().debug(ModInfo.MODNAME, "Forge config just got changed on the file system!"); + } + + + + }