Skip to content

Commit

Permalink
Add uproot values and light comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
Alveel committed Apr 2, 2024
1 parent 8e6d8d5 commit 36f9dc3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
11 changes: 7 additions & 4 deletions common/src/main/java/dev/schmarrn/lighty/api/LightyColors.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down
12 changes: 12 additions & 0 deletions common/src/main/java/dev/schmarrn/lighty/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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));
Expand All @@ -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));
Expand Down Expand Up @@ -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"));
}
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/lighty/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 36f9dc3

Please sign in to comment.