mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-03 08:26:11 +00:00
Stream api additions
This commit is contained in:
parent
92f5783f35
commit
1496d0e482
@ -20,6 +20,7 @@ package com.volmit.iris.engine.stream;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.hunk.Hunk;
|
||||
import com.volmit.iris.engine.object.IrisStyledRange;
|
||||
import com.volmit.iris.engine.object.common.IRare;
|
||||
import com.volmit.iris.engine.stream.arithmetic.*;
|
||||
import com.volmit.iris.engine.stream.convert.*;
|
||||
@ -30,6 +31,7 @@ import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.function.Function2;
|
||||
import com.volmit.iris.util.function.Function3;
|
||||
import com.volmit.iris.util.function.Function4;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
@ -63,6 +65,21 @@ public interface ProceduralStream<T> extends ProceduralLayer, Interpolated<T> {
|
||||
return new FunctionStream<>(f, f2, helper);
|
||||
}
|
||||
|
||||
default ProceduralStream<Boolean> chance(double chance)
|
||||
{
|
||||
return of((x, z) -> getDouble(x, z) < chance, Interpolated.BOOLEAN);
|
||||
}
|
||||
|
||||
default ProceduralStream<Boolean> seededChance(RNG brng, long rootSeed, double chance)
|
||||
{
|
||||
RNG rng = brng.nextParallelRNG(rootSeed - 3995L);
|
||||
return of((x, z) -> {
|
||||
double ch = getDouble(x, z);
|
||||
rng.setSeed((long) (ch * Long.MAX_VALUE));
|
||||
return rng.chance(chance);
|
||||
}, Interpolated.BOOLEAN);
|
||||
}
|
||||
|
||||
default ProceduralStream<T> profile() {
|
||||
return profile(10);
|
||||
}
|
||||
@ -326,6 +343,20 @@ public interface ProceduralStream<T> extends ProceduralLayer, Interpolated<T> {
|
||||
return new SelectionStream<V>(this, rarityTypes);
|
||||
}
|
||||
|
||||
default <V> int countPossibilities(List<V> types, Function<V, IRare> loader) {
|
||||
KList<V> rarityTypes = new KList<>();
|
||||
int totalRarity = 0;
|
||||
for (V i : types) {
|
||||
totalRarity += IRare.get(loader.apply(i));
|
||||
}
|
||||
|
||||
for (V i : types) {
|
||||
rarityTypes.addMultiple(i, totalRarity / IRare.get(loader.apply(i)));
|
||||
}
|
||||
|
||||
return rarityTypes.size();
|
||||
}
|
||||
|
||||
default ProceduralStream<T> clamp(double min, double max) {
|
||||
return new ClampedStream<T>(this, min, max);
|
||||
}
|
||||
@ -334,6 +365,14 @@ public interface ProceduralStream<T> extends ProceduralLayer, Interpolated<T> {
|
||||
return new FittedStream<T>(this, min, max);
|
||||
}
|
||||
|
||||
default ProceduralStream<Double> style(RNG rng, IrisStyledRange range)
|
||||
{
|
||||
return ProceduralStream.of((x, z) -> {
|
||||
double d = getDouble(x, z);
|
||||
return range.get(rng,d, -d);
|
||||
}, Interpolated.DOUBLE);
|
||||
}
|
||||
|
||||
default ProceduralStream<T> fit(double inMin, double inMax, double min, double max) {
|
||||
return new FittedStream<T>(this, inMin, inMax, min, max);
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ public interface Interpolated<T> {
|
||||
Interpolated<KList<CaveResult>> CAVE_RESULTS = of((t) -> 0D, (t) -> null);
|
||||
Interpolated<RNG> RNG = of((t) -> 0D, (t) -> null);
|
||||
Interpolated<Double> DOUBLE = of((t) -> t, (t) -> t);
|
||||
Interpolated<Boolean> BOOLEAN = of((t) -> 0D, (t) -> false);
|
||||
Interpolated<Integer> INT = of(Double::valueOf, Double::intValue);
|
||||
Interpolated<Long> LONG = of(Double::valueOf, Double::longValue);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user