diff options
Diffstat (limited to 'src/main/java/net/inyourwalls')
4 files changed, 96 insertions, 0 deletions
diff --git a/src/main/java/net/inyourwalls/customlevelcolour/ConfigScreen.java b/src/main/java/net/inyourwalls/customlevelcolour/ConfigScreen.java new file mode 100644 index 0000000..a901b50 --- /dev/null +++ b/src/main/java/net/inyourwalls/customlevelcolour/ConfigScreen.java @@ -0,0 +1,27 @@ +package net.inyourwalls.customlevelcolour; + +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.text.Text; + +public class ConfigScreen extends Screen { + private static final Text TITLE = Text.translatable("gui.customlevelcolour.title"); + private final Screen previous; + + public ConfigScreen() { + super(TITLE); + this.previous = null; + } + + public ConfigScreen(Screen previous) { + super(TITLE); + this.previous = previous; + } + + @Override + public void render(DrawContext context, int mouseX, int mouseY, float delta) { + super.renderBackground(context); + super.render(context, mouseX, mouseY, delta); + context.drawCenteredTextWithShadow(this.textRenderer, TITLE, this.width / 2, 5, 0xffffff); + } +} diff --git a/src/main/java/net/inyourwalls/customlevelcolour/CustomLevelColour.java b/src/main/java/net/inyourwalls/customlevelcolour/CustomLevelColour.java new file mode 100644 index 0000000..f80e0f4 --- /dev/null +++ b/src/main/java/net/inyourwalls/customlevelcolour/CustomLevelColour.java @@ -0,0 +1,30 @@ +package net.inyourwalls.customlevelcolour; + +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.loader.api.FabricLoader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.nio.file.Path; + +public class CustomLevelColour implements ClientModInitializer { + public static final Logger LOGGER = LoggerFactory.getLogger(CustomLevelColour.class); + private static final Path CONFIG_PATH = FabricLoader.getInstance().getConfigDir().resolve("customlevelcolour.json"); + private static CustomLevelColourConfig config; + + @Override + public void onInitializeClient() { + try { + config = CustomLevelColourConfig.load(CONFIG_PATH); + } catch (IOException ex) { + LOGGER.debug("Failed to load config", ex); + config = new CustomLevelColourConfig(); + } + } + + public static CustomLevelColourConfig getConfig() { + if (config == null) throw new IllegalStateException("Attempted to get the configuration before it was loaded"); + return config; + } +} diff --git a/src/main/java/net/inyourwalls/customlevelcolour/CustomLevelColourConfig.java b/src/main/java/net/inyourwalls/customlevelcolour/CustomLevelColourConfig.java new file mode 100644 index 0000000..b963f02 --- /dev/null +++ b/src/main/java/net/inyourwalls/customlevelcolour/CustomLevelColourConfig.java @@ -0,0 +1,26 @@ +package net.inyourwalls.customlevelcolour; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Path; + +public class CustomLevelColourConfig { + private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + public int outlineColour = 0x000000; + public int textColour = 0x80ff20; + + public static CustomLevelColourConfig load(Path path) throws IOException { + FileReader reader = new FileReader(path.toFile()); + return GSON.fromJson(reader, CustomLevelColourConfig.class); + } + + public static void save(Path path) throws IOException { + FileWriter writer = new FileWriter(path.toFile()); + GSON.toJson(writer); + writer.close(); + } +} diff --git a/src/main/java/net/inyourwalls/customlevelcolour/ModMenuIntegration.java b/src/main/java/net/inyourwalls/customlevelcolour/ModMenuIntegration.java new file mode 100644 index 0000000..f1270c2 --- /dev/null +++ b/src/main/java/net/inyourwalls/customlevelcolour/ModMenuIntegration.java @@ -0,0 +1,13 @@ +package net.inyourwalls.customlevelcolour; + +import com.terraformersmc.modmenu.api.ConfigScreenFactory; +import com.terraformersmc.modmenu.api.ModMenuApi; + +public class ModMenuIntegration implements ModMenuApi { + @Override + public ConfigScreenFactory<?> getModConfigScreenFactory() { + return parent -> { + return new ConfigScreen(parent); + }; + } +} |
