diff --git a/build.gradle b/build.gradle index 2625ef8fa..e34634823 100644 --- a/build.gradle +++ b/build.gradle @@ -18,9 +18,10 @@ plugins { id 'java' - id 'io.freefair.lombok' version '5.2.1' + id 'java-library' + id "io.freefair.lombok" version "6.3.0" id "com.github.johnrengelman.shadow" version "7.1.2" - id "de.undercouch.download" version "4.1.2" + id "de.undercouch.download" version "5.0.1" } group 'com.volmit.iris' diff --git a/settings.gradle b/settings.gradle index 42e2f2213..a3e1f97cb 100644 --- a/settings.gradle +++ b/settings.gradle @@ -15,5 +15,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - +pluginManagement { + repositories { + mavenLocal() + mavenCentral() + gradlePluginPortal() + maven { url "https://dl.cloudsmith.io/public/arcane/archive/maven/" } + } +} rootProject.name = 'Iris' \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/Iris.java b/src/main/java/com/volmit/iris/Iris.java index 66b036642..e4a308afc 100644 --- a/src/main/java/com/volmit/iris/Iris.java +++ b/src/main/java/com/volmit/iris/Iris.java @@ -699,8 +699,4 @@ public class Iris extends VolmitPlugin implements Listener { Iris.info("\n\n " + new KList<>(splash).toString("\n") + "\n"); } - - public boolean isMCA() { - return IrisSettings.get().getGenerator().isHeadlessPregeneration(); - } } diff --git a/src/main/java/com/volmit/iris/core/IrisSettings.java b/src/main/java/com/volmit/iris/core/IrisSettings.java index f7b0a9abb..4d64938a0 100644 --- a/src/main/java/com/volmit/iris/core/IrisSettings.java +++ b/src/main/java/com/volmit/iris/core/IrisSettings.java @@ -120,7 +120,6 @@ public class IrisSettings { @Data public static class IrisSettingsGenerator { public String defaultWorldType = "overworld"; - public boolean headlessPregeneration = false; public int maxBiomeChildDepth = 4; public boolean preventLeafDecay = true; } diff --git a/src/main/java/com/volmit/iris/core/pregenerator/methods/HeadlessPregenMethod.java b/src/main/java/com/volmit/iris/core/pregenerator/methods/HeadlessPregenMethod.java deleted file mode 100644 index 6ea95a9e5..000000000 --- a/src/main/java/com/volmit/iris/core/pregenerator/methods/HeadlessPregenMethod.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 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 . - */ - -package com.volmit.iris.core.pregenerator.methods; - -import com.volmit.iris.core.pregenerator.PregenListener; -import com.volmit.iris.core.pregenerator.PregeneratorMethod; -import com.volmit.iris.engine.object.HeadlessWorld; -import com.volmit.iris.engine.platform.HeadlessGenerator; -import com.volmit.iris.util.mantle.Mantle; -import lombok.Getter; - -public class HeadlessPregenMethod implements PregeneratorMethod { - - @Getter - private final HeadlessGenerator generator; - - public HeadlessPregenMethod(HeadlessWorld world) { - this(world, world.generate()); - } - - public HeadlessPregenMethod(HeadlessWorld world, HeadlessGenerator generator) { - this.generator = generator; - } - - @Override - public void init() { - - } - - @Override - public void close() { - generator.close(); - } - - @Override - public void save() { - generator.save(); - } - - @Override - public boolean supportsRegions(int x, int z, PregenListener listener) { - return true; - } - - @Override - public String getMethod(int x, int z) { - return "Headless"; - } - - @Override - public void generateRegion(int x, int z, PregenListener listener) { - generator.generateRegion(x, z, listener); - } - - @Override - public void generateChunk(int x, int z, PregenListener listener) { - throw new UnsupportedOperationException(); - } - - @Override - public Mantle getMantle() { - return generator.getEngine().getMantle().getMantle(); - } -} diff --git a/src/main/java/com/volmit/iris/core/pregenerator/methods/HybridPregenMethod.java b/src/main/java/com/volmit/iris/core/pregenerator/methods/HybridPregenMethod.java index 71677beeb..4cb537a2d 100644 --- a/src/main/java/com/volmit/iris/core/pregenerator/methods/HybridPregenMethod.java +++ b/src/main/java/com/volmit/iris/core/pregenerator/methods/HybridPregenMethod.java @@ -23,7 +23,6 @@ import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.pregenerator.PregenListener; import com.volmit.iris.core.pregenerator.PregeneratorMethod; import com.volmit.iris.core.tools.IrisToolbelt; -import com.volmit.iris.engine.object.HeadlessWorld; import com.volmit.iris.util.mantle.Mantle; import com.volmit.iris.util.math.Position2; import org.bukkit.World; @@ -31,68 +30,42 @@ import org.bukkit.World; import java.io.File; public class HybridPregenMethod implements PregeneratorMethod { - private final PregeneratorMethod headless; private final PregeneratorMethod inWorld; private final World world; public HybridPregenMethod(World world, int threads) { this.world = world; - headless = supportsHeadless(world) - ? new HeadlessPregenMethod(HeadlessWorld.from(world)) : new DummyPregenMethod(); inWorld = new AsyncOrMedievalPregenMethod(world, threads); } - private boolean supportsHeadless(World world) { - return IrisToolbelt.access(world) != null && IrisSettings.get().getGenerator().isHeadlessPregeneration(); - } - @Override public String getMethod(int x, int z) { - return "Hybrid<" + ((supportsRegions(x, z, null) ? headless.getMethod(x, z) : inWorld.getMethod(x, z)) + ">"); + return "Hybrid<" + inWorld.getMethod(x, z) + ">"; } @Override public void init() { - headless.init(); inWorld.init(); } @Override public void close() { - headless.close(); inWorld.close(); } @Override public void save() { - headless.save(); inWorld.save(); } @Override public boolean supportsRegions(int x, int z, PregenListener listener) { - if(headless instanceof DummyPregenMethod) { - return false; - } - - 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)) { - listener.onChunkExistsInRegionGen((x << 5) + i.getX(), (z << 5) + i.getZ()); - } - } catch(Throwable e) { - Iris.reportError(e); - } - } - - return r; + return inWorld.supportsRegions(x, z, listener); } @Override public void generateRegion(int x, int z, PregenListener listener) { - headless.generateRegion(x, z, listener); + inWorld.generateRegion(x, z, listener); } @Override @@ -102,10 +75,6 @@ public class HybridPregenMethod implements PregeneratorMethod { @Override public Mantle getMantle() { - if(headless == null) { - return inWorld.getMantle(); - } - - return headless.getMantle(); + return inWorld.getMantle(); } } diff --git a/src/main/java/com/volmit/iris/core/pregenerator/methods/SyndicatePregenMethod.java b/src/main/java/com/volmit/iris/core/pregenerator/methods/SyndicatePregenMethod.java deleted file mode 100644 index 16a884608..000000000 --- a/src/main/java/com/volmit/iris/core/pregenerator/methods/SyndicatePregenMethod.java +++ /dev/null @@ -1,274 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 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 . - */ - -package com.volmit.iris.core.pregenerator.methods; - -import com.google.common.util.concurrent.AtomicDouble; -import com.volmit.iris.Iris; -import com.volmit.iris.core.pregenerator.PregenListener; -import com.volmit.iris.core.pregenerator.PregenTask; -import com.volmit.iris.core.pregenerator.PregeneratorMethod; -import com.volmit.iris.core.pregenerator.syndicate.SyndicateClient; -import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateBusy; -import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateClose; -import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateGenerate; -import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateGetProgress; -import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateInstallFirst; -import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateInstallPack; -import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateOK; -import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateSendProgress; -import com.volmit.iris.engine.object.IrisDimension; -import com.volmit.iris.util.io.IO; -import com.volmit.iris.util.mantle.Mantle; -import com.volmit.iris.util.scheduling.J; -import lombok.Getter; -import org.zeroturnaround.zip.ZipUtil; - -import java.io.File; -import java.io.IOException; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicInteger; - -public class SyndicatePregenMethod implements PregeneratorMethod { - @Getter - private final String address; - private final int port; - private final String password; - private final IrisDimension dimension; - private final File worldFolder; - private final UUID pack = UUID.randomUUID(); - private final long seed; - private String nickname; - private boolean ready = false; - - 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; - this.port = port; - this.password = password; - this.dimension = dimension; - } - - private SyndicateClient.SyndicateClientBuilder connect() { - return SyndicateClient.builder().address(address).port(port); - } - - public synchronized void setup() { - if(ready) { - return; - } - - ready = false; - try { - connect().command(SyndicateInstallPack - .builder() - .dimension(dimension) - .pack(pack) - .seed(seed) - .build()) - .output((o) -> { - File to = new File(Iris.getTemp(), "send-" + pack + ".zip"); - ZipUtil.pack(dimension.getLoader().getDataFolder(), to); - - 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"); - } - - ready = true; - }); - ready = true; - } catch(Throwable throwable) { - if(throwable instanceof RuntimeException) { - ready = false; - return; - } - - throwable.printStackTrace(); - } - } - - public boolean canGenerate() { - if(!ready) { - J.a(this::setup); - } - - return ready; - } - - @Override - public void init() { - J.a(this::setup); - } - - @Override - public void close() { - if(ready) { - try { - connect() - .command(SyndicateClose - .builder() - .pack(pack) - .build()) - .build() - .go((__, __b) -> { - }); - } catch(Throwable throwable) { - throwable.printStackTrace(); - } - } - } - - @Override - public void save() { - - } - - @Override - public boolean supportsRegions(int x, int z, PregenListener listener) { - return true; - } - - @Override - public String getMethod(int x, int z) { - return "Syndicate<" + nickname + ">"; - } - - 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(); - } - } - } - }); - } catch(Throwable throwable) { - throwable.printStackTrace(); - } - - return progress.get(); - } - - @Override - public void generateRegion(int x, int z, PregenListener listener) { - if(!ready) { - throw new RuntimeException(); - } - - try { - connect().command(SyndicateGenerate - .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; - - 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; - } - - if(!installed) { - // TODO RETRY REGION - return; - } - - 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) { - throw (RuntimeException) throwable; - } - - throwable.printStackTrace(); - } - } - - @Override - public void generateChunk(int x, int z, PregenListener listener) { - - } - - @Override - public Mantle getMantle() { - return null; - } -} diff --git a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/SyndicateClient.java b/src/main/java/com/volmit/iris/core/pregenerator/syndicate/SyndicateClient.java deleted file mode 100644 index fd40a44d6..000000000 --- a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/SyndicateClient.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 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 . - */ - -package com.volmit.iris.core.pregenerator.syndicate; - -import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateCommand; -import com.volmit.iris.util.function.Consumer2; -import lombok.Builder; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.net.Socket; -import java.util.function.Consumer; - -@Builder -public class SyndicateClient { - private final String address; - private final int port; - private final SyndicateCommand command; - private final Consumer output; - - public void go(Consumer2 handler) throws Throwable { - Socket socket = new Socket(address, port); - DataInputStream i = new DataInputStream(socket.getInputStream()); - DataOutputStream o = new DataOutputStream(socket.getOutputStream()); - SyndicateCommandIO.write(command, o); - - if(output != null) { - output.accept(o); - } - - o.flush(); - handler.accept(SyndicateCommandIO.read(i), i); - socket.close(); - } -} diff --git a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/SyndicateCommandIO.java b/src/main/java/com/volmit/iris/core/pregenerator/syndicate/SyndicateCommandIO.java deleted file mode 100644 index d8e2ed258..000000000 --- a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/SyndicateCommandIO.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 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 . - */ - -package com.volmit.iris.core.pregenerator.syndicate; - -import com.google.gson.Gson; -import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateCommand; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -public class SyndicateCommandIO { - private static final Gson gson = new Gson(); - - public static SyndicateCommand read(DataInputStream in) throws IOException, ClassNotFoundException { - String clazz = in.readUTF(); - return (SyndicateCommand) gson.fromJson(in.readUTF(), Class.forName(clazz)); - } - - public static void write(SyndicateCommand c, DataOutputStream out) throws IOException { - out.writeUTF(c.getClass().getCanonicalName()); - out.writeUTF(gson.toJson(c)); - } -} diff --git a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/SyndicateServer.java b/src/main/java/com/volmit/iris/core/pregenerator/syndicate/SyndicateServer.java deleted file mode 100644 index 15341c669..000000000 --- a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/SyndicateServer.java +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 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 . - */ - -package com.volmit.iris.core.pregenerator.syndicate; - -import com.volmit.iris.core.pregenerator.PregenListener; -import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateBusy; -import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateClose; -import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateCommand; -import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateGenerate; -import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateGetProgress; -import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateInstallFirst; -import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateInstallPack; -import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateOK; -import com.volmit.iris.core.pregenerator.syndicate.command.SyndicateSendProgress; -import com.volmit.iris.engine.object.HeadlessWorld; -import com.volmit.iris.engine.platform.HeadlessGenerator; -import com.volmit.iris.util.io.IO; -import com.volmit.iris.util.scheduling.J; -import org.zeroturnaround.zip.ZipUtil; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.net.ServerSocket; -import java.net.Socket; -import java.net.SocketTimeoutException; -import java.util.Objects; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicInteger; - -public class SyndicateServer extends Thread implements PregenListener { - private final int port; - private final String password; - private final int tc; - private final ServerSocket server; - private final File cache; - private final AtomicInteger g = new AtomicInteger(0); - private boolean busy; - private HeadlessGenerator generator; - private UUID currentId = null; - private File lastGeneratedRegion = null; - - public SyndicateServer(File cache, int port, String password, int tc) throws IOException { - this.port = port; - this.cache = cache; - this.password = password; - this.tc = tc; - start(); - server = new ServerSocket(port); - server.setSoTimeout(1000); - } - - public void run() { - while(!interrupted()) { - try { - Socket client = server.accept(); - DataInputStream i = new DataInputStream(client.getInputStream()); - DataOutputStream o = new DataOutputStream(client.getOutputStream()); - try { - handle(client, i, o); - o.flush(); - } catch(Throwable throwable) { - throwable.printStackTrace(); - } - client.close(); - } catch(SocketTimeoutException ignored) { - - } catch(IOException e) { - e.printStackTrace(); - } - } - } - - private void handle(Socket client, DataInputStream i, DataOutputStream o) throws Throwable { - SyndicateCommand cmd = handle(SyndicateCommandIO.read(i), i, o); - - 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 SyndicateCommand handle(SyndicateCommand command, DataInputStream i, DataOutputStream o) throws Throwable { - if(command instanceof SyndicateInstallPack) { - if(busy) { - return new SyndicateBusy(); - } - - 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 cachestore = getCachedDim(id); - IO.delete(cachestore); - int len = i.readInt(); - cacheload.getParentFile().mkdirs(); - byte[] buf = new byte[8192]; - FileOutputStream fos = new FileOutputStream(cacheload); - IO.transfer(i, fos, buf, len); - fos.close(); - ZipUtil.unpack(cacheload, cachestore); - cacheload.deleteOnExit(); - HeadlessWorld w = new HeadlessWorld("turbo/" + id, ((SyndicateInstallPack) command).getDimension(), ((SyndicateInstallPack) command).getSeed()); - w.setStudio(true); - generator = w.generate(); - return new SyndicateOK(); - } - - if(command instanceof SyndicateGenerate) { - if(busy) { - return new SyndicateBusy(); - } - - if(generator == null || !Objects.equals(currentId, ((SyndicateGenerate) command).getPack())) { - return new SyndicateInstallFirst(); - } - - g.set(0); - busy = true; - J.a(() -> { - busy = false; - lastGeneratedRegion = generator.generateRegionToFile(((SyndicateGenerate) command).getX(), ((SyndicateGenerate) command).getZ(), this); - }); - return new SyndicateOK(); - } - - if(command instanceof SyndicateClose) { - if(generator != null && Objects.equals(currentId, ((SyndicateClose) command).getPack()) && !busy) { - generator.close(); - IO.delete(generator.getWorld().getWorld().worldFolder()); - generator = null; - currentId = null; - } - } - - 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() - .progress(1).available(true) - .build(), o); - o.writeLong(lastGeneratedRegion.length()); - IO.writeAll(lastGeneratedRegion, o); - return null; - } else if(generator == null) { - return new SyndicateInstallFirst(); - } else { - return new SyndicateBusy(); - } - } - - throw new IllegalStateException("Unexpected value: " + command.getClass()); - } - - public void close() throws IOException { - interrupt(); - generator.close(); - server.close(); - } - - @Override - public void onTick(double chunksPerSecond, double chunksPerMinute, double regionsPerMinute, double percent, int generated, int totalChunks, int chunksRemaining, long eta, long elapsed, String method) { - - } - - @Override - public void onChunkGenerating(int x, int z) { - - } - - @Override - public void onChunkGenerated(int x, int z) { - g.incrementAndGet(); - } - - @Override - public void onRegionGenerated(int x, int z) { - - } - - @Override - public void onRegionGenerating(int x, int z) { - - } - - @Override - public void onChunkCleaned(int x, int z) { - - } - - @Override - public void onRegionSkipped(int x, int z) { - - } - - @Override - public void onNetworkStarted(int x, int z) { - - } - - @Override - public void onNetworkFailed(int x, int z) { - - } - - @Override - public void onNetworkReclaim(int revert) { - - } - - @Override - public void onNetworkGeneratedChunk(int x, int z) { - - } - - @Override - public void onNetworkDownloaded(int x, int z) { - - } - - @Override - public void onClose() { - - } - - @Override - public void onSaving() { - - } - - @Override - public void onChunkExistsInRegionGen(int x, int z) { - - } -} diff --git a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateBusy.java b/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateBusy.java deleted file mode 100644 index 97df5dd05..000000000 --- a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateBusy.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 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 . - */ - -package com.volmit.iris.core.pregenerator.syndicate.command; - -public class SyndicateBusy implements SyndicateCommand { -} diff --git a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateClose.java b/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateClose.java deleted file mode 100644 index ef3ec06ac..000000000 --- a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateClose.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 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 . - */ - -package com.volmit.iris.core.pregenerator.syndicate.command; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.UUID; - -@Builder -@AllArgsConstructor -@NoArgsConstructor -@Data -public class SyndicateClose implements SyndicateCommand { - @Builder.Default - private UUID pack = UUID.randomUUID(); -} diff --git a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateCommand.java b/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateCommand.java deleted file mode 100644 index 91b0bd0c8..000000000 --- a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateCommand.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 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 . - */ - -package com.volmit.iris.core.pregenerator.syndicate.command; - -public interface SyndicateCommand { - -} diff --git a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateError.java b/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateError.java deleted file mode 100644 index 0057eacca..000000000 --- a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateError.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 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 . - */ - -package com.volmit.iris.core.pregenerator.syndicate.command; - -public class SyndicateError implements SyndicateCommand { -} diff --git a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateGenerate.java b/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateGenerate.java deleted file mode 100644 index 590c7f8c6..000000000 --- a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateGenerate.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 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 . - */ - -package com.volmit.iris.core.pregenerator.syndicate.command; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.UUID; - -@Builder -@AllArgsConstructor -@NoArgsConstructor -@Data -public class SyndicateGenerate implements SyndicateCommand { - @Builder.Default - private int x = 0; - @Builder.Default - private int z = 0; - @Builder.Default - private UUID pack = UUID.randomUUID(); -} diff --git a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateGetProgress.java b/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateGetProgress.java deleted file mode 100644 index 3ee1394b7..000000000 --- a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateGetProgress.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 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 . - */ - -package com.volmit.iris.core.pregenerator.syndicate.command; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.UUID; - -@Data -@Builder -@AllArgsConstructor -@NoArgsConstructor -public class SyndicateGetProgress implements SyndicateCommand { - @Builder.Default - private UUID pack = UUID.randomUUID(); -} diff --git a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateInstallFirst.java b/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateInstallFirst.java deleted file mode 100644 index 63450fafc..000000000 --- a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateInstallFirst.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 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 . - */ - -package com.volmit.iris.core.pregenerator.syndicate.command; - -public class SyndicateInstallFirst implements SyndicateCommand { -} diff --git a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateInstallPack.java b/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateInstallPack.java deleted file mode 100644 index d808b7618..000000000 --- a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateInstallPack.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 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 . - */ - -package com.volmit.iris.core.pregenerator.syndicate.command; - -import com.volmit.iris.engine.object.IrisDimension; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.UUID; - -@Builder -@AllArgsConstructor -@NoArgsConstructor -@Data -public class SyndicateInstallPack implements SyndicateCommand { - @Builder.Default - private UUID pack = UUID.randomUUID(); - - @Builder.Default - private long seed = 1337; - - @Builder.Default - private IrisDimension dimension = null; -} diff --git a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateOK.java b/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateOK.java deleted file mode 100644 index b4a37ea56..000000000 --- a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateOK.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 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 . - */ - -package com.volmit.iris.core.pregenerator.syndicate.command; - -public class SyndicateOK implements SyndicateCommand { -} diff --git a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateSendProgress.java b/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateSendProgress.java deleted file mode 100644 index 12f14861c..000000000 --- a/src/main/java/com/volmit/iris/core/pregenerator/syndicate/command/SyndicateSendProgress.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 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 . - */ - -package com.volmit.iris.core.pregenerator.syndicate.command; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class SyndicateSendProgress implements SyndicateCommand { - @Builder.Default - private double progress = 0; - @Builder.Default - private boolean available = false; -} diff --git a/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java b/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java index e4cd8e97b..e55697795 100644 --- a/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java +++ b/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java @@ -24,12 +24,10 @@ import com.volmit.iris.core.gui.PregeneratorJob; import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.core.pregenerator.PregenTask; import com.volmit.iris.core.pregenerator.PregeneratorMethod; -import com.volmit.iris.core.pregenerator.methods.HeadlessPregenMethod; import com.volmit.iris.core.pregenerator.methods.HybridPregenMethod; import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.object.IrisDimension; -import com.volmit.iris.engine.platform.HeadlessGenerator; import com.volmit.iris.engine.platform.PlatformChunkGenerator; import com.volmit.iris.util.plugin.VolmitSender; import org.bukkit.Bukkit; @@ -141,10 +139,6 @@ public class IrisToolbelt { * @return the pregenerator job (already started) */ public static PregeneratorJob pregenerate(PregenTask task, PlatformChunkGenerator gen) { - if(gen.isHeadless()) { - return pregenerate(task, new HeadlessPregenMethod(((HeadlessGenerator) gen).getWorld(), (HeadlessGenerator) gen), gen.getEngine()); - } - return pregenerate(task, new HybridPregenMethod(gen.getEngine().getWorld().realWorld(), IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getParallelism())), gen.getEngine()); } @@ -216,8 +210,4 @@ public class IrisToolbelt { public static boolean isStudio(World i) { return isIrisWorld(i) && access(i).isStudio(); } - - public static boolean isHeadless(World i) { - return isIrisWorld(i) && access(i).isHeadless(); - } } diff --git a/src/main/java/com/volmit/iris/engine/object/HeadlessWorld.java b/src/main/java/com/volmit/iris/engine/object/HeadlessWorld.java deleted file mode 100644 index 75f9d7fc5..000000000 --- a/src/main/java/com/volmit/iris/engine/object/HeadlessWorld.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 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 . - */ - -package com.volmit.iris.engine.object; - -import com.volmit.iris.Iris; -import com.volmit.iris.core.loader.IrisData; -import com.volmit.iris.core.service.StudioSVC; -import com.volmit.iris.core.tools.IrisToolbelt; -import com.volmit.iris.engine.framework.Engine; -import com.volmit.iris.engine.platform.BukkitChunkGenerator; -import com.volmit.iris.engine.platform.HeadlessGenerator; -import com.volmit.iris.util.plugin.VolmitSender; -import lombok.Data; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.WorldCreator; - -import java.io.File; - -@Data -@SuppressWarnings("ResultOfMethodCallIgnored") -public class HeadlessWorld { - private final IrisDimension dimension; - private final String worldName; - private final IrisWorld world; - private boolean studio; - - public HeadlessWorld(String worldName, IrisDimension dimension, long seed) { - this(worldName, dimension, seed, false); - } - - public HeadlessWorld(String worldName, IrisDimension dimension, long seed, boolean studio) { - this.worldName = worldName; - this.dimension = dimension; - this.studio = studio; - world = IrisWorld.builder() - .environment(dimension.getEnvironment()) - .worldFolder(new File(worldName)) - .seed(seed) - .maxHeight(dimension.getMaxHeight()) - .minHeight(dimension.getMinHeight()) - .name(worldName) - .build(); - world.worldFolder().mkdirs(); - new File(world.worldFolder(), "region").mkdirs(); - - if(!studio && !new File(world.worldFolder(), "iris/pack").exists()) { - Iris.service(StudioSVC.class).installIntoWorld(new VolmitSender(Bukkit.getConsoleSender(), Iris.instance.getTag("Headless")), dimension.getLoadKey(), world.worldFolder()); - } - } - - public static HeadlessWorld from(World world) { - return new HeadlessWorld(world.getName(), IrisToolbelt.access(world) - .getEngine().getTarget().getDimension(), world.getSeed()); - } - - public static HeadlessWorld from(String name, String dimension, long seed) { - return new HeadlessWorld(name, IrisData.loadAnyDimension(dimension), seed); - } - - @SuppressWarnings("ConstantConditions") - public HeadlessGenerator generate() { - Engine e = null; - - if(getWorld().tryGetRealWorld()) { - if(IrisToolbelt.isIrisWorld(getWorld().realWorld())) { - e = IrisToolbelt.access(getWorld().realWorld()).getEngine(); - } - } - - if(e != null) { - Iris.info("Using Existing Engine " + getWorld().name() + " for Headless Pregeneration."); - } - - return e != null ? new HeadlessGenerator(this, e) : new HeadlessGenerator(this); - } - - public World load() { - World w = new WorldCreator(worldName) - .environment(dimension.getEnvironment()) - .seed(world.getRawWorldSeed()) - .generator(new BukkitChunkGenerator(world, studio, dimension.getLoader().getDataFolder(), - dimension.getLoadKey())) - .createWorld(); - world.realWorld(w); - return w; - } -} diff --git a/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java b/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java index 81ddd23ac..45b08c037 100644 --- a/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java +++ b/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java @@ -127,11 +127,6 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun populators.clear(); } - @Override - public boolean isHeadless() { - return false; - } - @Override public void injectChunkReplacement(World world, int x, int z, Consumer jobs) { try { diff --git a/src/main/java/com/volmit/iris/engine/platform/HeadlessGenerator.java b/src/main/java/com/volmit/iris/engine/platform/HeadlessGenerator.java deleted file mode 100644 index f783774be..000000000 --- a/src/main/java/com/volmit/iris/engine/platform/HeadlessGenerator.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 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 . - */ - -package com.volmit.iris.engine.platform; - -import com.volmit.iris.Iris; -import com.volmit.iris.core.nms.INMS; -import com.volmit.iris.core.pregenerator.PregenListener; -import com.volmit.iris.core.pregenerator.PregenTask; -import com.volmit.iris.engine.IrisEngine; -import com.volmit.iris.engine.data.chunk.MCATerrainChunk; -import com.volmit.iris.engine.data.chunk.TerrainChunk; -import com.volmit.iris.engine.framework.Engine; -import com.volmit.iris.engine.framework.EngineTarget; -import com.volmit.iris.engine.object.HeadlessWorld; -import com.volmit.iris.util.collection.KList; -import com.volmit.iris.util.documentation.ChunkCoordinates; -import com.volmit.iris.util.documentation.RegionCoordinates; -import com.volmit.iris.util.hunk.Hunk; -import com.volmit.iris.util.math.Position2; -import com.volmit.iris.util.math.RNG; -import com.volmit.iris.util.nbt.mca.MCAFile; -import com.volmit.iris.util.nbt.mca.MCAUtil; -import com.volmit.iris.util.nbt.mca.NBTWorld; -import com.volmit.iris.util.nbt.tag.CompoundTag; -import com.volmit.iris.util.parallel.BurstExecutor; -import com.volmit.iris.util.parallel.MultiBurst; -import lombok.Data; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.data.BlockData; - -import java.io.File; -import java.io.IOException; -import java.util.List; -import java.util.function.Consumer; - -@Data -public class HeadlessGenerator implements PlatformChunkGenerator { - private static final BlockData ERROR_BLOCK = Material.RED_GLAZED_TERRACOTTA.createBlockData(); - private static KList EMPTYPOINTS = new KList<>(); - private final HeadlessWorld world; - private final NBTWorld writer; - private final MultiBurst burst; - private final Engine engine; - private final long rkey = RNG.r.lmax(); - private List last = new KList<>(); - - public HeadlessGenerator(HeadlessWorld world) { - this(world, new IrisEngine(new EngineTarget(world.getWorld(), world.getDimension(), world.getDimension().getLoader()), world.isStudio())); - } - - public HeadlessGenerator(HeadlessWorld world, Engine engine) { - this.engine = engine; - this.world = world; - burst = MultiBurst.burst; - writer = new NBTWorld(world.getWorld().worldFolder()); - } - - @ChunkCoordinates - public void generateChunk(MCAFile file, int x, int z) { - try { - int ox = x << 4; - int oz = z << 4; - com.volmit.iris.util.nbt.mca.Chunk chunk = writer.getChunk(file, x, z); - TerrainChunk tc = MCATerrainChunk.builder() - .writer(writer).ox(ox).oz(oz).mcaChunk(chunk) - .minHeight(world.getWorld().minHeight()).maxHeight(world.getWorld().maxHeight()) - .injector((xx, yy, zz, biomeBase) -> chunk.setBiomeAt(ox + xx, yy, oz + zz, - INMS.get().getTrueBiomeBaseId(biomeBase))) - .build(); - getEngine().generate(x << 4, z << 4, - Hunk.view(tc), Hunk.view(tc, tc.getMinHeight(), tc.getMaxHeight()), - false); - chunk.cleanupPalettesAndBlockStates(); - } catch(Throwable e) { - Iris.error("======================================"); - e.printStackTrace(); - Iris.reportErrorChunk(x, z, e, "MCA"); - Iris.error("======================================"); - com.volmit.iris.util.nbt.mca.Chunk chunk = writer.getChunk(x, z); - CompoundTag c = NBTWorld.getCompound(ERROR_BLOCK); - for(int i = 0; i < 16; i++) { - for(int j = 0; j < 16; j++) { - chunk.setBlockStateAt(i, 0, j, c, false); - } - } - } - } - - @Override - public void injectChunkReplacement(World world, int x, int z, Consumer jobs) { - - } - - @RegionCoordinates - public void generateRegion(int x, int z) { - generateRegion(x, z, null); - } - - @RegionCoordinates - public void generateRegion(int x, int z, PregenListener listener) { - BurstExecutor e = burst.burst(1024); - MCAFile f = writer.getMCA(x, z); - PregenTask.iterateRegion(x, z, (ii, jj) -> e.queue(() -> { - if(listener != null) { - listener.onChunkGenerating(ii, jj); - } - generateChunk(f, ii, jj); - if(listener != null) { - listener.onChunkGenerated(ii, jj); - } - }), avgLast(x, z)); - last.add(new Position2(x, z)); - e.complete(); - } - - private Position2 avgLast(int x, int z) { - while(last.size() > 3) { - last.remove(0); - } - - double xx = 0; - double zz = 0; - - for(Position2 i : last) { - xx += 27 * (i.getX() - x); - zz += 27 * (i.getZ() - z); - } - - return new Position2((int) xx, (int) zz); - } - - @RegionCoordinates - public File generateRegionToFile(int x, int z, PregenListener listener) { - generateRegion(x, z, listener); - flush(); - return writer.getRegionFile(x, z); - } - - public void flush() { - writer.flushNow(); - } - - public void save() { - writer.save(); - } - - public void close() { - writer.close(); - } - - @Override - public boolean isStudio() { - return false; - } - - @Override - public void touch(World world) { - - } - - public KList getChunksInRegion(int x, int z) { - try { - return MCAUtil.sampleChunkPositions(writer.getRegionFile(x, z)); - } catch(IOException e) { - e.printStackTrace(); - } - - return EMPTYPOINTS; - } - - @Override - public boolean isHeadless() { - return true; - } - - @Override - public void hotload() { - - } -} diff --git a/src/main/java/com/volmit/iris/engine/platform/PlatformChunkGenerator.java b/src/main/java/com/volmit/iris/engine/platform/PlatformChunkGenerator.java index c154662e0..fcedc1a3d 100644 --- a/src/main/java/com/volmit/iris/engine/platform/PlatformChunkGenerator.java +++ b/src/main/java/com/volmit/iris/engine/platform/PlatformChunkGenerator.java @@ -30,8 +30,6 @@ import java.util.function.Consumer; public interface PlatformChunkGenerator extends Hotloadable, DataProvider { Engine getEngine(); - boolean isHeadless(); - @Override default IrisData getData() { return getEngine().getData();