mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-19 15:09:18 +00:00
Cleanup Code
This commit is contained in:
@@ -2,10 +2,12 @@
|
||||
|
||||
For 1.16 and below, see the 1.14-1.16 branch. The master branch is for the latest version of minecraft.
|
||||
|
||||
# [Support](https://discord.gg/3xxPTpT) **|** [Documentation](https://docs.volmit.com/iris/) **|** [Git](https://github.com/IrisDimensions)
|
||||
# [Support](https://discord.gg/3xxPTpT) **|** [Documentation](https://docs.volmit.com/iris/) **
|
||||
|** [Git](https://github.com/IrisDimensions)
|
||||
|
||||
## Iris Toolbelt
|
||||
Everyone needs a toolbelt.
|
||||
|
||||
Everyone needs a toolbelt.
|
||||
|
||||
```java
|
||||
package com.volmit.iris.core.tools
|
||||
|
||||
@@ -56,10 +56,8 @@ public class IrisSettings {
|
||||
return getParallax().getParallaxRegionEvictionMS();
|
||||
}
|
||||
|
||||
public static int getThreadCount(int c)
|
||||
{
|
||||
if(c < 2 && c >= 0)
|
||||
{
|
||||
public static int getThreadCount(int c) {
|
||||
if (c < 2 && c >= 0) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ public class CommandIrisPregen extends MortarCommand {
|
||||
IrisToolbelt.pregenerate(PregenTask
|
||||
.builder()
|
||||
.center(new Position2(0, 0))
|
||||
.radius(((getVal(args[0])>>4)>>5) + 1)
|
||||
.radius(((getVal(args[0]) >> 4) >> 5) + 1)
|
||||
.build(), world);
|
||||
} catch (NumberFormatException e) {
|
||||
Iris.reportError(e);
|
||||
@@ -142,7 +142,7 @@ public class CommandIrisPregen extends MortarCommand {
|
||||
new PregeneratorJob(PregenTask
|
||||
.builder()
|
||||
.center(new Position2(0, 0))
|
||||
.radius(((getVal(args[0])>>4)>>5) + 1)
|
||||
.radius(((getVal(args[0]) >> 4) >> 5) + 1)
|
||||
.build(),
|
||||
new HybridPregenMethod(world, Runtime.getRuntime().availableProcessors()));
|
||||
} catch (NumberFormatException e) {
|
||||
|
||||
@@ -57,8 +57,7 @@ public class PregeneratorJob implements PregenListener {
|
||||
private Position2 min;
|
||||
private Position2 max;
|
||||
|
||||
public PregeneratorJob(PregenTask task, PregeneratorMethod method)
|
||||
{
|
||||
public PregeneratorJob(PregenTask task, PregeneratorMethod method) {
|
||||
instance = this;
|
||||
saving = false;
|
||||
info = new String[]{"Initializing..."};
|
||||
@@ -67,36 +66,32 @@ public class PregeneratorJob implements PregenListener {
|
||||
max = new Position2(0, 0);
|
||||
min = new Position2(0, 0);
|
||||
KList<Runnable> draw = new KList<>();
|
||||
task.iterateRegions((xx,zz) -> {
|
||||
task.iterateRegions((xx, zz) -> {
|
||||
min.setX(Math.min(xx << 5, min.getX()));
|
||||
min.setZ(Math.min(zz << 5, min.getZ()));
|
||||
max.setX(Math.max((xx << 5) + 31, max.getX()));
|
||||
max.setZ(Math.max((zz << 5) + 31, max.getZ()));
|
||||
});
|
||||
|
||||
if(IrisSettings.get().getGui().isUseServerLaunchedGuis())
|
||||
{
|
||||
if (IrisSettings.get().getGui().isUseServerLaunchedGuis()) {
|
||||
open();
|
||||
}
|
||||
|
||||
J.a(this.pregenerator::start, 20);
|
||||
}
|
||||
|
||||
public PregeneratorJob onProgress(Consumer<Double> c)
|
||||
{
|
||||
public PregeneratorJob onProgress(Consumer<Double> c) {
|
||||
onProgress.add(c);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PregeneratorJob whenDone(Runnable r)
|
||||
{
|
||||
public PregeneratorJob whenDone(Runnable r) {
|
||||
whenDone.add(r);
|
||||
return this;
|
||||
}
|
||||
|
||||
public static boolean shutdownInstance() {
|
||||
if(instance == null)
|
||||
{
|
||||
if (instance == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -109,59 +104,45 @@ public class PregeneratorJob implements PregenListener {
|
||||
}
|
||||
|
||||
public static void pauseResume() {
|
||||
if(instance == null)
|
||||
{
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(isPaused())
|
||||
{
|
||||
if (isPaused()) {
|
||||
instance.pregenerator.resume();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
} else {
|
||||
instance.pregenerator.pause();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isPaused() {
|
||||
if(instance == null)
|
||||
{
|
||||
if (instance == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return instance.paused();
|
||||
}
|
||||
|
||||
public void drawRegion(int x, int z, Color color)
|
||||
{
|
||||
public void drawRegion(int x, int z, Color color) {
|
||||
J.a(() -> {
|
||||
PregenTask.iterateRegion(x, z, (xx,zz)->{
|
||||
draw(xx,zz,color);
|
||||
PregenTask.iterateRegion(x, z, (xx, zz) -> {
|
||||
draw(xx, zz, color);
|
||||
J.sleep(3);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public void draw(int x, int z, Color color)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(renderer != null && frame != null && frame.isVisible())
|
||||
{
|
||||
public void draw(int x, int z, Color color) {
|
||||
try {
|
||||
if (renderer != null && frame != null && frame.isVisible()) {
|
||||
renderer.func.accept(new Position2(x, z), color);
|
||||
}
|
||||
}
|
||||
|
||||
catch(Throwable ignored)
|
||||
{
|
||||
} catch (Throwable ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void stop()
|
||||
{
|
||||
public void stop() {
|
||||
J.a(() -> {
|
||||
pregenerator.close();
|
||||
close();
|
||||
@@ -169,27 +150,20 @@ public class PregeneratorJob implements PregenListener {
|
||||
});
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
public void close() {
|
||||
J.a(() -> {
|
||||
try
|
||||
{
|
||||
try {
|
||||
J.sleep(3000);
|
||||
frame.setVisible(false);
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
} catch (Throwable e) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void open()
|
||||
{
|
||||
public void open() {
|
||||
J.a(() -> {
|
||||
try
|
||||
{
|
||||
try {
|
||||
frame = new JFrame("Pregen View");
|
||||
renderer = new PregenRenderer();
|
||||
frame.addKeyListener(renderer);
|
||||
@@ -205,10 +179,7 @@ public class PregeneratorJob implements PregenListener {
|
||||
frame.add(renderer);
|
||||
frame.setSize(1000, 1000);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
} catch (Throwable e) {
|
||||
|
||||
}
|
||||
});
|
||||
@@ -216,15 +187,14 @@ public class PregeneratorJob implements PregenListener {
|
||||
|
||||
@Override
|
||||
public void onTick(double chunksPerSecond, double chunksPerMinute, double regionsPerMinute, double percent, int generated, int totalChunks, int chunksRemaining, long eta, long elapsed, String method) {
|
||||
info = new String[] {
|
||||
(paused() ? "PAUSED" : (saving ? "Saving... " : "Generating")) + " " + Form.f(generated) + " of " + Form.f(totalChunks) + " (" + Form.pc(percent, 0) + " Complete)",
|
||||
"Speed: " + Form.f(chunksPerSecond, 0) + " Chunks/s, " + Form.f(regionsPerMinute, 1) + " Regions/m, " + Form.f(chunksPerMinute, 0) + " Chunks/m",
|
||||
Form.duration(eta, 2) + " Remaining " + " (" + Form.duration(elapsed, 2) + " Elapsed)",
|
||||
"Generation Method: " + method,
|
||||
info = new String[]{
|
||||
(paused() ? "PAUSED" : (saving ? "Saving... " : "Generating")) + " " + Form.f(generated) + " of " + Form.f(totalChunks) + " (" + Form.pc(percent, 0) + " Complete)",
|
||||
"Speed: " + Form.f(chunksPerSecond, 0) + " Chunks/s, " + Form.f(regionsPerMinute, 1) + " Regions/m, " + Form.f(chunksPerMinute, 0) + " Chunks/m",
|
||||
Form.duration(eta, 2) + " Remaining " + " (" + Form.duration(elapsed, 2) + " Elapsed)",
|
||||
"Generation Method: " + method,
|
||||
};
|
||||
|
||||
for(Consumer<Double> i : onProgress)
|
||||
{
|
||||
for (Consumer<Double> i : onProgress) {
|
||||
i.accept(percent);
|
||||
}
|
||||
}
|
||||
@@ -305,7 +275,7 @@ public class PregeneratorJob implements PregenListener {
|
||||
}
|
||||
|
||||
private boolean paused() {
|
||||
return pregenerator.paused();
|
||||
return pregenerator.paused();
|
||||
}
|
||||
|
||||
private String[] getProgress() {
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package com.volmit.iris.core.gui.components;
|
||||
|
||||
import com.volmit.iris.core.gui.components.RenderType;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.interpolation.IrisInterpolation;
|
||||
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
|
||||
package com.volmit.iris.core.pregenerator;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.math.Position2;
|
||||
@@ -54,8 +52,7 @@ public class IrisPregenerator {
|
||||
private final KSet<Position2> retry;
|
||||
private final KSet<Position2> net;
|
||||
|
||||
public IrisPregenerator(PregenTask task, PregeneratorMethod generator, PregenListener listener)
|
||||
{
|
||||
public IrisPregenerator(PregenTask task, PregeneratorMethod generator, PregenListener listener) {
|
||||
this.listener = listenify(listener);
|
||||
generatedRegions = new KSet<>();
|
||||
this.shutdown = new AtomicBoolean(false);
|
||||
@@ -83,17 +80,16 @@ public class IrisPregenerator {
|
||||
generatedLast.set(generated.get());
|
||||
chunksPerSecond.put(secondGenerated);
|
||||
|
||||
if(minuteLatch.flip())
|
||||
{
|
||||
if (minuteLatch.flip()) {
|
||||
int minuteGenerated = generated.get() - generatedLastMinute.get();
|
||||
generatedLastMinute.set(generated.get());
|
||||
chunksPerMinute.put(minuteGenerated);
|
||||
regionsPerMinute.put((double)minuteGenerated / 1024D);
|
||||
regionsPerMinute.put((double) minuteGenerated / 1024D);
|
||||
}
|
||||
|
||||
listener.onTick(chunksPerSecond.getAverage(), chunksPerMinute.getAverage(),
|
||||
regionsPerMinute.getAverage(),
|
||||
(double)generated.get() / (double)totalChunks.get(),
|
||||
(double) generated.get() / (double) totalChunks.get(),
|
||||
generated.get(), totalChunks.get(),
|
||||
totalChunks.get() - generated.get(),
|
||||
eta, M.ms() - startTime.get(), currentGeneratorMethod.get());
|
||||
@@ -108,18 +104,16 @@ public class IrisPregenerator {
|
||||
((double) (M.ms() - startTime.get()) / (double) generated.get()));
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
public void close() {
|
||||
shutdown.set(true);
|
||||
}
|
||||
|
||||
public void start()
|
||||
{
|
||||
public void start() {
|
||||
init();
|
||||
ticker.start();
|
||||
checkRegions();
|
||||
task.iterateRegions((x,z) -> visitRegion(x, z, true));
|
||||
task.iterateRegions((x,z) -> visitRegion(x, z, false));
|
||||
task.iterateRegions((x, z) -> visitRegion(x, z, true));
|
||||
task.iterateRegions((x, z) -> visitRegion(x, z, false));
|
||||
shutdown();
|
||||
}
|
||||
|
||||
@@ -140,42 +134,34 @@ public class IrisPregenerator {
|
||||
}
|
||||
|
||||
private void visitRegion(int x, int z, boolean regions) {
|
||||
while(paused.get() && !shutdown.get())
|
||||
{
|
||||
while (paused.get() && !shutdown.get()) {
|
||||
J.sleep(50);
|
||||
}
|
||||
|
||||
if(shutdown.get())
|
||||
{
|
||||
if (shutdown.get()) {
|
||||
listener.onRegionSkipped(x, z);
|
||||
return;
|
||||
}
|
||||
|
||||
Position2 pos = new Position2(x, z);
|
||||
|
||||
if(generatedRegions.contains(pos))
|
||||
{
|
||||
if (generatedRegions.contains(pos)) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentGeneratorMethod.set(generator.getMethod(x, z));
|
||||
boolean hit = false;
|
||||
if(generator.supportsRegions(x, z, listener) && regions)
|
||||
{
|
||||
if (generator.supportsRegions(x, z, listener) && regions) {
|
||||
hit = true;
|
||||
listener.onRegionGenerating(x, z);
|
||||
generator.generateRegion(x, z, listener);
|
||||
}
|
||||
|
||||
else if(!regions)
|
||||
{
|
||||
} else if (!regions) {
|
||||
hit = true;
|
||||
listener.onRegionGenerating(x, z);
|
||||
PregenTask.iterateRegion(x, z, (xx, zz) -> generator.generateChunk(xx, zz, listener));
|
||||
}
|
||||
|
||||
if(hit)
|
||||
{
|
||||
if (hit) {
|
||||
listener.onRegionGenerated(x, z);
|
||||
listener.onSaving();
|
||||
generator.save();
|
||||
@@ -185,21 +171,18 @@ public class IrisPregenerator {
|
||||
}
|
||||
|
||||
private void checkRegion(int x, int z) {
|
||||
if(generatedRegions.contains(new Position2(x, z)))
|
||||
{
|
||||
if (generatedRegions.contains(new Position2(x, z))) {
|
||||
return;
|
||||
}
|
||||
|
||||
generator.supportsRegions(x, z, listener);
|
||||
}
|
||||
|
||||
public void pause()
|
||||
{
|
||||
public void pause() {
|
||||
paused.set(true);
|
||||
}
|
||||
|
||||
public void resume()
|
||||
{
|
||||
public void resume() {
|
||||
paused.set(false);
|
||||
}
|
||||
|
||||
@@ -207,7 +190,7 @@ public class IrisPregenerator {
|
||||
return new PregenListener() {
|
||||
@Override
|
||||
public void onTick(double chunksPerSecond, double chunksPerMinute, double regionsPerMinute, double percent, int generated, int totalChunks, int chunksRemaining, long eta, long elapsed, String method) {
|
||||
listener.onTick( chunksPerSecond, chunksPerMinute, regionsPerMinute, percent, generated, totalChunks, chunksRemaining, eta, elapsed, method);
|
||||
listener.onTick(chunksPerSecond, chunksPerMinute, regionsPerMinute, percent, generated, totalChunks, chunksRemaining, eta, elapsed, method);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,29 +31,25 @@ import java.util.Comparator;
|
||||
@Data
|
||||
public class PregenTask {
|
||||
@Builder.Default
|
||||
private Position2 center = new Position2(0,0);
|
||||
private Position2 center = new Position2(0, 0);
|
||||
|
||||
@Builder.Default
|
||||
private int radius = 1;
|
||||
|
||||
private static final KList<Position2> order = computeChunkOrder();
|
||||
|
||||
public void iterateRegions(Spiraled s)
|
||||
{
|
||||
public void iterateRegions(Spiraled s) {
|
||||
new Spiraler(radius * 2, radius * 2, s)
|
||||
.setOffset(center.getX(), center.getZ()).drain();
|
||||
}
|
||||
|
||||
public static void iterateRegion(int xr, int zr, Spiraled s)
|
||||
{
|
||||
for(Position2 i : order)
|
||||
{
|
||||
public static void iterateRegion(int xr, int zr, Spiraled s) {
|
||||
for (Position2 i : order) {
|
||||
s.on(i.getX() + (xr << 5), i.getZ() + (zr << 5));
|
||||
}
|
||||
}
|
||||
|
||||
public void iterateAllChunks(Spiraled s)
|
||||
{
|
||||
public void iterateAllChunks(Spiraled s) {
|
||||
new Spiraler(radius * 2, radius * 2, (x, z) -> iterateRegion(x, z, s))
|
||||
.setOffset(center.getX(), center.getZ()).drain();
|
||||
}
|
||||
|
||||
@@ -40,33 +40,37 @@ public interface PregeneratorMethod {
|
||||
|
||||
/**
|
||||
* Return true if regions can be generated
|
||||
* @return true if they can be
|
||||
*
|
||||
* @param x the x region
|
||||
* @param z the z region
|
||||
* @return true if they can be
|
||||
*/
|
||||
boolean supportsRegions(int x, int z, PregenListener listener);
|
||||
|
||||
/**
|
||||
* Return the name of the method being used
|
||||
* @return the name
|
||||
*
|
||||
* @param x the x region
|
||||
* @param z the z region
|
||||
* @return the name
|
||||
*/
|
||||
String getMethod(int x, int z);
|
||||
|
||||
/**
|
||||
* Called to generate a region. Execute sync, if multicore internally, wait
|
||||
* for the task to complete
|
||||
* @param x the x
|
||||
* @param z the z
|
||||
*
|
||||
* @param x the x
|
||||
* @param z the z
|
||||
* @param listener signal chunks generating & generated. Parallel capable.
|
||||
*/
|
||||
void generateRegion(int x, int z, PregenListener listener);
|
||||
|
||||
/**
|
||||
* Called to generate a chunk. You can go async so long as save will wait on the threads to finish
|
||||
* @param x the x
|
||||
* @param z the z
|
||||
*
|
||||
* @param x the x
|
||||
* @param z the z
|
||||
* @param listener
|
||||
*/
|
||||
void generateChunk(int x, int z, PregenListener listener);
|
||||
|
||||
@@ -26,8 +26,7 @@ import org.bukkit.World;
|
||||
public class AsyncOrMedievalPregenMethod implements PregeneratorMethod {
|
||||
private final PregeneratorMethod method;
|
||||
|
||||
public AsyncOrMedievalPregenMethod(World world, int threads)
|
||||
{
|
||||
public AsyncOrMedievalPregenMethod(World world, int threads) {
|
||||
method = PaperLib.isPaper() ? new AsyncPregenMethod(world, threads) : new MedievalPregenMethod(world);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,17 +29,14 @@ import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
private final World world;
|
||||
private final MultiBurst burst;
|
||||
private final KList<CompletableFuture<?>> future;
|
||||
|
||||
public AsyncPregenMethod(World world, int threads)
|
||||
{
|
||||
if(!PaperLib.isPaper())
|
||||
{
|
||||
public AsyncPregenMethod(World world, int threads) {
|
||||
if (!PaperLib.isPaper()) {
|
||||
throw new UnsupportedOperationException("Cannot use PaperAsync on non paper!");
|
||||
}
|
||||
|
||||
@@ -51,8 +48,7 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
private void unloadAndSaveAllChunks() {
|
||||
try {
|
||||
J.sfut(() -> {
|
||||
for(Chunk i : world.getLoadedChunks())
|
||||
{
|
||||
for (Chunk i : world.getLoadedChunks()) {
|
||||
i.unload(true);
|
||||
}
|
||||
world.save();
|
||||
@@ -71,10 +67,8 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
}
|
||||
}
|
||||
|
||||
private void waitForChunks()
|
||||
{
|
||||
for(CompletableFuture<?> i : future)
|
||||
{
|
||||
private void waitForChunks() {
|
||||
for (CompletableFuture<?> i : future) {
|
||||
try {
|
||||
i.get();
|
||||
} catch (Throwable e) {
|
||||
@@ -120,8 +114,7 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
|
||||
@Override
|
||||
public void generateChunk(int x, int z, PregenListener listener) {
|
||||
if(future.size() > IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getPregenThreadCount()))
|
||||
{
|
||||
if (future.size() > IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getPregenThreadCount())) {
|
||||
waitForChunks();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,13 +30,11 @@ public class HeadlessPregenMethod implements PregeneratorMethod {
|
||||
@Getter
|
||||
private final HeadlessGenerator generator;
|
||||
|
||||
public HeadlessPregenMethod(HeadlessWorld world)
|
||||
{
|
||||
public HeadlessPregenMethod(HeadlessWorld world) {
|
||||
this(world, world.generate());
|
||||
}
|
||||
|
||||
public HeadlessPregenMethod(HeadlessWorld world, HeadlessGenerator generator)
|
||||
{
|
||||
public HeadlessPregenMethod(HeadlessWorld world, HeadlessGenerator generator) {
|
||||
this.world = world;
|
||||
this.generator = generator;
|
||||
}
|
||||
|
||||
@@ -33,8 +33,7 @@ public class HybridPregenMethod implements PregeneratorMethod {
|
||||
private final PregeneratorMethod inWorld;
|
||||
private final World world;
|
||||
|
||||
public HybridPregenMethod(World world, int threads)
|
||||
{
|
||||
public HybridPregenMethod(World world, int threads) {
|
||||
this.world = world;
|
||||
headless = supportsHeadless(world)
|
||||
? new HeadlessPregenMethod(HeadlessWorld.from(world)) : new DummyPregenMethod();
|
||||
@@ -76,18 +75,12 @@ public class HybridPregenMethod implements PregeneratorMethod {
|
||||
|
||||
boolean r = !new File(world.getWorldFolder(), "region/r." + x + "." + z + ".mca").exists();
|
||||
|
||||
if(!r && listener != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
for(Position2 i : ((HeadlessPregenMethod) headless).getGenerator().getChunksInRegion(x, z))
|
||||
{
|
||||
if (!r && listener != null) {
|
||||
try {
|
||||
for (Position2 i : ((HeadlessPregenMethod) headless).getGenerator().getChunksInRegion(x, z)) {
|
||||
listener.onChunkExistsInRegionGen((x << 5) + i.getX(), (z << 5) + i.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,16 +32,13 @@ public class MedievalPregenMethod implements PregeneratorMethod {
|
||||
private final World world;
|
||||
private final KList<CompletableFuture<?>> futures;
|
||||
|
||||
public MedievalPregenMethod(World world)
|
||||
{
|
||||
public MedievalPregenMethod(World world) {
|
||||
this.world = world;
|
||||
futures = new KList<>();
|
||||
}
|
||||
|
||||
private void waitForChunks()
|
||||
{
|
||||
for(CompletableFuture<?> i : futures)
|
||||
{
|
||||
private void waitForChunks() {
|
||||
for (CompletableFuture<?> i : futures) {
|
||||
try {
|
||||
i.get();
|
||||
} catch (Throwable e) {
|
||||
@@ -56,8 +53,7 @@ public class MedievalPregenMethod implements PregeneratorMethod {
|
||||
waitForChunks();
|
||||
try {
|
||||
J.sfut(() -> {
|
||||
for(Chunk i : world.getLoadedChunks())
|
||||
{
|
||||
for (Chunk i : world.getLoadedChunks()) {
|
||||
i.unload(true);
|
||||
}
|
||||
world.save();
|
||||
@@ -99,8 +95,7 @@ public class MedievalPregenMethod implements PregeneratorMethod {
|
||||
|
||||
@Override
|
||||
public void generateChunk(int x, int z, PregenListener listener) {
|
||||
if(futures.size() > IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getPregenThreadCount()))
|
||||
{
|
||||
if (futures.size() > IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getPregenThreadCount())) {
|
||||
waitForChunks();
|
||||
}
|
||||
|
||||
|
||||
@@ -36,8 +36,7 @@ import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class SyndicatePregenMethod implements PregeneratorMethod
|
||||
{
|
||||
public class SyndicatePregenMethod implements PregeneratorMethod {
|
||||
@Getter
|
||||
private String address;
|
||||
private String nickname;
|
||||
@@ -49,8 +48,7 @@ public class SyndicatePregenMethod implements PregeneratorMethod
|
||||
private UUID pack = UUID.randomUUID();
|
||||
private long seed;
|
||||
|
||||
public SyndicatePregenMethod(String nickname, File worldFolder, String address, int port, String password, IrisDimension dimension, long seed)
|
||||
{
|
||||
public SyndicatePregenMethod(String nickname, File worldFolder, String address, int port, String password, IrisDimension dimension, long seed) {
|
||||
this.seed = seed;
|
||||
this.worldFolder = worldFolder;
|
||||
this.address = address;
|
||||
@@ -59,50 +57,45 @@ public class SyndicatePregenMethod implements PregeneratorMethod
|
||||
this.dimension = dimension;
|
||||
}
|
||||
|
||||
private SyndicateClient.SyndicateClientBuilder connect()
|
||||
{
|
||||
private SyndicateClient.SyndicateClientBuilder connect() {
|
||||
return SyndicateClient.builder().address(address).port(port);
|
||||
}
|
||||
|
||||
public synchronized void setup()
|
||||
{
|
||||
if(ready)
|
||||
{
|
||||
public synchronized void setup() {
|
||||
if (ready) {
|
||||
return;
|
||||
}
|
||||
|
||||
ready = false;
|
||||
try {
|
||||
connect().command(SyndicateInstallPack
|
||||
.builder()
|
||||
.builder()
|
||||
.dimension(dimension)
|
||||
.pack(pack)
|
||||
.seed(seed)
|
||||
.build())
|
||||
.output((o) -> {
|
||||
File to = new File(Iris.getTemp(), "send-" + pack.toString() + ".zip");
|
||||
ZipUtil.pack(dimension.getLoader().getDataFolder(), to);
|
||||
.build())
|
||||
.output((o) -> {
|
||||
File to = new File(Iris.getTemp(), "send-" + pack.toString() + ".zip");
|
||||
ZipUtil.pack(dimension.getLoader().getDataFolder(), to);
|
||||
|
||||
try {
|
||||
IO.writeAll(to, o);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
IO.writeAll(to, o);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
to.deleteOnExit();
|
||||
})
|
||||
.build().go((response, data) -> {
|
||||
if(response instanceof SyndicateBusy)
|
||||
{
|
||||
throw new RuntimeException("Service is busy, will try later");
|
||||
}
|
||||
to.deleteOnExit();
|
||||
})
|
||||
.build().go((response, data) -> {
|
||||
if (response instanceof SyndicateBusy) {
|
||||
throw new RuntimeException("Service is busy, will try later");
|
||||
}
|
||||
|
||||
ready = true;
|
||||
ready = true;
|
||||
});
|
||||
ready = true;
|
||||
} catch (Throwable throwable) {
|
||||
if(throwable instanceof RuntimeException)
|
||||
{
|
||||
if (throwable instanceof RuntimeException) {
|
||||
ready = false;
|
||||
return;
|
||||
}
|
||||
@@ -111,10 +104,8 @@ public class SyndicatePregenMethod implements PregeneratorMethod
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canGenerate()
|
||||
{
|
||||
if(!ready)
|
||||
{
|
||||
public boolean canGenerate() {
|
||||
if (!ready) {
|
||||
J.a(this::setup);
|
||||
}
|
||||
|
||||
@@ -128,16 +119,16 @@ public class SyndicatePregenMethod implements PregeneratorMethod
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if(ready)
|
||||
{
|
||||
if (ready) {
|
||||
try {
|
||||
connect()
|
||||
.command(SyndicateClose
|
||||
.builder()
|
||||
.pack(pack)
|
||||
.build())
|
||||
.build()
|
||||
.go((__, __b) -> {});
|
||||
.command(SyndicateClose
|
||||
.builder()
|
||||
.pack(pack)
|
||||
.build())
|
||||
.build()
|
||||
.go((__, __b) -> {
|
||||
});
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
@@ -159,29 +150,26 @@ public class SyndicatePregenMethod implements PregeneratorMethod
|
||||
return "Syndicate<" + nickname + ">";
|
||||
}
|
||||
|
||||
private double checkProgress(int x, int z)
|
||||
{
|
||||
private double checkProgress(int x, int z) {
|
||||
AtomicDouble progress = new AtomicDouble(-1);
|
||||
try {
|
||||
connect()
|
||||
.command(SyndicateGetProgress.builder()
|
||||
.pack(pack).build()).output((i) -> {
|
||||
}).build().go((response, o) -> {
|
||||
if(response instanceof SyndicateSendProgress)
|
||||
{
|
||||
if(((SyndicateSendProgress) response).isAvailable())
|
||||
{
|
||||
progress.set(((SyndicateSendProgress) response).getProgress());
|
||||
File f = new File(worldFolder, "region/r." + x + "." + z + ".mca");
|
||||
try {
|
||||
f.getParentFile().mkdirs();
|
||||
IO.writeAll(f, o);
|
||||
progress.set(1000);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
.command(SyndicateGetProgress.builder()
|
||||
.pack(pack).build()).output((i) -> {
|
||||
}).build().go((response, o) -> {
|
||||
if (response instanceof SyndicateSendProgress) {
|
||||
if (((SyndicateSendProgress) response).isAvailable()) {
|
||||
progress.set(((SyndicateSendProgress) response).getProgress());
|
||||
File f = new File(worldFolder, "region/r." + x + "." + z + ".mca");
|
||||
try {
|
||||
f.getParentFile().mkdirs();
|
||||
IO.writeAll(f, o);
|
||||
progress.set(1000);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
@@ -192,94 +180,73 @@ public class SyndicatePregenMethod implements PregeneratorMethod
|
||||
|
||||
@Override
|
||||
public void generateRegion(int x, int z, PregenListener listener) {
|
||||
if(!ready)
|
||||
{
|
||||
if (!ready) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
try {
|
||||
connect().command(SyndicateGenerate
|
||||
.builder()
|
||||
.builder()
|
||||
.x(x).z(z).pack(pack)
|
||||
.build())
|
||||
.build().go((response, data) -> {
|
||||
if(response instanceof SyndicateOK)
|
||||
{
|
||||
listener.onNetworkStarted(x, z);
|
||||
J.a(() -> {
|
||||
double lastp = 0;
|
||||
int calls = 0;
|
||||
boolean installed = false;
|
||||
while(true)
|
||||
{
|
||||
J.sleep(100);
|
||||
double progress = checkProgress(x, z);
|
||||
|
||||
if(progress == 1000)
|
||||
{
|
||||
installed = true;
|
||||
AtomicInteger a = new AtomicInteger(calls);
|
||||
PregenTask.iterateRegion(x, z, (xx, zz) -> {
|
||||
if(a.decrementAndGet() < 0)
|
||||
{
|
||||
listener.onNetworkGeneratedChunk(xx, zz);
|
||||
}
|
||||
});
|
||||
calls = 1024;
|
||||
}
|
||||
|
||||
else if(progress < 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
int change = (int) Math.floor((progress - lastp) * 1024D);
|
||||
change = change == 0 ? 1 : change;
|
||||
.build())
|
||||
.build().go((response, data) -> {
|
||||
if (response instanceof SyndicateOK) {
|
||||
listener.onNetworkStarted(x, z);
|
||||
J.a(() -> {
|
||||
double lastp = 0;
|
||||
int calls = 0;
|
||||
boolean installed = false;
|
||||
while (true) {
|
||||
J.sleep(100);
|
||||
double progress = checkProgress(x, z);
|
||||
|
||||
if (progress == 1000) {
|
||||
installed = true;
|
||||
AtomicInteger a = new AtomicInteger(calls);
|
||||
AtomicInteger b = new AtomicInteger(change);
|
||||
PregenTask.iterateRegion(x, z, (xx, zz) -> {
|
||||
if(a.decrementAndGet() < 0)
|
||||
{
|
||||
if(b.decrementAndGet() >= 0)
|
||||
{
|
||||
listener.onNetworkGeneratedChunk(xx, zz);
|
||||
}
|
||||
if (a.decrementAndGet() < 0) {
|
||||
listener.onNetworkGeneratedChunk(xx, zz);
|
||||
}
|
||||
});
|
||||
calls += change;
|
||||
calls = 1024;
|
||||
} else if (progress < 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(!installed)
|
||||
{
|
||||
// TODO RETRY REGION
|
||||
return;
|
||||
}
|
||||
int change = (int) Math.floor((progress - lastp) * 1024D);
|
||||
change = change == 0 ? 1 : change;
|
||||
|
||||
listener.onNetworkDownloaded(x, z);
|
||||
});
|
||||
}
|
||||
AtomicInteger a = new AtomicInteger(calls);
|
||||
AtomicInteger b = new AtomicInteger(change);
|
||||
PregenTask.iterateRegion(x, z, (xx, zz) -> {
|
||||
if (a.decrementAndGet() < 0) {
|
||||
if (b.decrementAndGet() >= 0) {
|
||||
listener.onNetworkGeneratedChunk(xx, zz);
|
||||
}
|
||||
}
|
||||
});
|
||||
calls += change;
|
||||
}
|
||||
|
||||
else if(response instanceof SyndicateInstallFirst)
|
||||
{
|
||||
ready = false;
|
||||
throw new RuntimeException();
|
||||
}
|
||||
if (!installed) {
|
||||
// TODO RETRY REGION
|
||||
return;
|
||||
}
|
||||
|
||||
else if(response instanceof SyndicateBusy)
|
||||
{
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
throw new RuntimeException();
|
||||
}
|
||||
listener.onNetworkDownloaded(x, z);
|
||||
});
|
||||
} else if (response instanceof SyndicateInstallFirst) {
|
||||
ready = false;
|
||||
throw new RuntimeException();
|
||||
} else if (response instanceof SyndicateBusy) {
|
||||
throw new RuntimeException();
|
||||
} else {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
});
|
||||
} catch (Throwable throwable) {
|
||||
|
||||
if(throwable instanceof RuntimeException)
|
||||
{
|
||||
if (throwable instanceof RuntimeException) {
|
||||
throw (RuntimeException) throwable;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,8 +40,7 @@ public class SyndicateClient {
|
||||
DataOutputStream o = new DataOutputStream(socket.getOutputStream());
|
||||
SyndicateCommandIO.write(command, o);
|
||||
|
||||
if(output != null)
|
||||
{
|
||||
if (output != null) {
|
||||
output.accept(o);
|
||||
}
|
||||
|
||||
|
||||
@@ -56,10 +56,8 @@ public class SyndicateServer extends Thread implements PregenListener {
|
||||
server.setSoTimeout(1000);
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
while(!interrupted())
|
||||
{
|
||||
public void run() {
|
||||
while (!interrupted()) {
|
||||
try {
|
||||
Socket client = server.accept();
|
||||
DataInputStream i = new DataInputStream(client.getInputStream());
|
||||
@@ -79,40 +77,34 @@ public class SyndicateServer extends Thread implements PregenListener {
|
||||
}
|
||||
}
|
||||
|
||||
private void handle(Socket client, DataInputStream i, DataOutputStream o) throws Throwable
|
||||
{
|
||||
private void handle(Socket client, DataInputStream i, DataOutputStream o) throws Throwable {
|
||||
SyndicateCommand cmd = handle(SyndicateCommandIO.read(i), i, o);
|
||||
|
||||
if(cmd != null)
|
||||
{
|
||||
if (cmd != null) {
|
||||
SyndicateCommandIO.write(cmd, o);
|
||||
}
|
||||
|
||||
o.flush();
|
||||
}
|
||||
|
||||
private File getCachedDim(UUID id)
|
||||
{
|
||||
return new File(cache, id.toString().charAt(2) +"/" + id.toString().substring(0, 4)+ "/" + id);
|
||||
private File getCachedDim(UUID id) {
|
||||
return new File(cache, id.toString().charAt(2) + "/" + id.toString().substring(0, 4) + "/" + id);
|
||||
}
|
||||
|
||||
private SyndicateCommand handle(SyndicateCommand command, DataInputStream i, DataOutputStream o) throws Throwable {
|
||||
if(command instanceof SyndicateInstallPack)
|
||||
{
|
||||
if(busy)
|
||||
{
|
||||
if (command instanceof SyndicateInstallPack) {
|
||||
if (busy) {
|
||||
return new SyndicateBusy();
|
||||
}
|
||||
|
||||
if(generator != null)
|
||||
{
|
||||
if (generator != null) {
|
||||
generator.close();
|
||||
IO.delete(generator.getWorld().getWorld().worldFolder());
|
||||
generator = null;
|
||||
}
|
||||
|
||||
UUID id = ((SyndicateInstallPack) command).getPack();
|
||||
File cacheload = new File(cache, id.toString().charAt(2) +"/" + id.toString().substring(0, 4)+ "/" + id + ".zip");
|
||||
File cacheload = new File(cache, id.toString().charAt(2) + "/" + id.toString().substring(0, 4) + "/" + id + ".zip");
|
||||
File cachestore = getCachedDim(id);
|
||||
IO.delete(cachestore);
|
||||
int len = i.readInt();
|
||||
@@ -129,14 +121,12 @@ public class SyndicateServer extends Thread implements PregenListener {
|
||||
return new SyndicateOK();
|
||||
}
|
||||
|
||||
if(command instanceof SyndicateGenerate)
|
||||
{
|
||||
if(busy)
|
||||
{
|
||||
if (command instanceof SyndicateGenerate) {
|
||||
if (busy) {
|
||||
return new SyndicateBusy();
|
||||
}
|
||||
|
||||
if(generator == null || !Objects.equals(currentId, ((SyndicateGenerate) command).getPack())) {
|
||||
if (generator == null || !Objects.equals(currentId, ((SyndicateGenerate) command).getPack())) {
|
||||
return new SyndicateInstallFirst();
|
||||
}
|
||||
|
||||
@@ -149,10 +139,8 @@ public class SyndicateServer extends Thread implements PregenListener {
|
||||
return new SyndicateOK();
|
||||
}
|
||||
|
||||
if(command instanceof SyndicateClose)
|
||||
{
|
||||
if(generator != null && Objects.equals(currentId, ((SyndicateClose) command).getPack()) && !busy)
|
||||
{
|
||||
if (command instanceof SyndicateClose) {
|
||||
if (generator != null && Objects.equals(currentId, ((SyndicateClose) command).getPack()) && !busy) {
|
||||
generator.close();
|
||||
IO.delete(generator.getWorld().getWorld().worldFolder());
|
||||
generator = null;
|
||||
@@ -160,31 +148,20 @@ public class SyndicateServer extends Thread implements PregenListener {
|
||||
}
|
||||
}
|
||||
|
||||
if(command instanceof SyndicateGetProgress)
|
||||
{
|
||||
if(generator != null && busy && Objects.equals(currentId, ((SyndicateGetProgress) command).getPack()))
|
||||
{
|
||||
return SyndicateSendProgress.builder().progress((double)g.get() / 1024D).build();
|
||||
}
|
||||
|
||||
else if(generator != null && !busy && Objects.equals(currentId, ((SyndicateGetProgress) command).getPack()) && lastGeneratedRegion != null && lastGeneratedRegion.exists())
|
||||
{
|
||||
if (command instanceof SyndicateGetProgress) {
|
||||
if (generator != null && busy && Objects.equals(currentId, ((SyndicateGetProgress) command).getPack())) {
|
||||
return SyndicateSendProgress.builder().progress((double) g.get() / 1024D).build();
|
||||
} else if (generator != null && !busy && Objects.equals(currentId, ((SyndicateGetProgress) command).getPack()) && lastGeneratedRegion != null && lastGeneratedRegion.exists()) {
|
||||
SyndicateCommandIO.write(SyndicateSendProgress
|
||||
.builder()
|
||||
.builder()
|
||||
.progress(1).available(true)
|
||||
.build(), o);
|
||||
.build(), o);
|
||||
o.writeLong(lastGeneratedRegion.length());
|
||||
IO.writeAll(lastGeneratedRegion, o);
|
||||
return null;
|
||||
}
|
||||
|
||||
else if(generator == null)
|
||||
{
|
||||
} else if (generator == null) {
|
||||
return new SyndicateInstallFirst();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return new SyndicateBusy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package com.volmit.iris.core.pregenerator.syndicate.command;
|
||||
|
||||
public interface SyndicateCommand
|
||||
{
|
||||
public interface SyndicateCommand {
|
||||
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ public class IrisCreator {
|
||||
|
||||
/**
|
||||
* Create the IrisAccess (contains the world)
|
||||
*
|
||||
* @return the IrisAccess
|
||||
* @throws IrisException shit happens
|
||||
*/
|
||||
@@ -94,40 +95,29 @@ public class IrisCreator {
|
||||
IrisDimension d = IrisToolbelt.getDimension(dimension());
|
||||
IrisAccess access = null;
|
||||
Consumer<Double> prog = (pxx) -> {
|
||||
double px = (headless && pregen!=null) ? pxx/2 : pxx;
|
||||
double px = (headless && pregen != null) ? pxx / 2 : pxx;
|
||||
|
||||
if(pregen != null && !headless)
|
||||
{
|
||||
if (pregen != null && !headless) {
|
||||
px = (px / 2) + 0.5;
|
||||
}
|
||||
|
||||
if(sender != null)
|
||||
{
|
||||
if(sender.isPlayer())
|
||||
{
|
||||
if (sender != null) {
|
||||
if (sender.isPlayer()) {
|
||||
sender.player().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(C.WHITE + "Generating " + Form.pc(px)));
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
} else {
|
||||
sender.sendMessage("Generating " + Form.f(px, 0));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if(d == null)
|
||||
{
|
||||
if (d == null) {
|
||||
throw new MissingDimensionException("Cannot find dimension '" + dimension() + "'");
|
||||
}
|
||||
|
||||
if (headless)
|
||||
{
|
||||
if (headless) {
|
||||
HeadlessWorld w = new HeadlessWorld(name, d, seed, studio);
|
||||
access = w.generate().getGenerator();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
} else {
|
||||
O<Boolean> done = new O<>();
|
||||
done.set(false);
|
||||
WorldCreator wc = new IrisWorldCreator()
|
||||
@@ -146,9 +136,8 @@ public class IrisCreator {
|
||||
while (finalAccess1.getGenerated() < req && !done.get()) {
|
||||
double v = (double) finalAccess1.getGenerated() / (double) req;
|
||||
|
||||
if(pregen != null)
|
||||
{
|
||||
v /=2;
|
||||
if (pregen != null) {
|
||||
v /= 2;
|
||||
}
|
||||
|
||||
if (sender.isPlayer()) {
|
||||
@@ -173,8 +162,7 @@ public class IrisCreator {
|
||||
done.set(true);
|
||||
}
|
||||
|
||||
if(access == null)
|
||||
{
|
||||
if (access == null) {
|
||||
throw new IrisException("Access is null. Something bad happened.");
|
||||
}
|
||||
|
||||
@@ -182,8 +170,7 @@ public class IrisCreator {
|
||||
Runnable loadup = () -> {
|
||||
try {
|
||||
J.sfut(() -> {
|
||||
if(headless)
|
||||
{
|
||||
if (headless) {
|
||||
O<Boolean> done = new O<>();
|
||||
done.set(false);
|
||||
|
||||
@@ -193,7 +180,7 @@ public class IrisCreator {
|
||||
|
||||
while (finalAccess.getGenerated() < req && !done.get()) {
|
||||
double v = (double) finalAccess.getGenerated() / (double) req;
|
||||
v = (v/2) + 0.5;
|
||||
v = (v / 2) + 0.5;
|
||||
|
||||
if (sender.isPlayer()) {
|
||||
sender.player().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(C.WHITE + "Generating " + Form.pc(v) + ((C.GRAY + " (" + (req - finalAccess.getGenerated()) + " Left)"))));
|
||||
@@ -222,13 +209,9 @@ public class IrisCreator {
|
||||
}
|
||||
};
|
||||
|
||||
if(pregen != null)
|
||||
{
|
||||
if (pregen != null) {
|
||||
IrisToolbelt.pregenerate(pregen, access).onProgress(prog).whenDone(loadup);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
} else {
|
||||
loadup.run();
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ import com.volmit.iris.core.pregenerator.methods.HeadlessPregenMethod;
|
||||
import com.volmit.iris.core.pregenerator.methods.HybridPregenMethod;
|
||||
import com.volmit.iris.engine.framework.IrisAccess;
|
||||
import com.volmit.iris.engine.object.IrisDimension;
|
||||
import com.volmit.iris.util.math.Position2;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
@@ -42,83 +41,79 @@ import java.io.File;
|
||||
public class IrisToolbelt {
|
||||
/**
|
||||
* Will find / download / search for the dimension or return null
|
||||
*
|
||||
* <p>
|
||||
* - You can provide a dimenson in the packs folder by the folder name
|
||||
* - You can provide a github repo by using (assumes branch is master unless specified)
|
||||
* - GithubUsername/repository
|
||||
* - GithubUsername/repository/branch
|
||||
* - GithubUsername/repository
|
||||
* - GithubUsername/repository/branch
|
||||
*
|
||||
* @param dimension the dimension id such as overworld or flat
|
||||
* @return the IrisDimension or null
|
||||
*/
|
||||
public static IrisDimension getDimension(String dimension)
|
||||
{
|
||||
public static IrisDimension getDimension(String dimension) {
|
||||
File pack = Iris.instance.getDataFolder("packs", dimension);
|
||||
|
||||
if(!pack.exists())
|
||||
{
|
||||
if (!pack.exists()) {
|
||||
Iris.proj.downloadSearch(new VolmitSender(Bukkit.getConsoleSender(), Iris.instance.getTag()), dimension, false, false);
|
||||
}
|
||||
|
||||
if(!pack.exists())
|
||||
{
|
||||
if (!pack.exists()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new IrisDataManager(pack).getDimensionLoader().load(dimension);
|
||||
return new IrisDataManager(pack).getDimensionLoader().load(dimension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a world with plenty of options
|
||||
*
|
||||
* @return the creator builder
|
||||
*/
|
||||
public static IrisCreator createWorld()
|
||||
{
|
||||
public static IrisCreator createWorld() {
|
||||
return new IrisCreator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given world is an Iris World (same as access(world) != null)
|
||||
*
|
||||
* @param world the world
|
||||
* @return true if it is an Iris Access world
|
||||
*/
|
||||
public static boolean isIrisWorld(World world)
|
||||
{
|
||||
public static boolean isIrisWorld(World world) {
|
||||
return access(world) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Iris generator for the given world
|
||||
*
|
||||
* @param world the given world
|
||||
* @return the IrisAccess or null if it's not an Iris World
|
||||
*/
|
||||
public static IrisAccess access(World world)
|
||||
{
|
||||
public static IrisAccess access(World world) {
|
||||
return IrisWorlds.access(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a pregenerator task
|
||||
* @param task the scheduled task
|
||||
*
|
||||
* @param task the scheduled task
|
||||
* @param method the method to execute the task
|
||||
* @return the pregenerator job (already started)
|
||||
*/
|
||||
public static PregeneratorJob pregenerate(PregenTask task, PregeneratorMethod method)
|
||||
{
|
||||
public static PregeneratorJob pregenerate(PregenTask task, PregeneratorMethod method) {
|
||||
return new PregeneratorJob(task, method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a pregenerator task. If the supplied generator is headless, headless mode is used,
|
||||
* otherwise Hybrid mode is used.
|
||||
* @param task the scheduled task
|
||||
*
|
||||
* @param task the scheduled task
|
||||
* @param access the Iris Generator
|
||||
* @return the pregenerator job (already started)
|
||||
*/
|
||||
public static PregeneratorJob pregenerate(PregenTask task, IrisAccess access)
|
||||
{
|
||||
if(access.isHeadless())
|
||||
{
|
||||
public static PregeneratorJob pregenerate(PregenTask task, IrisAccess access) {
|
||||
if (access.isHeadless()) {
|
||||
return pregenerate(task, new HeadlessPregenMethod(access.getHeadlessGenerator().getWorld(), access.getHeadlessGenerator()));
|
||||
}
|
||||
|
||||
@@ -128,14 +123,13 @@ public class IrisToolbelt {
|
||||
/**
|
||||
* Start a pregenerator task. If the supplied generator is headless, headless mode is used,
|
||||
* otherwise Hybrid mode is used.
|
||||
* @param task the scheduled task
|
||||
*
|
||||
* @param task the scheduled task
|
||||
* @param world the World
|
||||
* @return the pregenerator job (already started)
|
||||
*/
|
||||
public static PregeneratorJob pregenerate(PregenTask task, World world)
|
||||
{
|
||||
if(isIrisWorld(world))
|
||||
{
|
||||
public static PregeneratorJob pregenerate(PregenTask task, World world) {
|
||||
if (isIrisWorld(world)) {
|
||||
return pregenerate(task, access(world));
|
||||
}
|
||||
|
||||
@@ -145,10 +139,10 @@ public class IrisToolbelt {
|
||||
/**
|
||||
* Evacuate all players from the world into literally any other world.
|
||||
* If there are no other worlds, kick them! Not the best but what's mine is mine sometimes...
|
||||
*
|
||||
* @param world the world to evac
|
||||
*/
|
||||
public static void evacuate(World world)
|
||||
{
|
||||
public static void evacuate(World world) {
|
||||
IrisWorlds.evacuate(world);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,8 +198,7 @@ public class IrisComplex implements DataProvider {
|
||||
}, Interpolated.DOUBLE).cache2D(cacheSize);
|
||||
slopeStream = heightStream.slope(3).interpolate().bilinear(3, 3).cache2D(cacheSize);
|
||||
objectChanceStream = ProceduralStream.ofDouble((x, z) -> {
|
||||
if(engine.getDimension().hasFeatures(engine))
|
||||
{
|
||||
if (engine.getDimension().hasFeatures(engine)) {
|
||||
AtomicDouble str = new AtomicDouble(1D);
|
||||
engine.getFramework().getEngineParallax().forEachFeature(x, z, (i)
|
||||
-> str.set(Math.min(str.get(), i.getObjectChanceModifier(x, z))));
|
||||
|
||||
@@ -39,7 +39,6 @@ import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -99,7 +98,7 @@ public class IrisEngineCompound implements EngineCompound {
|
||||
} else {
|
||||
double totalWeight = 0D;
|
||||
engines = new Engine[rootDimension.getDimensionalComposite().size()];
|
||||
burster = engines.length > 1 ? new MultiBurst("Iris Compound " + rootDimension.getName(), IrisSettings.get().getConcurrency().getEngineThreadPriority(), engines.length) : null;
|
||||
burster = engines.length > 1 ? new MultiBurst("Iris Compound " + rootDimension.getName(), IrisSettings.get().getConcurrency().getEngineThreadPriority(), engines.length) : null;
|
||||
int threadDist = (Math.max(2, maximumThreads - engines.length)) / engines.length;
|
||||
|
||||
if ((threadDist * engines.length) + engines.length > maximumThreads) {
|
||||
|
||||
@@ -28,7 +28,6 @@ import com.volmit.iris.engine.hunk.view.BiomeGridHunkView;
|
||||
import com.volmit.iris.engine.object.IrisBiome;
|
||||
import com.volmit.iris.engine.object.IrisBiomeCustom;
|
||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
@@ -25,7 +25,6 @@ import com.volmit.iris.util.collection.KSet;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.type.Farmland;
|
||||
|
||||
public class B {
|
||||
private static final Material AIR_MATERIAL = Material.AIR;
|
||||
|
||||
@@ -18,11 +18,9 @@
|
||||
|
||||
package com.volmit.iris.engine.data.chunk;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.BiomeBaseInjector;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.util.data.IrisBiomeStorage;
|
||||
import net.minecraft.world.level.chunk.BiomeStorage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@@ -39,13 +37,11 @@ public class LinkedTerrainChunk implements TerrainChunk {
|
||||
private ChunkData rawChunkData;
|
||||
private final BiomeGrid storage;
|
||||
|
||||
public LinkedTerrainChunk(World world)
|
||||
{
|
||||
public LinkedTerrainChunk(World world) {
|
||||
this(null, Bukkit.createChunkData(world));
|
||||
}
|
||||
|
||||
public LinkedTerrainChunk(World world, BiomeGrid storage)
|
||||
{
|
||||
public LinkedTerrainChunk(World world, BiomeGrid storage) {
|
||||
this(storage, Bukkit.createChunkData(world));
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
package com.volmit.iris.engine.data.mca;
|
||||
|
||||
import com.volmit.iris.engine.data.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.engine.hunk.storage.ArrayHunk;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.math.Position2;
|
||||
|
||||
@@ -242,8 +241,7 @@ public class MCAFile {
|
||||
return getChunk(getChunkIndex(chunkX, chunkZ));
|
||||
}
|
||||
|
||||
public boolean hasChunk(int chunkX, int chunkZ)
|
||||
{
|
||||
public boolean hasChunk(int chunkX, int chunkZ) {
|
||||
return getChunk(chunkX, chunkZ) != null;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,21 +24,20 @@ import com.volmit.iris.engine.cache.Cache;
|
||||
import com.volmit.iris.engine.data.B;
|
||||
import com.volmit.iris.engine.data.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.engine.data.nbt.tag.StringTag;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.scheduling.IrisLock;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class NBTWorld {
|
||||
private static final BlockData AIR = B.get("AIR");
|
||||
@@ -50,8 +49,7 @@ public class NBTWorld {
|
||||
private final File worldFolder;
|
||||
private final ExecutorService saveQueue;
|
||||
|
||||
public NBTWorld(File worldFolder)
|
||||
{
|
||||
public NBTWorld(File worldFolder) {
|
||||
this.worldFolder = worldFolder;
|
||||
this.loadedRegions = new KMap<>();
|
||||
this.lastUse = new KMap<>();
|
||||
@@ -63,20 +61,17 @@ public class NBTWorld {
|
||||
});
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
public void close() {
|
||||
regionLock.lock();
|
||||
|
||||
for(Long i : loadedRegions.k())
|
||||
{
|
||||
for (Long i : loadedRegions.k()) {
|
||||
queueSaveUnload(Cache.keyX(i), Cache.keyZ(i));
|
||||
}
|
||||
|
||||
regionLock.unlock();
|
||||
saveQueue.shutdown();
|
||||
try {
|
||||
while(!saveQueue.awaitTermination(3, TimeUnit.SECONDS))
|
||||
{
|
||||
while (!saveQueue.awaitTermination(3, TimeUnit.SECONDS)) {
|
||||
Iris.info("Still Waiting to save MCA Files...");
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
@@ -84,52 +79,43 @@ public class NBTWorld {
|
||||
}
|
||||
}
|
||||
|
||||
public void flushNow()
|
||||
{
|
||||
public void flushNow() {
|
||||
regionLock.lock();
|
||||
|
||||
for(Long i : loadedRegions.k())
|
||||
{
|
||||
for (Long i : loadedRegions.k()) {
|
||||
doSaveUnload(Cache.keyX(i), Cache.keyZ(i));
|
||||
}
|
||||
|
||||
regionLock.unlock();
|
||||
}
|
||||
|
||||
public void queueSaveUnload(int x, int z)
|
||||
{
|
||||
public void queueSaveUnload(int x, int z) {
|
||||
saveQueue.submit(() -> doSaveUnload(x, z));
|
||||
}
|
||||
|
||||
public void doSaveUnload(int x, int z)
|
||||
{
|
||||
public void doSaveUnload(int x, int z) {
|
||||
MCAFile f = getMCAOrNull(x, z);
|
||||
if(f != null)
|
||||
{
|
||||
if (f != null) {
|
||||
unloadRegion(x, z);
|
||||
}
|
||||
|
||||
saveRegion(x, z, f);
|
||||
}
|
||||
|
||||
public void save()
|
||||
{
|
||||
public void save() {
|
||||
regionLock.lock();
|
||||
|
||||
boolean saving = true;
|
||||
|
||||
for(Long i : loadedRegions.k())
|
||||
{
|
||||
for (Long i : loadedRegions.k()) {
|
||||
int x = Cache.keyX(i);
|
||||
int z = Cache.keyZ(i);
|
||||
|
||||
if(!lastUse.containsKey(i))
|
||||
{
|
||||
if (!lastUse.containsKey(i)) {
|
||||
lastUse.put(i, M.ms());
|
||||
}
|
||||
|
||||
if(shouldUnload(x, z))
|
||||
{
|
||||
if (shouldUnload(x, z)) {
|
||||
queueSaveUnload(x, z);
|
||||
}
|
||||
}
|
||||
@@ -139,13 +125,11 @@ public class NBTWorld {
|
||||
regionLock.unlock();
|
||||
}
|
||||
|
||||
public void queueSave()
|
||||
{
|
||||
public void queueSave() {
|
||||
|
||||
}
|
||||
|
||||
public synchronized void unloadRegion(int x, int z)
|
||||
{
|
||||
public synchronized void unloadRegion(int x, int z) {
|
||||
long key = Cache.key(x, z);
|
||||
regionLock.lock();
|
||||
loadedRegions.remove(key);
|
||||
@@ -154,8 +138,7 @@ public class NBTWorld {
|
||||
Iris.debug("Unloaded Region " + C.GOLD + x + " " + z);
|
||||
}
|
||||
|
||||
public void saveRegion(int x, int z)
|
||||
{
|
||||
public void saveRegion(int x, int z) {
|
||||
long k = Cache.key(x, z);
|
||||
MCAFile mca = getMCAOrNull(x, z);
|
||||
try {
|
||||
@@ -167,8 +150,7 @@ public class NBTWorld {
|
||||
}
|
||||
}
|
||||
|
||||
public void saveRegion(int x, int z, MCAFile mca)
|
||||
{
|
||||
public void saveRegion(int x, int z, MCAFile mca) {
|
||||
try {
|
||||
MCAUtil.write(mca, getRegionFile(x, z), true);
|
||||
Iris.debug("Saved Region " + C.GOLD + x + " " + z);
|
||||
@@ -178,8 +160,7 @@ public class NBTWorld {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean shouldUnload(int x, int z)
|
||||
{
|
||||
public boolean shouldUnload(int x, int z) {
|
||||
return getIdleDuration(x, z) > 60000;
|
||||
}
|
||||
|
||||
@@ -296,8 +277,7 @@ public class NBTWorld {
|
||||
return c;
|
||||
}
|
||||
|
||||
public long getIdleDuration(int x, int z)
|
||||
{
|
||||
public long getIdleDuration(int x, int z) {
|
||||
Long l = lastUse.get(Cache.key(x, z));
|
||||
|
||||
return l == null ? 0 : (M.ms() - l);
|
||||
@@ -311,8 +291,7 @@ public class NBTWorld {
|
||||
MCAFile mcaf = loadedRegions.get(key);
|
||||
regionLock.unlock();
|
||||
|
||||
if(mcaf == null)
|
||||
{
|
||||
if (mcaf == null) {
|
||||
mcaf = new MCAFile(x, z);
|
||||
regionLock.lock();
|
||||
loadedRegions.put(key, mcaf);
|
||||
@@ -327,8 +306,7 @@ public class NBTWorld {
|
||||
MCAFile ff = null;
|
||||
regionLock.lock();
|
||||
|
||||
if(loadedRegions.containsKey(key))
|
||||
{
|
||||
if (loadedRegions.containsKey(key)) {
|
||||
lastUse.put(key, M.ms());
|
||||
ff = loadedRegions.get(key);
|
||||
}
|
||||
|
||||
@@ -357,8 +357,7 @@ public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootPro
|
||||
return getCompound().isStudio();
|
||||
}
|
||||
|
||||
default MultiBurst burst()
|
||||
{
|
||||
default MultiBurst burst() {
|
||||
return getTarget().getBurster();
|
||||
}
|
||||
|
||||
|
||||
@@ -447,8 +447,7 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce
|
||||
IrisWorld ww = (getComposite() == null || getComposite().getWorld() == null) ? IrisWorld.fromWorld(world) : getComposite().getWorld();
|
||||
generateChunkRawData(ww, x, z, tc).run();
|
||||
|
||||
if(!getComposite().getWorld().hasRealWorld())
|
||||
{
|
||||
if (!getComposite().getWorld().hasRealWorld()) {
|
||||
getComposite().getWorld().bind(world);
|
||||
}
|
||||
|
||||
@@ -462,8 +461,7 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce
|
||||
return tc.getRaw();
|
||||
}
|
||||
|
||||
public void assignHeadlessGenerator(HeadlessGenerator headlessGenerator)
|
||||
{
|
||||
public void assignHeadlessGenerator(HeadlessGenerator headlessGenerator) {
|
||||
this.headlessGenerator = headlessGenerator;
|
||||
}
|
||||
|
||||
@@ -472,8 +470,7 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce
|
||||
return headlessGenerator;
|
||||
}
|
||||
|
||||
public void assignHeadlessNBTWriter(NBTWorld writer)
|
||||
{
|
||||
public void assignHeadlessNBTWriter(NBTWorld writer) {
|
||||
this.nbtWorld = writer;
|
||||
}
|
||||
|
||||
@@ -492,13 +489,11 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce
|
||||
BurstExecutor e = burst.burst(1024);
|
||||
|
||||
PregenTask.iterateRegion(x, z, (ii, jj) -> e.queue(() -> {
|
||||
if(l != null)
|
||||
{
|
||||
if (l != null) {
|
||||
l.onChunkGenerating(ii, jj);
|
||||
}
|
||||
directWriteChunk(w, ii, jj, writer);
|
||||
if(l != null)
|
||||
{
|
||||
if (l != null) {
|
||||
l.onChunkGenerated(ii, jj);
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -30,7 +30,6 @@ import com.volmit.iris.engine.object.common.IrisWorld;
|
||||
import com.volmit.iris.engine.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@@ -34,7 +34,6 @@ import com.volmit.iris.engine.object.tile.TileData;
|
||||
import com.volmit.iris.engine.parallax.ParallaxAccess;
|
||||
import com.volmit.iris.engine.parallax.ParallaxChunkMeta;
|
||||
import com.volmit.iris.engine.parallel.BurstExecutor;
|
||||
import com.volmit.iris.engine.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
@@ -205,8 +204,7 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
|
||||
IrisLock getFeatureLock();
|
||||
|
||||
default void forEachFeature(double x, double z, Consumer<IrisFeaturePositional> f) {
|
||||
if(!getEngine().getDimension().hasFeatures(getEngine()))
|
||||
{
|
||||
if (!getEngine().getDimension().hasFeatures(getEngine())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -235,8 +233,7 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
|
||||
for (j = -s; j <= s; j++) {
|
||||
ParallaxChunkMeta m = getParallaxAccess().getMetaR(i + cx, j + cz);
|
||||
|
||||
synchronized (m)
|
||||
{
|
||||
synchronized (m) {
|
||||
try {
|
||||
for (IrisFeaturePositional k : m.getFeatures()) {
|
||||
if (k.shouldFilter(x, z)) {
|
||||
|
||||
@@ -34,9 +34,7 @@ import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@@ -49,7 +47,7 @@ public interface IrisAccess extends Hotloadable, DataProvider {
|
||||
|
||||
HeadlessGenerator getHeadlessGenerator();
|
||||
|
||||
default boolean isHeadless(){
|
||||
default boolean isHeadless() {
|
||||
return getHeadlessGenerator() != null;
|
||||
}
|
||||
|
||||
@@ -98,8 +96,7 @@ public interface IrisAccess extends Hotloadable, DataProvider {
|
||||
boolean isStudio();
|
||||
|
||||
default Location lookForBiome(IrisBiome biome, long timeout, Consumer<Integer> triesc) {
|
||||
if(!getCompound().getWorld().hasRealWorld())
|
||||
{
|
||||
if (!getCompound().getWorld().hasRealWorld()) {
|
||||
Iris.error("Cannot GOTO without a bound world (headless mode)");
|
||||
return null;
|
||||
}
|
||||
@@ -184,8 +181,7 @@ public interface IrisAccess extends Hotloadable, DataProvider {
|
||||
}
|
||||
|
||||
default Location lookForRegion(IrisRegion reg, long timeout, Consumer<Integer> triesc) {
|
||||
if(!getCompound().getWorld().hasRealWorld())
|
||||
{
|
||||
if (!getCompound().getWorld().hasRealWorld()) {
|
||||
Iris.error("Cannot GOTO without a bound world (headless mode)");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@ package com.volmit.iris.engine.headless;
|
||||
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.pregenerator.PregenListener;
|
||||
import com.volmit.iris.engine.data.mca.LoadFlags;
|
||||
import com.volmit.iris.engine.data.mca.MCAFile;
|
||||
import com.volmit.iris.engine.data.mca.MCAUtil;
|
||||
import com.volmit.iris.engine.data.mca.NBTWorld;
|
||||
import com.volmit.iris.engine.framework.EngineCompositeGenerator;
|
||||
@@ -35,14 +33,13 @@ import java.io.IOException;
|
||||
|
||||
@Data
|
||||
public class HeadlessGenerator {
|
||||
private static KList<Position2> EMPTYPOINTS = new KList<>();
|
||||
private static KList<Position2> EMPTYPOINTS = new KList<>();
|
||||
private final HeadlessWorld world;
|
||||
private final EngineCompositeGenerator generator;
|
||||
private final NBTWorld writer;
|
||||
private final MultiBurst burst;
|
||||
|
||||
public HeadlessGenerator(HeadlessWorld world)
|
||||
{
|
||||
public HeadlessGenerator(HeadlessWorld world) {
|
||||
this.world = world;
|
||||
burst = new MultiBurst("Iris Headless Generator", 9, IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getPregenThreadCount()));
|
||||
writer = new NBTWorld(world.getWorld().worldFolder());
|
||||
@@ -52,40 +49,33 @@ public class HeadlessGenerator {
|
||||
generator.initialize(world.getWorld());
|
||||
}
|
||||
|
||||
public void generateChunk(int x, int z)
|
||||
{
|
||||
public void generateChunk(int x, int z) {
|
||||
generator.directWriteChunk(world.getWorld(), x, z, writer);
|
||||
}
|
||||
|
||||
public void generateRegion(int x, int z)
|
||||
{
|
||||
public void generateRegion(int x, int z) {
|
||||
generator.directWriteMCA(world.getWorld(), x, z, writer, burst);
|
||||
}
|
||||
|
||||
public void generateRegion(int x, int z, PregenListener listener)
|
||||
{
|
||||
public void generateRegion(int x, int z, PregenListener listener) {
|
||||
generator.directWriteMCA(world.getWorld(), x, z, writer, burst, listener);
|
||||
}
|
||||
|
||||
public File generateRegionToFile(int x, int z, PregenListener listener)
|
||||
{
|
||||
public File generateRegionToFile(int x, int z, PregenListener listener) {
|
||||
generateRegionToFile(x, z, listener);
|
||||
flush();
|
||||
return writer.getRegionFile(x, z);
|
||||
}
|
||||
|
||||
public void flush()
|
||||
{
|
||||
public void flush() {
|
||||
writer.flushNow();
|
||||
}
|
||||
|
||||
public void save()
|
||||
{
|
||||
public void save() {
|
||||
writer.save();
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
public void close() {
|
||||
burst.shutdownAndAwait();
|
||||
generator.close();
|
||||
writer.close();
|
||||
|
||||
@@ -40,13 +40,11 @@ public class HeadlessWorld {
|
||||
private final IrisWorld world;
|
||||
private boolean studio = false;
|
||||
|
||||
public HeadlessWorld(String worldName, IrisDimension dimension, long seed)
|
||||
{
|
||||
public HeadlessWorld(String worldName, IrisDimension dimension, long seed) {
|
||||
this(worldName, dimension, seed, false);
|
||||
}
|
||||
|
||||
public HeadlessWorld(String worldName, IrisDimension dimension, long seed, boolean studio)
|
||||
{
|
||||
public HeadlessWorld(String worldName, IrisDimension dimension, long seed, boolean studio) {
|
||||
this.worldName = worldName;
|
||||
this.dimension = dimension;
|
||||
this.studio = studio;
|
||||
@@ -61,19 +59,16 @@ public class HeadlessWorld {
|
||||
world.worldFolder().mkdirs();
|
||||
new File(world.worldFolder(), "region").mkdirs();
|
||||
|
||||
if(!studio && !new File(world.worldFolder(), "iris").exists())
|
||||
{
|
||||
if (!studio && !new File(world.worldFolder(), "iris").exists()) {
|
||||
Iris.proj.installIntoWorld(new VolmitSender(Bukkit.getConsoleSender(), Iris.instance.getTag("Headless")), dimension.getLoadKey(), world.worldFolder());
|
||||
}
|
||||
}
|
||||
|
||||
public HeadlessGenerator generate()
|
||||
{
|
||||
public HeadlessGenerator generate() {
|
||||
return new HeadlessGenerator(this);
|
||||
}
|
||||
|
||||
public World load()
|
||||
{
|
||||
public World load() {
|
||||
return new WorldCreator(worldName)
|
||||
.environment(dimension.getEnvironment())
|
||||
.seed(world.seed())
|
||||
@@ -85,8 +80,7 @@ public class HeadlessWorld {
|
||||
return new HeadlessWorld(world.getName(), IrisWorlds.access(world).getTarget().getDimension(), world.getSeed());
|
||||
}
|
||||
|
||||
public static HeadlessWorld from(String name, String dimension, long seed)
|
||||
{
|
||||
public static HeadlessWorld from(String name, String dimension, long seed) {
|
||||
return new HeadlessWorld(name, IrisDataManager.loadAnyDimension(dimension), seed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
import com.volmit.iris.util.function.Function2;
|
||||
import com.volmit.iris.util.function.Function3;
|
||||
import com.volmit.iris.util.math.Position2;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.math.Position2;
|
||||
import com.volmit.iris.util.oldnbt.ByteArrayTag;
|
||||
import com.volmit.iris.util.oldnbt.CompoundTag;
|
||||
import com.volmit.iris.util.oldnbt.Tag;
|
||||
@@ -101,8 +101,7 @@ public class HunkRegionSlice<T> {
|
||||
public synchronized void save(MultiBurst burst) {
|
||||
BurstExecutor e = burst.burst();
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
for (Position2 i : save.copy()) {
|
||||
if (i == null) {
|
||||
continue;
|
||||
@@ -118,10 +117,7 @@ public class HunkRegionSlice<T> {
|
||||
}
|
||||
|
||||
e.complete();
|
||||
}
|
||||
|
||||
catch(Throwable ee)
|
||||
{
|
||||
} catch (Throwable ee) {
|
||||
Iris.reportError(ee);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ import com.volmit.iris.engine.hunk.Hunk;
|
||||
import com.volmit.iris.engine.noise.CNG;
|
||||
import com.volmit.iris.engine.object.NoiseStyle;
|
||||
import com.volmit.iris.util.math.BlockPosition;
|
||||
import com.volmit.iris.util.math.Position2;
|
||||
import com.volmit.iris.util.math.MathHelper;
|
||||
import com.volmit.iris.util.math.Position2;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
import org.bukkit.Material;
|
||||
|
||||
@@ -515,37 +515,28 @@ public class IrisDimension extends IrisRegistrant {
|
||||
|
||||
public boolean hasFeatures(DataProvider data) {
|
||||
return featuresUsed.aquire(() -> {
|
||||
if(getFeatures().isNotEmpty() || getSpecificFeatures().isNotEmpty())
|
||||
{
|
||||
if (getFeatures().isNotEmpty() || getSpecificFeatures().isNotEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for(IrisRegion i : getAllRegions(data))
|
||||
{
|
||||
if(i.getFeatures().isNotEmpty())
|
||||
{
|
||||
for (IrisRegion i : getAllRegions(data)) {
|
||||
if (i.getFeatures().isNotEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for(IrisObjectPlacement j : i.getObjects())
|
||||
{
|
||||
if(j.isVacuum())
|
||||
{
|
||||
for (IrisObjectPlacement j : i.getObjects()) {
|
||||
if (j.isVacuum()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for(IrisBiome j : i.getAllBiomes(data))
|
||||
{
|
||||
if(j.getFeatures().isNotEmpty())
|
||||
{
|
||||
for (IrisBiome j : i.getAllBiomes(data)) {
|
||||
if (j.getFeatures().isNotEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for(IrisObjectPlacement k : i.getObjects())
|
||||
{
|
||||
if(k.isVacuum())
|
||||
{
|
||||
for (IrisObjectPlacement k : i.getObjects()) {
|
||||
if (k.isVacuum()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,13 +142,9 @@ public class IrisLoot {
|
||||
i.apply(rng, m);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
m.setCustomModelData(getCustomModel());
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
}
|
||||
m.setLocalizedName(C.translateAlternateColorCodes('&', displayName));
|
||||
@@ -231,13 +227,9 @@ public class IrisLoot {
|
||||
i.apply(rng, m);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
m.setCustomModelData(getCustomModel());
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,31 +47,27 @@ public class IrisWorld {
|
||||
private int minHeight;
|
||||
private int maxHeight;
|
||||
|
||||
public static IrisWorld fromWorld(World world)
|
||||
{
|
||||
public static IrisWorld fromWorld(World world) {
|
||||
return bindWorld(IrisWorld.builder().build(), world);
|
||||
}
|
||||
|
||||
private static IrisWorld bindWorld(IrisWorld iw, World world)
|
||||
{
|
||||
private static IrisWorld bindWorld(IrisWorld iw, World world) {
|
||||
return iw.name(world.getName())
|
||||
.worldFolder(world.getWorldFolder())
|
||||
.seed(world.getSeed())
|
||||
.minHeight(world.getMinHeight())
|
||||
.maxHeight(world.getMaxHeight())
|
||||
.realWorld(world)
|
||||
.environment(world.getEnvironment());
|
||||
.worldFolder(world.getWorldFolder())
|
||||
.seed(world.getSeed())
|
||||
.minHeight(world.getMinHeight())
|
||||
.maxHeight(world.getMaxHeight())
|
||||
.realWorld(world)
|
||||
.environment(world.getEnvironment());
|
||||
}
|
||||
|
||||
public boolean hasRealWorld()
|
||||
{
|
||||
public boolean hasRealWorld() {
|
||||
return realWorld != null;
|
||||
}
|
||||
|
||||
public List<Player> getPlayers() {
|
||||
|
||||
if(hasRealWorld())
|
||||
{
|
||||
if (hasRealWorld()) {
|
||||
return realWorld().getPlayers();
|
||||
}
|
||||
|
||||
@@ -79,8 +75,7 @@ public class IrisWorld {
|
||||
}
|
||||
|
||||
public void evacuate() {
|
||||
if(hasRealWorld())
|
||||
{
|
||||
if (hasRealWorld()) {
|
||||
IrisWorlds.evacuate(realWorld());
|
||||
}
|
||||
}
|
||||
@@ -90,8 +85,7 @@ public class IrisWorld {
|
||||
}
|
||||
|
||||
public Location spawnLocation() {
|
||||
if(hasRealWorld())
|
||||
{
|
||||
if (hasRealWorld()) {
|
||||
return realWorld().getSpawnLocation();
|
||||
}
|
||||
|
||||
@@ -100,8 +94,7 @@ public class IrisWorld {
|
||||
}
|
||||
|
||||
public <T extends Entity> Collection<? extends T> getEntitiesByClass(Class<T> t) {
|
||||
if(hasRealWorld())
|
||||
{
|
||||
if (hasRealWorld()) {
|
||||
return realWorld().getEntitiesByClass(t);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import com.google.gson.Gson;
|
||||
import com.volmit.iris.engine.hunk.io.HunkIOAdapter;
|
||||
import com.volmit.iris.engine.hunk.io.PaletteHunkIOAdapter;
|
||||
import com.volmit.iris.engine.object.IrisFeaturePositional;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.oldnbt.CompoundTag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -27,12 +27,10 @@ import com.volmit.iris.engine.object.tile.TileData;
|
||||
import com.volmit.iris.engine.parallel.GridLock;
|
||||
import com.volmit.iris.engine.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.oldnbt.ByteArrayTag;
|
||||
import com.volmit.iris.util.oldnbt.CompoundTag;
|
||||
import com.volmit.iris.util.oldnbt.Tag;
|
||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
import org.bukkit.block.TileState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
@@ -167,7 +165,7 @@ public class ParallaxRegion extends HunkRegion {
|
||||
tileSlice.save(burst);
|
||||
updateSlice.save(burst);
|
||||
saveMetaHunk();
|
||||
Iris.debug("Saved Parallax Region "+ C.GOLD + getX() + " " + getZ());
|
||||
Iris.debug("Saved Parallax Region " + C.GOLD + getX() + " " + getZ());
|
||||
super.save();
|
||||
}
|
||||
|
||||
|
||||
@@ -99,16 +99,11 @@ public class MultiBurst {
|
||||
public void shutdownAndAwait() {
|
||||
service.shutdown();
|
||||
|
||||
try
|
||||
{
|
||||
while(!service.awaitTermination(10, TimeUnit.SECONDS))
|
||||
{
|
||||
try {
|
||||
while (!service.awaitTermination(10, TimeUnit.SECONDS)) {
|
||||
Iris.info("Still waiting to shutdown burster...");
|
||||
}
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
Iris.reportError(e);
|
||||
}
|
||||
|
||||
@@ -18,8 +18,7 @@
|
||||
|
||||
package com.volmit.iris.util.exceptions;
|
||||
|
||||
public class IrisException extends Exception
|
||||
{
|
||||
public class IrisException extends Exception {
|
||||
public IrisException() {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -18,8 +18,7 @@
|
||||
|
||||
package com.volmit.iris.util.exceptions;
|
||||
|
||||
public class MissingDimensionException extends IrisException
|
||||
{
|
||||
public class MissingDimensionException extends IrisException {
|
||||
public MissingDimensionException() {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -43,8 +43,7 @@ public class Position2 {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
return "[" + x + "," + z + "]";
|
||||
}
|
||||
|
||||
@@ -57,8 +56,7 @@ public class Position2 {
|
||||
return result;
|
||||
}
|
||||
|
||||
public Position2 regionToChunk()
|
||||
{
|
||||
public Position2 regionToChunk() {
|
||||
return new Position2(x << 5, z << 5);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,9 @@ import com.volmit.iris.util.function.NastyRunnable;
|
||||
import com.volmit.iris.util.math.FinalInteger;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
Reference in New Issue
Block a user