mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-28 03:29:06 +00:00
Chunk regeneration
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -41,6 +41,7 @@ import com.volmit.iris.util.matter.Matter;
|
||||
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 +152,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 +431,19 @@ 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;
|
||||
@@ -925,4 +936,8 @@ public class Mantle {
|
||||
public int getWorldHeight() {
|
||||
return worldHeight;
|
||||
}
|
||||
|
||||
public MantleChunk getChunk(Chunk e) {
|
||||
return getChunk(e.getX(), e.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
@@ -24,7 +24,8 @@ public enum MantleFlag {
|
||||
OBJECT,
|
||||
UPDATE,
|
||||
JIGSAW,
|
||||
FEATURE;
|
||||
FEATURE,
|
||||
INITIAL_SPAWNED;
|
||||
|
||||
static StateList getStateList() {
|
||||
return new StateList(MantleFlag.values());
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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,12 @@ 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);
|
||||
|
||||
@@ -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(() -> {
|
||||
|
||||
Reference in New Issue
Block a user