9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-28 03:29:06 +00:00

Merge remote-tracking branch 'upstream/master' into DecreeCommands

This commit is contained in:
CocoTheOwner
2021-08-28 16:19:29 +02:00
154 changed files with 2709 additions and 2771 deletions

View File

@@ -19,7 +19,7 @@
package com.volmit.iris.util.context;
import com.volmit.iris.Iris;
import com.volmit.iris.core.project.loader.IrisData;
import com.volmit.iris.core.loader.IrisData;
import com.volmit.iris.engine.IrisComplex;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.util.collection.KMap;

View File

@@ -28,6 +28,7 @@ import it.unimi.dsi.fastutil.ints.IntSets;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Waterlogged;
import org.bukkit.block.data.type.Leaves;
import java.util.Arrays;
@@ -510,4 +511,8 @@ public class B {
return bt.toArray(new String[0]);
}
public static boolean isWaterLogged(BlockData b) {
return (b instanceof Waterlogged) && ((Waterlogged)b).isWaterlogged();
}
}

View File

@@ -18,7 +18,7 @@
package com.volmit.iris.util.data;
import com.volmit.iris.core.project.loader.IrisData;
import com.volmit.iris.core.loader.IrisData;
public interface DataProvider {
IrisData getData();

View File

@@ -21,8 +21,9 @@ package com.volmit.iris.util.data;
import com.volmit.iris.util.math.IrisMathHelper;
import org.bukkit.block.Biome;
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
import org.jetbrains.annotations.NotNull;
public class IrisBiomeStorage {
public class IrisBiomeStorage implements BiomeGrid {
private static final int e;
private static final int f;
public static final int a;
@@ -67,6 +68,12 @@ public class IrisBiomeStorage {
}
}
@NotNull
@Override
public Biome getBiome(int x, int z) {
return null;
}
public Biome getBiome(final int x, final int y, final int z) {
final int l = x & IrisBiomeStorage.b;
final int i2 = IrisMathHelper.clamp(y, 0, IrisBiomeStorage.c);
@@ -74,6 +81,11 @@ public class IrisBiomeStorage {
return this.g[i2 << IrisBiomeStorage.e + IrisBiomeStorage.e | j2 << IrisBiomeStorage.e | l];
}
@Override
public void setBiome(int x, int z, @NotNull Biome bio) {
}
public void setBiome(final int x, final int y, final int z, final Biome biome) {
final int l = x & IrisBiomeStorage.b;
final int i2 = IrisMathHelper.clamp(y, 0, IrisBiomeStorage.c);

View File

@@ -1,127 +0,0 @@
/*
* 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.data;
import com.volmit.iris.Iris;
import com.volmit.iris.core.service.StudioSVC;
import com.volmit.iris.util.format.Form;
import com.volmit.iris.util.plugin.VolmitSender;
import com.volmit.iris.util.scheduling.jobs.DownloadJob;
import com.volmit.iris.util.scheduling.jobs.JobCollection;
import com.volmit.iris.util.scheduling.jobs.SingleJob;
import lombok.Builder;
import lombok.Data;
import org.zeroturnaround.zip.ZipUtil;
import org.zeroturnaround.zip.commons.FileUtils;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.UUID;
@Data
@Builder
public class IrisPackRepository {
@Builder.Default
private String user = "IrisDimensions";
@Builder.Default
private String repo = "overworld";
@Builder.Default
private String branch = "master";
@Builder.Default
private String tag = "";
public static IrisPackRepository from(String g) {
// https://github.com/IrisDimensions/overworld
if (g.startsWith("https://github.com/")) {
String sub = g.split("\\Qgithub.com/\\E")[1];
IrisPackRepository r = IrisPackRepository.builder()
.user(sub.split("\\Q/\\E")[0])
.repo(sub.split("\\Q/\\E")[1]).build();
if (g.contains("/tree/")) {
r.setBranch(g.split("/tree/")[1]);
}
return r;
} else if (g.contains("/")) {
String[] f = g.split("\\Q/\\E");
if (f.length == 1) {
return from(g);
} else if (f.length == 2) {
return IrisPackRepository.builder()
.user(f[0])
.repo(f[1])
.build();
} else if (f.length >= 3) {
IrisPackRepository r = IrisPackRepository.builder()
.user(f[0])
.repo(f[1])
.build();
if (f[2].startsWith("#")) {
r.setTag(f[2].substring(1));
} else {
r.setBranch(f[2]);
}
return r;
}
} else {
return IrisPackRepository.builder()
.user("IrisDimensions")
.repo(g)
.branch(g.equals("overworld") ? "stable" : "master")
.build();
}
return null;
}
public String toURL() {
if (!tag.trim().isEmpty()) {
return "https://codeload.github.com/" + user + "/" + repo + "/zip/refs/tags/" + tag;
}
return "https://codeload.github.com/" + user + "/" + repo + "/zip/refs/heads/" + branch;
}
public void install(VolmitSender sender) throws MalformedURLException {
File pack = Iris.instance.getDataFolder(StudioSVC.WORKSPACE_NAME, getRepo());
if (!pack.exists()) {
File dl = new File(Iris.getTemp(), "dltk-" + UUID.randomUUID() + ".zip");
File work = new File(Iris.getTemp(), "extk-" + UUID.randomUUID());
new JobCollection(Form.capitalize(getRepo()),
new DownloadJob(toURL(), pack),
new SingleJob("Extracting", () -> ZipUtil.unpack(dl, work)),
new SingleJob("Installing", () -> {
try {
FileUtils.copyDirectory(work.listFiles()[0], pack);
} catch (IOException e) {
e.printStackTrace();
}
})).execute(sender);
}
}
}

View File

@@ -19,7 +19,7 @@
package com.volmit.iris.util.decree.handlers;
import com.volmit.iris.Iris;
import com.volmit.iris.core.project.loader.IrisData;
import com.volmit.iris.core.loader.IrisData;
import com.volmit.iris.engine.object.biome.IrisBiome;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KMap;

View File

@@ -19,7 +19,7 @@
package com.volmit.iris.util.decree.handlers;
import com.volmit.iris.Iris;
import com.volmit.iris.core.project.loader.IrisData;
import com.volmit.iris.core.loader.IrisData;
import com.volmit.iris.engine.object.dimensional.IrisDimension;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KMap;

View File

@@ -19,7 +19,7 @@
package com.volmit.iris.util.decree.handlers;
import com.volmit.iris.Iris;
import com.volmit.iris.core.project.loader.IrisData;
import com.volmit.iris.core.loader.IrisData;
import com.volmit.iris.engine.object.entity.IrisEntity;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KMap;

View File

@@ -19,7 +19,7 @@
package com.volmit.iris.util.decree.handlers;
import com.volmit.iris.Iris;
import com.volmit.iris.core.project.loader.IrisData;
import com.volmit.iris.core.loader.IrisData;
import com.volmit.iris.engine.object.noise.IrisGenerator;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KMap;

View File

@@ -19,7 +19,7 @@
package com.volmit.iris.util.decree.handlers;
import com.volmit.iris.Iris;
import com.volmit.iris.core.project.loader.IrisData;
import com.volmit.iris.core.loader.IrisData;
import com.volmit.iris.engine.object.regional.IrisRegion;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KMap;

View File

@@ -19,7 +19,7 @@
package com.volmit.iris.util.decree.handlers;
import com.volmit.iris.Iris;
import com.volmit.iris.core.project.loader.IrisData;
import com.volmit.iris.core.loader.IrisData;
import com.volmit.iris.engine.object.common.IrisScript;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KMap;

View File

@@ -19,7 +19,7 @@
package com.volmit.iris.util.decree.specialhandlers;
import com.volmit.iris.Iris;
import com.volmit.iris.core.project.loader.IrisData;
import com.volmit.iris.core.loader.IrisData;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.decree.DecreeParameterHandler;
import com.volmit.iris.util.decree.exceptions.DecreeParsingException;

View File

@@ -26,4 +26,12 @@ public class IrisException extends Exception {
public IrisException(String message) {
super(message);
}
public IrisException(Throwable message) {
super(message);
}
public IrisException(String message, Throwable e) {
super(message, e);
}
}

View File

@@ -38,9 +38,11 @@ import com.volmit.iris.util.math.KochanekBartelsInterpolation;
import com.volmit.iris.util.math.M;
import com.volmit.iris.util.math.PathInterpolation;
import com.volmit.iris.util.matter.Matter;
import com.volmit.iris.util.matter.MatterCavern;
import com.volmit.iris.util.parallel.BurstExecutor;
import com.volmit.iris.util.parallel.HyperLock;
import com.volmit.iris.util.parallel.MultiBurst;
import org.bukkit.Chunk;
import org.bukkit.util.Vector;
import java.io.File;
@@ -151,6 +153,10 @@ public class Mantle {
get(x >> 5, z >> 5).getOrCreate(x & 31, z & 31).flag(flag, flagged);
}
public void deleteChunk(int x, int z) {
get(x >> 5, z >> 5).delete(x & 31, z & 31);
}
/**
* Check very quickly if a tectonic plate exists via cached or the file system
*
@@ -426,13 +432,18 @@ public class Mantle {
if (file.exists()) {
try {
region = TectonicPlate.read(worldHeight, file);
if (region.getX() != x || region.getZ() != z) {
Iris.warn("Loaded Tectonic Plate " + x + "," + z + " but read it as " + region.getX() + "," + region.getZ() + "... Assuming " + x + "," + z);
}
loadedRegions.put(k, region);
Iris.debug("Loaded Tectonic Plate " + C.DARK_GREEN + x + " " + z + C.DARK_AQUA + " " + file.getName());
} catch (Throwable e) {
Iris.error("Failed to read Tectonic Plate " + file.getAbsolutePath() + " creating a new chunk instead.");
Iris.reportError(e);
e.printStackTrace();
region = new TectonicPlate(worldHeight);
region = new TectonicPlate(worldHeight, x, z);
loadedRegions.put(k, region);
Iris.debug("Created new Tectonic Plate (Due to Load Failure) " + C.DARK_GREEN + x + " " + z);
}
@@ -440,7 +451,7 @@ public class Mantle {
return region;
}
region = new TectonicPlate(worldHeight);
region = new TectonicPlate(worldHeight, x, z);
loadedRegions.put(k, region);
Iris.debug("Created new Tectonic Plate " + C.DARK_GREEN + x + " " + z);
return region;
@@ -489,440 +500,15 @@ public class Mantle {
}
/**
* Set a sphere into the mantle
*
* @param cx the center x
* @param cy the center y
* @param cz the center z
* @param radius the radius of this sphere
* @param fill should it be filled? or just the outer shell?
* @param data the data to set
* @param <T> the type of data to apply to the mantle
*/
public <T> void setSphere(int cx, int cy, int cz, double radius, boolean fill, T data) {
setElipsoid(cx, cy, cz, radius, radius, radius, fill, data);
}
/**
* Set an elipsoid into the mantle
*
* @param cx the center x
* @param cy the center y
* @param cz the center z
* @param rx the x radius
* @param ry the y radius
* @param rz the z radius
* @param fill should it be filled or just the outer shell?
* @param data the data to set
* @param <T> the type of data to apply to the mantle
*/
public <T> void setElipsoid(int cx, int cy, int cz, double rx, double ry, double rz, boolean fill, T data) {
rx += 0.5;
ry += 0.5;
rz += 0.5;
final double invRadiusX = 1 / rx;
final double invRadiusY = 1 / ry;
final double invRadiusZ = 1 / rz;
final int ceilRadiusX = (int) Math.ceil(rx);
final int ceilRadiusY = (int) Math.ceil(ry);
final int ceilRadiusZ = (int) Math.ceil(rz);
double nextXn = 0;
forX:
for (int x = 0; x <= ceilRadiusX; ++x) {
final double xn = nextXn;
nextXn = (x + 1) * invRadiusX;
double nextYn = 0;
forY:
for (int y = 0; y <= ceilRadiusY; ++y) {
final double yn = nextYn;
nextYn = (y + 1) * invRadiusY;
double nextZn = 0;
for (int z = 0; z <= ceilRadiusZ; ++z) {
final double zn = nextZn;
nextZn = (z + 1) * invRadiusZ;
double distanceSq = lengthSq(xn, yn, zn);
if (distanceSq > 1) {
if (z == 0) {
if (y == 0) {
break forX;
}
break forY;
}
break;
}
if (!fill) {
if (lengthSq(nextXn, yn, zn) <= 1 && lengthSq(xn, nextYn, zn) <= 1 && lengthSq(xn, yn, nextZn) <= 1) {
continue;
}
}
set(x + cx, y + cy, z + cz, data);
set(-x + cx, y + cy, z + cz, data);
set(x + cx, -y + cy, z + cz, data);
set(x + cx, y + cy, -z + cz, data);
set(-x + cx, y + cy, -z + cz, data);
set(-x + cx, -y + cy, z + cz, data);
set(x + cx, -y + cy, -z + cz, data);
set(-x + cx, y + cy, -z + cz, data);
set(-x + cx, -y + cy, -z + cz, data);
}
}
}
}
/**
* Set a cuboid of data in the mantle
*
* @param x1 the min x
* @param y1 the min y
* @param z1 the min z
* @param x2 the max x
* @param y2 the max y
* @param z2 the max z
* @param data the data to set
* @param <T> the type of data to apply to the mantle
*/
public <T> void setCuboid(int x1, int y1, int z1, int x2, int y2, int z2, T data) {
int j, k;
for (int i = x1; i <= x2; i++) {
for (j = x1; j <= x2; j++) {
for (k = x1; k <= x2; k++) {
set(i, j, k, data);
}
}
}
}
/**
* Set a pyramid of data in the mantle
*
* @param cx the center x
* @param cy the base y
* @param cz the center z
* @param data the data to set
* @param size the size of the pyramid (width of base & height)
* @param filled should it be filled or hollow
* @param <T> the type of data to apply to the mantle
*/
@SuppressWarnings("ConstantConditions")
public <T> void setPyramid(int cx, int cy, int cz, T data, int size, boolean filled) {
int height = size;
for (int y = 0; y <= height; ++y) {
size--;
for (int x = 0; x <= size; ++x) {
for (int z = 0; z <= size; ++z) {
if ((filled && z <= size && x <= size) || z == size || x == size) {
set(x + cx, y + cy, z + cz, data);
set(-x + cx, y + cy, z + cz, data);
set(x + cx, y + cy, -z + cz, data);
set(-x + cx, y + cy, -z + cz, data);
}
}
}
}
}
/**
* Set a 3d tube spline interpolated with Kochanek Bartels
*
* @param nodevectors the vector points
* @param radius the radius
* @param filled if it should be filled or hollow
* @param data the data to set
*/
public <T> void setSpline(List<Vector> nodevectors, double radius, boolean filled, T data) {
setSpline(nodevectors, 0, 0, 0, 10, radius, filled, data);
}
/**
* Set a 3d tube spline interpolated with Kochanek Bartels
*
* @param nodevectors the spline points
* @param tension the tension 0
* @param bias the bias 0
* @param continuity the continuity 0
* @param quality the quality 10
* @param radius the radius
* @param filled filled or hollow
* @param data the data to set
* @param <T> the type of data to apply to the mantle
*/
public <T> void setSpline(List<Vector> nodevectors, double tension, double bias, double continuity, double quality, double radius, boolean filled, T data) {
Set<IrisPosition> vset = new KSet<>();
List<INode> nodes = new ArrayList<>(nodevectors.size());
PathInterpolation interpol = new KochanekBartelsInterpolation();
for (Vector nodevector : nodevectors) {
INode n = new INode(nodevector);
n.setTension(tension);
n.setBias(bias);
n.setContinuity(continuity);
nodes.add(n);
}
interpol.setNodes(nodes);
double splinelength = interpol.arcLength(0, 1);
for (double loop = 0; loop <= 1; loop += 1D / splinelength / quality) {
Vector tipv = interpol.getPosition(loop);
vset.add(new IrisPosition(tipv.toBlockVector()));
}
vset = getBallooned(vset, radius);
if (!filled) {
vset = getHollowed(vset);
}
set(vset, data);
}
/**
* Set a 3d line
*
* @param a the first point
* @param b the second point
* @param radius the radius
* @param filled hollow or filled?
* @param data the data
* @param <T> the type of data to apply to the mantle
*/
public <T> void setLine(IrisPosition a, IrisPosition b, double radius, boolean filled, T data) {
setLine(ImmutableList.of(a, b), radius, filled, data);
}
/**
* Set lines for points
*
* @param vectors the points
* @param radius the radius
* @param filled hollow or filled?
* @param data the data to set
* @param <T> the type of data to apply to the mantle
*/
public <T> void setLine(List<IrisPosition> vectors, double radius, boolean filled, T data) {
Set<IrisPosition> vset = new KSet<>();
for (int i = 0; vectors.size() != 0 && i < vectors.size() - 1; i++) {
IrisPosition pos1 = vectors.get(i);
IrisPosition pos2 = vectors.get(i + 1);
int x1 = pos1.getX();
int y1 = pos1.getY();
int z1 = pos1.getZ();
int x2 = pos2.getX();
int y2 = pos2.getY();
int z2 = pos2.getZ();
int tipx = x1;
int tipy = y1;
int tipz = z1;
int dx = Math.abs(x2 - x1);
int dy = Math.abs(y2 - y1);
int dz = Math.abs(z2 - z1);
if (dx + dy + dz == 0) {
vset.add(new IrisPosition(tipx, tipy, tipz));
continue;
}
int dMax = Math.max(Math.max(dx, dy), dz);
if (dMax == dx) {
for (int domstep = 0; domstep <= dx; domstep++) {
tipx = x1 + domstep * (x2 - x1 > 0 ? 1 : -1);
tipy = (int) Math.round(y1 + domstep * ((double) dy) / ((double) dx) * (y2 - y1 > 0 ? 1 : -1));
tipz = (int) Math.round(z1 + domstep * ((double) dz) / ((double) dx) * (z2 - z1 > 0 ? 1 : -1));
vset.add(new IrisPosition(tipx, tipy, tipz));
}
} else if (dMax == dy) {
for (int domstep = 0; domstep <= dy; domstep++) {
tipy = y1 + domstep * (y2 - y1 > 0 ? 1 : -1);
tipx = (int) Math.round(x1 + domstep * ((double) dx) / ((double) dy) * (x2 - x1 > 0 ? 1 : -1));
tipz = (int) Math.round(z1 + domstep * ((double) dz) / ((double) dy) * (z2 - z1 > 0 ? 1 : -1));
vset.add(new IrisPosition(tipx, tipy, tipz));
}
} else /* if (dMax == dz) */ {
for (int domstep = 0; domstep <= dz; domstep++) {
tipz = z1 + domstep * (z2 - z1 > 0 ? 1 : -1);
tipy = (int) Math.round(y1 + domstep * ((double) dy) / ((double) dz) * (y2 - y1 > 0 ? 1 : -1));
tipx = (int) Math.round(x1 + domstep * ((double) dx) / ((double) dz) * (x2 - x1 > 0 ? 1 : -1));
vset.add(new IrisPosition(tipx, tipy, tipz));
}
}
}
vset = getBallooned(vset, radius);
if (!filled) {
vset = getHollowed(vset);
}
set(vset, data);
}
/**
* Set a cylinder in the mantle
*
* @param cx the center x
* @param cy the base y
* @param cz the center z
* @param data the data to set
* @param radius the radius
* @param height the height of the cyl
* @param filled filled or not
*/
public <T> void setCylinder(int cx, int cy, int cz, T data, double radius, int height, boolean filled) {
setCylinder(cx, cy, cz, data, radius, radius, height, filled);
}
/**
* Set a cylinder in the mantle
*
* @param cx the center x
* @param cy the base y
* @param cz the center z
* @param data the data to set
* @param radiusX the x radius
* @param radiusZ the z radius
* @param height the height of this cyl
* @param filled filled or hollow?
*/
public <T> void setCylinder(int cx, int cy, int cz, T data, double radiusX, double radiusZ, int height, boolean filled) {
int affected = 0;
radiusX += 0.5;
radiusZ += 0.5;
if (height == 0) {
return;
} else if (height < 0) {
height = -height;
cy = cy - height;
}
if (cy < 0) {
cy = 0;
} else if (cy + height - 1 > worldHeight) {
height = worldHeight - cy + 1;
}
final double invRadiusX = 1 / radiusX;
final double invRadiusZ = 1 / radiusZ;
final int ceilRadiusX = (int) Math.ceil(radiusX);
final int ceilRadiusZ = (int) Math.ceil(radiusZ);
double nextXn = 0;
forX:
for (int x = 0; x <= ceilRadiusX; ++x) {
final double xn = nextXn;
nextXn = (x + 1) * invRadiusX;
double nextZn = 0;
for (int z = 0; z <= ceilRadiusZ; ++z) {
final double zn = nextZn;
nextZn = (z + 1) * invRadiusZ;
double distanceSq = lengthSq(xn, zn);
if (distanceSq > 1) {
if (z == 0) {
break forX;
}
break;
}
if (!filled) {
if (lengthSq(nextXn, zn) <= 1 && lengthSq(xn, nextZn) <= 1) {
continue;
}
}
for (int y = 0; y < height; ++y) {
set(cx + x, cy + y, cz + z, data);
set(cx + -x, cy + y, cz + z, data);
set(cx + x, cy + y, cz + -z, data);
set(cx + -x, cy + y, cz + -z, data);
}
}
}
}
public <T> void set(IrisPosition pos, T data) {
set(pos.getX(), pos.getY(), pos.getZ(), data);
}
public <T> void set(List<IrisPosition> positions, T data) {
for (IrisPosition i : positions) {
set(i, data);
}
}
public <T> void set(Set<IrisPosition> positions, T data) {
for (IrisPosition i : positions) {
set(i, data);
}
}
private static Set<IrisPosition> getBallooned(Set<IrisPosition> vset, double radius) {
Set<IrisPosition> returnset = new HashSet<>();
int ceilrad = (int) Math.ceil(radius);
for (IrisPosition v : vset) {
int tipx = v.getX();
int tipy = v.getY();
int tipz = v.getZ();
for (int loopx = tipx - ceilrad; loopx <= tipx + ceilrad; loopx++) {
for (int loopy = tipy - ceilrad; loopy <= tipy + ceilrad; loopy++) {
for (int loopz = tipz - ceilrad; loopz <= tipz + ceilrad; loopz++) {
if (hypot(loopx - tipx, loopy - tipy, loopz - tipz) <= radius) {
returnset.add(new IrisPosition(loopx, loopy, loopz));
}
}
}
}
}
return returnset;
}
private static Set<IrisPosition> getHollowed(Set<IrisPosition> vset) {
Set<IrisPosition> returnset = new KSet<>();
for (IrisPosition v : vset) {
double x = v.getX();
double y = v.getY();
double z = v.getZ();
if (!(vset.contains(new IrisPosition(x + 1, y, z))
&& vset.contains(new IrisPosition(x - 1, y, z))
&& vset.contains(new IrisPosition(x, y + 1, z))
&& vset.contains(new IrisPosition(x, y - 1, z))
&& vset.contains(new IrisPosition(x, y, z + 1))
&& vset.contains(new IrisPosition(x, y, z - 1)))) {
returnset.add(v);
}
}
return returnset;
}
private static double hypot(double... pars) {
double sum = 0;
for (double d : pars) {
sum += Math.pow(d, 2);
}
return Math.sqrt(sum);
}
private static double lengthSq(double x, double y, double z) {
return (x * x) + (y * y) + (z * z);
}
private static double lengthSq(double x, double z) {
return (x * x) + (z * z);
}
public int getWorldHeight() {
return worldHeight;
}
public MantleChunk getChunk(Chunk e) {
return getChunk(e.getX(), e.getZ());
}
public void deleteChunkSlice(int x, int z, Class<?> c) {
getChunk(x, z).deleteSlices(c);
}
}

View File

@@ -25,6 +25,7 @@ import com.volmit.iris.util.matter.IrisMatter;
import com.volmit.iris.util.matter.Matter;
import com.volmit.iris.util.matter.MatterSlice;
import com.volmit.iris.util.matter.slices.ZoneMatter;
import lombok.Getter;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@@ -39,6 +40,10 @@ import java.util.concurrent.atomic.AtomicReferenceArray;
* Mantle Chunks are fully atomic & thread safe
*/
public class MantleChunk {
@Getter
private final int x;
@Getter
private final int z;
private static final ZoneMatter zm = new ZoneMatter();
private final AtomicIntegerArray flags;
private final AtomicReferenceArray<Matter> sections;
@@ -50,10 +55,12 @@ public class MantleChunk {
* @param sectionHeight the height of the world in sections (blocks >> 4)
*/
@ChunkCoordinates
public MantleChunk(int sectionHeight) {
public MantleChunk(int sectionHeight, int x, int z) {
sections = new AtomicReferenceArray<>(sectionHeight);
flags = new AtomicIntegerArray(MantleFlag.values().length);
features = new CopyOnWriteArrayList<>();
this.x = x;
this.z = z;
for (int i = 0; i < flags.length(); i++) {
flags.set(i, 0);
@@ -69,7 +76,7 @@ public class MantleChunk {
* @throws ClassNotFoundException shit happens
*/
public MantleChunk(int sectionHeight, DataInputStream din) throws IOException, ClassNotFoundException {
this(sectionHeight);
this(sectionHeight, din.readByte(), din.readByte());
int s = din.readByte();
for (int i = 0; i < flags.length(); i++) {
@@ -93,6 +100,13 @@ public class MantleChunk {
flags.set(flag.ordinal(), f ? 1 : 0);
}
public void raiseFlag(MantleFlag flag, Runnable r) {
if (!isFlagged(flag)) {
flag(flag, true);
r.run();
}
}
public boolean isFlagged(MantleFlag flag) {
return flags.get(flag.ordinal()) == 1;
}
@@ -163,6 +177,8 @@ public class MantleChunk {
* @throws IOException shit happens
*/
public void write(DataOutputStream dos) throws IOException {
dos.writeByte(x);
dos.writeByte(z);
dos.writeByte(sections.length());
for (int i = 0; i < flags.length(); i++) {
@@ -225,4 +241,15 @@ public class MantleChunk {
public List<IrisFeaturePositional> getFeatures() {
return features;
}
public void deleteSlices(Class<?> c) {
for(int i = 0; i < sections.length(); i++)
{
Matter m = sections.get(i);
if(m != null && m.hasSlice(c))
{
m.deleteSlice(c);
}
}
}
}

View File

@@ -24,7 +24,10 @@ public enum MantleFlag {
OBJECT,
UPDATE,
JIGSAW,
FEATURE;
FEATURE,
INITIAL_SPAWNED,
REAL,
CARVED;
static StateList getStateList() {
return new StateList(MantleFlag.values());

View File

@@ -24,6 +24,7 @@ import com.volmit.iris.util.documentation.ChunkCoordinates;
import com.volmit.iris.util.format.C;
import com.volmit.iris.util.format.Form;
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
import lombok.Getter;
import java.io.*;
import java.util.concurrent.atomic.AtomicReferenceArray;
@@ -38,14 +39,22 @@ public class TectonicPlate {
private final int sectionHeight;
private final AtomicReferenceArray<MantleChunk> chunks;
@Getter
private final int x;
@Getter
private final int z;
/**
* Create a new tectonic plate
*
* @param worldHeight the height of the world
*/
public TectonicPlate(int worldHeight) {
public TectonicPlate(int worldHeight, int x, int z) {
this.sectionHeight = worldHeight >> 4;
this.chunks = new AtomicReferenceArray<>(1024);
this.x = x;
this.z = z;
}
/**
@@ -57,8 +66,7 @@ public class TectonicPlate {
* @throws ClassNotFoundException real shit bro
*/
public TectonicPlate(int worldHeight, DataInputStream din) throws IOException, ClassNotFoundException {
this(worldHeight);
this(worldHeight, din.readInt(), din.readInt());
for (int i = 0; i < chunks.length(); i++) {
if (din.readBoolean()) {
chunks.set(i, new MantleChunk(sectionHeight, din));
@@ -132,7 +140,7 @@ public class TectonicPlate {
MantleChunk chunk = get(x, z);
if (chunk == null) {
chunk = new MantleChunk(sectionHeight);
chunk = new MantleChunk(sectionHeight, x & 31, z & 31);
chunks.set(index(x, z), chunk);
}
@@ -167,6 +175,9 @@ public class TectonicPlate {
* @throws IOException shit happens
*/
public void write(DataOutputStream dos) throws IOException {
dos.writeInt(x);
dos.writeInt(z);
for (int i = 0; i < chunks.length(); i++) {
MantleChunk chunk = chunks.get(i);

View File

@@ -16,25 +16,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.util.noise;
package com.volmit.iris.util.matter;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
public class Worm {
private double position;
private double velocity;
public Worm(double startPosition, double startVelocity) {
this.position = startPosition;
this.velocity = startVelocity;
}
public void unstep() {
position -= velocity;
}
public void step() {
position += velocity;
}
@AllArgsConstructor
public class MatterCavern {
private final boolean cavern;
}

View File

@@ -16,31 +16,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.util.noise;
package com.volmit.iris.util.matter;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
public class Worm2 {
private final Worm x;
private final Worm z;
public Worm2(Worm x, Worm z) {
this.x = x;
this.z = z;
}
public Worm2(int x, int z, int vx, int vz) {
this(new Worm(x, vx), new Worm(z, vz));
}
public void step() {
x.step();
z.step();
}
public void unstep() {
x.unstep();
z.unstep();
}
}
@AllArgsConstructor
public class MatterUpdate {
private final boolean update;
}

View File

@@ -0,0 +1,52 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.util.matter.slices;
import com.volmit.iris.util.matter.MatterCavern;
import com.volmit.iris.util.matter.Sliced;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@Sliced
public class CavernMatter extends RawMatter<MatterCavern> {
public static final MatterCavern ON = new MatterCavern(true);
public static final MatterCavern OFF = new MatterCavern(false);
public CavernMatter() {
this(1, 1, 1);
}
public CavernMatter(int width, int height, int depth) {
super(width, height, depth, MatterCavern.class);
}
@Override
public void writeNode(MatterCavern b, DataOutputStream dos) throws IOException {
dos.writeBoolean(b.isCavern());
}
@Override
public MatterCavern readNode(DataInputStream din) throws IOException {
return din.readBoolean() ? ON : OFF;
}
}

View File

@@ -18,7 +18,7 @@
package com.volmit.iris.util.matter.slices;
import com.volmit.iris.core.project.loader.IrisRegistrant;
import com.volmit.iris.core.loader.IrisRegistrant;
import com.volmit.iris.util.matter.Sliced;
@Sliced

View File

@@ -18,7 +18,7 @@
package com.volmit.iris.util.matter.slices;
import com.volmit.iris.core.project.loader.IrisRegistrant;
import com.volmit.iris.core.loader.IrisRegistrant;
import com.volmit.iris.util.context.IrisContext;
import java.io.DataInputStream;

View File

@@ -0,0 +1,52 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2021 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.util.matter.slices;
import com.volmit.iris.util.matter.MatterUpdate;
import com.volmit.iris.util.matter.Sliced;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@Sliced
public class UpdateMatter extends RawMatter<MatterUpdate> {
public static final MatterUpdate ON = new MatterUpdate(true);
public static final MatterUpdate OFF = new MatterUpdate(false);
public UpdateMatter() {
this(1, 1, 1);
}
public UpdateMatter(int width, int height, int depth) {
super(width, height, depth, MatterUpdate.class);
}
@Override
public void writeNode(MatterUpdate b, DataOutputStream dos) throws IOException {
dos.writeBoolean(b.isUpdate());
}
@Override
public MatterUpdate readNode(DataInputStream din) throws IOException {
return din.readBoolean() ? ON : OFF;
}
}

View File

@@ -388,6 +388,11 @@ public class CNG {
return noise(dim);
}
public double noiseSym(double... dim)
{
return (noise(dim) * 2) - 1;
}
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;

View File

@@ -1,50 +0,0 @@
/*
* 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 lombok.Data;
@Data
public class Worm3 {
private final Worm x;
private final Worm y;
private final Worm z;
public Worm3(Worm x, Worm y, Worm z) {
this.x = x;
this.y = y;
this.z = z;
}
public Worm3(int x, int y, int z, int vx, int vy, int vz) {
this(new Worm(x, vx), new Worm(y, vy), new Worm(z, vz));
}
public void step() {
x.step();
y.step();
z.step();
}
public void unstep() {
x.unstep();
y.unstep();
z.unstep();
}
}

View File

@@ -1,54 +0,0 @@
/*
* 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.function.NoiseProvider;
import lombok.Builder;
import lombok.Data;
@Builder
@Data
public class WormIterator2 {
private transient Worm2 worm;
private transient NoiseProvider noise;
private int x;
private int z;
private int maxDistance;
private int maxIterations;
public boolean hasNext() {
double dist = maxDistance - (Math.max(Math.abs(worm.getX().getVelocity()), Math.abs(worm.getZ().getVelocity())) + 1);
return maxIterations > 0 &&
((x * x) - (worm.getX().getPosition() * worm.getX().getPosition()))
+ ((z * z) - (worm.getZ().getPosition() * worm.getZ().getPosition())) < dist * dist;
}
public Worm2 next() {
if (worm == null) {
worm = new Worm2(x, z, 0, 0);
return worm;
}
worm.getX().setVelocity(noise.noise(worm.getX().getPosition(), 0));
worm.getZ().setVelocity(noise.noise(worm.getZ().getPosition(), 0));
worm.step();
return worm;
}
}

View File

@@ -1,65 +0,0 @@
/*
* 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.function.NoiseProvider;
import lombok.Builder;
import lombok.Data;
@Builder
@Data
public class WormIterator3 {
private transient Worm3 worm;
private int x;
private int y;
private int z;
private transient NoiseProvider noise;
private int maxDistance;
private int maxIterations;
public boolean hasNext() {
if (worm == null) {
return true;
}
double dist = maxDistance - (Math.max(Math.max(Math.abs(worm.getX().getVelocity()),
Math.abs(worm.getZ().getVelocity())),
Math.abs(worm.getY().getVelocity())) + 1);
return maxIterations > 0 &&
((x * x) - (worm.getX().getPosition() * worm.getX().getPosition()))
+ ((y * y) - (worm.getY().getPosition() * worm.getY().getPosition()))
+ ((z * z) - (worm.getZ().getPosition() * worm.getZ().getPosition())) < dist * dist;
}
public Worm3 next() {
maxIterations--;
if (worm == null) {
worm = new Worm3(x, y, z, 0, 0, 0);
return worm;
}
worm.getX().setVelocity(worm.getX().getVelocity() + noise.noise(worm.getX().getPosition() + 10000, 0));
worm.getY().setVelocity(worm.getY().getVelocity() + noise.noise(worm.getY().getPosition() + 1000, 0));
worm.getZ().setVelocity(worm.getZ().getVelocity() + noise.noise(worm.getZ().getPosition() - 10000, 0));
worm.step();
return worm;
}
}

View File

@@ -23,6 +23,7 @@ import com.volmit.iris.util.collection.KList;
import lombok.Setter;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
@@ -41,6 +42,11 @@ public class BurstExecutor {
@SuppressWarnings("UnusedReturnValue")
public Future<?> queue(Runnable r) {
if (!multicore) {
r.run();
return CompletableFuture.completedFuture(null);
}
synchronized (futures) {
Future<?> c = executor.submit(r);

View File

@@ -231,6 +231,15 @@ public class J {
return f;
}
public static CompletableFuture sfut(Runnable r, int delay) {
CompletableFuture f = new CompletableFuture();
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> {
r.run();
f.complete(null);
}, delay);
return f;
}
public static CompletableFuture afut(Runnable r) {
CompletableFuture f = new CompletableFuture();
J.a(() -> {
@@ -247,7 +256,11 @@ public class J {
* @param delay the delay to wait in ticks before running
*/
public static void s(Runnable r, int delay) {
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, r, delay);
try {
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, r, delay);
} catch (Throwable e) {
Iris.reportError(e);
}
}
/**

View File

@@ -48,7 +48,12 @@ public interface Job {
return (double) getWorkCompleted() / (double) getTotalWork();
}
default void execute(VolmitSender sender) {
execute(sender, () -> {});
}
default void execute(VolmitSender sender, Runnable whenComplete) {
PrecisionStopwatch p = PrecisionStopwatch.start();
CompletableFuture<?> f = J.afut(this::execute);
int c = J.ar(() -> {
@@ -61,6 +66,7 @@ public interface Job {
f.whenComplete((fs, ff) -> {
J.car(c);
sender.sendMessage("Completed " + getName() + " in " + Form.duration(p.getMilliseconds(), 1));
whenComplete.run();
});
}
}

View File

@@ -19,7 +19,7 @@
package com.volmit.iris.util.stream;
import com.volmit.iris.Iris;
import com.volmit.iris.core.project.loader.IrisData;
import com.volmit.iris.core.loader.IrisData;
import com.volmit.iris.engine.object.common.IRare;
import com.volmit.iris.engine.object.noise.IrisStyledRange;
import com.volmit.iris.util.collection.KList;