mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-28 11:39:07 +00:00
Move a lot of utilities in engine to util because they are utilities
This commit is contained in:
1286
src/main/java/com/volmit/iris/util/hunk/Hunk.java
Normal file
1286
src/main/java/com/volmit/iris/util/hunk/Hunk.java
Normal file
File diff suppressed because it is too large
Load Diff
28
src/main/java/com/volmit/iris/util/hunk/HunkFace.java
Normal file
28
src/main/java/com/volmit/iris/util/hunk/HunkFace.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.util.hunk;
|
||||
|
||||
public enum HunkFace {
|
||||
TOP,
|
||||
BOTTOM,
|
||||
EAST,
|
||||
WEST,
|
||||
NORTH,
|
||||
SOUTH
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.util.hunk.io;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.function.Function3;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public abstract class BasicHunkIOAdapter<T> implements HunkIOAdapter<T> {
|
||||
@Override
|
||||
public void write(Hunk<T> t, OutputStream out) throws IOException {
|
||||
DataOutputStream dos = new DataOutputStream(out);
|
||||
dos.writeShort(t.getWidth() + Short.MIN_VALUE);
|
||||
dos.writeShort(t.getHeight() + Short.MIN_VALUE);
|
||||
dos.writeShort(t.getDepth() + Short.MIN_VALUE);
|
||||
dos.writeInt(t.getNonNullEntries() + Integer.MIN_VALUE);
|
||||
|
||||
AtomicBoolean failure = new AtomicBoolean(false);
|
||||
t.iterate(0, (x, y, z, w) -> {
|
||||
if (w != null) {
|
||||
try {
|
||||
dos.writeShort(x + Short.MIN_VALUE);
|
||||
dos.writeShort(y + Short.MIN_VALUE);
|
||||
dos.writeShort(z + Short.MIN_VALUE);
|
||||
write(w, dos);
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
failure.set(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dos.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hunk<T> read(Function3<Integer, Integer, Integer, Hunk<T>> factory, InputStream in) throws IOException {
|
||||
DataInputStream din = new DataInputStream(in);
|
||||
int w = din.readShort() - Short.MIN_VALUE;
|
||||
int h = din.readShort() - Short.MIN_VALUE;
|
||||
int d = din.readShort() - Short.MIN_VALUE;
|
||||
int e = din.readInt() - Integer.MIN_VALUE;
|
||||
Hunk<T> t = factory.apply(w, h, d);
|
||||
|
||||
for (int i = 0; i < e; i++) {
|
||||
int x = din.readShort() - Short.MIN_VALUE;
|
||||
int y = din.readShort() - Short.MIN_VALUE;
|
||||
int z = din.readShort() - Short.MIN_VALUE;
|
||||
T v = read(din);
|
||||
|
||||
if (v == null) {
|
||||
throw new IOException("NULL VALUE AT " + x + " " + y + " " + z);
|
||||
}
|
||||
|
||||
t.setRaw(x, y, z, v);
|
||||
}
|
||||
|
||||
in.close();
|
||||
return t;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.util.hunk.io;
|
||||
|
||||
import com.volmit.iris.engine.data.B;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class BlockDataHunkIOAdapter extends PaletteHunkIOAdapter<BlockData> {
|
||||
|
||||
@Override
|
||||
public void write(BlockData blockData, DataOutputStream dos) throws IOException {
|
||||
dos.writeUTF(blockData.getAsString(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockData read(DataInputStream din) throws IOException {
|
||||
return B.get(din.readUTF());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.util.hunk.io;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class BooleanHunkIOAdapter extends PaletteHunkIOAdapter<Boolean> {
|
||||
|
||||
@Override
|
||||
public void write(Boolean data, DataOutputStream dos) throws IOException {
|
||||
dos.writeBoolean(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean read(DataInputStream din) throws IOException {
|
||||
return din.readBoolean();
|
||||
}
|
||||
}
|
||||
@@ -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.util.hunk.io;
|
||||
|
||||
import com.volmit.iris.engine.data.IOAdapter;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.function.Function3;
|
||||
import com.volmit.iris.util.io.CustomOutputStream;
|
||||
import com.volmit.iris.util.oldnbt.ByteArrayTag;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
public interface HunkIOAdapter<T> extends IOAdapter<T> {
|
||||
void write(Hunk<T> t, OutputStream out) throws IOException;
|
||||
|
||||
Hunk<T> read(Function3<Integer, Integer, Integer, Hunk<T>> factory, InputStream in) throws IOException;
|
||||
|
||||
default void write(Hunk<T> t, File f) throws IOException {
|
||||
f.getParentFile().mkdirs();
|
||||
FileOutputStream fos = new FileOutputStream(f);
|
||||
GZIPOutputStream gzo = new CustomOutputStream(fos, 6);
|
||||
write(t, gzo);
|
||||
}
|
||||
|
||||
default Hunk<T> read(Function3<Integer, Integer, Integer, Hunk<T>> factory, File f) throws IOException {
|
||||
return read(factory, new GZIPInputStream(new FileInputStream(f)));
|
||||
}
|
||||
|
||||
default Hunk<T> read(Function3<Integer, Integer, Integer, Hunk<T>> factory, ByteArrayTag f) throws IOException {
|
||||
return read(factory, new ByteArrayInputStream(f.getValue()));
|
||||
}
|
||||
|
||||
default ByteArrayTag writeByteArrayTag(Hunk<T> tHunk, String name) throws IOException {
|
||||
ByteArrayOutputStream boas = new ByteArrayOutputStream();
|
||||
write(tHunk, boas);
|
||||
return new ByteArrayTag(name, boas.toByteArray());
|
||||
}
|
||||
}
|
||||
101
src/main/java/com/volmit/iris/util/hunk/io/HunkRegion.java
Normal file
101
src/main/java/com/volmit/iris/util/hunk/io/HunkRegion.java
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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.util.hunk.io;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.oldnbt.CompoundTag;
|
||||
import com.volmit.iris.util.oldnbt.NBTInputStream;
|
||||
import com.volmit.iris.util.oldnbt.NBTOutputStream;
|
||||
import com.volmit.iris.util.oldnbt.Tag;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("SynchronizeOnNonFinalField")
|
||||
public class HunkRegion {
|
||||
private final File folder;
|
||||
private CompoundTag compound;
|
||||
private final int x;
|
||||
private final int z;
|
||||
|
||||
public HunkRegion(File folder, int x, int z, CompoundTag compound) {
|
||||
this.compound = fix(compound);
|
||||
this.folder = folder;
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
folder.mkdirs();
|
||||
}
|
||||
|
||||
public HunkRegion(File folder, int x, int z) {
|
||||
this(folder, x, z, new CompoundTag(x + "." + z, new KMap<>()));
|
||||
File f = getFile();
|
||||
|
||||
if (f.exists()) {
|
||||
try {
|
||||
NBTInputStream in = new NBTInputStream(new FileInputStream(f));
|
||||
compound = fix((CompoundTag) in.readTag());
|
||||
in.close();
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CompoundTag getCompound() {
|
||||
return compound;
|
||||
}
|
||||
|
||||
private CompoundTag fix(CompoundTag readTag) {
|
||||
Map<String, Tag> v = readTag.getValue();
|
||||
|
||||
if (!(v instanceof KMap)) {
|
||||
return new CompoundTag(readTag.getName(), new KMap<>(v));
|
||||
}
|
||||
|
||||
return readTag;
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return new File(folder, x + "." + z + ".dat");
|
||||
}
|
||||
|
||||
public void save() throws IOException {
|
||||
synchronized (compound) {
|
||||
File f = getFile();
|
||||
FileOutputStream fos = new FileOutputStream(f);
|
||||
NBTOutputStream out = new NBTOutputStream(fos);
|
||||
out.writeTag(compound);
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
}
|
||||
262
src/main/java/com/volmit/iris/util/hunk/io/HunkRegionSlice.java
Normal file
262
src/main/java/com/volmit/iris/util/hunk/io/HunkRegionSlice.java
Normal file
@@ -0,0 +1,262 @@
|
||||
/*
|
||||
* 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.util.hunk.io;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.engine.object.tile.TileData;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
import com.volmit.iris.util.function.Function2;
|
||||
import com.volmit.iris.util.function.Function3;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.math.Position2;
|
||||
import com.volmit.iris.util.oldnbt.ByteArrayTag;
|
||||
import com.volmit.iris.util.oldnbt.CompoundTag;
|
||||
import com.volmit.iris.util.oldnbt.Tag;
|
||||
import org.bukkit.block.TileState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class HunkRegionSlice<T> {
|
||||
public static final Function2<Integer, CompoundTag, HunkRegionSlice<BlockData>> BLOCKDATA = (h, c) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new BlockDataHunkIOAdapter(), c, "blockdata");
|
||||
public static final Function2<Integer, CompoundTag, HunkRegionSlice<TileData<? extends TileState>>> TILE = (h, c) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new TileDataHunkIOAdapter(), c, "tile");
|
||||
public static final Function3<Integer, CompoundTag, String, HunkRegionSlice<String>> STRING = (h, c, t) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new StringHunkIOAdapter(), c, t);
|
||||
public static final Function3<Integer, CompoundTag, String, HunkRegionSlice<Boolean>> BOOLEAN = (h, c, t) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new BooleanHunkIOAdapter(), c, t);
|
||||
private final Function3<Integer, Integer, Integer, Hunk<T>> factory;
|
||||
private final HunkIOAdapter<T> adapter;
|
||||
private final CompoundTag compound;
|
||||
private final String key;
|
||||
private final KMap<Position2, Hunk<T>> loadedChunks;
|
||||
private final KMap<Position2, Long> lastUse;
|
||||
private final KSet<Position2> save;
|
||||
private final int height;
|
||||
|
||||
public HunkRegionSlice(int height, Function3<Integer, Integer, Integer, Hunk<T>> factory, HunkIOAdapter<T> adapter, CompoundTag compound, String key) {
|
||||
this.height = height;
|
||||
this.loadedChunks = new KMap<>();
|
||||
this.factory = factory;
|
||||
this.adapter = adapter;
|
||||
this.compound = compound;
|
||||
this.save = new KSet<>();
|
||||
this.key = key;
|
||||
this.lastUse = new KMap<>();
|
||||
}
|
||||
|
||||
public synchronized int cleanup(long t) {
|
||||
int v = 0;
|
||||
if (loadedChunks.size() != lastUse.size()) {
|
||||
Iris.warn("Incorrect chunk use counts in " + key + " region slice.");
|
||||
|
||||
for (Position2 i : lastUse.k()) {
|
||||
if (!loadedChunks.containsKey(i)) {
|
||||
Iris.warn(" Missing LoadChunkKey " + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Position2 i : lastUse.k()) {
|
||||
Long l = lastUse.get(i);
|
||||
if (l == null || M.ms() - l > t) {
|
||||
v++;
|
||||
MultiBurst.burst.lazy(() -> {
|
||||
unload(i.getX(), i.getZ());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
public synchronized void clear() {
|
||||
for (String i : new KList<>(compound.getValue().keySet())) {
|
||||
if (i.startsWith(key + ".")) {
|
||||
compound.getValue().remove(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void save(MultiBurst burst) {
|
||||
|
||||
try {
|
||||
for (Position2 i : save.copy()) {
|
||||
if (i == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
save(i.getX(), i.getZ());
|
||||
|
||||
try {
|
||||
save.remove(i);
|
||||
} catch (Throwable eer) {
|
||||
Iris.reportError(eer);
|
||||
}
|
||||
}
|
||||
} catch (Throwable ee) {
|
||||
Iris.reportError(ee);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean contains(int x, int z) {
|
||||
return compound.getValue().containsKey(key(x, z));
|
||||
}
|
||||
|
||||
public void delete(int x, int z) {
|
||||
compound.getValue().remove(key(x, z));
|
||||
}
|
||||
|
||||
public Hunk<T> read(int x, int z) throws IOException {
|
||||
AtomicReference<IOException> e = new AtomicReference<>();
|
||||
Hunk<T> xt = null;
|
||||
|
||||
Tag t = compound.getValue().get(key(x, z));
|
||||
|
||||
if ((t instanceof ByteArrayTag)) {
|
||||
try {
|
||||
xt = adapter.read(factory, (ByteArrayTag) t);
|
||||
} catch (IOException xe) {
|
||||
Iris.reportError(xe);
|
||||
e.set(xe);
|
||||
}
|
||||
}
|
||||
|
||||
if (xt != null) {
|
||||
return xt;
|
||||
}
|
||||
|
||||
if (e.get() != null) {
|
||||
throw e.get();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write(Hunk<T> hunk, int x, int z) throws IOException {
|
||||
compound.getValue().put(key(x, z), hunk.writeByteArrayTag(adapter, key(x, z)));
|
||||
}
|
||||
|
||||
public synchronized int unloadAll() {
|
||||
int v = 0;
|
||||
for (Position2 i : loadedChunks.k()) {
|
||||
unload(i.getX(), i.getZ());
|
||||
v++;
|
||||
}
|
||||
|
||||
save.clear();
|
||||
loadedChunks.clear();
|
||||
lastUse.clear();
|
||||
return v;
|
||||
}
|
||||
|
||||
public void save(Hunk<T> region, int x, int z) {
|
||||
try {
|
||||
write(region, x, z);
|
||||
} catch (IOException e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isLoaded(int x, int z) {
|
||||
return loadedChunks.containsKey(new Position2(x, z));
|
||||
}
|
||||
|
||||
public void save(int x, int z) {
|
||||
if (isLoaded(x, z)) {
|
||||
save(get(x, z), x, z);
|
||||
}
|
||||
}
|
||||
|
||||
public void unload(int x, int z) {
|
||||
Position2 key = new Position2(x, z);
|
||||
if (isLoaded(x, z)) {
|
||||
if (save.contains(key)) {
|
||||
save(x, z);
|
||||
save.remove(key);
|
||||
}
|
||||
|
||||
lastUse.remove(key);
|
||||
loadedChunks.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
public Hunk<T> load(int x, int z) {
|
||||
if (isLoaded(x, z)) {
|
||||
return loadedChunks.get(new Position2(x, z));
|
||||
}
|
||||
|
||||
Hunk<T> v = null;
|
||||
|
||||
if (contains(x, z)) {
|
||||
try {
|
||||
v = read(x, z);
|
||||
} catch (IOException e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (v == null) {
|
||||
v = factory.apply(16, height, 16);
|
||||
}
|
||||
|
||||
loadedChunks.put(new Position2(x, z), v);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
public Hunk<T> get(int x, int z) {
|
||||
Position2 key = new Position2(x, z);
|
||||
|
||||
Hunk<T> c = loadedChunks.get(key);
|
||||
|
||||
if (c == null) {
|
||||
c = load(x, z);
|
||||
}
|
||||
|
||||
lastUse.put(new Position2(x, z), M.ms());
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
public Hunk<T> getR(int x, int z) {
|
||||
return get(x, z).readOnly();
|
||||
}
|
||||
|
||||
public Hunk<T> getRW(int x, int z) {
|
||||
save.add(new Position2(x, z));
|
||||
return get(x, z);
|
||||
}
|
||||
|
||||
private String key(int x, int z) {
|
||||
if (x < 0 || x >= 32 || z < 0 || z >= 32) {
|
||||
throw new IndexOutOfBoundsException("The chunk " + x + " " + z + " is out of bounds max is 31x31");
|
||||
}
|
||||
|
||||
return key + "." + x + "." + z;
|
||||
}
|
||||
|
||||
public int getLoadCount() {
|
||||
return loadedChunks.size();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* 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.util.hunk.io;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.data.DataPalette;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.function.Function3;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public abstract class PaletteHunkIOAdapter<T> implements HunkIOAdapter<T> {
|
||||
@Override
|
||||
public void write(Hunk<T> t, OutputStream out) throws IOException {
|
||||
DataOutputStream dos = new DataOutputStream(out);
|
||||
dos.writeShort(t.getWidth() + Short.MIN_VALUE);
|
||||
dos.writeShort(t.getHeight() + Short.MIN_VALUE);
|
||||
dos.writeShort(t.getDepth() + Short.MIN_VALUE);
|
||||
AtomicInteger nonNull = new AtomicInteger(0);
|
||||
DataPalette<T> palette = new DataPalette<>();
|
||||
|
||||
t.iterateSync((x, y, z, w) -> {
|
||||
if (w != null) {
|
||||
palette.getIndex(w);
|
||||
nonNull.getAndAdd(1);
|
||||
}
|
||||
});
|
||||
|
||||
palette.write(this, dos);
|
||||
dos.writeInt(nonNull.get() + Integer.MIN_VALUE);
|
||||
AtomicBoolean failure = new AtomicBoolean(false);
|
||||
t.iterateSync((x, y, z, w) -> {
|
||||
if (w != null) {
|
||||
try {
|
||||
dos.writeShort(x + Short.MIN_VALUE);
|
||||
dos.writeShort(y + Short.MIN_VALUE);
|
||||
dos.writeShort(z + Short.MIN_VALUE);
|
||||
dos.writeShort(palette.getIndex(w) + Short.MIN_VALUE);
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
failure.set(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dos.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hunk<T> read(Function3<Integer, Integer, Integer, Hunk<T>> factory, InputStream in) throws IOException {
|
||||
DataInputStream din = new DataInputStream(in);
|
||||
int w = din.readShort() - Short.MIN_VALUE;
|
||||
int h = din.readShort() - Short.MIN_VALUE;
|
||||
int d = din.readShort() - Short.MIN_VALUE;
|
||||
DataPalette<T> palette = DataPalette.getPalette(this, din);
|
||||
int e = din.readInt() - Integer.MIN_VALUE;
|
||||
Hunk<T> t = factory.apply(w, h, d);
|
||||
|
||||
for (int i = 0; i < e; i++) {
|
||||
int x = din.readShort() - Short.MIN_VALUE;
|
||||
int y = din.readShort() - Short.MIN_VALUE;
|
||||
int z = din.readShort() - Short.MIN_VALUE;
|
||||
int vf = din.readShort() - Short.MIN_VALUE;
|
||||
|
||||
T v = null;
|
||||
if (palette.getPalette().hasIndex(vf)) {
|
||||
v = palette.getPalette().get(vf);
|
||||
}
|
||||
|
||||
if (v != null) {
|
||||
t.setRaw(x, y, z, v);
|
||||
}
|
||||
}
|
||||
|
||||
in.close();
|
||||
return t;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.util.hunk.io;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class StringHunkIOAdapter extends PaletteHunkIOAdapter<String> {
|
||||
|
||||
@Override
|
||||
public void write(String data, DataOutputStream dos) throws IOException {
|
||||
dos.writeUTF(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String read(DataInputStream din) throws IOException {
|
||||
return din.readUTF();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.util.hunk.io;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.object.tile.TileData;
|
||||
import org.bukkit.block.TileState;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class TileDataHunkIOAdapter extends PaletteHunkIOAdapter<TileData<? extends TileState>> {
|
||||
@Override
|
||||
public void write(TileData<? extends TileState> data, DataOutputStream dos) throws IOException {
|
||||
data.toBinary(dos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileData<? extends TileState> read(DataInputStream din) throws IOException {
|
||||
try {
|
||||
return TileData.read(din);
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
e.printStackTrace();
|
||||
throw new IOException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.util.hunk.storage;
|
||||
|
||||
import com.volmit.iris.engine.cache.Cache;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@SuppressWarnings("Lombok")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class ArrayHunk<T> extends StorageHunk<T> implements Hunk<T> {
|
||||
private final T[] data;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public ArrayHunk(int w, int h, int d) {
|
||||
super(w, h, d);
|
||||
data = (T[]) new Object[w * h * d];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
data[index(x, y, z)] = t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getRaw(int x, int y, int z) {
|
||||
return data[index(x, y, z)];
|
||||
}
|
||||
|
||||
private int index(int x, int y, int z) {
|
||||
return Cache.to1D(x, y, z, getWidth(), getHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fill(T t) {
|
||||
Arrays.fill(data, t);
|
||||
}
|
||||
}
|
||||
@@ -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.util.hunk.storage;
|
||||
|
||||
import com.google.common.util.concurrent.AtomicDoubleArray;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@SuppressWarnings({"DefaultAnnotationParam", "Lombok"})
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class AtomicDoubleHunk extends StorageHunk<Double> implements Hunk<Double> {
|
||||
private final AtomicDoubleArray data;
|
||||
|
||||
public AtomicDoubleHunk(int w, int h, int d) {
|
||||
super(w, h, d);
|
||||
data = new AtomicDoubleArray(w * h * d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAtomic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, Double t) {
|
||||
data.set(index(x, y, z), t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getRaw(int x, int y, int z) {
|
||||
return data.get(index(x, y, z));
|
||||
}
|
||||
|
||||
private int index(int x, int y, int z) {
|
||||
return (z * getWidth() * getHeight()) + (y * getWidth()) + x;
|
||||
}
|
||||
}
|
||||
@@ -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.util.hunk.storage;
|
||||
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
|
||||
@SuppressWarnings({"DefaultAnnotationParam", "Lombok"})
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class AtomicHunk<T> extends StorageHunk<T> implements Hunk<T> {
|
||||
private final AtomicReferenceArray<T> data;
|
||||
|
||||
public AtomicHunk(int w, int h, int d) {
|
||||
super(w, h, d);
|
||||
data = new AtomicReferenceArray<>(w * h * d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAtomic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
data.set(index(x, y, z), t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getRaw(int x, int y, int z) {
|
||||
return data.get(index(x, y, z));
|
||||
}
|
||||
|
||||
private int index(int x, int y, int z) {
|
||||
return (z * getWidth() * getHeight()) + (y * getWidth()) + x;
|
||||
}
|
||||
}
|
||||
@@ -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.util.hunk.storage;
|
||||
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicIntegerArray;
|
||||
|
||||
@SuppressWarnings({"DefaultAnnotationParam", "Lombok"})
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class AtomicIntegerHunk extends StorageHunk<Integer> implements Hunk<Integer> {
|
||||
private final AtomicIntegerArray data;
|
||||
|
||||
public AtomicIntegerHunk(int w, int h, int d) {
|
||||
super(w, h, d);
|
||||
data = new AtomicIntegerArray(w * h * d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAtomic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, Integer t) {
|
||||
data.set(index(x, y, z), t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getRaw(int x, int y, int z) {
|
||||
return data.get(index(x, y, z));
|
||||
}
|
||||
|
||||
private int index(int x, int y, int z) {
|
||||
return (z * getWidth() * getHeight()) + (y * getWidth()) + x;
|
||||
}
|
||||
}
|
||||
@@ -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.util.hunk.storage;
|
||||
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLongArray;
|
||||
|
||||
@SuppressWarnings({"DefaultAnnotationParam", "Lombok"})
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class AtomicLongHunk extends StorageHunk<Long> implements Hunk<Long> {
|
||||
private final AtomicLongArray data;
|
||||
|
||||
public AtomicLongHunk(int w, int h, int d) {
|
||||
super(w, h, d);
|
||||
data = new AtomicLongArray(w * h * d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAtomic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, Long t) {
|
||||
data.set(index(x, y, z), t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getRaw(int x, int y, int z) {
|
||||
return data.get(index(x, y, z));
|
||||
}
|
||||
|
||||
private int index(int x, int y, int z) {
|
||||
return (z * getWidth() * getHeight()) + (y * getWidth()) + x;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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.util.hunk.storage;
|
||||
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.function.Consumer4;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings({"DefaultAnnotationParam", "Lombok"})
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class MappedHunk<T> extends StorageHunk<T> implements Hunk<T> {
|
||||
private final Map<Integer, T> data;
|
||||
|
||||
public MappedHunk(int w, int h, int d) {
|
||||
super(w, h, d);
|
||||
data = new KMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
if (t == null) {
|
||||
data.remove(index(x, y, z));
|
||||
return;
|
||||
}
|
||||
|
||||
data.put(index(x, y, z), t);
|
||||
}
|
||||
|
||||
private Integer index(int x, int y, int z) {
|
||||
return (z * getWidth() * getHeight()) + (y * getWidth()) + x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Hunk<T> iterateSync(Consumer4<Integer, Integer, Integer, T> c) {
|
||||
int idx, z;
|
||||
|
||||
for (Map.Entry<Integer, T> g : data.entrySet()) {
|
||||
idx = g.getKey();
|
||||
z = idx / (getWidth() * getHeight());
|
||||
idx -= (z * getWidth() * getHeight());
|
||||
c.accept(idx % getWidth(), idx / getWidth(), z, g.getValue());
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void empty(T b) {
|
||||
data.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getRaw(int x, int y, int z) {
|
||||
return data.get(index(x, y, z));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.util.hunk.storage;
|
||||
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public abstract class StorageHunk<T> implements Hunk<T> {
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final int depth;
|
||||
|
||||
public StorageHunk(int width, int height, int depth) {
|
||||
if (width <= 0 || height <= 0 || depth <= 0) {
|
||||
throw new RuntimeException("Unsupported size " + width + " " + height + " " + depth);
|
||||
}
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.depth = depth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void setRaw(int x, int y, int z, T t);
|
||||
|
||||
@Override
|
||||
public abstract T getRaw(int x, int y, int z);
|
||||
}
|
||||
@@ -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.util.hunk.storage;
|
||||
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@SuppressWarnings({"DefaultAnnotationParam", "Lombok"})
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class SynchronizedArrayHunk<T> extends StorageHunk<T> implements Hunk<T> {
|
||||
private final T[] data;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public SynchronizedArrayHunk(int w, int h, int d) {
|
||||
super(w, h, d);
|
||||
data = (T[]) new Object[w * h * d];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
synchronized (data) {
|
||||
data[index(x, y, z)] = t;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getRaw(int x, int y, int z) {
|
||||
synchronized (data) {
|
||||
return data[index(x, y, z)];
|
||||
}
|
||||
}
|
||||
|
||||
private int index(int x, int y, int z) {
|
||||
return (z * getWidth() * getHeight()) + (y * getWidth()) + x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fill(T t) {
|
||||
synchronized (data) {
|
||||
Arrays.fill(data, t);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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.util.hunk.view;
|
||||
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.engine.data.chunk.LinkedTerrainChunk;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
||||
|
||||
@SuppressWarnings("ClassCanBeRecord")
|
||||
public class BiomeGridHunkView implements Hunk<Biome> {
|
||||
@Getter
|
||||
private final BiomeGrid chunk;
|
||||
|
||||
public BiomeGridHunkView(BiomeGrid chunk) {
|
||||
this.chunk = chunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDepth() {
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
// TODO: WARNING HEIGHT
|
||||
return 256;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, Biome t) {
|
||||
chunk.setBiome(x, y, z, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getRaw(int x, int y, int z) {
|
||||
return chunk.getBiome(x, y, z);
|
||||
}
|
||||
|
||||
public void forceBiomeBaseInto(int x, int y, int z, Object somethingVeryDirty) {
|
||||
if (chunk instanceof LinkedTerrainChunk) {
|
||||
INMS.get().forceBiomeInto(x, y, z, somethingVeryDirty, ((LinkedTerrainChunk) chunk).getRawBiome());
|
||||
return;
|
||||
}
|
||||
INMS.get().forceBiomeInto(x, y, z, somethingVeryDirty, chunk);
|
||||
}
|
||||
}
|
||||
@@ -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.util.hunk.view;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
@SuppressWarnings("ClassCanBeRecord")
|
||||
public class ChunkBiomeHunkView implements Hunk<Biome> {
|
||||
private final Chunk chunk;
|
||||
|
||||
public ChunkBiomeHunkView(Chunk chunk) {
|
||||
this.chunk = chunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDepth() {
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return chunk.getWorld().getMaxHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, Biome t) {
|
||||
if (t == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Iris.edit.setBiome(chunk.getWorld(), x + (chunk.getX() * 16), y, z + (chunk.getZ() * 16), t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getRaw(int x, int y, int z) {
|
||||
return Iris.edit.getBiome(chunk.getWorld(), x + (chunk.getX() * 16), y, z + (chunk.getZ() * 16));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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.util.hunk.view;
|
||||
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.generator.ChunkGenerator.ChunkData;
|
||||
|
||||
@SuppressWarnings("ClassCanBeRecord")
|
||||
public class ChunkDataHunkView implements Hunk<BlockData> {
|
||||
private final ChunkData chunk;
|
||||
|
||||
public ChunkDataHunkView(ChunkData chunk) {
|
||||
this.chunk = chunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDepth() {
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return chunk.getMaxHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x1, int y1, int z1, int x2, int y2, int z2, BlockData t) {
|
||||
if (t == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
chunk.setRegion(x1, y1, z1, x2, y2, z2, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, BlockData t) {
|
||||
if (t == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
chunk.setBlock(x, y, z, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockData getRaw(int x, int y, int z) {
|
||||
return chunk.getBlockData(x, y, z);
|
||||
}
|
||||
}
|
||||
@@ -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.util.hunk.view;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
@SuppressWarnings("ClassCanBeRecord")
|
||||
public class ChunkHunkView implements Hunk<BlockData> {
|
||||
private final Chunk chunk;
|
||||
|
||||
public ChunkHunkView(Chunk chunk) {
|
||||
this.chunk = chunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDepth() {
|
||||
return 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return chunk.getWorld().getMaxHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, BlockData t) {
|
||||
if (t == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Iris.edit.set(chunk.getWorld(), x + (chunk.getX() * 16), y, z + (chunk.getZ() * 16), t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockData getRaw(int x, int y, int z) {
|
||||
return Iris.edit.get(chunk.getWorld(), x + (chunk.getX() * 16), y, z + (chunk.getZ() * 16));
|
||||
}
|
||||
}
|
||||
@@ -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.util.hunk.view;
|
||||
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
|
||||
@SuppressWarnings("ClassCanBeRecord")
|
||||
public class DriftHunkView<T> implements Hunk<T> {
|
||||
private final int ox;
|
||||
private final int oy;
|
||||
private final int oz;
|
||||
private final Hunk<T> src;
|
||||
|
||||
public DriftHunkView(Hunk<T> src, int ox, int oy, int oz) {
|
||||
this.src = src;
|
||||
this.ox = ox;
|
||||
this.oy = oy;
|
||||
this.oz = oz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
src.setRaw(x + ox, y + oy, z + oz, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getRaw(int x, int y, int z) {
|
||||
return src.getRaw(x + ox, y + oy, z + oz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return src.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return src.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDepth() {
|
||||
return src.getDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hunk<T> getSource() {
|
||||
return src;
|
||||
}
|
||||
}
|
||||
@@ -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.util.hunk.view;
|
||||
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
|
||||
@SuppressWarnings("ClassCanBeRecord")
|
||||
public class FringedHunkView<T> implements Hunk<T> {
|
||||
private final Hunk<T> src;
|
||||
private final Hunk<T> out;
|
||||
|
||||
public FringedHunkView(Hunk<T> src, Hunk<T> out) {
|
||||
this.src = src;
|
||||
this.out = out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
out.setRaw(x, y, z, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getRaw(int x, int y, int z) {
|
||||
return src.getRaw(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return src.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return src.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDepth() {
|
||||
return src.getDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hunk<T> getSource() {
|
||||
return src;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.util.hunk.view;
|
||||
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class FunctionalHunkView<R, T> implements Hunk<T> {
|
||||
private final Hunk<R> src;
|
||||
private final Function<R, T> converter;
|
||||
private final Function<T, R> backConverter;
|
||||
|
||||
public FunctionalHunkView(Hunk<R> src, Function<R, T> converter, Function<T, R> backConverter) {
|
||||
this.src = src;
|
||||
this.converter = converter;
|
||||
this.backConverter = backConverter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
if (backConverter == null) {
|
||||
throw new UnsupportedOperationException("You cannot write to this hunk (Read Only)");
|
||||
}
|
||||
|
||||
src.setRaw(x, y, z, backConverter.apply(t));
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getRaw(int x, int y, int z) {
|
||||
if (converter == null) {
|
||||
throw new UnsupportedOperationException("You cannot read this hunk (Write Only)");
|
||||
}
|
||||
|
||||
return converter.apply(src.getRaw(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return src.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDepth() {
|
||||
return src.getDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return src.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hunk<T> getSource() {
|
||||
throw new UnsupportedOperationException("You cannot read this hunk's source because it's a different type.");
|
||||
}
|
||||
}
|
||||
79
src/main/java/com/volmit/iris/util/hunk/view/HunkView.java
Normal file
79
src/main/java/com/volmit/iris/util/hunk/view/HunkView.java
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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.util.hunk.view;
|
||||
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
|
||||
public class HunkView<T> implements Hunk<T> {
|
||||
private final int ox;
|
||||
private final int oy;
|
||||
private final int oz;
|
||||
private final int w;
|
||||
private final int h;
|
||||
private final int d;
|
||||
private final Hunk<T> src;
|
||||
|
||||
public HunkView(Hunk<T> src) {
|
||||
this(src, src.getWidth(), src.getHeight(), src.getDepth());
|
||||
}
|
||||
|
||||
public HunkView(Hunk<T> src, int w, int h, int d) {
|
||||
this(src, w, h, d, 0, 0, 0);
|
||||
}
|
||||
|
||||
public HunkView(Hunk<T> src, int w, int h, int d, int ox, int oy, int oz) {
|
||||
this.src = src;
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
this.d = d;
|
||||
this.ox = ox;
|
||||
this.oy = oy;
|
||||
this.oz = oz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
src.setRaw(x + ox, y + oy, z + oz, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getRaw(int x, int y, int z) {
|
||||
return src.getRaw(x + ox, y + oy, z + oz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return w;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDepth() {
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return h;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hunk<T> getSource() {
|
||||
return src;
|
||||
}
|
||||
}
|
||||
@@ -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.util.hunk.view;
|
||||
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
|
||||
@SuppressWarnings("ClassCanBeRecord")
|
||||
public class InvertedHunkView<T> implements Hunk<T> {
|
||||
private final Hunk<T> src;
|
||||
|
||||
public InvertedHunkView(Hunk<T> src) {
|
||||
this.src = src;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
src.setRaw(x, (getHeight() - 1) - y, z, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getRaw(int x, int y, int z) {
|
||||
return src.getRaw(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return src.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDepth() {
|
||||
return src.getDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return src.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hunk<T> getSource() {
|
||||
return src;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.util.hunk.view;
|
||||
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.function.Consumer4;
|
||||
|
||||
@SuppressWarnings("ClassCanBeRecord")
|
||||
public class ListeningHunk<T> implements Hunk<T> {
|
||||
private final Hunk<T> src;
|
||||
private final Consumer4<Integer, Integer, Integer, T> listener;
|
||||
|
||||
public ListeningHunk(Hunk<T> src, Consumer4<Integer, Integer, Integer, T> listener) {
|
||||
this.src = src;
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
listener.accept(x, y, z, t);
|
||||
src.setRaw(x, y, z, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getRaw(int x, int y, int z) {
|
||||
return src.getRaw(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return src.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return src.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDepth() {
|
||||
return src.getDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hunk<T> getSource() {
|
||||
return src;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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.util.hunk.view;
|
||||
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
|
||||
@SuppressWarnings("ClassCanBeRecord")
|
||||
public class ReadOnlyHunk<T> implements Hunk<T> {
|
||||
private final Hunk<T> src;
|
||||
|
||||
public ReadOnlyHunk(Hunk<T> src) {
|
||||
this.src = src;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
throw new IllegalStateException("This hunk is read only!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getRaw(int x, int y, int z) {
|
||||
return src.getRaw(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x1, int y1, int z1, int x2, int y2, int z2, T t) {
|
||||
throw new IllegalStateException("This hunk is read only!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fill(T t) {
|
||||
throw new IllegalStateException("This hunk is read only!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return src.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return src.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDepth() {
|
||||
return src.getDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hunk<T> getSource() {
|
||||
return src;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.util.hunk.view;
|
||||
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
|
||||
public class RotatedXHunkView<T> implements Hunk<T> {
|
||||
private final Hunk<T> src;
|
||||
private final double sin;
|
||||
private final double cos;
|
||||
|
||||
public RotatedXHunkView(Hunk<T> src, double deg) {
|
||||
this.src = src;
|
||||
this.sin = Math.sin(Math.toRadians(deg));
|
||||
this.cos = Math.cos(Math.toRadians(deg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
int yc = (int) Math.round(cos * (getHeight() / 2f) - sin * (getDepth() / 2f));
|
||||
int zc = (int) Math.round(sin * (getHeight() / 2f) + cos * (getDepth() / 2f));
|
||||
src.setIfExists(x,
|
||||
(int) Math.round(cos * (y - yc) - sin * (z - zc)) - yc,
|
||||
(int) Math.round(sin * y - yc + cos * (z - zc)) - zc,
|
||||
t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getRaw(int x, int y, int z) {
|
||||
int yc = (int) Math.round(cos * (getHeight() / 2f) - sin * (getDepth() / 2f));
|
||||
int zc = (int) Math.round(sin * (getHeight() / 2f) + cos * (getDepth() / 2f));
|
||||
return src.getIfExists(x,
|
||||
(int) Math.round(cos * (y - yc) - sin * (z - zc)) - yc,
|
||||
(int) Math.round(sin * y - yc + cos * (z - zc)) - zc
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return src.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDepth() {
|
||||
return src.getDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return src.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hunk<T> getSource() {
|
||||
return src;
|
||||
}
|
||||
}
|
||||
@@ -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.util.hunk.view;
|
||||
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
|
||||
public class RotatedYHunkView<T> implements Hunk<T> {
|
||||
private final Hunk<T> src;
|
||||
private final double sin;
|
||||
private final double cos;
|
||||
|
||||
public RotatedYHunkView(Hunk<T> src, double deg) {
|
||||
this.src = src;
|
||||
this.sin = Math.sin(Math.toRadians(deg));
|
||||
this.cos = Math.cos(Math.toRadians(deg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
int xc = (int) Math.round(cos * (getWidth() / 2f) + sin * (getDepth() / 2f));
|
||||
int zc = (int) Math.round(-sin * (getWidth() / 2f) + cos * (getDepth() / 2f));
|
||||
src.setIfExists((int)
|
||||
Math.round(cos * (x - xc) + sin * (z - zc)) - xc,
|
||||
y,
|
||||
(int) Math.round(-sin * (x - xc) + cos * (z - zc)) - zc, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getRaw(int x, int y, int z) {
|
||||
int xc = (int) Math.round(cos * (getWidth() / 2f) + sin * (getDepth() / 2f));
|
||||
int zc = (int) Math.round(-sin * (getWidth() / 2f) + cos * (getDepth() / 2f));
|
||||
return src.getIfExists(
|
||||
(int) Math.round(cos * (x - xc) + sin * (z - zc)) - xc,
|
||||
y,
|
||||
(int) Math.round(-sin * (x - xc) + cos * (z - zc)) - zc
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return src.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDepth() {
|
||||
return src.getDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return src.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hunk<T> getSource() {
|
||||
return src;
|
||||
}
|
||||
}
|
||||
@@ -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.util.hunk.view;
|
||||
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
|
||||
public class RotatedZHunkView<T> implements Hunk<T> {
|
||||
private final Hunk<T> src;
|
||||
private final double sin;
|
||||
private final double cos;
|
||||
|
||||
public RotatedZHunkView(Hunk<T> src, double deg) {
|
||||
this.src = src;
|
||||
this.sin = Math.sin(Math.toRadians(deg));
|
||||
this.cos = Math.cos(Math.toRadians(deg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
int xc = (int) Math.round(cos * (getWidth() / 2f) - sin * (getHeight() / 2f));
|
||||
int yc = (int) Math.round(sin * (getWidth() / 2f) + cos * (getHeight() / 2f));
|
||||
src.setIfExists((int) Math.round(cos * (x - xc) - sin * (y - yc)) - xc, (int) Math.round(sin * (x - xc) + cos * (y - yc)) - yc, z, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getRaw(int x, int y, int z) {
|
||||
int xc = (int) Math.round(cos * (getWidth() / 2f) - sin * (getHeight() / 2f));
|
||||
int yc = (int) Math.round(sin * (getWidth() / 2f) + cos * (getHeight() / 2f));
|
||||
return src.getIfExists((int) Math.round(cos * (x - xc) - sin * (y - yc)) - xc,
|
||||
(int) Math.round(sin * (x - xc) + cos * (y - yc)) - yc
|
||||
, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return src.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDepth() {
|
||||
return src.getDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return src.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hunk<T> getSource() {
|
||||
return src;
|
||||
}
|
||||
}
|
||||
@@ -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.util.hunk.view;
|
||||
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
|
||||
@SuppressWarnings("ClassCanBeRecord")
|
||||
public class SynchronizedHunkView<T> implements Hunk<T> {
|
||||
private final Hunk<T> src;
|
||||
|
||||
public SynchronizedHunkView(Hunk<T> src) {
|
||||
this.src = src;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
synchronized (src) {
|
||||
src.setRaw(x, y, z, t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getRaw(int x, int y, int z) {
|
||||
return src.getRaw(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return src.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return src.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDepth() {
|
||||
return src.getDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hunk<T> getSource() {
|
||||
return src;
|
||||
}
|
||||
}
|
||||
@@ -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.util.hunk.view;
|
||||
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@SuppressWarnings("ClassCanBeRecord")
|
||||
public class WriteTrackHunk<T> implements Hunk<T> {
|
||||
private final Hunk<T> src;
|
||||
private final AtomicBoolean b;
|
||||
|
||||
public WriteTrackHunk(Hunk<T> src, AtomicBoolean b) {
|
||||
this.src = src;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
if (!b.get()) {
|
||||
b.set(true);
|
||||
}
|
||||
|
||||
src.setRaw(x, y, z, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getRaw(int x, int y, int z) {
|
||||
return src.getRaw(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return src.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return src.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDepth() {
|
||||
return src.getDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hunk<T> getSource() {
|
||||
return src;
|
||||
}
|
||||
}
|
||||
426
src/main/java/com/volmit/iris/util/noise/CNG.java
Normal file
426
src/main/java/com/volmit/iris/util/noise/CNG.java
Normal file
@@ -0,0 +1,426 @@
|
||||
/*
|
||||
* 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.util.noise;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.interpolation.IrisInterpolation;
|
||||
import com.volmit.iris.engine.object.common.IRare;
|
||||
import com.volmit.iris.util.stream.ProceduralStream;
|
||||
import com.volmit.iris.util.stream.arithmetic.FittedStream;
|
||||
import com.volmit.iris.util.stream.sources.CNGStream;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.function.NoiseInjector;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class CNG {
|
||||
public static long hits = 0;
|
||||
public static long creates = 0;
|
||||
public static final NoiseInjector ADD = (s, v) -> new double[]{s + v, 1};
|
||||
public static final NoiseInjector SRC_SUBTRACT = (s, v) -> new double[]{s - v < 0 ? 0 : s - v, -1};
|
||||
public static final NoiseInjector DST_SUBTRACT = (s, v) -> new double[]{v - s < 0 ? 0 : s - v, -1};
|
||||
public static final NoiseInjector MULTIPLY = (s, v) -> new double[]{s * v, 0};
|
||||
public static final NoiseInjector MAX = (s, v) -> new double[]{Math.max(s, v), 0};
|
||||
public static final NoiseInjector MIN = (s, v) -> new double[]{Math.min(s, v), 0};
|
||||
public static final NoiseInjector SRC_MOD = (s, v) -> new double[]{s % v, 0};
|
||||
public static final NoiseInjector SRC_POW = (s, v) -> new double[]{Math.pow(s, v), 0};
|
||||
public static final NoiseInjector DST_MOD = (s, v) -> new double[]{v % s, 0};
|
||||
public static final NoiseInjector DST_POW = (s, v) -> new double[]{Math.pow(v, s), 0};
|
||||
private double scale;
|
||||
private double bakedScale;
|
||||
private double fscale;
|
||||
private boolean trueFracturing = false;
|
||||
private KList<CNG> children;
|
||||
private CNG fracture;
|
||||
private NoiseGenerator generator;
|
||||
private final double opacity;
|
||||
private NoiseInjector injector;
|
||||
private RNG rng;
|
||||
private boolean noscale;
|
||||
private int oct;
|
||||
private double patch;
|
||||
private double up;
|
||||
private double down;
|
||||
private double power;
|
||||
private ProceduralStream<Double> customGenerator;
|
||||
|
||||
public NoiseGenerator getGen() {
|
||||
return generator;
|
||||
}
|
||||
|
||||
public ProceduralStream<Double> stream() {
|
||||
return new CNGStream(this);
|
||||
}
|
||||
|
||||
public ProceduralStream<Double> stream(double min, double max) {
|
||||
return new FittedStream<>(stream(), min, max);
|
||||
}
|
||||
|
||||
public static CNG signature(RNG rng) {
|
||||
return signature(rng, NoiseType.SIMPLEX);
|
||||
}
|
||||
|
||||
public static CNG signatureHalf(RNG rng) {
|
||||
return signatureHalf(rng, NoiseType.SIMPLEX);
|
||||
}
|
||||
|
||||
public static CNG signatureThick(RNG rng) {
|
||||
return signatureThick(rng, NoiseType.SIMPLEX);
|
||||
}
|
||||
|
||||
public static CNG signatureDouble(RNG rng) {
|
||||
return signatureDouble(rng, NoiseType.SIMPLEX);
|
||||
}
|
||||
|
||||
public static CNG signatureDouble(RNG rng, NoiseType t) {
|
||||
return signatureThick(rng, t).fractureWith(signature(rng.nextParallelRNG(4956)), 93);
|
||||
}
|
||||
|
||||
|
||||
public static CNG signatureDoubleFast(RNG rng, NoiseType t, NoiseType f) {
|
||||
return signatureThickFast(rng, t, f)
|
||||
.fractureWith(signatureFast(rng.nextParallelRNG(4956), t, f), 93);
|
||||
}
|
||||
|
||||
public static CNG signature(RNG rng, NoiseType t) {
|
||||
// @NoArgsConstructor
|
||||
return new CNG(rng.nextParallelRNG(17), t, 1D, 1).fractureWith(new CNG(rng.nextParallelRNG(18), 1, 1).scale(0.9).fractureWith(new CNG(rng.nextParallelRNG(20), 1, 1).scale(0.21).fractureWith(new CNG(rng.nextParallelRNG(20), 1, 1).scale(0.9), 620), 145), 44).bake();
|
||||
// @done
|
||||
}
|
||||
|
||||
public static CNG signaturePerlin(RNG rng) {
|
||||
return signaturePerlin(rng, NoiseType.PERLIN);
|
||||
}
|
||||
|
||||
public static CNG signaturePerlin(RNG rng, NoiseType t) {
|
||||
// @NoArgsConstructor
|
||||
return new CNG(rng.nextParallelRNG(124996), t, 1D, 1)
|
||||
.fractureWith(new CNG(rng.nextParallelRNG(18), NoiseType.PERLIN, 1, 1).scale(1.25), 250)
|
||||
.bake();
|
||||
// @done
|
||||
}
|
||||
|
||||
public static CNG signatureFast(RNG rng, NoiseType t, NoiseType f) {
|
||||
// @NoArgsConstructor
|
||||
return new CNG(rng.nextParallelRNG(17), t, 1D, 1)
|
||||
.fractureWith(new CNG(rng.nextParallelRNG(18), f, 1, 1)
|
||||
.scale(0.9)
|
||||
.fractureWith(new CNG(rng.nextParallelRNG(20), f, 1, 1)
|
||||
.scale(0.21)
|
||||
.fractureWith(new CNG(rng.nextParallelRNG(20), f, 1, 1).scale(0.9), 620), 145), 44)
|
||||
.bake();
|
||||
// @done
|
||||
}
|
||||
|
||||
public static CNG signatureThick(RNG rng, NoiseType t) {
|
||||
// @NoArgsConstructor
|
||||
return new CNG(rng.nextParallelRNG(133), t, 1D, 1).fractureWith(new CNG(rng.nextParallelRNG(18), 1, 1).scale(0.5).fractureWith(new CNG(rng.nextParallelRNG(20), 1, 1).scale(0.11).fractureWith(new CNG(rng.nextParallelRNG(20), 1, 1).scale(0.4), 620), 145), 44).bake();
|
||||
// @done
|
||||
}
|
||||
|
||||
public static CNG signatureThickFast(RNG rng, NoiseType t, NoiseType f) {
|
||||
// @NoArgsConstructor
|
||||
return new CNG(rng.nextParallelRNG(133), t, 1D, 1)
|
||||
.fractureWith(new CNG(rng.nextParallelRNG(18), f, 1, 1)
|
||||
.scale(0.5).fractureWith(new CNG(rng.nextParallelRNG(20), f, 1, 1)
|
||||
.scale(0.11).fractureWith(new CNG(rng.nextParallelRNG(20), f, 1, 1)
|
||||
.scale(0.4), 620), 145), 44).bake();
|
||||
// @done
|
||||
}
|
||||
|
||||
public static CNG signatureHalf(RNG rng, NoiseType t) {
|
||||
// @NoArgsConstructor
|
||||
return new CNG(rng.nextParallelRNG(127), t, 1D, 1).fractureWith(new CNG(rng.nextParallelRNG(18), 1, 1).scale(0.9).fractureWith(new CNG(rng.nextParallelRNG(20), 1, 1).scale(0.21).fractureWith(new CNG(rng.nextParallelRNG(20), 1, 1).scale(0.9), 420), 99), 22).bake();
|
||||
// @done
|
||||
}
|
||||
|
||||
public static CNG signatureHalfFast(RNG rng, NoiseType t, NoiseType f) {
|
||||
// @NoArgsConstructor
|
||||
return new CNG(rng.nextParallelRNG(127), t, 1D, 1)
|
||||
.fractureWith(new CNG(rng.nextParallelRNG(18), f, 1, 1).scale(0.9)
|
||||
.fractureWith(new CNG(rng.nextParallelRNG(20), f, 1, 1).scale(0.21)
|
||||
.fractureWith(new CNG(rng.nextParallelRNG(20), f, 1, 1).scale(0.9), 420), 99), 22).bake();
|
||||
// @done
|
||||
}
|
||||
|
||||
public CNG(RNG random) {
|
||||
this(random, 1);
|
||||
}
|
||||
|
||||
public CNG(RNG random, int octaves) {
|
||||
this(random, 1D, octaves);
|
||||
}
|
||||
|
||||
public CNG(RNG random, double opacity, int octaves) {
|
||||
this(random, NoiseType.SIMPLEX, opacity, octaves);
|
||||
}
|
||||
|
||||
public CNG(RNG random, NoiseType type, double opacity, int octaves) {
|
||||
this(random, type.create(random.nextParallelRNG((long) ((1113334944L * opacity) + 12922 + octaves)).lmax()), opacity, octaves);
|
||||
}
|
||||
|
||||
public CNG(RNG random, NoiseGenerator generator, double opacity, int octaves) {
|
||||
customGenerator = null;
|
||||
creates++;
|
||||
noscale = generator.isNoScale();
|
||||
this.oct = octaves;
|
||||
this.rng = random;
|
||||
power = 1;
|
||||
scale = 1;
|
||||
patch = 1;
|
||||
bakedScale = 1;
|
||||
fscale = 1;
|
||||
down = 0;
|
||||
up = 0;
|
||||
fracture = null;
|
||||
this.generator = generator;
|
||||
this.opacity = opacity;
|
||||
this.injector = ADD;
|
||||
|
||||
if (generator instanceof OctaveNoise) {
|
||||
((OctaveNoise) generator).setOctaves(octaves);
|
||||
}
|
||||
}
|
||||
|
||||
public CNG bake() {
|
||||
bakedScale *= scale;
|
||||
scale = 1;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CNG child(CNG c) {
|
||||
if (children == null) {
|
||||
children = new KList<>();
|
||||
}
|
||||
|
||||
children.add(c);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RNG getRNG() {
|
||||
return rng;
|
||||
}
|
||||
|
||||
public CNG fractureWith(CNG c, double scale) {
|
||||
fracture = c;
|
||||
fscale = scale;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CNG scale(double c) {
|
||||
scale = c;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CNG patch(double c) {
|
||||
patch = c;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CNG up(double c) {
|
||||
up = c;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CNG down(double c) {
|
||||
down = c;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CNG injectWith(NoiseInjector i) {
|
||||
injector = i;
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T extends IRare> T fitRarity(KList<T> b, double... dim) {
|
||||
if (b.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (b.size() == 1) {
|
||||
return b.get(0);
|
||||
}
|
||||
|
||||
KList<T> rarityMapped = new KList<>();
|
||||
boolean o = false;
|
||||
int max = 1;
|
||||
for (T i : b) {
|
||||
if (i.getRarity() > max) {
|
||||
max = i.getRarity();
|
||||
}
|
||||
}
|
||||
|
||||
max++;
|
||||
|
||||
for (T i : b) {
|
||||
for (int j = 0; j < max - i.getRarity(); j++) {
|
||||
if (o = !o) {
|
||||
rarityMapped.add(i);
|
||||
} else {
|
||||
rarityMapped.add(0, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rarityMapped.size() == 1) {
|
||||
return rarityMapped.get(0);
|
||||
}
|
||||
|
||||
if (rarityMapped.isEmpty()) {
|
||||
throw new RuntimeException("BAD RARITY MAP! RELATED TO: " + b.toString(", or possibly "));
|
||||
}
|
||||
|
||||
return fit(rarityMapped, dim);
|
||||
}
|
||||
|
||||
public <T> T fit(T[] v, double... dim) {
|
||||
if (v.length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (v.length == 1) {
|
||||
return v[0];
|
||||
}
|
||||
|
||||
return v[fit(0, v.length - 1, dim)];
|
||||
}
|
||||
|
||||
public <T> T fit(List<T> v, double... dim) {
|
||||
if (v.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (v.size() == 1) {
|
||||
return v.get(0);
|
||||
}
|
||||
|
||||
try {
|
||||
return v.get(fit(0, v.size() - 1, dim));
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
}
|
||||
|
||||
return v.get(0);
|
||||
}
|
||||
|
||||
public int fit(int min, int max, double... dim) {
|
||||
if (min == max) {
|
||||
return min;
|
||||
}
|
||||
|
||||
double noise = noise(dim);
|
||||
|
||||
return (int) Math.round(IrisInterpolation.lerp(min, max, noise));
|
||||
}
|
||||
|
||||
public int fit(double min, double max, double... dim) {
|
||||
if (min == max) {
|
||||
return (int) Math.round(min);
|
||||
}
|
||||
|
||||
double noise = noise(dim);
|
||||
|
||||
return (int) Math.round(IrisInterpolation.lerp(min, max, noise));
|
||||
}
|
||||
|
||||
public double fitDouble(double min, double max, double... dim) {
|
||||
if (min == max) {
|
||||
return min;
|
||||
}
|
||||
|
||||
double noise = noise(dim);
|
||||
|
||||
return IrisInterpolation.lerp(min, max, noise);
|
||||
}
|
||||
|
||||
private double getNoise(double... dim) {
|
||||
double scale = noscale ? 1 : this.bakedScale * this.scale;
|
||||
|
||||
if (fracture == null || noscale) {
|
||||
return generator.noise(
|
||||
(dim.length > 0 ? dim[0] : 0D) * scale,
|
||||
(dim.length > 1 ? dim[1] : 0D) * scale,
|
||||
(dim.length > 2 ? dim[2] : 0D) * scale) * opacity;
|
||||
}
|
||||
|
||||
if (fracture.isTrueFracturing()) {
|
||||
double x = dim.length > 0 ? dim[0] + ((fracture.noise(dim) - 0.5) * fscale) : 0D;
|
||||
double y = dim.length > 1 ? dim[1] + ((fracture.noise(dim[1], dim[0]) - 0.5) * fscale) : 0D;
|
||||
double z = dim.length > 2 ? dim[2] + ((fracture.noise(dim[2], dim[0], dim[1]) - 0.5) * fscale) : 0D;
|
||||
return generator.noise(x * scale, y * scale, z * scale) * opacity;
|
||||
}
|
||||
|
||||
double f = fracture.noise(dim) * fscale;
|
||||
double x = dim.length > 0 ? dim[0] + f : 0D;
|
||||
double y = dim.length > 1 ? dim[1] - f : 0D;
|
||||
double z = dim.length > 2 ? dim[2] - f : 0D;
|
||||
return generator.noise(x * scale, y * scale, z * scale) * opacity;
|
||||
}
|
||||
|
||||
public double invertNoise(double... dim) {
|
||||
if (dim.length == 1) {
|
||||
return noise(-dim[0]);
|
||||
} else if (dim.length == 2) {
|
||||
return noise(dim[1], dim[0]);
|
||||
} else if (dim.length == 3) {
|
||||
return noise(dim[1], dim[2], dim[0]);
|
||||
}
|
||||
|
||||
return noise(dim);
|
||||
}
|
||||
|
||||
public double noise(double... dim) {
|
||||
double n = getNoise(dim);
|
||||
n = power != 1D ? (n < 0 ? -Math.pow(Math.abs(n), power) : Math.pow(n, power)) : n;
|
||||
double m = 1;
|
||||
hits += oct;
|
||||
if (children == null) {
|
||||
return (n - down + up) * patch;
|
||||
}
|
||||
|
||||
for (CNG i : children) {
|
||||
double[] r = injector.combine(n, i.noise(dim));
|
||||
n = r[0];
|
||||
m += r[1];
|
||||
}
|
||||
|
||||
return ((n / m) - down + up) * patch;
|
||||
}
|
||||
|
||||
public CNG pow(double power) {
|
||||
this.power = power;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CNG oct(int octaves) {
|
||||
oct = octaves;
|
||||
return this;
|
||||
}
|
||||
|
||||
public double getScale() {
|
||||
return scale;
|
||||
}
|
||||
|
||||
public boolean isStatic() {
|
||||
return generator != null && generator.isStatic();
|
||||
}
|
||||
}
|
||||
26
src/main/java/com/volmit/iris/util/noise/CNGFactory.java
Normal file
26
src/main/java/com/volmit/iris/util/noise/CNGFactory.java
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.util.noise;
|
||||
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface CNGFactory {
|
||||
CNG create(RNG seed);
|
||||
}
|
||||
93
src/main/java/com/volmit/iris/util/noise/CellGenerator.java
Normal file
93
src/main/java/com/volmit/iris/util/noise/CellGenerator.java
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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.util.noise;
|
||||
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
public class CellGenerator {
|
||||
private final FastNoiseDouble fn;
|
||||
private final FastNoiseDouble fd;
|
||||
private final CNG cng;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private double cellScale;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private double shuffle;
|
||||
|
||||
public CellGenerator(RNG rng) {
|
||||
shuffle = 128;
|
||||
cellScale = 0.73;
|
||||
cng = CNG.signature(rng.nextParallelRNG(3204));
|
||||
RNG rx = rng.nextParallelRNG(8735652);
|
||||
long s = rx.lmax();
|
||||
fn = new FastNoiseDouble(s);
|
||||
fn.setNoiseType(FastNoiseDouble.NoiseType.Cellular);
|
||||
fn.setCellularReturnType(FastNoiseDouble.CellularReturnType.CellValue);
|
||||
fn.setCellularDistanceFunction(FastNoiseDouble.CellularDistanceFunction.Natural);
|
||||
fd = new FastNoiseDouble(s);
|
||||
fd.setNoiseType(FastNoiseDouble.NoiseType.Cellular);
|
||||
fd.setCellularReturnType(FastNoiseDouble.CellularReturnType.Distance2Sub);
|
||||
fd.setCellularDistanceFunction(FastNoiseDouble.CellularDistanceFunction.Natural);
|
||||
}
|
||||
|
||||
public double getDistance(double x, double z) {
|
||||
return ((fd.GetCellular(((x * cellScale) + (cng.noise(x, z) * shuffle)), ((z * cellScale) + (cng.noise(z, x) * shuffle)))) + 1f) / 2f;
|
||||
}
|
||||
|
||||
public double getDistance(double x, double y, double z) {
|
||||
return ((fd.GetCellular(((x * cellScale) + (cng.noise(x, y, z) * shuffle)), ((y * cellScale) + (cng.noise(x, y, z) * shuffle)), ((z * cellScale) + (cng.noise(z, y, x) * shuffle)))) + 1f) / 2f;
|
||||
}
|
||||
|
||||
public double getValue(double x, double z, int possibilities) {
|
||||
if (possibilities == 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ((fn.GetCellular(((x * cellScale) + (cng.noise(x, z) * shuffle)), ((z * cellScale) + (cng.noise(z, x) * shuffle))) + 1f) / 2f) * (possibilities - 1);
|
||||
}
|
||||
|
||||
public double getValue(double x, double y, double z, int possibilities) {
|
||||
if (possibilities == 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ((fn.GetCellular(((x * cellScale) + (cng.noise(x, z) * shuffle)), ((y * 8 * cellScale) + (cng.noise(x, y * 8) * shuffle)), ((z * cellScale) + (cng.noise(z, x) * shuffle))) + 1f) / 2f) * (possibilities - 1);
|
||||
}
|
||||
|
||||
public int getIndex(double x, double z, int possibilities) {
|
||||
if (possibilities == 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int) Math.round(getValue(x, z, possibilities));
|
||||
}
|
||||
|
||||
public int getIndex(double x, double y, double z, int possibilities) {
|
||||
if (possibilities == 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int) Math.round(getValue(x, y, z, possibilities));
|
||||
}
|
||||
}
|
||||
@@ -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.util.noise;
|
||||
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
public class CellHeightNoise implements NoiseGenerator {
|
||||
private final FastNoiseDouble n;
|
||||
|
||||
public CellHeightNoise(long seed) {
|
||||
this.n = new FastNoiseDouble(new RNG(seed).lmax());
|
||||
n.setNoiseType(FastNoiseDouble.NoiseType.Cellular);
|
||||
n.setCellularReturnType(FastNoiseDouble.CellularReturnType.Distance2Sub);
|
||||
n.setCellularDistanceFunction(FastNoiseDouble.CellularDistanceFunction.Natural);
|
||||
}
|
||||
|
||||
private double filter(double noise) {
|
||||
return M.clip(1D - ((noise / 2D) + 0.5D), 0D, 1D);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
return filter(n.GetCellular(x, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
return filter(n.GetCellular(x, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return filter(n.GetCellular(x, y, z));
|
||||
}
|
||||
}
|
||||
47
src/main/java/com/volmit/iris/util/noise/CellularNoise.java
Normal file
47
src/main/java/com/volmit/iris/util/noise/CellularNoise.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.util.noise;
|
||||
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
public class CellularNoise implements NoiseGenerator {
|
||||
private final FastNoise n;
|
||||
|
||||
public CellularNoise(long seed) {
|
||||
this.n = new FastNoise(new RNG(seed).imax());
|
||||
n.SetNoiseType(FastNoise.NoiseType.Cellular);
|
||||
n.SetCellularReturnType(FastNoise.CellularReturnType.CellValue);
|
||||
n.SetCellularDistanceFunction(FastNoise.CellularDistanceFunction.Natural);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
return (n.GetCellular((float) x, 0) / 2D) + 0.5D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
return (n.GetCellular((float) x, (float) z) / 2D) + 0.5D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return (n.GetCellular((float) x, (float) y, (float) z) / 2D) + 0.5D;
|
||||
}
|
||||
}
|
||||
1052
src/main/java/com/volmit/iris/util/noise/CloverNoise.java
Normal file
1052
src/main/java/com/volmit/iris/util/noise/CloverNoise.java
Normal file
File diff suppressed because it is too large
Load Diff
48
src/main/java/com/volmit/iris/util/noise/CubicNoise.java
Normal file
48
src/main/java/com/volmit/iris/util/noise/CubicNoise.java
Normal 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.util.noise;
|
||||
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
public class CubicNoise implements NoiseGenerator {
|
||||
private final FastNoiseDouble n;
|
||||
|
||||
public CubicNoise(long seed) {
|
||||
this.n = new FastNoiseDouble(new RNG(seed).lmax());
|
||||
}
|
||||
|
||||
private double f(double n) {
|
||||
return (n / 2D) + 0.5D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
return f(n.GetCubic(x, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
return f(n.GetCubic(x, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return f(n.GetCubic(x, y, z));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.util.noise;
|
||||
|
||||
import com.volmit.iris.engine.object.IrisExpression;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
public class ExpressionNoise implements NoiseGenerator {
|
||||
private final RNG rng;
|
||||
private final IrisExpression expression;
|
||||
|
||||
public ExpressionNoise(RNG rng, IrisExpression expression) {
|
||||
this.rng = rng;
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
return expression.evaluate(rng, x, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
return expression.evaluate(rng, x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return expression.evaluate(rng, x, y, z);
|
||||
}
|
||||
}
|
||||
2121
src/main/java/com/volmit/iris/util/noise/FastNoise.java
Normal file
2121
src/main/java/com/volmit/iris/util/noise/FastNoise.java
Normal file
File diff suppressed because one or more lines are too long
2004
src/main/java/com/volmit/iris/util/noise/FastNoiseDouble.java
Normal file
2004
src/main/java/com/volmit/iris/util/noise/FastNoiseDouble.java
Normal file
File diff suppressed because one or more lines are too long
40
src/main/java/com/volmit/iris/util/noise/FlatNoise.java
Normal file
40
src/main/java/com/volmit/iris/util/noise/FlatNoise.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.util.noise;
|
||||
|
||||
public class FlatNoise implements NoiseGenerator {
|
||||
public FlatNoise(long seed) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
return 1D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
return 1D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return 1D;
|
||||
}
|
||||
}
|
||||
@@ -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.util.noise;
|
||||
|
||||
import com.volmit.iris.util.noise.FastNoiseDouble.FractalType;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
public class FractalBillowPerlinNoise implements NoiseGenerator, OctaveNoise {
|
||||
private final FastNoiseDouble n;
|
||||
|
||||
public FractalBillowPerlinNoise(long seed) {
|
||||
this.n = new FastNoiseDouble(new RNG(seed).lmax());
|
||||
n.setFractalOctaves(1);
|
||||
n.setFractalType(FractalType.Billow);
|
||||
}
|
||||
|
||||
public double f(double v) {
|
||||
return (v / 2D) + 0.5D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
return f(n.GetPerlinFractal(x, 0f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
return f(n.GetPerlinFractal(x, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return f(n.GetPerlinFractal(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOctaves(int o) {
|
||||
n.setFractalOctaves(o);
|
||||
}
|
||||
}
|
||||
@@ -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.util.noise;
|
||||
|
||||
import com.volmit.iris.util.noise.FastNoiseDouble.FractalType;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
public class FractalBillowSimplexNoise implements NoiseGenerator, OctaveNoise {
|
||||
private final FastNoiseDouble n;
|
||||
|
||||
public FractalBillowSimplexNoise(long seed) {
|
||||
this.n = new FastNoiseDouble(new RNG(seed).lmax());
|
||||
n.setFractalOctaves(1);
|
||||
n.setFractalType(FractalType.Billow);
|
||||
}
|
||||
|
||||
public double f(double v) {
|
||||
return (v / 2D) + 0.5D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
return f(n.GetSimplexFractal(x, 0d));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
return f(n.GetSimplexFractal(x, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return f(n.GetSimplexFractal(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOctaves(int o) {
|
||||
n.setFractalOctaves(o);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.util.noise;
|
||||
|
||||
import com.volmit.iris.util.noise.FastNoiseDouble.FractalType;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
public class FractalCubicNoise implements NoiseGenerator {
|
||||
private final FastNoiseDouble n;
|
||||
|
||||
public FractalCubicNoise(long seed) {
|
||||
this.n = new FastNoiseDouble(new RNG(seed).lmax());
|
||||
n.setFractalType(FractalType.Billow);
|
||||
}
|
||||
|
||||
private double f(double n) {
|
||||
return (n / 2D) + 0.5D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
return f(n.GetCubicFractal(x, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
return f(n.GetCubicFractal(x, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return f(n.GetCubicFractal(x, y, z));
|
||||
}
|
||||
}
|
||||
@@ -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.util.noise;
|
||||
|
||||
import com.volmit.iris.util.noise.FastNoiseDouble.FractalType;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
public class FractalFBMSimplexNoise implements NoiseGenerator, OctaveNoise {
|
||||
private final FastNoiseDouble n;
|
||||
|
||||
public FractalFBMSimplexNoise(long seed) {
|
||||
this.n = new FastNoiseDouble(new RNG(seed).lmax());
|
||||
n.setFractalOctaves(1);
|
||||
n.setFractalType(FractalType.FBM);
|
||||
}
|
||||
|
||||
public double f(double v) {
|
||||
return (v / 2D) + 0.5D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
return f(n.GetSimplexFractal(x, 0d));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
return f(n.GetSimplexFractal(x, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return f(n.GetSimplexFractal(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOctaves(int o) {
|
||||
n.setFractalOctaves(o);
|
||||
}
|
||||
}
|
||||
@@ -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.util.noise;
|
||||
|
||||
import com.volmit.iris.util.noise.FastNoiseDouble.FractalType;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
public class FractalRigidMultiSimplexNoise implements NoiseGenerator, OctaveNoise {
|
||||
private final FastNoiseDouble n;
|
||||
|
||||
public FractalRigidMultiSimplexNoise(long seed) {
|
||||
this.n = new FastNoiseDouble(new RNG(seed).lmax());
|
||||
n.setFractalOctaves(1);
|
||||
n.setFractalType(FractalType.RigidMulti);
|
||||
}
|
||||
|
||||
public double f(double v) {
|
||||
return (v / 2D) + 0.5D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
return f(n.GetSimplexFractal(x, 0d));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
return f(n.GetSimplexFractal(x, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return f(n.GetSimplexFractal(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOctaves(int o) {
|
||||
n.setFractalOctaves(o);
|
||||
}
|
||||
}
|
||||
51
src/main/java/com/volmit/iris/util/noise/GlobNoise.java
Normal file
51
src/main/java/com/volmit/iris/util/noise/GlobNoise.java
Normal 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.util.noise;
|
||||
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
public class GlobNoise implements NoiseGenerator {
|
||||
private final FastNoiseDouble n;
|
||||
|
||||
public GlobNoise(long seed) {
|
||||
this.n = new FastNoiseDouble(new RNG(seed).lmax());
|
||||
n.setNoiseType(FastNoiseDouble.NoiseType.Cellular);
|
||||
n.setCellularReturnType(FastNoiseDouble.CellularReturnType.Distance2Div);
|
||||
n.setCellularDistanceFunction(FastNoiseDouble.CellularDistanceFunction.Natural);
|
||||
}
|
||||
|
||||
private double f(double n) {
|
||||
return n + 1D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
return f(n.GetCellular(x, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
return f(n.GetCellular(x, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return f(n.GetCellular(x, y, z));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.util.noise;
|
||||
|
||||
import com.volmit.iris.engine.interpolation.InterpolationMethod;
|
||||
import com.volmit.iris.engine.interpolation.IrisInterpolation;
|
||||
import com.volmit.iris.util.function.NoiseProvider;
|
||||
|
||||
public class InterpolatedNoise implements NoiseGenerator {
|
||||
private final InterpolationMethod method;
|
||||
private final NoiseProvider p;
|
||||
|
||||
public InterpolatedNoise(long seed, NoiseType type, InterpolationMethod method) {
|
||||
this.method = method;
|
||||
NoiseGenerator g = type.create(seed);
|
||||
p = g::noise;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
return noise(x, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
return IrisInterpolation.getNoise(method, (int) x, (int) z, 32, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
if (z == 0) {
|
||||
return noise(x, y);
|
||||
}
|
||||
|
||||
return IrisInterpolation.getNoise(method, (int) x, (int) z, 32, p);
|
||||
}
|
||||
}
|
||||
24
src/main/java/com/volmit/iris/util/noise/NoiseFactory.java
Normal file
24
src/main/java/com/volmit/iris/util/noise/NoiseFactory.java
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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.util.noise;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface NoiseFactory {
|
||||
NoiseGenerator create(long seed);
|
||||
}
|
||||
35
src/main/java/com/volmit/iris/util/noise/NoiseGenerator.java
Normal file
35
src/main/java/com/volmit/iris/util/noise/NoiseGenerator.java
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.util.noise;
|
||||
|
||||
public interface NoiseGenerator {
|
||||
double noise(double x);
|
||||
|
||||
double noise(double x, double z);
|
||||
|
||||
double noise(double x, double y, double z);
|
||||
|
||||
default boolean isStatic() {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean isNoScale() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
82
src/main/java/com/volmit/iris/util/noise/NoiseType.java
Normal file
82
src/main/java/com/volmit/iris/util/noise/NoiseType.java
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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.util.noise;
|
||||
|
||||
import com.volmit.iris.engine.interpolation.InterpolationMethod;
|
||||
|
||||
public enum NoiseType {
|
||||
WHITE(WhiteNoise::new),
|
||||
WHITE_BILINEAR((s) -> new InterpolatedNoise(s, WHITE, InterpolationMethod.BILINEAR)),
|
||||
WHITE_BICUBIC((s) -> new InterpolatedNoise(s, WHITE, InterpolationMethod.BICUBIC)),
|
||||
WHITE_HERMITE((s) -> new InterpolatedNoise(s, WHITE, InterpolationMethod.HERMITE)),
|
||||
SIMPLEX(SimplexNoise::new),
|
||||
PERLIN(seed -> new PerlinNoise(seed).hermite()),
|
||||
FRACTAL_BILLOW_SIMPLEX(FractalBillowSimplexNoise::new),
|
||||
FRACTAL_BILLOW_PERLIN(FractalBillowPerlinNoise::new),
|
||||
FRACTAL_FBM_SIMPLEX(FractalFBMSimplexNoise::new),
|
||||
FRACTAL_RIGID_MULTI_SIMPLEX(FractalRigidMultiSimplexNoise::new),
|
||||
FLAT(FlatNoise::new),
|
||||
CELLULAR(CellularNoise::new),
|
||||
CELLULAR_BILINEAR((s) -> new InterpolatedNoise(s, CELLULAR, InterpolationMethod.BILINEAR)),
|
||||
CELLULAR_BILINEAR_STARCAST_3((s) -> new InterpolatedNoise(s, CELLULAR, InterpolationMethod.BILINEAR_STARCAST_3)),
|
||||
CELLULAR_BILINEAR_STARCAST_6((s) -> new InterpolatedNoise(s, CELLULAR, InterpolationMethod.BILINEAR_STARCAST_6)),
|
||||
CELLULAR_BILINEAR_STARCAST_9((s) -> new InterpolatedNoise(s, CELLULAR, InterpolationMethod.BILINEAR_STARCAST_9)),
|
||||
CELLULAR_BILINEAR_STARCAST_12((s) -> new InterpolatedNoise(s, CELLULAR, InterpolationMethod.BILINEAR_STARCAST_12)),
|
||||
CELLULAR_BICUBIC((s) -> new InterpolatedNoise(s, CELLULAR, InterpolationMethod.BICUBIC)),
|
||||
CELLULAR_HERMITE((s) -> new InterpolatedNoise(s, CELLULAR, InterpolationMethod.HERMITE)),
|
||||
CELLULAR_STARCAST_3((s) -> new InterpolatedNoise(s, CELLULAR, InterpolationMethod.STARCAST_3)),
|
||||
CELLULAR_STARCAST_6((s) -> new InterpolatedNoise(s, CELLULAR, InterpolationMethod.STARCAST_6)),
|
||||
CELLULAR_STARCAST_9((s) -> new InterpolatedNoise(s, CELLULAR, InterpolationMethod.STARCAST_9)),
|
||||
CELLULAR_STARCAST_12((s) -> new InterpolatedNoise(s, CELLULAR, InterpolationMethod.STARCAST_12)),
|
||||
CELLULAR_HERMITE_STARCAST_3((s) -> new InterpolatedNoise(s, CELLULAR, InterpolationMethod.HERMITE_STARCAST_3)),
|
||||
CELLULAR_HERMITE_STARCAST_6((s) -> new InterpolatedNoise(s, CELLULAR, InterpolationMethod.HERMITE_STARCAST_6)),
|
||||
CELLULAR_HERMITE_STARCAST_9((s) -> new InterpolatedNoise(s, CELLULAR, InterpolationMethod.HERMITE_STARCAST_9)),
|
||||
CELLULAR_HERMITE_STARCAST_12((s) -> new InterpolatedNoise(s, CELLULAR, InterpolationMethod.HERMITE_STARCAST_12)),
|
||||
GLOB(GlobNoise::new),
|
||||
CUBIC(CubicNoise::new),
|
||||
FRACTAL_CUBIC(FractalCubicNoise::new),
|
||||
CELLULAR_HEIGHT(CellHeightNoise::new),
|
||||
CLOVER(CloverNoise::new),
|
||||
CLOVER_BILINEAR((s) -> new InterpolatedNoise(s, CLOVER, InterpolationMethod.BILINEAR)),
|
||||
CLOVER_BILINEAR_STARCAST_3((s) -> new InterpolatedNoise(s, CLOVER, InterpolationMethod.BILINEAR_STARCAST_3)),
|
||||
CLOVER_BILINEAR_STARCAST_6((s) -> new InterpolatedNoise(s, CLOVER, InterpolationMethod.BILINEAR_STARCAST_6)),
|
||||
CLOVER_BILINEAR_STARCAST_9((s) -> new InterpolatedNoise(s, CLOVER, InterpolationMethod.BILINEAR_STARCAST_9)),
|
||||
CLOVER_BILINEAR_STARCAST_12((s) -> new InterpolatedNoise(s, CLOVER, InterpolationMethod.BILINEAR_STARCAST_12)),
|
||||
CLOVER_BICUBIC((s) -> new InterpolatedNoise(s, CLOVER, InterpolationMethod.BICUBIC)),
|
||||
CLOVER_HERMITE((s) -> new InterpolatedNoise(s, CLOVER, InterpolationMethod.HERMITE)),
|
||||
CLOVER_STARCAST_3((s) -> new InterpolatedNoise(s, CLOVER, InterpolationMethod.STARCAST_3)),
|
||||
CLOVER_STARCAST_6((s) -> new InterpolatedNoise(s, CLOVER, InterpolationMethod.STARCAST_6)),
|
||||
CLOVER_STARCAST_9((s) -> new InterpolatedNoise(s, CLOVER, InterpolationMethod.STARCAST_9)),
|
||||
CLOVER_STARCAST_12((s) -> new InterpolatedNoise(s, CLOVER, InterpolationMethod.STARCAST_12)),
|
||||
CLOVER_HERMITE_STARCAST_3((s) -> new InterpolatedNoise(s, CLOVER, InterpolationMethod.HERMITE_STARCAST_3)),
|
||||
CLOVER_HERMITE_STARCAST_6((s) -> new InterpolatedNoise(s, CLOVER, InterpolationMethod.HERMITE_STARCAST_6)),
|
||||
CLOVER_HERMITE_STARCAST_9((s) -> new InterpolatedNoise(s, CLOVER, InterpolationMethod.HERMITE_STARCAST_9)),
|
||||
CLOVER_HERMITE_STARCAST_12((s) -> new InterpolatedNoise(s, CLOVER, InterpolationMethod.HERMITE_STARCAST_12)),
|
||||
VASCULAR(VascularNoise::new);
|
||||
|
||||
private final NoiseFactory f;
|
||||
|
||||
NoiseType(NoiseFactory f) {
|
||||
this.f = f;
|
||||
}
|
||||
|
||||
public NoiseGenerator create(long seed) {
|
||||
return f.create(seed);
|
||||
}
|
||||
}
|
||||
23
src/main/java/com/volmit/iris/util/noise/OctaveNoise.java
Normal file
23
src/main/java/com/volmit/iris/util/noise/OctaveNoise.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.util.noise;
|
||||
|
||||
public interface OctaveNoise {
|
||||
void setOctaves(int o);
|
||||
}
|
||||
104
src/main/java/com/volmit/iris/util/noise/PerlinNoise.java
Normal file
104
src/main/java/com/volmit/iris/util/noise/PerlinNoise.java
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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.util.noise;
|
||||
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
public class PerlinNoise implements NoiseGenerator, OctaveNoise {
|
||||
private final FastNoiseDouble n;
|
||||
private int octaves;
|
||||
|
||||
public PerlinNoise(long seed) {
|
||||
this.n = new FastNoiseDouble(new RNG(seed).lmax());
|
||||
octaves = 1;
|
||||
}
|
||||
|
||||
public double f(double v) {
|
||||
return (v / 2D) + 0.5D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
if (octaves <= 1) {
|
||||
return f(n.GetPerlin(x, 0));
|
||||
}
|
||||
|
||||
double f = 1;
|
||||
double m = 0;
|
||||
double v = 0;
|
||||
|
||||
for (int i = 0; i < octaves; i++) {
|
||||
v += n.GetPerlin((x * (f == 1 ? f++ : (f *= 2))), 0) * f;
|
||||
m += f;
|
||||
}
|
||||
|
||||
return f(v / m);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
if (octaves <= 1) {
|
||||
return f(n.GetPerlin(x, z));
|
||||
}
|
||||
double f = 1;
|
||||
double m = 0;
|
||||
double v = 0;
|
||||
|
||||
for (int i = 0; i < octaves; i++) {
|
||||
f = f == 1 ? f + 1 : f * 2;
|
||||
v += n.GetPerlin((x * f), (z * f)) * f;
|
||||
m += f;
|
||||
}
|
||||
|
||||
return f(v / m);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
if (octaves <= 1) {
|
||||
return f(n.GetPerlin(x, y, z));
|
||||
}
|
||||
double f = 1;
|
||||
double m = 0;
|
||||
double v = 0;
|
||||
|
||||
for (int i = 0; i < octaves; i++) {
|
||||
f = f == 1 ? f + 1 : f * 2;
|
||||
v += n.GetPerlin((x * f), (y * f), (z * f)) * f;
|
||||
m += f;
|
||||
}
|
||||
|
||||
return f(v / m);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOctaves(int o) {
|
||||
octaves = o;
|
||||
}
|
||||
|
||||
public NoiseGenerator hermite() {
|
||||
n.m_longerp = FastNoiseDouble.Longerp.Hermite;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NoiseGenerator quad() {
|
||||
n.m_longerp = FastNoiseDouble.Longerp.Qulongic;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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.util.noise;
|
||||
|
||||
import com.volmit.iris.engine.object.common.IRare;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
public class RarityCellGenerator<T extends IRare> extends CellGenerator {
|
||||
public RarityCellGenerator(RNG rng) {
|
||||
super(rng);
|
||||
}
|
||||
|
||||
public T get(double x, double z, KList<T> b) {
|
||||
if (b.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (b.size() == 1) {
|
||||
return b.get(0);
|
||||
}
|
||||
|
||||
KList<T> rarityMapped = new KList<>();
|
||||
boolean o = false;
|
||||
int max = 1;
|
||||
for (T i : b) {
|
||||
if (i.getRarity() > max) {
|
||||
max = i.getRarity();
|
||||
}
|
||||
}
|
||||
|
||||
max++;
|
||||
|
||||
for (T i : b) {
|
||||
for (int j = 0; j < max - i.getRarity(); j++) {
|
||||
if (o = !o) {
|
||||
rarityMapped.add(i);
|
||||
} else {
|
||||
rarityMapped.add(0, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (rarityMapped.size() == 1) {
|
||||
return rarityMapped.get(0);
|
||||
}
|
||||
|
||||
if (rarityMapped.isEmpty()) {
|
||||
throw new RuntimeException("BAD RARITY MAP! RELATED TO: " + b.toString(", or possibly "));
|
||||
}
|
||||
|
||||
return rarityMapped.get(getIndex(x, z, rarityMapped.size()));
|
||||
}
|
||||
}
|
||||
94
src/main/java/com/volmit/iris/util/noise/SimplexNoise.java
Normal file
94
src/main/java/com/volmit/iris/util/noise/SimplexNoise.java
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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.util.noise;
|
||||
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
public class SimplexNoise implements NoiseGenerator, OctaveNoise {
|
||||
private final FastNoiseDouble n;
|
||||
private int octaves;
|
||||
|
||||
public SimplexNoise(long seed) {
|
||||
this.n = new FastNoiseDouble(new RNG(seed).lmax());
|
||||
octaves = 1;
|
||||
}
|
||||
|
||||
public double f(double v) {
|
||||
return (v / 2D) + 0.5D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
if (octaves <= 1) {
|
||||
return f(n.GetSimplex(x, 0d));
|
||||
}
|
||||
|
||||
double f = 1;
|
||||
double m = 0;
|
||||
double v = 0;
|
||||
|
||||
for (int i = 0; i < octaves; i++) {
|
||||
v += n.GetSimplex((x * (f == 1 ? f++ : (f *= 2))), 0d) * f;
|
||||
m += f;
|
||||
}
|
||||
|
||||
return f(v / m);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
if (octaves <= 1) {
|
||||
return f(n.GetSimplex(x, z));
|
||||
}
|
||||
double f = 1;
|
||||
double m = 0;
|
||||
double v = 0;
|
||||
|
||||
for (int i = 0; i < octaves; i++) {
|
||||
f = f == 1 ? f + 1 : f * 2;
|
||||
v += n.GetSimplex((x * f), (z * f)) * f;
|
||||
m += f;
|
||||
}
|
||||
|
||||
return f(v / m);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
if (octaves <= 1) {
|
||||
return f(n.GetSimplex(x, y, z));
|
||||
}
|
||||
double f = 1;
|
||||
double m = 0;
|
||||
double v = 0;
|
||||
|
||||
for (int i = 0; i < octaves; i++) {
|
||||
f = f == 1 ? f + 1 : f * 2;
|
||||
v += n.GetSimplex((x * f), (y * f), (z * f)) * f;
|
||||
m += f;
|
||||
}
|
||||
|
||||
return f(v / m);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOctaves(int o) {
|
||||
octaves = o;
|
||||
}
|
||||
}
|
||||
52
src/main/java/com/volmit/iris/util/noise/VascularNoise.java
Normal file
52
src/main/java/com/volmit/iris/util/noise/VascularNoise.java
Normal 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.util.noise;
|
||||
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
public class VascularNoise implements NoiseGenerator {
|
||||
private final FastNoiseDouble n;
|
||||
|
||||
public VascularNoise(long seed) {
|
||||
this.n = new FastNoiseDouble(new RNG(seed).lmax());
|
||||
n.setNoiseType(FastNoiseDouble.NoiseType.Cellular);
|
||||
n.setCellularReturnType(FastNoiseDouble.CellularReturnType.Distance2Sub);
|
||||
n.setCellularDistanceFunction(FastNoiseDouble.CellularDistanceFunction.Natural);
|
||||
}
|
||||
|
||||
private double filter(double noise) {
|
||||
return M.clip((noise / 2D) + 0.5D, 0D, 1D);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
return filter(n.GetCellular(x, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
return filter(n.GetCellular(x, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return filter(n.GetCellular(x, y, z));
|
||||
}
|
||||
}
|
||||
56
src/main/java/com/volmit/iris/util/noise/WhiteNoise.java
Normal file
56
src/main/java/com/volmit/iris/util/noise/WhiteNoise.java
Normal 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.util.noise;
|
||||
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
public class WhiteNoise implements NoiseGenerator {
|
||||
private final FastNoise n;
|
||||
|
||||
public WhiteNoise(long seed) {
|
||||
n = new FastNoise(new RNG(seed).imax());
|
||||
}
|
||||
|
||||
public boolean isStatic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isNoScale() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private double f(double m) {
|
||||
return (m % 8192) * 1024;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x) {
|
||||
return (n.GetWhiteNoise(f(x), 0d) / 2D) + 0.5D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double z) {
|
||||
return (n.GetWhiteNoise(f(x), f(z)) / 2D) + 0.5D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double noise(double x, double y, double z) {
|
||||
return (n.GetWhiteNoise(f(x), f(y), f(z)) / 2D) + 0.5D;
|
||||
}
|
||||
}
|
||||
104
src/main/java/com/volmit/iris/util/parallel/BurstExecutor.java
Normal file
104
src/main/java/com/volmit/iris/util/parallel/BurstExecutor.java
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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.util.parallel;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
public class BurstExecutor {
|
||||
private final ExecutorService executor;
|
||||
private final KList<CompletableFuture<Void>> futures;
|
||||
|
||||
public BurstExecutor(ExecutorService executor, int burstSizeEstimate) {
|
||||
this.executor = executor;
|
||||
futures = new KList<CompletableFuture<Void>>(burstSizeEstimate);
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public CompletableFuture<Void> queue(Runnable r) {
|
||||
synchronized (futures) {
|
||||
CompletableFuture<Void> c = CompletableFuture.runAsync(r, executor);
|
||||
futures.add(c);
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
public BurstExecutor queue(KList<Runnable> r) {
|
||||
synchronized (futures) {
|
||||
for (Runnable i : r) {
|
||||
CompletableFuture<Void> c = CompletableFuture.runAsync(i, executor);
|
||||
futures.add(c);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public BurstExecutor queue(Runnable[] r) {
|
||||
synchronized (futures) {
|
||||
for (Runnable i : r) {
|
||||
CompletableFuture<Void> c = CompletableFuture.runAsync(i, executor);
|
||||
futures.add(c);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public void complete() {
|
||||
synchronized (futures) {
|
||||
if (futures.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).get();
|
||||
futures.clear();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
Iris.reportError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean complete(long maxDur) {
|
||||
synchronized (futures) {
|
||||
if (futures.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
try {
|
||||
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).get(maxDur, TimeUnit.MILLISECONDS);
|
||||
} catch (TimeoutException e) {
|
||||
return false;
|
||||
}
|
||||
futures.clear();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
Iris.reportError(e);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
30
src/main/java/com/volmit/iris/util/parallel/BurstedHunk.java
Normal file
30
src/main/java/com/volmit/iris/util/parallel/BurstedHunk.java
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.util.parallel;
|
||||
|
||||
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
|
||||
public interface BurstedHunk<T> extends Hunk<T> {
|
||||
int getOffsetX();
|
||||
|
||||
int getOffsetY();
|
||||
|
||||
int getOffsetZ();
|
||||
}
|
||||
99
src/main/java/com/volmit/iris/util/parallel/GridLock.java
Normal file
99
src/main/java/com/volmit/iris/util/parallel/GridLock.java
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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.util.parallel;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.function.NastyRunnable;
|
||||
import com.volmit.iris.util.io.IORunnable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class GridLock {
|
||||
private final Hunk<ReentrantLock> locks;
|
||||
|
||||
public GridLock(int x, int z) {
|
||||
this.locks = Hunk.newAtomicHunk(x, 1, z);
|
||||
locks.iterateSync((a, b, c) -> locks.set(a, b, c, new ReentrantLock()));
|
||||
}
|
||||
|
||||
public void with(int x, int z, Runnable r) {
|
||||
lock(x, z);
|
||||
r.run();
|
||||
unlock(x, z);
|
||||
}
|
||||
|
||||
public void withNasty(int x, int z, NastyRunnable r) throws Throwable {
|
||||
lock(x, z);
|
||||
r.run();
|
||||
unlock(x, z);
|
||||
}
|
||||
|
||||
public void withIO(int x, int z, IORunnable r) throws IOException {
|
||||
lock(x, z);
|
||||
r.run();
|
||||
unlock(x, z);
|
||||
}
|
||||
|
||||
public <T> T withResult(int x, int z, Supplier<T> r) {
|
||||
lock(x, z);
|
||||
T t = r.get();
|
||||
unlock(x, z);
|
||||
return t;
|
||||
}
|
||||
|
||||
public void withAll(Runnable r) {
|
||||
locks.iterateSync((a, b, c, d) -> d.lock());
|
||||
r.run();
|
||||
locks.iterateSync((a, b, c, d) -> d.unlock());
|
||||
}
|
||||
|
||||
public <T> T withAllResult(Supplier<T> r) {
|
||||
locks.iterateSync((a, b, c, d) -> d.lock());
|
||||
T t = r.get();
|
||||
locks.iterateSync((a, b, c, d) -> d.unlock());
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
public boolean tryLock(int x, int z) {
|
||||
return locks.get(x, 0, z).tryLock();
|
||||
}
|
||||
|
||||
public boolean tryLock(int x, int z, long timeout) {
|
||||
try {
|
||||
return locks.get(x, 0, z).tryLock(timeout, TimeUnit.MILLISECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
Iris.reportError(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void lock(int x, int z) {
|
||||
locks.get(x, 0, z).lock();
|
||||
}
|
||||
|
||||
public void unlock(int x, int z) {
|
||||
locks.get(x, 0, z).unlock();
|
||||
}
|
||||
}
|
||||
109
src/main/java/com/volmit/iris/util/parallel/HyperLock.java
Normal file
109
src/main/java/com/volmit/iris/util/parallel/HyperLock.java
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* 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.util.parallel;
|
||||
|
||||
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.cache.Cache;
|
||||
import com.volmit.iris.util.function.NastyRunnable;
|
||||
import com.volmit.iris.util.io.IORunnable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class HyperLock {
|
||||
private final ConcurrentLinkedHashMap<Long, ReentrantLock> locks;
|
||||
private final BiFunction<? super Long, ? super ReentrantLock, ? extends ReentrantLock> accessor;
|
||||
|
||||
public HyperLock() {
|
||||
this(1024, false);
|
||||
}
|
||||
|
||||
public HyperLock(int capacity) {
|
||||
this(capacity, false);
|
||||
}
|
||||
|
||||
public HyperLock(int capacity, boolean fair) {
|
||||
locks = new ConcurrentLinkedHashMap.Builder<Long, ReentrantLock>()
|
||||
.initialCapacity(capacity)
|
||||
.maximumWeightedCapacity(capacity)
|
||||
.listener((k, v) -> {
|
||||
if (v.isLocked() || v.isHeldByCurrentThread()) {
|
||||
Iris.warn("InfiniLock Eviction of " + k + " still has locks on it!");
|
||||
}
|
||||
})
|
||||
.concurrencyLevel(32)
|
||||
.build();
|
||||
accessor = (k, v) -> v == null ? new ReentrantLock(fair) : v;
|
||||
}
|
||||
|
||||
public void with(int x, int z, Runnable r) {
|
||||
lock(x, z);
|
||||
r.run();
|
||||
unlock(x, z);
|
||||
}
|
||||
|
||||
public void withNasty(int x, int z, NastyRunnable r) throws Throwable {
|
||||
lock(x, z);
|
||||
r.run();
|
||||
unlock(x, z);
|
||||
}
|
||||
|
||||
public void withIO(int x, int z, IORunnable r) throws IOException {
|
||||
lock(x, z);
|
||||
r.run();
|
||||
unlock(x, z);
|
||||
}
|
||||
|
||||
public <T> T withResult(int x, int z, Supplier<T> r) {
|
||||
lock(x, z);
|
||||
T t = r.get();
|
||||
unlock(x, z);
|
||||
return t;
|
||||
}
|
||||
|
||||
public boolean tryLock(int x, int z) {
|
||||
return getLock(x, z).tryLock();
|
||||
}
|
||||
|
||||
public boolean tryLock(int x, int z, long timeout) {
|
||||
try {
|
||||
return getLock(x, z).tryLock(timeout, TimeUnit.MILLISECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
Iris.reportError(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private ReentrantLock getLock(int x, int z) {
|
||||
return locks.compute(Cache.key(x, z), accessor);
|
||||
}
|
||||
|
||||
public void lock(int x, int z) {
|
||||
getLock(x, z).lock();
|
||||
}
|
||||
|
||||
public void unlock(int x, int z) {
|
||||
getLock(x, z).unlock();
|
||||
}
|
||||
}
|
||||
174
src/main/java/com/volmit/iris/util/parallel/MultiBurst.java
Normal file
174
src/main/java/com/volmit/iris/util/parallel/MultiBurst.java
Normal file
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* 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.util.parallel;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import com.volmit.iris.util.scheduling.Looper;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class MultiBurst {
|
||||
public static final MultiBurst burst = new MultiBurst("Iris", IrisSettings.get().getConcurrency().getMiscThreadPriority(), IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getMiscThreadCount()));
|
||||
private ExecutorService service;
|
||||
private final Looper heartbeat;
|
||||
private final AtomicLong last;
|
||||
private int tid;
|
||||
private final String name;
|
||||
private final int tc;
|
||||
private final int priority;
|
||||
|
||||
public MultiBurst(int tc) {
|
||||
this("Iris", 6, tc);
|
||||
}
|
||||
|
||||
public MultiBurst(String name, int priority, int tc) {
|
||||
this.name = name;
|
||||
this.priority = priority;
|
||||
this.tc = tc;
|
||||
last = new AtomicLong(M.ms());
|
||||
heartbeat = new Looper() {
|
||||
@Override
|
||||
protected long loop() {
|
||||
if (M.ms() - last.get() > TimeUnit.MINUTES.toMillis(1) && service != null) {
|
||||
service.shutdown();
|
||||
service = null;
|
||||
Iris.debug("Shutting down MultiBurst Pool " + getName() + " to conserve resource.");
|
||||
}
|
||||
|
||||
return 60000;
|
||||
}
|
||||
};
|
||||
heartbeat.setName(name);
|
||||
heartbeat.start();
|
||||
}
|
||||
|
||||
private synchronized ExecutorService getService() {
|
||||
last.set(M.ms());
|
||||
if (service == null || service.isShutdown()) {
|
||||
service = Executors.newFixedThreadPool(Math.max(tc, 1), r -> {
|
||||
tid++;
|
||||
Thread t = new Thread(r);
|
||||
t.setName(name + " " + tid);
|
||||
t.setPriority(priority);
|
||||
t.setUncaughtExceptionHandler((et, e) ->
|
||||
{
|
||||
Iris.info("Exception encountered in " + et.getName());
|
||||
e.printStackTrace();
|
||||
});
|
||||
|
||||
return t;
|
||||
});
|
||||
Iris.debug("Started MultiBurst Pool " + name + " with " + tc + " threads at " + priority + " priority.");
|
||||
}
|
||||
|
||||
return service;
|
||||
}
|
||||
|
||||
public void burst(Runnable... r) {
|
||||
burst(r.length).queue(r).complete();
|
||||
}
|
||||
|
||||
public void burst(KList<Runnable> r) {
|
||||
burst(r.size()).queue(r).complete();
|
||||
}
|
||||
|
||||
public void sync(Runnable... r) {
|
||||
for (Runnable i : r) {
|
||||
i.run();
|
||||
}
|
||||
}
|
||||
|
||||
public BurstExecutor burst(int estimate) {
|
||||
return new BurstExecutor(getService(), estimate);
|
||||
}
|
||||
|
||||
public BurstExecutor burst() {
|
||||
return burst(16);
|
||||
}
|
||||
|
||||
public <T> Future<T> lazySubmit(Callable<T> o) {
|
||||
return getService().submit(o);
|
||||
}
|
||||
|
||||
public void lazy(Runnable o) {
|
||||
getService().execute(o);
|
||||
}
|
||||
|
||||
public Future<?> future(Runnable o) {
|
||||
return getService().submit(o);
|
||||
}
|
||||
|
||||
public CompletableFuture<?> complete(Runnable o) {
|
||||
return CompletableFuture.runAsync(o, getService());
|
||||
}
|
||||
|
||||
public void shutdownNow() {
|
||||
Iris.debug("Shutting down MultiBurst Pool " + heartbeat.getName() + ".");
|
||||
heartbeat.interrupt();
|
||||
|
||||
if (service != null) {
|
||||
service.shutdownNow().forEach(Runnable::run);
|
||||
}
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
Iris.debug("Shutting down MultiBurst Pool " + heartbeat.getName() + ".");
|
||||
heartbeat.interrupt();
|
||||
|
||||
if (service != null) {
|
||||
service.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
public void shutdownLater() {
|
||||
if (service != null) {
|
||||
service.submit(() -> {
|
||||
J.sleep(3000);
|
||||
Iris.debug("Shutting down MultiBurst Pool " + heartbeat.getName() + ".");
|
||||
|
||||
if (service != null) {
|
||||
service.shutdown();
|
||||
}
|
||||
});
|
||||
|
||||
heartbeat.interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
public void shutdownAndAwait() {
|
||||
Iris.debug("Shutting down MultiBurst Pool " + heartbeat.getName() + ".");
|
||||
heartbeat.interrupt();
|
||||
if (service != null) {
|
||||
service.shutdown();
|
||||
try {
|
||||
while (!service.awaitTermination(10, TimeUnit.SECONDS)) {
|
||||
Iris.info("Still waiting to shutdown burster...");
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
Iris.reportError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.util.parallel;
|
||||
|
||||
import com.volmit.iris.util.function.NastyRunnable;
|
||||
import com.volmit.iris.util.io.IORunnable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class NOOPGridLock extends GridLock {
|
||||
public NOOPGridLock(int x, int z) {
|
||||
super(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void with(int x, int z, Runnable r) {
|
||||
r.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void withNasty(int x, int z, NastyRunnable r) throws Throwable {
|
||||
r.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void withIO(int x, int z, IORunnable r) throws IOException {
|
||||
r.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T withResult(int x, int z, Supplier<T> r) {
|
||||
return r.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void withAll(Runnable r) {
|
||||
r.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T withAllResult(Supplier<T> r) {
|
||||
return r.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tryLock(int x, int z) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tryLock(int x, int z, long timeout) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lock(int x, int z) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unlock(int x, int z) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@
|
||||
package com.volmit.iris.util.scheduling;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.function.NastyFunction;
|
||||
import com.volmit.iris.util.function.NastyFuture;
|
||||
|
||||
@@ -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.util.stream;
|
||||
|
||||
import com.volmit.iris.util.collection.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;
|
||||
}
|
||||
}
|
||||
44
src/main/java/com/volmit/iris/util/stream/BasicLayer.java
Normal file
44
src/main/java/com/volmit/iris/util/stream/BasicLayer.java
Normal 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.util.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);
|
||||
}
|
||||
}
|
||||
55
src/main/java/com/volmit/iris/util/stream/BasicStream.java
Normal file
55
src/main/java/com/volmit/iris/util/stream/BasicStream.java
Normal 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.util.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);
|
||||
}
|
||||
@@ -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.util.stream;
|
||||
|
||||
public interface ProceduralLayer {
|
||||
long getSeed();
|
||||
|
||||
double getOffsetX();
|
||||
|
||||
double getOffsetY();
|
||||
|
||||
double getOffsetZ();
|
||||
|
||||
double getZoom();
|
||||
}
|
||||
523
src/main/java/com/volmit/iris/util/stream/ProceduralStream.java
Normal file
523
src/main/java/com/volmit/iris/util/stream/ProceduralStream.java
Normal file
@@ -0,0 +1,523 @@
|
||||
/*
|
||||
* 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.util.stream;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.project.loader.IrisData;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.engine.object.IrisStyledRange;
|
||||
import com.volmit.iris.engine.object.common.IRare;
|
||||
import com.volmit.iris.util.stream.arithmetic.*;
|
||||
import com.volmit.iris.util.stream.convert.*;
|
||||
import com.volmit.iris.util.stream.interpolation.Interpolated;
|
||||
import com.volmit.iris.util.stream.sources.FunctionStream;
|
||||
import com.volmit.iris.util.stream.utility.*;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.function.Function2;
|
||||
import com.volmit.iris.util.function.Function3;
|
||||
import com.volmit.iris.util.function.Function4;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
@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<Boolean> chance(double chance) {
|
||||
return of((x, z) -> getDouble(x, z) < chance, Interpolated.BOOLEAN);
|
||||
}
|
||||
|
||||
default ProceduralStream<Boolean> seededChance(RNG brng, long rootSeed, double chance) {
|
||||
RNG rng = brng.nextParallelRNG(rootSeed - 3995L);
|
||||
return of((x, z) -> {
|
||||
double ch = getDouble(x, z);
|
||||
rng.setSeed((long) (ch * Long.MAX_VALUE));
|
||||
return rng.chance(chance);
|
||||
}, Interpolated.BOOLEAN);
|
||||
}
|
||||
|
||||
default ProceduralStream<T> profile() {
|
||||
return profile(10);
|
||||
}
|
||||
|
||||
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> add(ProceduralStream<Double> a) {
|
||||
return add2D((x, z) -> a.get(x, z));
|
||||
}
|
||||
|
||||
default ProceduralStream<T> subtract(ProceduralStream<Double> a) {
|
||||
return subtract2D((x, z) -> a.get(x, z));
|
||||
}
|
||||
|
||||
default ProceduralStream<T> add2D(Function2<Double, Double, Double> a) {
|
||||
return new AddingStream<>(this, a);
|
||||
}
|
||||
|
||||
default ProceduralStream<T> subtract2D(Function2<Double, Double, Double> a) {
|
||||
return new SubtractingStream<T>(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 ProceduralStream<T> cache3D(int maxSize) {
|
||||
return new CachedStream3D<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<>();
|
||||
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) {
|
||||
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 <V> int countPossibilities(List<V> types, Function<V, IRare> loader) {
|
||||
KList<V> rarityTypes = new KList<>();
|
||||
int totalRarity = 0;
|
||||
for (V i : types) {
|
||||
totalRarity += IRare.get(loader.apply(i));
|
||||
}
|
||||
|
||||
for (V i : types) {
|
||||
rarityTypes.addMultiple(i, totalRarity / IRare.get(loader.apply(i)));
|
||||
}
|
||||
|
||||
return rarityTypes.size();
|
||||
}
|
||||
|
||||
default ProceduralStream<T> clamp(double min, double max) {
|
||||
return new ClampedStream<T>(this, min, max);
|
||||
}
|
||||
|
||||
default ProceduralStream<T> fit(double min, double max) {
|
||||
return new FittedStream<T>(this, min, max);
|
||||
}
|
||||
|
||||
default ProceduralStream<Double> style(RNG rng, IrisStyledRange range, IrisData data) {
|
||||
return ProceduralStream.of((x, z) -> {
|
||||
double d = getDouble(x, z);
|
||||
return range.get(rng, d, -d, data);
|
||||
}, Interpolated.DOUBLE);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
29
src/main/java/com/volmit/iris/util/stream/Significance.java
Normal file
29
src/main/java/com/volmit/iris/util/stream/Significance.java
Normal 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.util.stream;
|
||||
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
|
||||
public interface Significance<T> {
|
||||
KList<T> getFactorTypes();
|
||||
|
||||
double getSignificance(T t);
|
||||
|
||||
T getMostSignificantType();
|
||||
}
|
||||
@@ -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.util.stream.arithmetic;
|
||||
|
||||
import com.volmit.iris.util.stream.BasicStream;
|
||||
import com.volmit.iris.util.stream.ProceduralStream;
|
||||
import com.volmit.iris.util.function.Function2;
|
||||
import com.volmit.iris.util.function.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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.util.stream.arithmetic;
|
||||
|
||||
import com.volmit.iris.util.stream.BasicStream;
|
||||
import com.volmit.iris.util.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)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.util.stream.arithmetic;
|
||||
|
||||
import com.volmit.iris.util.stream.BasicStream;
|
||||
import com.volmit.iris.util.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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.util.stream.arithmetic;
|
||||
|
||||
import com.volmit.iris.util.stream.BasicStream;
|
||||
import com.volmit.iris.util.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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.util.stream.arithmetic;
|
||||
|
||||
import com.volmit.iris.util.stream.BasicStream;
|
||||
import com.volmit.iris.util.stream.ProceduralStream;
|
||||
import com.volmit.iris.util.function.Function2;
|
||||
import com.volmit.iris.util.function.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));
|
||||
}
|
||||
}
|
||||
@@ -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.util.stream.arithmetic;
|
||||
|
||||
import com.volmit.iris.util.stream.BasicStream;
|
||||
import com.volmit.iris.util.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)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.util.stream.arithmetic;
|
||||
|
||||
import com.volmit.iris.util.stream.BasicStream;
|
||||
import com.volmit.iris.util.stream.ProceduralStream;
|
||||
import com.volmit.iris.util.function.Function2;
|
||||
import com.volmit.iris.util.function.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)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.util.stream.arithmetic;
|
||||
|
||||
import com.volmit.iris.util.stream.BasicStream;
|
||||
import com.volmit.iris.util.stream.ProceduralStream;
|
||||
import com.volmit.iris.util.function.Function2;
|
||||
import com.volmit.iris.util.function.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)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.util.stream.arithmetic;
|
||||
|
||||
import com.volmit.iris.util.stream.BasicStream;
|
||||
import com.volmit.iris.util.stream.ProceduralStream;
|
||||
import com.volmit.iris.util.function.Function2;
|
||||
import com.volmit.iris.util.function.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));
|
||||
}
|
||||
}
|
||||
@@ -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.util.stream.arithmetic;
|
||||
|
||||
import com.volmit.iris.util.stream.BasicStream;
|
||||
import com.volmit.iris.util.stream.ProceduralStream;
|
||||
import com.volmit.iris.util.function.Function2;
|
||||
import com.volmit.iris.util.function.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));
|
||||
}
|
||||
}
|
||||
@@ -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.util.stream.arithmetic;
|
||||
|
||||
import com.volmit.iris.util.stream.BasicStream;
|
||||
import com.volmit.iris.util.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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.util.stream.arithmetic;
|
||||
|
||||
import com.volmit.iris.util.stream.BasicStream;
|
||||
import com.volmit.iris.util.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)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.util.stream.arithmetic;
|
||||
|
||||
import com.volmit.iris.util.stream.BasicStream;
|
||||
import com.volmit.iris.util.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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.util.stream.arithmetic;
|
||||
|
||||
import com.volmit.iris.util.stream.BasicStream;
|
||||
import com.volmit.iris.util.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)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.util.stream.arithmetic;
|
||||
|
||||
import com.volmit.iris.util.stream.BasicStream;
|
||||
import com.volmit.iris.util.stream.ProceduralStream;
|
||||
import com.volmit.iris.util.function.Function2;
|
||||
import com.volmit.iris.util.function.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));
|
||||
}
|
||||
}
|
||||
@@ -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.util.stream.arithmetic;
|
||||
|
||||
import com.volmit.iris.util.stream.BasicStream;
|
||||
import com.volmit.iris.util.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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.util.stream.convert;
|
||||
|
||||
import com.volmit.iris.util.stream.BasicStream;
|
||||
import com.volmit.iris.util.stream.ProceduralStream;
|
||||
import com.volmit.iris.util.function.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);
|
||||
}
|
||||
}
|
||||
@@ -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.util.stream.convert;
|
||||
|
||||
import com.volmit.iris.util.stream.BasicStream;
|
||||
import com.volmit.iris.util.stream.ProceduralStream;
|
||||
import com.volmit.iris.util.function.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);
|
||||
}
|
||||
}
|
||||
@@ -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.util.stream.convert;
|
||||
|
||||
import com.volmit.iris.util.stream.BasicLayer;
|
||||
import com.volmit.iris.util.stream.ProceduralStream;
|
||||
import com.volmit.iris.util.collection.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));
|
||||
}
|
||||
}
|
||||
@@ -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.util.stream.convert;
|
||||
|
||||
import com.volmit.iris.util.stream.BasicLayer;
|
||||
import com.volmit.iris.util.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));
|
||||
}
|
||||
}
|
||||
@@ -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.util.stream.convert;
|
||||
|
||||
import com.volmit.iris.util.stream.BasicStream;
|
||||
import com.volmit.iris.util.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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.util.stream.convert;
|
||||
|
||||
import com.volmit.iris.util.stream.BasicStream;
|
||||
import com.volmit.iris.util.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));
|
||||
}
|
||||
}
|
||||
@@ -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.util.stream.convert;
|
||||
|
||||
import com.volmit.iris.util.stream.BasicStream;
|
||||
import com.volmit.iris.util.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)];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.util.stream.convert;
|
||||
|
||||
import com.volmit.iris.util.stream.ArraySignificance;
|
||||
import com.volmit.iris.util.stream.BasicStream;
|
||||
import com.volmit.iris.util.stream.ProceduralStream;
|
||||
import com.volmit.iris.util.stream.Significance;
|
||||
import com.volmit.iris.util.collection.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);
|
||||
}
|
||||
}
|
||||
@@ -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.util.stream.convert;
|
||||
|
||||
import com.volmit.iris.util.stream.BasicStream;
|
||||
import com.volmit.iris.util.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);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user