import java.io.FileOutputStream;
import java.io.IOException;
import java.text.DecimalFormat;
-import java.util.Map;
import java.util.Properties;
@OnlyIn(Dist.CLIENT)
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
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);
}
}
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();
}