]> git.lizzy.rs Git - LightOverlay.git/commitdiff
3,3
authorUnknown <shekwancheung0528@gmail.com>
Tue, 30 Jul 2019 05:59:00 +0000 (13:59 +0800)
committerUnknown <shekwancheung0528@gmail.com>
Tue, 30 Jul 2019 05:59:00 +0000 (13:59 +0800)
build.gradle
src/main/java/me/shedaniel/lightoverlay/LightOverlay.java

index 1a190d4cb7ba52996ba9258298c970a1eeb3ca39..8ede9aaefb9a9d237f63485fbedf113d4fad8d23 100644 (file)
@@ -11,7 +11,7 @@ buildscript {
 apply plugin: 'net.minecraftforge.gradle'
 apply plugin: 'eclipse'
 
-version = "3.2"
+version = "3.3"
 group = "me.shedaniel" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
 archivesBaseName = "LightOverlay"
 
index c984b96e364384df85a1fe06f8b27bb3cbbc96f4..6f8520aec110181843099c8bf22713126e24590c 100644 (file)
@@ -42,7 +42,6 @@ import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.text.DecimalFormat;
-import java.util.Map;
 import java.util.Properties;
 
 @OnlyIn(Dist.CLIENT)
@@ -58,10 +57,11 @@ public class LightOverlay {
     private static final DecimalFormat FORMAT = new DecimalFormat("#.#");
     private static KeyBinding enableOverlay, increaseReach, decreaseReach, increaseLineWidth, decreaseLineWidth;
     private static boolean enabled = false;
-    private static int reach = 12;
+    private static int reach = 7;
     private static EntityType<Entity> testingEntityType;
     private static float lineWidth = 1.0F;
     private static File configFile = new File(new File(Minecraft.getInstance().gameDir, "config"), "lightoverlay.properties");
+    private static Color yellowColor = Color.yellow, redColor = Color.red;
     
     public LightOverlay() {
         // Load Config
@@ -190,7 +190,7 @@ public class LightOverlay {
                     CrossType type = LightOverlay.getCrossType(pos, world, playerEntity);
                     if (type != CrossType.NONE) {
                         VoxelShape shape = world.getBlockState(pos).getCollisionShape(world, pos);
-                        Color color = type == CrossType.RED ? Color.RED : Color.YELLOW;
+                        Color color = type == CrossType.RED ? redColor : yellowColor;
                         LightOverlay.renderCross(world, pos, color, playerEntity);
                     }
                 }
@@ -208,46 +208,64 @@ public class LightOverlay {
     
     private void loadConfig(File file) {
         try {
+            redColor = Color.red;
+            yellowColor = Color.yellow;
             if (!file.exists() || !file.canRead())
                 saveConfig(file);
             FileInputStream fis = new FileInputStream(file);
             Properties properties = new Properties();
             properties.load(fis);
             fis.close();
-            for(Map.Entry<Object, Object> entry : properties.entrySet()) {
-                if (entry.getKey() instanceof String && entry.getValue() instanceof String) {
-                    String key = (String) entry.getKey();
-                    String value = (String) entry.getValue();
-                    if (key.equals("reach")) {
-                        try {
-                            reach = Integer.valueOf(value);
-                        } catch (NumberFormatException e) {
-                            e.printStackTrace();
-                            reach = 12;
-                        }
-                    } else if (key.equals("lineWidth")) {
-                        try {
-                            lineWidth = Float.valueOf(value);
-                        } catch (NumberFormatException e) {
-                            e.printStackTrace();
-                            lineWidth = 1.0F;
-                        }
-                    }
-                }
+            reach = Integer.parseInt((String) properties.computeIfAbsent("reach", a -> "7"));
+            lineWidth = Float.valueOf((String) properties.computeIfAbsent("lineWidth", a -> "1"));
+            {
+                int r, g, b;
+                r = Integer.parseInt((String) properties.computeIfAbsent("yellowColorRed", a -> "255"));
+                g = Integer.parseInt((String) properties.computeIfAbsent("yellowColorGreen", a -> "255"));
+                b = Integer.parseInt((String) properties.computeIfAbsent("yellowColorBlue", a -> "0"));
+                yellowColor = new Color(r, g, b);
+            }
+            {
+                int r, g, b;
+                r = Integer.parseInt((String) properties.computeIfAbsent("redColorRed", a -> "255"));
+                g = Integer.parseInt((String) properties.computeIfAbsent("redColorGreen", a -> "0"));
+                b = Integer.parseInt((String) properties.computeIfAbsent("redColorBlue", a -> "0"));
+                redColor = new Color(r, g, b);
             }
             saveConfig(file);
         } catch (Exception e) {
             e.printStackTrace();
-            reach = 12;
+            reach = 7;
             lineWidth = 1.0F;
+            redColor = Color.red;
+            yellowColor = Color.yellow;
+            try {
+                saveConfig(file);
+            } catch (IOException ex) {
+                ex.printStackTrace();
+            }
         }
     }
     
     private void saveConfig(File file) throws IOException {
         FileOutputStream fos = new FileOutputStream(file, false);
+        fos.write("# Light Overlay Config".getBytes());
+        fos.write("\n".getBytes());
         fos.write(("reach=" + String.valueOf(reach)).getBytes());
         fos.write("\n".getBytes());
         fos.write(("lineWidth=" + FORMAT.format(lineWidth)).getBytes());
+        fos.write("\n".getBytes());
+        fos.write(("yellowColorRed=" + String.valueOf(yellowColor.getRed())).getBytes());
+        fos.write("\n".getBytes());
+        fos.write(("yellowColorGreen=" + String.valueOf(yellowColor.getGreen())).getBytes());
+        fos.write("\n".getBytes());
+        fos.write(("yellowColorBlue=" + String.valueOf(yellowColor.getBlue())).getBytes());
+        fos.write("\n".getBytes());
+        fos.write(("redColorRed=" + String.valueOf(redColor.getRed())).getBytes());
+        fos.write("\n".getBytes());
+        fos.write(("redColorGreen=" + String.valueOf(redColor.getGreen())).getBytes());
+        fos.write("\n".getBytes());
+        fos.write(("redColorBlue=" + String.valueOf(redColor.getBlue())).getBytes());
         fos.close();
     }