Эх сурвалжийг харах

Added /ashcolor command and save config;

umollu 6 жил өмнө
parent
commit
b65211442c

+ 2 - 0
build.gradle

@@ -21,6 +21,8 @@ dependencies {
 
 	// Fabric API. This is technically optional, but you probably want it anyway.
 	modCompile "net.fabricmc:fabric:${project.fabric_version}"
+
+	implementation 'com.google.code.gson:gson:2.8.5'
 }
 
 processResources {

+ 2 - 1
gradle/wrapper/gradle-wrapper.properties

@@ -1,5 +1,6 @@
+#Sat Mar 09 18:58:18 GMT 2019
 distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip

+ 1 - 0
settings.gradle

@@ -6,5 +6,6 @@ pluginManagement {
             url = 'https://maven.fabricmc.net/'
         }
         gradlePluginPortal()
+        mavenCentral()
     }
 }

+ 31 - 0
src/main/java/com/umollu/ash/AshConfig.java

@@ -0,0 +1,31 @@
+package com.umollu.ash;
+
+import com.google.gson.Gson;
+import net.fabricmc.loader.api.FabricLoader;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+public class AshConfig {
+
+    public boolean showHud = true;
+
+    public int hudColor = 0xeeeeee;
+
+    public void saveConfig() {
+        String configPath = FabricLoader.getInstance().getConfigDirectory() + "/" + AshMod.MOD_ID + ".json";
+        File configFile = new File(configPath);
+        String result = new Gson().toJson(this);
+        try {
+            FileOutputStream out = new FileOutputStream(configFile, false);
+
+            out.write(result.getBytes());
+            out.flush();
+            out.close();
+
+        } catch (IOException ex) {
+            ex.printStackTrace();
+        }
+    }
+}

+ 60 - 6
src/main/java/com/umollu/ash/AshMod.java

@@ -1,26 +1,80 @@
 package com.umollu.ash;
 
+import com.google.gson.Gson;
+import com.mojang.brigadier.arguments.IntegerArgumentType;
 import net.fabricmc.api.ModInitializer;
 import net.fabricmc.fabric.api.registry.CommandRegistry;
+import net.fabricmc.loader.api.FabricLoader;
 import net.minecraft.server.command.ServerCommandManager;
-import net.minecraft.server.network.ServerPlayerEntity;
-import net.minecraft.text.Style;
-import net.minecraft.text.TextFormat;
-import net.minecraft.text.TranslatableTextComponent;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
 
 public class AshMod implements ModInitializer {
 
     public static final String MOD_ID = "umollu_ash";
-    public static boolean showHUD = true;
+    public static AshConfig config;
 
     @Override
     public void onInitialize() {
+        String configPath = FabricLoader.getInstance().getConfigDirectory() + "/" + MOD_ID + ".json";
+
+        Gson gson = new Gson();
+
+        File configFile = new File(configPath);
+
+        if(!configFile.exists()) {
+            config = new AshConfig();
+            String result = gson.toJson(config);
+            try {
+                FileOutputStream out = new FileOutputStream(configFile, false);
+
+                out.write(result.getBytes());
+                out.flush();
+                out.close();
+
+            } catch (IOException ex) {
+                ex.printStackTrace();
+            }
+        }
+        else {
+
+            try {
+                config = gson.fromJson( new FileReader(configFile), AshConfig.class);
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+            finally {
+                config = (config == null? new AshConfig() : config);
+            }
+        }
+
+
         CommandRegistry.INSTANCE.register(false, serverCommandSourceCommandDispatcher -> serverCommandSourceCommandDispatcher.register(
                 ServerCommandManager.literal("toggleash")
                         .executes(context -> {
-                            showHUD = !showHUD;
+                            config.showHud = !config.showHud;
+                            config.saveConfig();
                             return 1;
                         })
         ));
+
+        CommandRegistry.INSTANCE.register(false, serverCommandSourceCommandDispatcher -> serverCommandSourceCommandDispatcher.register(
+                ServerCommandManager.literal("ashcolor")
+                        .then(ServerCommandManager.argument("r", IntegerArgumentType.integer())
+                                .then(ServerCommandManager.argument("g", IntegerArgumentType.integer())
+                                        .then(ServerCommandManager.argument("b", IntegerArgumentType.integer())
+                                            .executes(context -> {
+                                                int r = IntegerArgumentType.getInteger(context,"r");
+                                                int g = IntegerArgumentType.getInteger(context,"g");
+                                                int b = IntegerArgumentType.getInteger(context,"b");
+
+                                                config.hudColor = b + (g << 8) + (r << 16);
+                                                config.saveConfig();
+                                                return 1;
+                                }))))
+        ));
     }
 }

+ 2 - 2
src/main/java/com/umollu/ash/mixin/GameRendererMixin.java

@@ -19,12 +19,12 @@ public class GameRendererMixin {
 	public void render(float float_1, long long_1, boolean boolean_1, CallbackInfo info) {
 
 		MinecraftClient client = MinecraftClient.getInstance();
-		if(!client.options.debugEnabled && AshMod.showHUD) {
+		if(!client.options.debugEnabled && AshMod.config.showHud) {
 			BlockPos blockPos = new BlockPos(client.getCameraEntity().x, client.getCameraEntity().getBoundingBox().minY, client.getCameraEntity().z);
 			double scaleFactor = client.window.getScaleFactor();
 			GlStateManager.pushMatrix();
 			GlStateManager.scaled(1 * scaleFactor, 1 * scaleFactor, 1 * scaleFactor);
-			client.textRenderer.drawWithShadow(String.format("%d fps %d %d %d", MinecraftClient.getCurrentFps(), blockPos.getX(), blockPos.getY(), blockPos.getZ()), 5, 5, 0xeeeeee);
+			client.textRenderer.drawWithShadow(String.format("%d fps %d %d %d", MinecraftClient.getCurrentFps(), blockPos.getX(), blockPos.getY(), blockPos.getZ()), 5, 5, AshMod.config.hudColor);
 			GlStateManager.popMatrix();
 		}
 	}