Restructure Packages (read commit description)

There are now three root packages
- Engine: Generator & JSON Scaffolding
- Core: Managers, Commands, NMS
- Util: Random utility packages
This commit is contained in:
Daniel Mills
2021-07-16 01:46:22 -04:00
parent eef548f6a1
commit c984eb9b8c
423 changed files with 1001 additions and 1977 deletions

View File

@@ -0,0 +1,69 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream;
import com.volmit.iris.util.KList;
public class ArraySignificance<T> implements Significance<T> {
private final KList<T> types;
private final KList<Double> significance;
private final T significant;
public ArraySignificance(KList<T> types, KList<Double> significance, T significant) {
this.types = types;
this.significance = significance;
this.significant = significant;
}
public ArraySignificance(KList<T> types, KList<Double> significance) {
this.types = types;
this.significance = significance;
double s = 0;
int v = 0;
for (int i = 0; i < significance.size(); i++) {
if (significance.get(i) > s) {
s = significance.get(i);
v = i;
}
}
significant = types.get(v);
}
@Override
public KList<T> getFactorTypes() {
return types;
}
@Override
public double getSignificance(T t) {
for (int i = 0; i < types.size(); i++) {
if (types.get(i).equals(t)) {
return significance.get(i);
}
}
return 0;
}
@Override
public T getMostSignificantType() {
return significant;
}
}

View File

@@ -0,0 +1,44 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class BasicLayer implements ProceduralLayer {
private final long seed;
private final double zoom;
private final double offsetX;
private final double offsetY;
private final double offsetZ;
public BasicLayer(long seed, double zoom) {
this(seed, zoom, 0D, 0D, 0D);
}
public BasicLayer(long seed) {
this(seed, 1D);
}
public BasicLayer() {
this(1337);
}
}

View File

@@ -0,0 +1,55 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream;
public abstract class BasicStream<T> extends BasicLayer implements ProceduralStream<T> {
private final ProceduralStream<T> source;
public BasicStream(ProceduralStream<T> source) {
super();
this.source = source;
}
public BasicStream() {
this(null);
}
@Override
public ProceduralStream<T> getTypedSource() {
return source;
}
@Override
public ProceduralStream<?> getSource() {
return getTypedSource();
}
@Override
public abstract T get(double x, double z);
@Override
public abstract T get(double x, double y, double z);
@Override
public abstract double toDouble(T t);
@Override
public abstract T fromDouble(double d);
}

View File

@@ -0,0 +1,31 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream;
public interface ProceduralLayer {
long getSeed();
double getOffsetX();
double getOffsetY();
double getOffsetZ();
double getZoom();
}

View File

@@ -0,0 +1,461 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream;
import com.volmit.iris.Iris;
import com.volmit.iris.engine.hunk.Hunk;
import com.volmit.iris.engine.stream.arithmetic.*;
import com.volmit.iris.engine.stream.convert.*;
import com.volmit.iris.engine.stream.interpolation.Interpolated;
import com.volmit.iris.engine.stream.sources.FunctionStream;
import com.volmit.iris.engine.stream.utility.*;
import com.volmit.iris.util.*;
import java.util.List;
import java.util.function.Function;
@SuppressWarnings("ALL")
public interface ProceduralStream<T> extends ProceduralLayer, Interpolated<T> {
static ProceduralStream<Double> ofDouble(Function2<Double, Double, Double> f) {
try {
return of(f, Interpolated.DOUBLE);
} catch (IncompatibleClassChangeError e) {
Iris.warn(f.toString());Iris.reportError(e);
e.printStackTrace();
return null;
}
}
static ProceduralStream<Double> ofDouble(Function3<Double, Double, Double, Double> f) {
return of(f, Interpolated.DOUBLE);
}
static <T> ProceduralStream<T> of(Function2<Double, Double, T> f, Interpolated<T> helper) {
return of(f, (x, y, z) -> f.apply(x, z), helper);
}
static <T> ProceduralStream<T> of(Function3<Double, Double, Double, T> f, Interpolated<T> helper) {
return of((x, z) -> f.apply(x, 0D, z), f, helper);
}
static <T> ProceduralStream<T> of(Function2<Double, Double, T> f, Function3<Double, Double, Double, T> f2, Interpolated<T> helper) {
return new FunctionStream<>(f, f2, helper);
}
default ProceduralStream<T> profile() {
return profile(10);
}
default ProceduralStream<T> profile(int memory) {
return new ProfiledStream<>(this, memory);
}
default ProceduralStream<T> onNull(T v) {
return new NullSafeStream<>(this, v);
}
default ProceduralStream<T> add(Function3<Double, Double, Double, Double> a) {
return new AddingStream<>(this, a);
}
default ProceduralStream<T> add(Function2<Double, Double, Double> a) {
return new AddingStream<>(this, a);
}
default ProceduralStream<T> add2D(Function2<Double, Double, Double> a) {
return new AddingStream<>(this, a);
}
default ProceduralStream<T> add(double a) {
return new AddingStream<>(this, a);
}
default ProceduralStream<T> blockToChunkCoords() {
return bitShiftCoordsRight(4);
}
default ProceduralStream<T> chunkToRegionCoords() {
return bitShiftCoordsRight(5);
}
default ProceduralStream<T> blockToRegionCoords() {
return blockToChunkCoords().chunkToRegionCoords();
}
default ProceduralStream<T> regionToBlockCoords() {
return regionToChunkCoords().chunkToBlockCoords();
}
default ProceduralStream<T> regionToChunkCoords() {
return bitShiftCoordsLeft(5);
}
default ProceduralStream<T> chunkToBlockCoords() {
return bitShiftCoordsLeft(4);
}
default ProceduralStream<T> bitShiftCoordsRight(int a) {
return new CoordinateBitShiftRightStream<>(this, a);
}
default ProceduralStream<T> synchronize() {
return new SynchronizedStream<>(this);
}
default ProceduralStream<T> semaphore(int permits) {
return new SemaphoreStream<>(this, permits);
}
default ProceduralStream<T> bitShiftCoordsLeft(int a) {
return new CoordinateBitShiftLeftStream<>(this, a);
}
default ProceduralStream<T> max(Function3<Double, Double, Double, Double> a) {
return new MaxingStream<>(this, a);
}
default ProceduralStream<T> max(Function2<Double, Double, Double> a) {
return new MaxingStream<>(this, a);
}
default ProceduralStream<T> slope() {
return slope(1);
}
default ProceduralStream<T> slope(int range) {
return new SlopeStream<>(this, range);
}
default ProceduralStream<T> max(double a) {
return new MaxingStream<>(this, a);
}
default ProceduralStream<T> min(Function3<Double, Double, Double, Double> a) {
return new MinningStream<>(this, a);
}
default ProceduralStream<T> min(Function2<Double, Double, Double> a) {
return new MinningStream<>(this, a);
}
default ProceduralStream<T> min(double a) {
return new MinningStream<>(this, a);
}
default ProceduralStream<T> subtract(Function3<Double, Double, Double, Double> a) {
return new SubtractingStream<>(this, a);
}
default ProceduralStream<T> subtract(Function2<Double, Double, Double> a) {
return new SubtractingStream<>(this, a);
}
default ProceduralStream<T> subtract(double a) {
return new SubtractingStream<>(this, a);
}
default ProceduralStream<T> multiply(Function3<Double, Double, Double, Double> a) {
return new MultiplyingStream<>(this, a);
}
default ProceduralStream<T> multiply(Function2<Double, Double, Double> a) {
return new MultiplyingStream<>(this, a);
}
default ProceduralStream<T> multiply(double a) {
return new MultiplyingStream<>(this, a);
}
default ProceduralStream<T> divide(Function3<Double, Double, Double, Double> a) {
return new DividingStream<>(this, a);
}
default ProceduralStream<T> divide(Function2<Double, Double, Double> a) {
return new DividingStream<>(this, a);
}
default ProceduralStream<T> divide(double a) {
return new DividingStream<>(this, a);
}
default ProceduralStream<T> modulo(Function3<Double, Double, Double, Double> a) {
return new ModuloStream<>(this, a);
}
default ProceduralStream<T> modulo(Function2<Double, Double, Double> a) {
return new ModuloStream<>(this, a);
}
default ProceduralStream<T> modulo(double a) {
return new ModuloStream<>(this, a);
}
default ProceduralStream<Integer> round() {
return new RoundingStream(this);
}
default ProceduralStream<Double> roundDouble() {
return new RoundingDoubleStream(this);
}
default ProceduralStream<Double> forceDouble() {
return new ForceDoubleStream(this);
}
default ProceduralStream<Significance<T>> significance(double radius, int checks) {
return new SignificanceStream<Significance<T>, T>(this, radius, checks);
}
default ProceduralStream<T> to3D() {
return new To3DStream<T>(this);
}
default ProceduralStream<T> cache2D(int maxSize) {
return new CachedStream2D<T>(this, maxSize);
}
default <V> ProceduralStream<V> convert(Function<T, V> converter) {
return new ConversionStream<T, V>(this, converter);
}
default <V> ProceduralStream<V> convertAware2D(Function3<T, Double, Double, V> converter) {
return new AwareConversionStream2D<T, V>(this, converter);
}
default <V> ProceduralStream<V> convertAware3D(Function4<T, Double, Double, Double, V> converter) {
return new AwareConversionStream3D<T, V>(this, converter);
}
default <V> ProceduralStream<V> convertCached(Function<T, V> converter) {
return new CachedConversionStream<T, V>(this, converter);
}
default ProceduralStream<T> offset(double x, double y, double z) {
return new OffsetStream<T>(this, x, y, z);
}
default ProceduralStream<T> offset(double x, double z) {
return new OffsetStream<T>(this, x, 0, z);
}
default ProceduralStream<T> zoom(double x, double y, double z) {
return new ZoomStream<T>(this, x, y, z);
}
default ProceduralStream<T> zoom(double x, double z) {
return new ZoomStream<T>(this, x, 1, z);
}
default ProceduralStream<T> zoom(double all) {
return new ZoomStream<T>(this, all, all, all);
}
default ProceduralStream<T> radial(double scale) {
return new RadialStream<>(this, scale);
}
default ProceduralStream<T> radial() {
return radial(1D);
}
default <V> ProceduralStream<V> select(V... types) {
return new SelectionStream<V>(this, types);
}
default <V> ProceduralStream<V> select(List<V> types) {
return new SelectionStream<V>(this, types);
}
@SuppressWarnings("unchecked")
default <V> ProceduralStream<V> selectRarity(V... types) {
KList<V> rarityTypes = new KList<>();
for (V i : types) {
rarityTypes.addMultiple(i, IRare.get(i));
}
return new SelectionStream<V>(this, rarityTypes);
}
default <V> ProceduralStream<V> selectRarity(List<V> types) {
KList<V> rarityTypes = new KList<>();
int totalRarity = 0;
for (V i : types) {
totalRarity += IRare.get(i);
}
for (V i : types) {
rarityTypes.addMultiple(i, totalRarity / IRare.get(i));
}
return new SelectionStream<V>(this, rarityTypes);
}
default <V> ProceduralStream<V> selectRarity(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 new SelectionStream<V>(this, rarityTypes);
}
default ProceduralStream<T> clamp(double min, double max) {
return new ClampedStream<T>(this, min, max);
}
default ProceduralStream<T> fit(double min, double max) {
return new FittedStream<T>(this, min, max);
}
default ProceduralStream<T> fit(double inMin, double inMax, double min, double max) {
return new FittedStream<T>(this, inMin, inMax, min, max);
}
default void fill(Hunk<T> h, double x, double y, double z, int parallelism) {
h.compute3D(parallelism, (xx, yy, zz, hh) -> hh.iterate((xv, yv, zv) -> hh.set(xv, yv, zv, get(xx + xv + x, yy + yv + y, zz + zv + z))));
}
default <V> void fill2D(Hunk<V> h, double x, double z, V v, int parallelism) {
h.compute2D(parallelism, (xx, __, zz, hh) ->
{
for (int i = 0; i < hh.getWidth(); i++) {
for (int k = 0; k < hh.getDepth(); k++) {
double n = getDouble(i + x + xx, k + z + zz);
for (int j = 0; j < Math.min(h.getHeight(), n); j++) {
hh.set(i, j, k, v);
}
}
}
});
}
default <V> void fill2D(Hunk<V> h, double x, double z, ProceduralStream<V> v, int parallelism) {
h.compute2D(parallelism, (xx, yy, zz, hh) ->
{
for (int i = 0; i < hh.getWidth(); i++) {
for (int k = 0; k < hh.getDepth(); k++) {
double n = getDouble(i + x + xx, k + z + zz);
for (int j = 0; j < Math.min(h.getHeight(), n); j++) {
hh.set(i, j, k, v.get(i + x + xx, j + yy, k + z + zz));
}
}
}
});
}
default <V> void fill2DYLocked(Hunk<V> h, double x, double z, V v, int parallelism) {
h.compute2D(parallelism, (xx, yy, zz, hh) ->
{
for (int i = 0; i < hh.getWidth(); i++) {
for (int k = 0; k < hh.getDepth(); k++) {
double n = getDouble(i + x + xx, k + z + zz);
for (int j = 0; j < Math.min(h.getHeight(), n); j++) {
hh.set(i, j, k, v);
}
}
}
});
}
default <V> void fill2DYLocked(Hunk<V> h, double x, double z, ProceduralStream<V> v, int parallelism) {
h.compute2D(parallelism, (xx, yy, zz, hh) ->
{
for (int i = 0; i < hh.getWidth(); i++) {
for (int k = 0; k < hh.getDepth(); k++) {
double n = getDouble(i + x + xx, k + z + zz);
for (int j = 0; j < Math.min(h.getHeight(), n); j++) {
hh.set(i, j, k, v.get(i + x + xx, k + z + zz));
}
}
}
});
}
default <V> void fill3D(Hunk<V> h, double x, int y, double z, V v, int parallelism) {
h.compute3D(parallelism, (xx, yy, zz, hh) -> hh.iterate((xv, yv, zv) ->
{
if (getDouble(xx + xv + x, yy + yv + y, zz + zv + z) > 0.5) {
hh.set(xv, yv, zv, v);
}
}));
}
default <V> void fill3D(Hunk<V> h, double x, int y, double z, ProceduralStream<V> v, int parallelism) {
h.compute3D(parallelism, (xx, yy, zz, hh) -> hh.iterate((xv, yv, zv) ->
{
if (getDouble(xx + xv + x, yy + yv + y, zz + zv + z) > 0.5) {
hh.set(xv, yv, zv, v.get(xx + xv + x, yy + yv + y, zz + zv + z));
}
}));
}
default void fill(Hunk<T> h, double x, double y, double z) {
fill(h, x, z, 4);
}
default <V> void fill2D(Hunk<V> h, double x, double z, V v) {
fill2D(h, x, z, v, 4);
}
default <V> void fill2D(Hunk<V> h, double x, double z, ProceduralStream<V> v) {
fill2D(h, x, z, v, 4);
}
default <V> void fill2DYLocked(Hunk<V> h, double x, double z, V v) {
fill2DYLocked(h, x, z, v, 4);
}
default <V> void fill2DYLocked(Hunk<V> h, double x, double z, ProceduralStream<V> v) {
fill2DYLocked(h, x, z, v, 4);
}
default <V> void fill3D(Hunk<V> h, double x, int y, double z, V v) {
fill3D(h, x, y, z, v, 4);
}
default <V> void fill3D(Hunk<V> h, double x, int y, double z, ProceduralStream<V> v) {
fill3D(h, x, y, z, v, 4);
}
default double getDouble(double x, double z) {
return toDouble(get(x, z));
}
default double getDouble(double x, double y, double z) {
return toDouble(get(x, y, z));
}
ProceduralStream<T> getTypedSource();
ProceduralStream<?> getSource();
T get(double x, double z);
T get(double x, double y, double z);
}

View File

@@ -0,0 +1,29 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream;
import com.volmit.iris.util.KList;
public interface Significance<T> {
KList<T> getFactorTypes();
double getSignificance(T t);
T getMostSignificantType();
}

View File

@@ -0,0 +1,62 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.arithmetic;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
import com.volmit.iris.util.Function2;
import com.volmit.iris.util.Function3;
public class AddingStream<T> extends BasicStream<T> {
private final Function3<Double, Double, Double, Double> add;
public AddingStream(ProceduralStream<T> stream, Function3<Double, Double, Double, Double> add) {
super(stream);
this.add = add;
}
public AddingStream(ProceduralStream<T> stream, Function2<Double, Double, Double> add) {
this(stream, (x, y, z) -> add.apply(x, z));
}
public AddingStream(ProceduralStream<T> stream, double add) {
this(stream, (x, y, z) -> add);
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
@Override
public T get(double x, double z) {
return fromDouble(add.apply(x, 0D, z) + getTypedSource().getDouble(x, z));
}
@Override
public T get(double x, double y, double z) {
return fromDouble(add.apply(x, y, z) + getTypedSource().getDouble(x, y, z));
}
}

View File

@@ -0,0 +1,58 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.arithmetic;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
public class ClampedStream<T> extends BasicStream<T> implements ProceduralStream<T> {
private final double min;
private final double max;
public ClampedStream(ProceduralStream<T> stream, double min, double max) {
super(stream);
this.min = min;
this.max = max;
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
private double clamp(double v) {
return Math.max(Math.min(v, max), min);
}
@Override
public T get(double x, double z) {
return fromDouble(clamp(getTypedSource().getDouble(x, z)));
}
@Override
public T get(double x, double y, double z) {
return fromDouble(clamp(getTypedSource().getDouble(x, y, z)));
}
}

View File

@@ -0,0 +1,52 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.arithmetic;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
public class CoordinateBitShiftLeftStream<T> extends BasicStream<T> implements ProceduralStream<T> {
private final int amount;
public CoordinateBitShiftLeftStream(ProceduralStream<T> stream, int amount) {
super(stream);
this.amount = amount;
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
@Override
public T get(double x, double z) {
return getTypedSource().get((int) x << amount, (int) z << amount);
}
@Override
public T get(double x, double y, double z) {
return getTypedSource().get((int) x << amount, (int) y << amount, (int) z << amount);
}
}

View File

@@ -0,0 +1,52 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.arithmetic;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
public class CoordinateBitShiftRightStream<T> extends BasicStream<T> implements ProceduralStream<T> {
private final int amount;
public CoordinateBitShiftRightStream(ProceduralStream<T> stream, int amount) {
super(stream);
this.amount = amount;
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
@Override
public T get(double x, double z) {
return getTypedSource().get((int) x >> amount, (int) z >> amount);
}
@Override
public T get(double x, double y, double z) {
return getTypedSource().get((int) x >> amount, (int) y >> amount, (int) z >> amount);
}
}

View File

@@ -0,0 +1,61 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.arithmetic;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
import com.volmit.iris.util.Function2;
import com.volmit.iris.util.Function3;
public class DividingStream<T> extends BasicStream<T> implements ProceduralStream<T> {
private final Function3<Double, Double, Double, Double> add;
public DividingStream(ProceduralStream<T> stream, Function3<Double, Double, Double, Double> add) {
super(stream);
this.add = add;
}
public DividingStream(ProceduralStream<T> stream, Function2<Double, Double, Double> add) {
this(stream, (x, y, z) -> add.apply(x, z));
}
public DividingStream(ProceduralStream<T> stream, double add) {
this(stream, (x, y, z) -> add);
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
@Override
public T get(double x, double z) {
return fromDouble(getTypedSource().getDouble(x, z) / add.apply(x, 0D, z));
}
@Override
public T get(double x, double y, double z) {
return fromDouble(getTypedSource().getDouble(x, y, z) / add.apply(x, y, z));
}
}

View File

@@ -0,0 +1,66 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.arithmetic;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
public class FittedStream<T> extends BasicStream<T> implements ProceduralStream<T> {
private final double min;
private final double max;
private final double inMin;
private final double inMax;
public FittedStream(ProceduralStream<T> stream, double inMin, double inMax, double min, double max) {
super(stream);
this.inMin = inMin;
this.inMax = inMax;
this.min = min;
this.max = max;
}
public FittedStream(ProceduralStream<T> stream, double min, double max) {
this(stream, 0, 1, min, max);
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
private double dlerp(double v) {
return min + ((max - min) * ((v - inMin) / (inMax - inMin)));
}
@Override
public T get(double x, double z) {
return fromDouble(dlerp(getTypedSource().getDouble(x, z)));
}
@Override
public T get(double x, double y, double z) {
return fromDouble(dlerp(getTypedSource().getDouble(x, y, z)));
}
}

View File

@@ -0,0 +1,62 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.arithmetic;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
import com.volmit.iris.util.Function2;
import com.volmit.iris.util.Function3;
public class MaxingStream<T> extends BasicStream<T> {
private final Function3<Double, Double, Double, Double> add;
public MaxingStream(ProceduralStream<T> stream, Function3<Double, Double, Double, Double> add) {
super(stream);
this.add = add;
}
public MaxingStream(ProceduralStream<T> stream, Function2<Double, Double, Double> add) {
this(stream, (x, y, z) -> add.apply(x, z));
}
public MaxingStream(ProceduralStream<T> stream, double add) {
this(stream, (x, y, z) -> add);
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
@Override
public T get(double x, double z) {
return fromDouble(Math.max(add.apply(x, 0D, z), getTypedSource().getDouble(x, z)));
}
@Override
public T get(double x, double y, double z) {
return fromDouble(Math.max(add.apply(x, y, z), getTypedSource().getDouble(x, y, z)));
}
}

View File

@@ -0,0 +1,62 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.arithmetic;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
import com.volmit.iris.util.Function2;
import com.volmit.iris.util.Function3;
public class MinningStream<T> extends BasicStream<T> {
private final Function3<Double, Double, Double, Double> add;
public MinningStream(ProceduralStream<T> stream, Function3<Double, Double, Double, Double> add) {
super(stream);
this.add = add;
}
public MinningStream(ProceduralStream<T> stream, Function2<Double, Double, Double> add) {
this(stream, (x, y, z) -> add.apply(x, z));
}
public MinningStream(ProceduralStream<T> stream, double add) {
this(stream, (x, y, z) -> add);
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
@Override
public T get(double x, double z) {
return fromDouble(Math.min(add.apply(x, 0D, z), getTypedSource().getDouble(x, z)));
}
@Override
public T get(double x, double y, double z) {
return fromDouble(Math.min(add.apply(x, y, z), getTypedSource().getDouble(x, y, z)));
}
}

View File

@@ -0,0 +1,61 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.arithmetic;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
import com.volmit.iris.util.Function2;
import com.volmit.iris.util.Function3;
public class ModuloStream<T> extends BasicStream<T> {
private final Function3<Double, Double, Double, Double> add;
public ModuloStream(ProceduralStream<T> stream, Function3<Double, Double, Double, Double> add) {
super(stream);
this.add = add;
}
public ModuloStream(ProceduralStream<T> stream, Function2<Double, Double, Double> add) {
this(stream, (x, y, z) -> add.apply(x, z));
}
public ModuloStream(ProceduralStream<T> stream, double add) {
this(stream, (x, y, z) -> add);
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
@Override
public T get(double x, double z) {
return fromDouble(getTypedSource().getDouble(x, z) % add.apply(x, 0D, z));
}
@Override
public T get(double x, double y, double z) {
return fromDouble(getTypedSource().getDouble(x, y, z) % add.apply(x, y, z));
}
}

View File

@@ -0,0 +1,61 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.arithmetic;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
import com.volmit.iris.util.Function2;
import com.volmit.iris.util.Function3;
public class MultiplyingStream<T> extends BasicStream<T> {
private final Function3<Double, Double, Double, Double> add;
public MultiplyingStream(ProceduralStream<T> stream, Function3<Double, Double, Double, Double> add) {
super(stream);
this.add = add;
}
public MultiplyingStream(ProceduralStream<T> stream, Function2<Double, Double, Double> add) {
this(stream, (x, y, z) -> add.apply(x, z));
}
public MultiplyingStream(ProceduralStream<T> stream, double add) {
this(stream, (x, y, z) -> add);
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
@Override
public T get(double x, double z) {
return fromDouble(getTypedSource().getDouble(x, z) * add.apply(x, 0D, z));
}
@Override
public T get(double x, double y, double z) {
return fromDouble(getTypedSource().getDouble(x, y, z) * add.apply(x, y, z));
}
}

View File

@@ -0,0 +1,56 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.arithmetic;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
public class OffsetStream<T> extends BasicStream<T> implements ProceduralStream<T> {
private final double ox;
private final double oy;
private final double oz;
public OffsetStream(ProceduralStream<T> stream, double x, double y, double z) {
super(stream);
this.ox = x;
this.oy = y;
this.oz = z;
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
@Override
public T get(double x, double z) {
return getTypedSource().get(x + ox, z + oz);
}
@Override
public T get(double x, double y, double z) {
return getTypedSource().get(x + ox, y + oy, z + oz);
}
}

View File

@@ -0,0 +1,60 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.arithmetic;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
public class RadialStream<T> extends BasicStream<T> implements ProceduralStream<T> {
private final double scale;
public RadialStream(ProceduralStream<T> stream) {
this(stream, 1D);
}
public RadialStream(ProceduralStream<T> stream, double scale) {
super(stream);
this.scale = scale;
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
private double radii(double v) {
return (v / (360D * scale)) % 360D;
}
@Override
public T get(double x, double z) {
return fromDouble(radii(getTypedSource().getDouble(x, z)));
}
@Override
public T get(double x, double y, double z) {
return fromDouble(radii(getTypedSource().getDouble(x, y, z)));
}
}

View File

@@ -0,0 +1,56 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.arithmetic;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
public class RoundingDoubleStream extends BasicStream<Double> {
private final ProceduralStream<?> stream;
public RoundingDoubleStream(ProceduralStream<?> stream) {
super();
this.stream = stream;
}
@Override
public double toDouble(Double t) {
return t;
}
@Override
public Double fromDouble(double d) {
return (double) Math.round(d);
}
private double round(double v) {
return Math.round(v);
}
@Override
public Double get(double x, double z) {
return round(stream.getDouble(x, z));
}
@Override
public Double get(double x, double y, double z) {
return round(stream.getDouble(x, y, z));
}
}

View File

@@ -0,0 +1,61 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.arithmetic;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
public class SlopeStream<T> extends BasicStream<T> {
private final int range;
public SlopeStream(ProceduralStream<T> stream, int range) {
super(stream);
this.range = range;
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
@Override
public T get(double x, double z) {
double height = getTypedSource().getDouble(x, z);
double dx = getTypedSource().getDouble(x + range, z) - height;
double dy = getTypedSource().getDouble(x, z + range) - height;
return fromDouble(Math.sqrt(dx * dx + dy * dy));
}
@Override
public T get(double x, double y, double z) {
double height = getTypedSource().getDouble(x, y, z);
double dx = getTypedSource().getDouble(x + range, y, z) - height;
double dy = getTypedSource().getDouble(x, y + range, z) - height;
double dz = getTypedSource().getDouble(x, y, z + range) - height;
return fromDouble(Math.cbrt((dx * dx) + (dy * dy) + (dz * dz)));
}
}

View File

@@ -0,0 +1,61 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.arithmetic;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
import com.volmit.iris.util.Function2;
import com.volmit.iris.util.Function3;
public class SubtractingStream<T> extends BasicStream<T> {
private final Function3<Double, Double, Double, Double> add;
public SubtractingStream(ProceduralStream<T> stream, Function3<Double, Double, Double, Double> add) {
super(stream);
this.add = add;
}
public SubtractingStream(ProceduralStream<T> stream, Function2<Double, Double, Double> add) {
this(stream, (x, y, z) -> add.apply(x, z));
}
public SubtractingStream(ProceduralStream<T> stream, double add) {
this(stream, (x, y, z) -> add);
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
@Override
public T get(double x, double z) {
return fromDouble(getTypedSource().getDouble(x, z) - add.apply(x, 0D, z));
}
@Override
public T get(double x, double y, double z) {
return fromDouble(getTypedSource().getDouble(x, y, z) - add.apply(x, y, z));
}
}

View File

@@ -0,0 +1,56 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.arithmetic;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
public class ZoomStream<T> extends BasicStream<T> {
private final double ox;
private final double oy;
private final double oz;
public ZoomStream(ProceduralStream<T> stream, double x, double y, double z) {
super(stream);
this.ox = x;
this.oy = y;
this.oz = z;
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
@Override
public T get(double x, double z) {
return getTypedSource().get(x / ox, z / oz);
}
@Override
public T get(double x, double y, double z) {
return getTypedSource().get(x / ox, y / oy, z / oz);
}
}

View File

@@ -0,0 +1,63 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.convert;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
import com.volmit.iris.util.Function3;
public class AwareConversionStream2D<T, V> extends BasicStream<V> {
private final ProceduralStream<T> stream;
private final Function3<T, Double, Double, V> converter;
public AwareConversionStream2D(ProceduralStream<T> stream, Function3<T, Double, Double, V> converter) {
super(null);
this.stream = stream;
this.converter = converter;
}
@Override
public double toDouble(V t) {
if (t instanceof Double) {
return (Double) t;
}
return 0;
}
@Override
public V fromDouble(double d) {
return null;
}
@Override
public ProceduralStream<?> getSource() {
return stream;
}
@Override
public V get(double x, double z) {
return converter.apply(stream.get(x, z), x, z);
}
@Override
public V get(double x, double y, double z) {
return converter.apply(stream.get(x, y, z), x, z);
}
}

View File

@@ -0,0 +1,65 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.convert;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
import com.volmit.iris.util.Function4;
public class AwareConversionStream3D<T, V> extends BasicStream<V> {
private final ProceduralStream<T> stream;
private final Function4<T, Double, Double, Double, V> converter;
public AwareConversionStream3D(ProceduralStream<T> stream, Function4<T, Double, Double, Double, V> converter) {
super(null);
this.stream = stream;
this.converter = converter;
}
@Override
public double toDouble(V t) {
if (t instanceof Double) {
return (Double) t;
}
return 0;
}
@Override
public V fromDouble(double d) {
return null;
}
@Override
public ProceduralStream<?> getSource() {
return stream;
}
@Override
public V get(double x, double z) {
return converter.apply(stream.get(x, z), x, 0D, z);
}
@Override
public V get(double x, double y, double z) {
return converter.apply(stream.get(x, y, z), x, y, z);
}
}

View File

@@ -0,0 +1,68 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.convert;
import com.volmit.iris.engine.stream.BasicLayer;
import com.volmit.iris.engine.stream.ProceduralStream;
import com.volmit.iris.util.KMap;
import java.util.function.Function;
public class CachedConversionStream<T, V> extends BasicLayer implements ProceduralStream<V> {
private final ProceduralStream<T> stream;
private final Function<T, V> converter;
private final KMap<T, V> cache;
public CachedConversionStream(ProceduralStream<T> stream, Function<T, V> converter) {
super();
this.stream = stream;
this.converter = converter;
cache = new KMap<>();
}
@Override
public double toDouble(V t) {
return 0;
}
@Override
public V fromDouble(double d) {
return null;
}
@Override
public ProceduralStream<V> getTypedSource() {
return null;
}
@Override
public ProceduralStream<?> getSource() {
return stream;
}
@Override
public V get(double x, double z) {
return cache.compute(stream.get(x, z), (k, v) -> v != null ? v : converter.apply(k));
}
@Override
public V get(double x, double y, double z) {
return cache.compute(stream.get(x, y, z), (k, v) -> v != null ? v : converter.apply(k));
}
}

View File

@@ -0,0 +1,69 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.convert;
import com.volmit.iris.engine.stream.BasicLayer;
import com.volmit.iris.engine.stream.ProceduralStream;
import java.util.function.Function;
public class ConversionStream<T, V> extends BasicLayer implements ProceduralStream<V> {
private final ProceduralStream<T> stream;
private final Function<T, V> converter;
public ConversionStream(ProceduralStream<T> stream, Function<T, V> converter) {
super();
this.stream = stream;
this.converter = converter;
}
@Override
public double toDouble(V t) {
if (t instanceof Double) {
return (Double) t;
}
return 0;
}
@Override
public V fromDouble(double d) {
return null;
}
@Override
public ProceduralStream<V> getTypedSource() {
return null;
}
@Override
public ProceduralStream<?> getSource() {
return null;
}
@Override
public V get(double x, double z) {
return converter.apply(stream.get(x, z));
}
@Override
public V get(double x, double y, double z) {
return converter.apply(stream.get(x, y, z));
}
}

View File

@@ -0,0 +1,51 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.convert;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
public class ForceDoubleStream extends BasicStream<Double> {
private ProceduralStream<?> stream;
public ForceDoubleStream(ProceduralStream<?> stream) {
super(null);
}
@Override
public double toDouble(Double t) {
return t;
}
@Override
public Double fromDouble(double d) {
return d;
}
@Override
public Double get(double x, double z) {
return stream.getDouble(x, z);
}
@Override
public Double get(double x, double y, double z) {
return stream.getDouble(x, y, z);
}
}

View File

@@ -0,0 +1,55 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.convert;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
public class RoundingStream extends BasicStream<Integer> {
private final ProceduralStream<?> stream;
public RoundingStream(ProceduralStream<?> stream) {
super();
this.stream = stream;
}
@Override
public double toDouble(Integer t) {
return t.doubleValue();
}
@Override
public Integer fromDouble(double d) {
return (int) Math.round(d);
}
private int round(double v) {
return (int) Math.round(v);
}
@Override
public Integer get(double x, double z) {
return round(stream.getDouble(x, z));
}
@Override
public Integer get(double x, double y, double z) {
return round(stream.getDouble(x, y, z));
}
}

View File

@@ -0,0 +1,69 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.convert;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
import java.util.List;
public class SelectionStream<T> extends BasicStream<T> {
private final ProceduralStream<Integer> stream;
private final T[] options;
public SelectionStream(ProceduralStream<?> stream, T[] options) {
super();
this.stream = stream.fit(0, options.length - 1).round();
this.options = options;
}
@SuppressWarnings("unchecked")
public SelectionStream(ProceduralStream<?> stream, List<T> options) {
this(stream, (T[]) options.toArray());
}
@Override
public double toDouble(T t) {
throw new UnsupportedOperationException();
}
@Override
public T fromDouble(double d) {
throw new UnsupportedOperationException();
}
@Override
public T get(double x, double z) {
if (options.length == 0) {
return null;
}
return options[stream.get(x, z)];
}
@Override
public T get(double x, double y, double z) {
if (options.length == 0) {
return null;
}
return options[stream.get(x, y, z)];
}
}

View File

@@ -0,0 +1,85 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.convert;
import com.volmit.iris.engine.stream.ArraySignificance;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
import com.volmit.iris.engine.stream.Significance;
import com.volmit.iris.util.KList;
public class SignificanceStream<K extends Significance<T>, T> extends BasicStream<K> {
private final ProceduralStream<T> stream;
private final double radius;
private final int checks;
public SignificanceStream(ProceduralStream<T> stream, double radius, int checks) {
super();
this.stream = stream;
this.radius = radius;
this.checks = checks;
}
@Override
public double toDouble(K t) {
return 0;
}
@Override
public K fromDouble(double d) {
return null;
}
@SuppressWarnings("unchecked")
@Override
public K get(double x, double z) {
KList<T> ke = new KList<>(8);
KList<Double> va = new KList<>(8);
double m = (360d / checks);
double v = 0;
for (int i = 0; i < 360; i += m) {
double sin = Math.sin(Math.toRadians(i));
double cos = Math.cos(Math.toRadians(i));
double cx = x + ((radius * cos) - (radius * sin));
double cz = z + ((radius * sin) + (radius * cos));
T t = stream.get(cx, cz);
if (ke.addIfMissing(t)) {
va.add(1D);
v++;
} else {
int ind = ke.indexOf(t);
va.set(ind, va.get(ind) + 1D);
}
}
for (int i = 0; i < va.size(); i++) {
va.set(i, va.get(i) / v);
}
return (K) new ArraySignificance<>(ke, va);
}
@Override
public K get(double x, double y, double z) {
return get(x, z);
}
}

View File

@@ -0,0 +1,48 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.convert;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
public class To3DStream<T> extends BasicStream<T> {
public To3DStream(ProceduralStream<T> stream) {
super(stream);
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
@Override
public T get(double x, double z) {
return getTypedSource().get(x, z);
}
@Override
public T get(double x, double y, double z) {
return getTypedSource().fromDouble(getTypedSource().getDouble(x, z) >= y ? 1D : 0D);
}
}

View File

@@ -0,0 +1,98 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.interpolation;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
import com.volmit.iris.util.IrisInterpolation;
public class BiHermiteStream<T> extends BasicStream<T> implements Interpolator<T> {
private final int rx;
private final int ry;
private final double tension;
private final double bias;
public BiHermiteStream(ProceduralStream<T> stream, int rx, int ry, double tension, double bias) {
super(stream);
this.rx = rx;
this.ry = ry;
this.tension = tension;
this.bias = bias;
}
public BiHermiteStream(ProceduralStream<T> stream, int rx, int ry) {
this(stream, rx, ry, 0.5, 0);
}
public T interpolate(double x, double y) {
int fx = (int) Math.floor(x / rx);
int fz = (int) Math.floor(y / ry);
int x0 = Math.round((fx - 1) * rx);
int z0 = Math.round((fz - 1) * ry);
int x1 = Math.round(fx * rx);
int z1 = Math.round(fz * ry);
int x2 = Math.round((fx + 1) * rx);
int z2 = Math.round((fz + 1) * ry);
int x3 = Math.round((fx + 2) * rx);
int z3 = Math.round((fz + 2) * ry);
double px = IrisInterpolation.rangeScale(0, 1, x1, x2, x);
double pz = IrisInterpolation.rangeScale(0, 1, z1, z2, y);
//@builder
return getTypedSource().fromDouble(IrisInterpolation.bihermite(
getTypedSource().getDouble(x0, z0),
getTypedSource().getDouble(x0, z1),
getTypedSource().getDouble(x0, z2),
getTypedSource().getDouble(x0, z3),
getTypedSource().getDouble(x1, z0),
getTypedSource().getDouble(x1, z1),
getTypedSource().getDouble(x1, z2),
getTypedSource().getDouble(x1, z3),
getTypedSource().getDouble(x2, z0),
getTypedSource().getDouble(x2, z1),
getTypedSource().getDouble(x2, z2),
getTypedSource().getDouble(x2, z3),
getTypedSource().getDouble(x3, z0),
getTypedSource().getDouble(x3, z1),
getTypedSource().getDouble(x3, z2),
getTypedSource().getDouble(x3, z3),
px, pz, tension, bias));
//@done
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
@Override
public T get(double x, double z) {
return interpolate(x, z);
}
@Override
public T get(double x, double y, double z) {
return interpolate(x, z);
}
}

View File

@@ -0,0 +1,68 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.interpolation;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
public class BiStarcastStream<T> extends BasicStream<T> implements Interpolator<T> {
private final int rad;
private final int checks;
public BiStarcastStream(ProceduralStream<T> stream, int rad, int checks) {
super(stream);
this.rad = rad;
this.checks = checks;
}
public T interpolate(double x, double y) {
double m = (360D / checks);
double v = 0;
for (int i = 0; i < 360; i += m) {
double sin = Math.sin(Math.toRadians(i));
double cos = Math.cos(Math.toRadians(i));
double cx = x + ((rad * cos) - (rad * sin));
double cz = y + ((rad * sin) + (rad * cos));
v += getTypedSource().getDouble(cx, cz);
}
return getTypedSource().fromDouble(v / checks);
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
@Override
public T get(double x, double z) {
return interpolate(x, z);
}
@Override
public T get(double x, double y, double z) {
return interpolate(x, z);
}
}

View File

@@ -0,0 +1,90 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.interpolation;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
import com.volmit.iris.util.IrisInterpolation;
public class BicubicStream<T> extends BasicStream<T> implements Interpolator<T> {
private final int rx;
private final int ry;
public BicubicStream(ProceduralStream<T> stream, int rx, int ry) {
super(stream);
this.rx = rx;
this.ry = ry;
}
public T interpolate(double x, double y) {
int fx = (int) Math.floor(x / rx);
int fz = (int) Math.floor(y / ry);
int x0 = Math.round((fx - 1) * rx);
int z0 = Math.round((fz - 1) * ry);
int x1 = Math.round(fx * rx);
int z1 = Math.round(fz * ry);
int x2 = Math.round((fx + 1) * rx);
int z2 = Math.round((fz + 1) * ry);
int x3 = Math.round((fx + 2) * rx);
int z3 = Math.round((fz + 2) * ry);
double px = IrisInterpolation.rangeScale(0, 1, x1, x2, x);
double pz = IrisInterpolation.rangeScale(0, 1, z1, z2, y);
//@builder
return getTypedSource().fromDouble(IrisInterpolation.bicubic(
getTypedSource().getDouble(x0, z0),
getTypedSource().getDouble(x0, z1),
getTypedSource().getDouble(x0, z2),
getTypedSource().getDouble(x0, z3),
getTypedSource().getDouble(x1, z0),
getTypedSource().getDouble(x1, z1),
getTypedSource().getDouble(x1, z2),
getTypedSource().getDouble(x1, z3),
getTypedSource().getDouble(x2, z0),
getTypedSource().getDouble(x2, z1),
getTypedSource().getDouble(x2, z2),
getTypedSource().getDouble(x2, z3),
getTypedSource().getDouble(x3, z0),
getTypedSource().getDouble(x3, z1),
getTypedSource().getDouble(x3, z2),
getTypedSource().getDouble(x3, z3),
px, pz));
//@done
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
@Override
public T get(double x, double z) {
return interpolate(x, z);
}
@Override
public T get(double x, double y, double z) {
return interpolate(x, z);
}
}

View File

@@ -0,0 +1,74 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.interpolation;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
import com.volmit.iris.util.IrisInterpolation;
public class BilinearStream<T> extends BasicStream<T> implements Interpolator<T> {
private final int rx;
private final int ry;
public BilinearStream(ProceduralStream<T> stream, int rx, int ry) {
super(stream);
this.rx = rx;
this.ry = ry;
}
public T interpolate(double x, double y) {
int fx = (int) Math.floor(x / rx);
int fz = (int) Math.floor(y / ry);
int x1 = Math.round(fx * rx);
int z1 = Math.round(fz * ry);
int x2 = Math.round((fx + 1) * rx);
int z2 = Math.round((fz + 1) * ry);
double px = IrisInterpolation.rangeScale(0, 1, x1, x2, x);
double pz = IrisInterpolation.rangeScale(0, 1, z1, z2, y);
//@builder
return getTypedSource().fromDouble(IrisInterpolation.blerp(
getTypedSource().getDouble(x1, z1),
getTypedSource().getDouble(x2, z1),
getTypedSource().getDouble(x1, z2),
getTypedSource().getDouble(x2, z2),
px, pz));
//@done
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
@Override
public T get(double x, double z) {
return interpolate(x, z);
}
@Override
public T get(double x, double y, double z) {
return interpolate(x, z);
}
}

View File

@@ -0,0 +1,62 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.interpolation;
import com.volmit.iris.engine.stream.ProceduralStream;
import com.volmit.iris.util.CaveResult;
import com.volmit.iris.util.KList;
import com.volmit.iris.util.RNG;
import org.bukkit.block.data.BlockData;
import java.util.function.Function;
public interface Interpolated<T> {
Interpolated<BlockData> BLOCK_DATA = of((t) -> 0D, (t) -> null);
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<Integer> INT = of(Double::valueOf, Double::intValue);
Interpolated<Long> LONG = of(Double::valueOf, Double::longValue);
double toDouble(T t);
T fromDouble(double d);
default InterpolatorFactory<T> interpolate() {
if (this instanceof ProceduralStream) {
return new InterpolatorFactory<>((ProceduralStream<T>) this);
}
return null;
}
static <T> Interpolated<T> of(Function<T, Double> a, Function<Double, T> b) {
return new Interpolated<>() {
@Override
public double toDouble(T t) {
return a.apply(t);
}
@Override
public T fromDouble(double d) {
return b.apply(d);
}
};
}
}

View File

@@ -0,0 +1,62 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.interpolation;
import com.volmit.iris.object.InterpolationMethod;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
import com.volmit.iris.util.IrisInterpolation;
import com.volmit.iris.util.NoiseProvider;
public class InterpolatingStream<T> extends BasicStream<T> implements Interpolator<T> {
private final InterpolationMethod type;
private final NoiseProvider np;
private final int rx;
public InterpolatingStream(ProceduralStream<T> stream, int rx, InterpolationMethod type) {
super(stream);
this.type = type;
this.rx = rx;
this.np = (xf, zf) -> getTypedSource().getDouble(xf, zf);
}
public T interpolate(double x, double y) {
return fromDouble(IrisInterpolation.getNoise(type, (int) x, (int) y, rx, np));
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
@Override
public T get(double x, double z) {
return interpolate(x, z);
}
@Override
public T get(double x, double y, double z) {
return interpolate(x, z);
}
}

View File

@@ -0,0 +1,32 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.interpolation;
import com.volmit.iris.engine.stream.ProceduralStream;
public interface Interpolator<T> {
@SuppressWarnings("unchecked")
default InterpolatorFactory<T> into() {
if (this instanceof ProceduralStream) {
return new InterpolatorFactory<>((ProceduralStream<T>) this);
}
return null;
}
}

View File

@@ -0,0 +1,107 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.interpolation;
import com.volmit.iris.object.InterpolationMethod;
import com.volmit.iris.engine.stream.ProceduralStream;
@SuppressWarnings("ClassCanBeRecord")
public class InterpolatorFactory<T> {
private final ProceduralStream<T> stream;
public InterpolatorFactory(ProceduralStream<T> stream) {
this.stream = stream;
}
public InterpolatingStream<T> with(InterpolationMethod t, int rx) {
return new InterpolatingStream<>(stream, rx, t);
}
public TrilinearStream<T> trilinear(int rx, int ry, int rz) {
return new TrilinearStream<>(stream, rx, ry, rz);
}
public TricubicStream<T> tricubic(int rx, int ry, int rz) {
return new TricubicStream<>(stream, rx, ry, rz);
}
public BicubicStream<T> bicubic(int rx, int ry) {
return new BicubicStream<>(stream, rx, ry);
}
public BicubicStream<T> bicubic(int r) {
return bicubic(r, r);
}
public BilinearStream<T> bilinear(int rx, int ry) {
return new BilinearStream<>(stream, rx, ry);
}
public BilinearStream<T> bilinear(int r) {
return bilinear(r, r);
}
public TriStarcastStream<T> tristarcast(int radius, int checks) {
return new TriStarcastStream<>(stream, radius, checks);
}
public TriStarcastStream<T> tristarcast3(int radius) {
return tristarcast(radius, 3);
}
public TriStarcastStream<T> tristarcast6(int radius) {
return tristarcast(radius, 6);
}
public TriStarcastStream<T> tristarcast9(int radius) {
return tristarcast(radius, 9);
}
public BiStarcastStream<T> bistarcast(int radius, int checks) {
return new BiStarcastStream<>(stream, radius, checks);
}
public BiStarcastStream<T> bistarcast3(int radius) {
return bistarcast(radius, 3);
}
public BiStarcastStream<T> bistarcast6(int radius) {
return bistarcast(radius, 6);
}
public BiStarcastStream<T> bistarcast9(int radius) {
return bistarcast(radius, 9);
}
public BiHermiteStream<T> bihermite(int rx, int ry, double tension, double bias) {
return new BiHermiteStream<>(stream, rx, ry, tension, bias);
}
public BiHermiteStream<T> bihermite(int rx, int ry) {
return new BiHermiteStream<>(stream, rx, ry);
}
public BiHermiteStream<T> bihermite(int r) {
return bihermite(r, r);
}
public BiHermiteStream<T> bihermite(int r, double tension, double bias) {
return bihermite(r, r, tension, bias);
}
}

View File

@@ -0,0 +1,150 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.interpolation;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
import com.volmit.iris.util.IrisInterpolation;
public class TriHermiteStream<T> extends BasicStream<T> implements Interpolator<T> {
private final int rx;
private final int ry;
private final int rz;
private final double tension;
private final double bias;
public TriHermiteStream(ProceduralStream<T> stream, int rx, int ry, int rz, double tension, double bias) {
super(stream);
this.rx = rx;
this.ry = ry;
this.rz = rz;
this.tension = tension;
this.bias = bias;
}
public T interpolate(double x, double y, double z) {
int fx = (int) Math.floor(x / rx);
int fy = (int) Math.floor(y / ry);
int fz = (int) Math.floor(z / rz);
int x0 = Math.round((fx - 1) * rx);
int y0 = Math.round((fy - 1) * ry);
int z0 = Math.round((fz - 1) * rz);
int x1 = Math.round(fx * rx);
int y1 = Math.round(fy * ry);
int z1 = Math.round(fz * rz);
int x2 = Math.round((fx + 1) * rx);
int y2 = Math.round((fy + 1) * ry);
int z2 = Math.round((fz + 1) * rz);
int x3 = Math.round((fx + 2) * rx);
int y3 = Math.round((fy + 2) * ry);
int z3 = Math.round((fz + 2) * rz);
double px = IrisInterpolation.rangeScale(0, 1, x1, x2, x);
double py = IrisInterpolation.rangeScale(0, 1, y1, y2, y);
double pz = IrisInterpolation.rangeScale(0, 1, z1, z2, z);
//@builder
return getTypedSource().fromDouble(IrisInterpolation.trihermite(
getTypedSource().getDouble(x0, y0, z0),
getTypedSource().getDouble(x0, y0, z1),
getTypedSource().getDouble(x0, y0, z2),
getTypedSource().getDouble(x0, y0, z3),
getTypedSource().getDouble(x1, y0, z0),
getTypedSource().getDouble(x1, y0, z1),
getTypedSource().getDouble(x1, y0, z2),
getTypedSource().getDouble(x1, y0, z3),
getTypedSource().getDouble(x2, y0, z0),
getTypedSource().getDouble(x2, y0, z1),
getTypedSource().getDouble(x2, y0, z2),
getTypedSource().getDouble(x2, y0, z3),
getTypedSource().getDouble(x3, y0, z0),
getTypedSource().getDouble(x3, y0, z1),
getTypedSource().getDouble(x3, y0, z2),
getTypedSource().getDouble(x3, y0, z3),
getTypedSource().getDouble(x0, y1, z0),
getTypedSource().getDouble(x0, y1, z1),
getTypedSource().getDouble(x0, y1, z2),
getTypedSource().getDouble(x0, y1, z3),
getTypedSource().getDouble(x1, y1, z0),
getTypedSource().getDouble(x1, y1, z1),
getTypedSource().getDouble(x1, y1, z2),
getTypedSource().getDouble(x1, y1, z3),
getTypedSource().getDouble(x2, y1, z0),
getTypedSource().getDouble(x2, y1, z1),
getTypedSource().getDouble(x2, y1, z2),
getTypedSource().getDouble(x2, y1, z3),
getTypedSource().getDouble(x3, y1, z0),
getTypedSource().getDouble(x3, y1, z1),
getTypedSource().getDouble(x3, y1, z2),
getTypedSource().getDouble(x3, y1, z3),
getTypedSource().getDouble(x0, y2, z0),
getTypedSource().getDouble(x0, y2, z1),
getTypedSource().getDouble(x0, y2, z2),
getTypedSource().getDouble(x0, y2, z3),
getTypedSource().getDouble(x1, y2, z0),
getTypedSource().getDouble(x1, y2, z1),
getTypedSource().getDouble(x1, y2, z2),
getTypedSource().getDouble(x1, y2, z3),
getTypedSource().getDouble(x2, y2, z0),
getTypedSource().getDouble(x2, y2, z1),
getTypedSource().getDouble(x2, y2, z2),
getTypedSource().getDouble(x2, y2, z3),
getTypedSource().getDouble(x3, y2, z0),
getTypedSource().getDouble(x3, y2, z1),
getTypedSource().getDouble(x3, y2, z2),
getTypedSource().getDouble(x3, y2, z3),
getTypedSource().getDouble(x0, y3, z0),
getTypedSource().getDouble(x0, y3, z1),
getTypedSource().getDouble(x0, y3, z2),
getTypedSource().getDouble(x0, y3, z3),
getTypedSource().getDouble(x1, y3, z0),
getTypedSource().getDouble(x1, y3, z1),
getTypedSource().getDouble(x1, y3, z2),
getTypedSource().getDouble(x1, y3, z3),
getTypedSource().getDouble(x2, y3, z0),
getTypedSource().getDouble(x2, y3, z1),
getTypedSource().getDouble(x2, y3, z2),
getTypedSource().getDouble(x2, y3, z3),
getTypedSource().getDouble(x3, y3, z0),
getTypedSource().getDouble(x3, y3, z1),
getTypedSource().getDouble(x3, y3, z2),
getTypedSource().getDouble(x3, y3, z3),
px, pz, py, tension, bias));
//@done
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
@Override
public T get(double x, double z) {
return interpolate(x, 0, z);
}
@Override
public T get(double x, double y, double z) {
return interpolate(x, y, z);
}
}

View File

@@ -0,0 +1,69 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.interpolation;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
public class TriStarcastStream<T> extends BasicStream<T> implements Interpolator<T> {
private final int rad;
private final int checks;
public TriStarcastStream(ProceduralStream<T> stream, int rad, int checks) {
super(stream);
this.rad = rad;
this.checks = checks;
}
public T interpolate(double x, double y, double z) {
double m = (360D / checks);
double v = 0;
for (int i = 0; i < 360; i += m) {
double sin = Math.sin(Math.toRadians(i));
double cos = Math.cos(Math.toRadians(i));
double cx = x + ((rad * cos) - (rad * sin));
double cy = y + ((rad * sin) + (rad * cos));
double cz = z + ((rad * cos) - (rad * sin));
v += getTypedSource().getDouble(cx, cy, cz);
}
return getTypedSource().fromDouble(v / checks);
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
@Override
public T get(double x, double z) {
return interpolate(x, 0, z);
}
@Override
public T get(double x, double y, double z) {
return interpolate(x, y, z);
}
}

View File

@@ -0,0 +1,149 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.interpolation;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
import com.volmit.iris.util.IrisInterpolation;
public class TricubicStream<T> extends BasicStream<T> implements Interpolator<T> {
private final int rx;
private final int ry;
private final int rz;
public TricubicStream(ProceduralStream<T> stream, int rx, int ry, int rz) {
super(stream);
this.rx = rx;
this.ry = ry;
this.rz = rz;
}
public T interpolate(double x, double y, double z) {
int fx = (int) Math.floor(x / rx);
int fy = (int) Math.floor(y / ry);
int fz = (int) Math.floor(z / rz);
int x0 = Math.round((fx - 1) * rx);
int y0 = Math.round((fy - 1) * ry);
int z0 = Math.round((fz - 1) * rz);
int x1 = Math.round(fx * rx);
int y1 = Math.round(fy * ry);
int z1 = Math.round(fz * rz);
int x2 = Math.round((fx + 1) * rx);
int y2 = Math.round((fy + 1) * ry);
int z2 = Math.round((fz + 1) * rz);
int x3 = Math.round((fx + 2) * rx);
int y3 = Math.round((fy + 2) * ry);
int z3 = Math.round((fz + 2) * rz);
double px = IrisInterpolation.rangeScale(0, 1, x1, x2, x);
double py = IrisInterpolation.rangeScale(0, 1, y1, y2, y);
double pz = IrisInterpolation.rangeScale(0, 1, z1, z2, z);
//@builder
return getTypedSource().fromDouble(IrisInterpolation.tricubic(
getTypedSource().getDouble(x0, y0, z0),
getTypedSource().getDouble(x0, y0, z1),
getTypedSource().getDouble(x0, y0, z2),
getTypedSource().getDouble(x0, y0, z3),
getTypedSource().getDouble(x1, y0, z0),
getTypedSource().getDouble(x1, y0, z1),
getTypedSource().getDouble(x1, y0, z2),
getTypedSource().getDouble(x1, y0, z3),
getTypedSource().getDouble(x2, y0, z0),
getTypedSource().getDouble(x2, y0, z1),
getTypedSource().getDouble(x2, y0, z2),
getTypedSource().getDouble(x2, y0, z3),
getTypedSource().getDouble(x3, y0, z0),
getTypedSource().getDouble(x3, y0, z1),
getTypedSource().getDouble(x3, y0, z2),
getTypedSource().getDouble(x3, y0, z3),
getTypedSource().getDouble(x0, y1, z0),
getTypedSource().getDouble(x0, y1, z1),
getTypedSource().getDouble(x0, y1, z2),
getTypedSource().getDouble(x0, y1, z3),
getTypedSource().getDouble(x1, y1, z0),
getTypedSource().getDouble(x1, y1, z1),
getTypedSource().getDouble(x1, y1, z2),
getTypedSource().getDouble(x1, y1, z3),
getTypedSource().getDouble(x2, y1, z0),
getTypedSource().getDouble(x2, y1, z1),
getTypedSource().getDouble(x2, y1, z2),
getTypedSource().getDouble(x2, y1, z3),
getTypedSource().getDouble(x3, y1, z0),
getTypedSource().getDouble(x3, y1, z1),
getTypedSource().getDouble(x3, y1, z2),
getTypedSource().getDouble(x3, y1, z3),
getTypedSource().getDouble(x0, y2, z0),
getTypedSource().getDouble(x0, y2, z1),
getTypedSource().getDouble(x0, y2, z2),
getTypedSource().getDouble(x0, y2, z3),
getTypedSource().getDouble(x1, y2, z0),
getTypedSource().getDouble(x1, y2, z1),
getTypedSource().getDouble(x1, y2, z2),
getTypedSource().getDouble(x1, y2, z3),
getTypedSource().getDouble(x2, y2, z0),
getTypedSource().getDouble(x2, y2, z1),
getTypedSource().getDouble(x2, y2, z2),
getTypedSource().getDouble(x2, y2, z3),
getTypedSource().getDouble(x3, y2, z0),
getTypedSource().getDouble(x3, y2, z1),
getTypedSource().getDouble(x3, y2, z2),
getTypedSource().getDouble(x3, y2, z3),
getTypedSource().getDouble(x0, y3, z0),
getTypedSource().getDouble(x0, y3, z1),
getTypedSource().getDouble(x0, y3, z2),
getTypedSource().getDouble(x0, y3, z3),
getTypedSource().getDouble(x1, y3, z0),
getTypedSource().getDouble(x1, y3, z1),
getTypedSource().getDouble(x1, y3, z2),
getTypedSource().getDouble(x1, y3, z3),
getTypedSource().getDouble(x2, y3, z0),
getTypedSource().getDouble(x2, y3, z1),
getTypedSource().getDouble(x2, y3, z2),
getTypedSource().getDouble(x2, y3, z3),
getTypedSource().getDouble(x3, y3, z0),
getTypedSource().getDouble(x3, y3, z1),
getTypedSource().getDouble(x3, y3, z2),
getTypedSource().getDouble(x3, y3, z3),
px, pz, py));
//@done
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
@Override
public T get(double x, double z) {
return interpolate(x, 0, z);
}
@Override
public T get(double x, double y, double z) {
return interpolate(x, y, z);
}
}

View File

@@ -0,0 +1,84 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.interpolation;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
import com.volmit.iris.util.IrisInterpolation;
public class TrilinearStream<T> extends BasicStream<T> implements Interpolator<T> {
private final int rx;
private final int ry;
private final int rz;
public TrilinearStream(ProceduralStream<T> stream, int rx, int ry, int rz) {
super(stream);
this.rx = rx;
this.ry = ry;
this.rz = rz;
}
public T interpolate(double x, double y, double z) {
int fx = (int) Math.floor(x / rx);
int fy = (int) Math.floor(y / ry);
int fz = (int) Math.floor(z / rz);
int x1 = Math.round(fx * rx);
int y1 = Math.round(fy * ry);
int z1 = Math.round(fz * rz);
int x2 = Math.round((fx + 1) * rx);
int y2 = Math.round((fy + 1) * ry);
int z2 = Math.round((fz + 1) * rz);
double px = IrisInterpolation.rangeScale(0, 1, x1, x2, x);
double py = IrisInterpolation.rangeScale(0, 1, y1, y2, y);
double pz = IrisInterpolation.rangeScale(0, 1, z1, z2, z);
//@builder
return getTypedSource().fromDouble(IrisInterpolation.trilerp(
getTypedSource().getDouble(x1, y1, z1),
getTypedSource().getDouble(x2, y1, z1),
getTypedSource().getDouble(x1, y1, z2),
getTypedSource().getDouble(x2, y1, z2),
getTypedSource().getDouble(x1, y2, z1),
getTypedSource().getDouble(x2, y2, z1),
getTypedSource().getDouble(x1, y2, z2),
getTypedSource().getDouble(x2, y2, z2),
px, pz, py));
//@done
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
@Override
public T get(double x, double z) {
return interpolate(x, 0, z);
}
@Override
public T get(double x, double y, double z) {
return interpolate(x, y, z);
}
}

View File

@@ -0,0 +1,72 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.sources;
import com.volmit.iris.engine.noise.CNG;
import com.volmit.iris.engine.stream.BasicLayer;
import com.volmit.iris.engine.stream.ProceduralStream;
public class CNGStream extends BasicLayer implements ProceduralStream<Double> {
private final CNG cng;
public CNGStream(CNG cng) {
this.cng = cng;
}
public CNGStream(CNG cng, double zoom, double offsetX, double offsetY, double offsetZ) {
super(1337, zoom, offsetX, offsetY, offsetZ);
this.cng = cng;
}
public CNGStream(CNG cng, double zoom) {
super(1337, zoom);
this.cng = cng;
}
@Override
public double toDouble(Double t) {
return t;
}
@Override
public Double fromDouble(double d) {
return d;
}
@Override
public ProceduralStream<Double> getTypedSource() {
return null;
}
@Override
public ProceduralStream<?> getSource() {
return null;
}
@Override
public Double get(double x, double z) {
return cng.noise((x + getOffsetX()) / getZoom(), (z + getOffsetZ()) / getZoom());
}
@Override
public Double get(double x, double y, double z) {
return cng.noise((x + getOffsetX()) / getZoom(), (y + getOffsetY()) / getZoom(), (z + getOffsetZ()) * getZoom());
}
}

View File

@@ -0,0 +1,57 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.sources;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.interpolation.Interpolated;
import com.volmit.iris.util.Function2;
import com.volmit.iris.util.Function3;
public class FunctionStream<T> extends BasicStream<T> {
private final Function2<Double, Double, T> f2;
private final Function3<Double, Double, Double, T> f3;
private final Interpolated<T> helper;
public FunctionStream(Function2<Double, Double, T> f2, Function3<Double, Double, Double, T> f3, Interpolated<T> helper) {
super();
this.f2 = f2;
this.f3 = f3;
this.helper = helper;
}
@Override
public double toDouble(T t) {
return helper.toDouble(t);
}
@Override
public T fromDouble(double d) {
return helper.fromDouble(d);
}
@Override
public T get(double x, double z) {
return f2.apply(x, z);
}
@Override
public T get(double x, double y, double z) {
return f3.apply(x, y, z);
}
}

View File

@@ -0,0 +1,59 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.utility;
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
import com.volmit.iris.engine.cache.Cache;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
public class CachedStream2D<T> extends BasicStream<T> implements ProceduralStream<T> {
private final ProceduralStream<T> stream;
private final ConcurrentLinkedHashMap<Long, T> cache;
public CachedStream2D(ProceduralStream<T> stream, int size) {
super();
this.stream = stream;
cache = new ConcurrentLinkedHashMap.Builder<Long, T>()
.initialCapacity(size)
.maximumWeightedCapacity(size)
.concurrencyLevel(32)
.build();
}
@Override
public double toDouble(T t) {
return stream.toDouble(t);
}
@Override
public T fromDouble(double d) {
return stream.fromDouble(d);
}
@Override
public T get(double x, double z) {
return cache.compute(Cache.key((int) x, (int) z), (k, v) -> v != null ? v : stream.get((int) x, (int) z));
}
@Override
public T get(double x, double y, double z) {
return stream.get(x, y, z);
}
}

View File

@@ -0,0 +1,65 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.utility;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
public class NullSafeStream<T> extends BasicStream<T> implements ProceduralStream<T> {
private final ProceduralStream<T> stream;
private final T ifNull;
public NullSafeStream(ProceduralStream<T> stream, T ifNull) {
super();
this.stream = stream;
this.ifNull = ifNull;
}
@Override
public double toDouble(T t) {
return stream.toDouble(t);
}
@Override
public T fromDouble(double d) {
return stream.fromDouble(d);
}
@Override
public T get(double x, double z) {
T t = stream.get(x, z);
if (t == null) {
return ifNull;
}
return t;
}
@Override
public T get(double x, double y, double z) {
T t = stream.get(x, y, z);
if (t == null) {
return ifNull;
}
return t;
}
}

View File

@@ -0,0 +1,173 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.utility;
import com.volmit.iris.Iris;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
import com.volmit.iris.util.Form;
import com.volmit.iris.util.KList;
import com.volmit.iris.util.PrecisionStopwatch;
import com.volmit.iris.util.RollingSequence;
import lombok.Data;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
public class ProfiledStream<T> extends BasicStream<T> {
public static final AtomicInteger ids = new AtomicInteger();
private final int id;
private final RollingSequence metrics;
public ProfiledStream(ProceduralStream<T> stream, int memory) {
super(stream);
this.metrics = new RollingSequence(memory);
this.id = ids.getAndAdd(1);
}
public int getId() {
return id;
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
@Override
public T get(double x, double z) {
PrecisionStopwatch p = PrecisionStopwatch.start();
T t = getTypedSource().get(x, z);
try {
metrics.put(p.getMilliseconds());
} catch (Throwable e) {
Iris.reportError(e);
}
return t;
}
@Override
public T get(double x, double y, double z) {
PrecisionStopwatch p = PrecisionStopwatch.start();
T t = getTypedSource().get(x, y, z);
try {
metrics.put(p.getMilliseconds());
} catch (Throwable e) {Iris.reportError(e);
}
return t;
}
public RollingSequence getMetrics() {
return metrics;
}
public static void print(Consumer<String> printer, ProceduralStream<?> stream) {
KList<ProfiledTail> tails = getTails(stream);
int ind = tails.size();
for (ProfiledTail i : tails) {
printer.accept(Form.repeat(" ", ind) + i);
ind--;
}
}
private static KList<ProceduralStream<?>> getAllChildren(ProceduralStream<?> s) {
KList<ProceduralStream<?>> v = new KList<>();
ProceduralStream<?> cursor = s;
for (int i = 0; i < 32; i++) {
v.add(cursor);
cursor = nextChuld(cursor);
if (cursor == null) {
break;
}
}
return v;
}
private static ProceduralStream<?> nextChuld(ProceduralStream<?> s) {
ProceduralStream<?> v = s.getTypedSource();
return v == null ? s.getSource() : v;
}
private static ProfiledTail getTail(ProceduralStream<?> t) {
if (t instanceof ProfiledStream<?> s) {
return new ProfiledTail(s.getId(), s.getMetrics(), s.getClass().getSimpleName().replaceAll("\\QStream\\E", ""));
}
return null;
}
private static KList<ProfiledTail> getTails(ProceduralStream<?> t) {
KList<ProfiledTail> tails = new KList<>();
for (ProceduralStream<?> v : getAllChildren(t)) {
ProfiledTail p = getTail(v);
if (p != null) {
tails.add(p);
}
}
if (tails.isEmpty()) {
return null;
}
ProfiledTail cursor = tails.popLast();
KList<ProfiledTail> tailx = new KList<>();
tailx.add(cursor);
while (tails.isNotEmpty()) {
tailx.add(cursor);
ProfiledTail parent = tails.popLast();
parent.setChild(cursor);
cursor = parent;
tailx.add(cursor);
}
return tailx;
}
@Data
private static class ProfiledTail {
private final int id;
private final RollingSequence metrics;
private ProfiledTail child;
private final String name;
public ProfiledTail(int id, RollingSequence metrics, String name) {
this.id = id;
this.metrics = metrics;
this.name = name;
}
public String toString() {
return id + "-" + name + ": " + Form.duration(metrics.getAverage(), 2);
}
}
}

View File

@@ -0,0 +1,57 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.utility;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
import java.util.concurrent.Semaphore;
public class SemaphoreStream<T> extends BasicStream<T> {
private final Semaphore semaphore;
public SemaphoreStream(ProceduralStream<T> stream, int permits) {
super(stream);
this.semaphore = new Semaphore(permits);
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
@Override
public T get(double x, double z) {
synchronized (getTypedSource()) {
return getTypedSource().get(x, z);
}
}
@Override
public T get(double x, double y, double z) {
synchronized (getTypedSource()) {
return getTypedSource().get(x, y, z);
}
}
}

View File

@@ -0,0 +1,52 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.stream.utility;
import com.volmit.iris.engine.stream.BasicStream;
import com.volmit.iris.engine.stream.ProceduralStream;
public class SynchronizedStream<T> extends BasicStream<T> {
public SynchronizedStream(ProceduralStream<T> stream) {
super(stream);
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
@Override
public T get(double x, double z) {
synchronized (getTypedSource()) {
return getTypedSource().get(x, z);
}
}
@Override
public T get(double x, double y, double z) {
synchronized (getTypedSource()) {
return getTypedSource().get(x, y, z);
}
}
}