Restructure Packages (read commit description)

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

File diff suppressed because it is too large Load Diff

View 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.engine.hunk;
public enum HunkFace {
TOP,
BOTTOM,
EAST,
WEST,
NORTH,
SOUTH
}

View File

@@ -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.engine.hunk.io;
import com.volmit.iris.Iris;
import com.volmit.iris.engine.hunk.Hunk;
import com.volmit.iris.util.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;
}
}

View File

@@ -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.engine.hunk.io;
import com.volmit.iris.util.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());
}
}

View File

@@ -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.engine.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();
}
}

View File

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

View File

@@ -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.engine.hunk.io;
import com.volmit.iris.Iris;
import com.volmit.iris.util.*;
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;
}
}

View File

@@ -0,0 +1,265 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.hunk.io;
import com.volmit.iris.Iris;
import com.volmit.iris.object.tile.TileData;
import com.volmit.iris.engine.hunk.Hunk;
import com.volmit.iris.engine.parallel.BurstExecutor;
import com.volmit.iris.engine.parallel.GridLock;
import com.volmit.iris.engine.parallel.MultiBurst;
import com.volmit.iris.util.*;
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::newMappedHunkSynced, new BlockDataHunkIOAdapter(), c, "blockdata");
public static final Function2<Integer, CompoundTag, HunkRegionSlice<TileData<? extends TileState>>> TILE = (h, c) -> new HunkRegionSlice<>(h, Hunk::newMappedHunkSynced, new TileDataHunkIOAdapter(), c, "tile");
public static final Function3<Integer, CompoundTag, String, HunkRegionSlice<String>> STRING = (h, c, t) -> new HunkRegionSlice<>(h, Hunk::newMappedHunkSynced, new StringHunkIOAdapter(), c, t);
public static final Function3<Integer, CompoundTag, String, HunkRegionSlice<Boolean>> BOOLEAN = (h, c, t) -> new HunkRegionSlice<>(h, Hunk::newMappedHunkSynced, new BooleanHunkIOAdapter(), c, t);
private final Function3<Integer, Integer, Integer, Hunk<T>> factory;
private final GridLock lock;
private final HunkIOAdapter<T> adapter;
private final CompoundTag compound;
private final String key;
private final KMap<ChunkPosition, Hunk<T>> loadedChunks;
private final KMap<ChunkPosition, Long> lastUse;
private final KSet<ChunkPosition> save;
private final int height;
public HunkRegionSlice(int height, Function3<Integer, Integer, Integer, Hunk<T>> factory, HunkIOAdapter<T> adapter, CompoundTag compound, String key) {
this.lock = new GridLock(32, 32);
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);
for (ChunkPosition i : lastUse.k()) {
if (!loadedChunks.containsKey(i)) {
Iris.warn(" Missing LoadChunkKey " + i);
}
}
}
for (ChunkPosition i : lastUse.k()) {
Long l = lastUse.get(i);
if (l == null || M.ms() - l > t) {
v++;
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() {
BurstExecutor e = MultiBurst.burst.burst();
for (ChunkPosition i : save.copy()) {
if (i == null) {
continue;
}
e.queue(() -> save(i.getX(), i.getZ()));
try {
lock.withNasty(i.getX(), i.getZ(), () -> save.remove(i));
} catch (Throwable eer) {Iris.reportError(eer);
}
}
e.complete();
}
public boolean contains(int x, int z) {
return compound.getValue().containsKey(key(x, z));
}
public void delete(int x, int z) {
lock.with(x, 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 = lock.withResult(x, z, () -> {
Tag t = compound.getValue().get(key(x, z));
if (!(t instanceof ByteArrayTag)) {
Iris.verbose("NOT BYTE ARRAY!");
return null;
}
try {
return adapter.read(factory, (ByteArrayTag) t);
} catch (IOException xe) {Iris.reportError(xe);
e.set(xe);
}
return null;
});
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 {
lock.withIO(x, z, () -> compound.getValue().put(key(x, z), hunk.writeByteArrayTag(adapter, key(x, z))));
}
public synchronized int unloadAll() {
int v = 0;
for (ChunkPosition 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 {
lock.withIO(x, z, () -> write(region, x, z));
} catch (IOException e) {Iris.reportError(e);
e.printStackTrace();
}
}
public boolean isLoaded(int x, int z) {
return lock.withResult(x, z, () -> loadedChunks.containsKey(new ChunkPosition(x, z)));
}
public void save(int x, int z) {
lock.with(x, z, () -> {
if (isLoaded(x, z)) {
save(get(x, z), x, z);
}
});
}
public void unload(int x, int z) {
lock.with(x, z, () -> {
ChunkPosition key = new ChunkPosition(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) {
return lock.withResult(x, z, () -> {
if (isLoaded(x, z)) {
return loadedChunks.get(new ChunkPosition(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 ChunkPosition(x, z), v);
return v;
});
}
public Hunk<T> get(int x, int z) {
return lock.withResult(x, z, () -> {
ChunkPosition key = new ChunkPosition(x, z);
Hunk<T> c = loadedChunks.get(key);
if (c == null) {
c = load(x, z);
}
lastUse.put(new ChunkPosition(x, z), M.ms());
return c;
});
}
public Hunk<T> getR(int x, int z) {
return lock.withResult(x, z, () -> get(x, z).readOnly());
}
public Hunk<T> getRW(int x, int z) {
return lock.withResult(x, z, () -> {
save.add(new ChunkPosition(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();
}
}

View File

@@ -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.engine.hunk.io;
import com.volmit.iris.Iris;
import com.volmit.iris.engine.data.DataPalette;
import com.volmit.iris.engine.hunk.Hunk;
import com.volmit.iris.util.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;
}
}

View File

@@ -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.engine.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();
}
}

View File

@@ -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.engine.hunk.io;
import com.volmit.iris.Iris;
import com.volmit.iris.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();
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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.engine.hunk.storage;
import com.volmit.iris.engine.hunk.Hunk;
import com.volmit.iris.util.Consumer4;
import com.volmit.iris.util.KMap;
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));
}
}

View File

@@ -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.engine.hunk.storage;
import com.volmit.iris.engine.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);
}

View File

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

View File

@@ -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.engine.hunk.view;
import com.volmit.iris.nms.INMS;
import com.volmit.iris.engine.hunk.Hunk;
import com.volmit.iris.util.LinkedTerrainChunk;
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);
}
}

View File

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

View File

@@ -0,0 +1,71 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.engine.hunk.view;
import com.volmit.iris.engine.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;
}
enforceBounds(x1, y1, z1, x2 - x1, y2 - y1, z2 - z1);
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);
}
}

View File

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

View File

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

View File

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

View 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.engine.hunk.view;
import com.volmit.iris.engine.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;
}
}

View File

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

View File

@@ -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.engine.hunk.view;
import com.volmit.iris.engine.hunk.Hunk;
import com.volmit.iris.util.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;
}
}

View File

@@ -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.engine.hunk.view;
import com.volmit.iris.engine.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;
}
}

View File

@@ -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.engine.hunk.view;
import com.volmit.iris.engine.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;
}
}

View File

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

View File

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

View File

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

View File

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