TerraForged/src/main/java/com/terraforged/util/RangeModifier.java
dags- b935b9ab81 - steppier steppes & plainier plains
- more tree types converted to poisson/context decorators
- more work on threadpool/batching
2020-05-15 22:21:13 +01:00

38 lines
917 B
Java

package com.terraforged.util;
public abstract class RangeModifier {
protected final float from;
protected final float to;
protected final float max;
private final float range;
public RangeModifier(float from, float max, boolean exclusive) {
this.from = from;
this.to = max;
this.max = exclusive ? 0 : 1;
this.range = Math.abs(max - from);
}
public float apply(float value) {
if (from < to) {
if (value <= from) {
return 0F;
}
if (value >= to) {
return max;
}
return (value - from) / range;
} else if (from > to) {
if (value <= to) {
return max;
}
if (value >= from) {
return 0F;
}
return 1 - ((value - to) / range);
}
return 0F;
}
}