diff --git a/common/src/main/java/dev/schmarrn/lighty/api/LightyColors.java b/common/src/main/java/dev/schmarrn/lighty/api/LightyColors.java index 6c0fa44..5eaf780 100644 --- a/common/src/main/java/dev/schmarrn/lighty/api/LightyColors.java +++ b/common/src/main/java/dev/schmarrn/lighty/api/LightyColors.java @@ -64,12 +64,15 @@ public static int getARGB(int blockLightLevel, int skyLightLevel) { return LightyColors.getDangerARGB(); } - public static int getGrowthARGB(int blockLightLevel) { - if (blockLightLevel <= Config.getFarmGrowthThreshold()) { + public static int getGrowthARGB(int blockLightLevel, int skyLightLevel) { + // Equal to above the growth threshold crops always grow + if (blockLightLevel >= Config.getFarmGrowthThreshold()) return LightyColors.getSafeARGB(); + // Crops won't grow at night without artificial light + if (skyLightLevel > Config.getFarmUprootThreshold() || blockLightLevel > Config.getFarmUprootThreshold()) { return LightyColors.getWarningARGB(); } - - return LightyColors.getSafeARGB(); + // There is insufficient artificial and skylight here; crops will uproot themselves and can't be planted + return LightyColors.getDangerARGB(); } private LightyColors() {} diff --git a/common/src/main/java/dev/schmarrn/lighty/config/Config.java b/common/src/main/java/dev/schmarrn/lighty/config/Config.java index 30df355..97ccec0 100644 --- a/common/src/main/java/dev/schmarrn/lighty/config/Config.java +++ b/common/src/main/java/dev/schmarrn/lighty/config/Config.java @@ -33,6 +33,7 @@ public class Config { private static final String SKY_THRESHOLD = "lighty.sky_threshold"; private static final String BLOCK_THRESHOLD = "lighty.block_threshold"; private static final String FARM_GROWTH_THRESHOLD = "lighty.farm_growth_threshold"; + private static final String FARM_UPROOT_THRESHOLD = "lighty.farm_uproot_threshold"; private static final String OVERLAY_DISTANCE = "lighty.overlay_distance"; private static final String OVERLAY_BRIGHTNESS = "lighty.overlay_brightness"; private static final String SHOW_SAFE = "lighty.show_safe"; @@ -52,6 +53,7 @@ private Config() { properties.putIfAbsent(SKY_THRESHOLD, "0"); properties.putIfAbsent(BLOCK_THRESHOLD, "0"); properties.putIfAbsent(FARM_GROWTH_THRESHOLD, "9"); + properties.putIfAbsent(FARM_UPROOT_THRESHOLD, "7"); properties.putIfAbsent(OVERLAY_DISTANCE, "2"); properties.putIfAbsent(OVERLAY_BRIGHTNESS, "10"); properties.putIfAbsent(SHOW_SAFE, String.valueOf(true)); @@ -66,6 +68,7 @@ private Config() { properties.setProperty(SKY_THRESHOLD, "0"); properties.setProperty(BLOCK_THRESHOLD, "0"); properties.setProperty(FARM_GROWTH_THRESHOLD, "9"); + properties.setProperty(FARM_UPROOT_THRESHOLD, "7"); properties.setProperty(OVERLAY_DISTANCE, "2"); properties.setProperty(OVERLAY_BRIGHTNESS, "10"); properties.setProperty(SHOW_SAFE, String.valueOf(true)); @@ -100,6 +103,10 @@ public static int getFarmGrowthThreshold() { return Integer.parseInt(config.properties.getProperty(FARM_GROWTH_THRESHOLD, "9")); } + public static int getFarmUprootThreshold() { + return Integer.parseInt(config.properties.getProperty(FARM_UPROOT_THRESHOLD, "7")); + } + public static int getOverlayDistance() { return Integer.parseInt(config.properties.getProperty(OVERLAY_DISTANCE, "2")); } @@ -135,6 +142,11 @@ public static void setFarmGrowthThreshold(int i) { config.write(); } + public static void setFarmUprootThreshold(int i) { + config.properties.setProperty(FARM_UPROOT_THRESHOLD, String.valueOf(i)); + config.write(); + } + public static void setOverlayDistance(int i) { config.properties.setProperty(OVERLAY_DISTANCE, String.valueOf(i)); config.write(); diff --git a/common/src/main/java/dev/schmarrn/lighty/mode/FarmlandMode.java b/common/src/main/java/dev/schmarrn/lighty/mode/FarmlandMode.java index e5ef835..7b04e7a 100644 --- a/common/src/main/java/dev/schmarrn/lighty/mode/FarmlandMode.java +++ b/common/src/main/java/dev/schmarrn/lighty/mode/FarmlandMode.java @@ -31,7 +31,8 @@ public void compute(ClientLevel world, BlockPos pos, BufferBuilder builder) { } int blockLightLevel = world.getBrightness(LightLayer.BLOCK, posUp); - int color = LightyColors.getGrowthARGB(blockLightLevel); + int skyLightLevel = world.getBrightness(LightLayer.SKY, posUp); + int color = LightyColors.getGrowthARGB(blockLightLevel, skyLightLevel); double offset = LightyHelper.getOffset(blockState, pos, world); if (offset == -1f) { diff --git a/common/src/main/java/dev/schmarrn/lighty/ui/SettingsScreen.java b/common/src/main/java/dev/schmarrn/lighty/ui/SettingsScreen.java index b3e2e2f..0eb0d19 100644 --- a/common/src/main/java/dev/schmarrn/lighty/ui/SettingsScreen.java +++ b/common/src/main/java/dev/schmarrn/lighty/ui/SettingsScreen.java @@ -89,6 +89,15 @@ protected void init() { Config.getFarmGrowthThreshold(), Config::setFarmGrowthThreshold ), + new OptionInstance<>( + "lighty.options.farm_uproot_threshold", + object -> Tooltip.create(Component.translatable("lighty.options.farm_uproot_threshold.tooltip", object)), + (component, integer) -> Options.genericValueLabel(component, Component.literal(integer.toString())), + new OptionInstance.IntRange(0, 15), + Codec.intRange(0, 15), + Config.getFarmUprootThreshold(), + Config::setFarmUprootThreshold + ), OptionInstance.createBoolean( "lighty.options.show_safe", object -> Tooltip.create(Component.translatable("lighty.options.show_safe.tooltip", object)), diff --git a/common/src/main/resources/assets/lighty/lang/en_us.json b/common/src/main/resources/assets/lighty/lang/en_us.json index 5ff8e47..b3330d5 100644 --- a/common/src/main/resources/assets/lighty/lang/en_us.json +++ b/common/src/main/resources/assets/lighty/lang/en_us.json @@ -17,6 +17,8 @@ "lighty.options.block_threshold.tooltip": "If the block light level is less than or equal to %d, the overlay is red or orange, depending on the sky light level. Otherwise, it is green.", "lighty.options.farm_growth_threshold": "Farmland Growth Threshold", "lighty.options.farm_growth_threshold.tooltip": "If the block light level is less than or equal to %d, crops won't grow at night and the overlay is orange. Otherwise, it is green.", + "lighty.options.farm_uproot_threshold": "Farmland Uproot Threshold", + "lighty.options.farm_uproot_threshold.tooltip": "If the block light level is less than or equal to %d, crops will un-plant themselves at night and the overlay is red.", "lighty.options.sky_threshold": "Sky Threshold", "lighty.options.sky_threshold.tooltip": "If the block light level is below the value specified in 'Block Threshold' and the sky light level is less than or equal to %d, the overlay is red. Otherwise, it is orange.", "lighty.options.overlay_distance": "Overlay Distance",