From: Unknown Date: Tue, 30 Jul 2019 05:59:00 +0000 (+0800) Subject: 3,3 X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=a93011d8301c1dca27f51477081a3c2513438cb6;p=LightOverlay.git 3,3 --- diff --git a/build.gradle b/build.gradle index 1a190d4..8ede9aa 100644 --- a/build.gradle +++ b/build.gradle @@ -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" diff --git a/src/main/java/me/shedaniel/lightoverlay/LightOverlay.java b/src/main/java/me/shedaniel/lightoverlay/LightOverlay.java index c984b96..6f8520a 100644 --- a/src/main/java/me/shedaniel/lightoverlay/LightOverlay.java +++ b/src/main/java/me/shedaniel/lightoverlay/LightOverlay.java @@ -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 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 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(); }