mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Fix world create commands & pregnes
This commit is contained in:
parent
9453b86907
commit
bd8d9cc3aa
@ -21,10 +21,12 @@ package com.volmit.iris.core.command.world;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||
import com.volmit.iris.core.tools.IrisWorldCreator;
|
||||
import com.volmit.iris.engine.object.dimensional.IrisDimension;
|
||||
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.exceptions.IrisException;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.plugin.MortarCommand;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
@ -89,7 +91,6 @@ public class CommandIrisCreate extends MortarCommand {
|
||||
|
||||
@Override
|
||||
public boolean handle(VolmitSender sender, String[] args) {
|
||||
|
||||
String worldName;
|
||||
File folder;
|
||||
String dimensionName;
|
||||
@ -124,21 +125,25 @@ public class CommandIrisCreate extends MortarCommand {
|
||||
seed = i.startsWith("seed=") ? Long.parseLong(i.split("\\Q=\\E")[1]) : seed;
|
||||
}
|
||||
|
||||
dimension = Iris.proj.installIntoWorld(sender, dimensionName, folder);
|
||||
String finalDimensionName = dimensionName;
|
||||
|
||||
if (dimension == null) {
|
||||
sender.sendMessage("Cannot find dimension '" + dimensionName + "'. Did you forget to /iris download " + dimensionName + "?");
|
||||
return true;
|
||||
|
||||
|
||||
long finalSeed = seed;
|
||||
J.a(() -> {
|
||||
try {
|
||||
IrisToolbelt.createWorld()
|
||||
.dimension(finalDimensionName)
|
||||
.name(worldName)
|
||||
.seed(finalSeed)
|
||||
.sender(sender)
|
||||
.studio(false)
|
||||
.create();
|
||||
} catch (IrisException e) {
|
||||
e.printStackTrace();
|
||||
sender.sendMessage("Creation Failed! Check Console.");
|
||||
}
|
||||
|
||||
if (dimension.getEnvironment() == null) {
|
||||
dimension.setEnvironment(World.Environment.NORMAL);
|
||||
}
|
||||
|
||||
File iris = new File(folder, "iris");
|
||||
iris.mkdirs();
|
||||
|
||||
onDone(sender, createWorld(sender, worldName, dimension, seed));
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -146,147 +151,4 @@ public class CommandIrisCreate extends MortarCommand {
|
||||
protected String getArgsUsage() {
|
||||
return "<name> [type=<type>] [seed=<seed>]";
|
||||
}
|
||||
|
||||
/**
|
||||
* Ran when world is created
|
||||
*
|
||||
* @param sender The sender to send updates to
|
||||
* @param world The created world
|
||||
*/
|
||||
private void onDone(VolmitSender sender, World world) {
|
||||
sender.sendMessage(world.getName() + " Spawn Area generated.");
|
||||
sender.sendMessage("You must remember to either have multiverse installed or use the Bukkit method to load this world with the Iris Generator on startup.");
|
||||
sender.sendMessage("Wiki: https://volmitsoftware.gitbook.io/iris/getting-started");
|
||||
|
||||
if (sender.isPlayer()) {
|
||||
try {
|
||||
sender.player().teleport(world.getSpawnLocation());
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
}
|
||||
}
|
||||
|
||||
O<Boolean> b = new O<>();
|
||||
b.set(true);
|
||||
|
||||
J.a(() ->
|
||||
{
|
||||
while (!b.get()) {
|
||||
J.sleep(1000);
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () ->
|
||||
{
|
||||
world.save();
|
||||
sender.sendMessage("All Done!");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a world with either Multiverse (preferred, if supported) or NMS
|
||||
*
|
||||
* @param sender The sender to send updates to
|
||||
* @param worldName The name of the world to create
|
||||
* @param dimension The dimension to create the world with
|
||||
* @param seed The seed to use to generate
|
||||
* @return The created world
|
||||
*/
|
||||
private World createWorld(VolmitSender sender, String worldName, IrisDimension dimension, long seed) {
|
||||
if (Iris.linkMultiverseCore.isSupported()) {
|
||||
return createMultiverseWorld(sender, worldName, dimension, seed);
|
||||
} else {
|
||||
return createNMSWorld(sender, worldName, dimension, seed);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a world with Multiverse
|
||||
*
|
||||
* @param sender The sender to send updates to
|
||||
* @param worldName The name of the world to create
|
||||
* @param dimension The dimension to create the world with
|
||||
* @param seed The seed to use to generate
|
||||
* @return The created world
|
||||
*/
|
||||
public World createMultiverseWorld(VolmitSender sender, String worldName, IrisDimension dimension, long seed) {
|
||||
|
||||
if (!Iris.linkMultiverseCore.isSupported()) {
|
||||
sender.sendMessage("A world was attempted to be created with Multiverse but it is not supported!");
|
||||
return null;
|
||||
}
|
||||
|
||||
Iris.linkMultiverseCore.assignWorldType(worldName, dimension.getName());
|
||||
|
||||
StringBuilder command = new StringBuilder("mv create")
|
||||
.append(worldName)
|
||||
.append(" ")
|
||||
.append(Iris.linkMultiverseCore.envName(dimension.getEnvironment()))
|
||||
.append(" -s ")
|
||||
.append(seed)
|
||||
.append(" -g Iris:")
|
||||
.append(dimension.getLoadKey());
|
||||
|
||||
sender.sendMessage("Delegating " + command);
|
||||
Bukkit.dispatchCommand(sender, command.toString());
|
||||
return Bukkit.getWorld(worldName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a world using NMS
|
||||
*
|
||||
* @param sender The sender to send updates to
|
||||
* @param worldName The name of the world to create
|
||||
* @param dimension The dimension to create the world with
|
||||
* @param seed The seed to use to generate
|
||||
* @return The created world
|
||||
*/
|
||||
public World createNMSWorld(VolmitSender sender, String worldName, IrisDimension dimension, long seed) {
|
||||
|
||||
WorldCreator wc = new IrisWorldCreator()
|
||||
.dimension(dimension.getLoadKey())
|
||||
.name(worldName)
|
||||
.seed(seed)
|
||||
.productionMode()
|
||||
.create();
|
||||
PlatformChunkGenerator gen = (PlatformChunkGenerator) wc.generator();
|
||||
|
||||
if (gen == null) {
|
||||
sender.sendMessage("Failed to create generator! Gen is null!");
|
||||
return null;
|
||||
}
|
||||
|
||||
AtomicReference<World> world = new AtomicReference<>();
|
||||
|
||||
J.s(() -> {
|
||||
O<Boolean> done = new O<>();
|
||||
done.set(false);
|
||||
|
||||
J.a(() ->
|
||||
{
|
||||
double last = 0;
|
||||
int req = 800;
|
||||
while (!done.get()) {
|
||||
|
||||
boolean shouldBeDone = false;
|
||||
double v = (double) gen.getEngine().getGenerated() / req;
|
||||
|
||||
if (last > v || v > 1) {
|
||||
shouldBeDone = true;
|
||||
v = last;
|
||||
} else {
|
||||
last = v;
|
||||
}
|
||||
|
||||
sender.sendMessage("Generating " + Form.pc(v) + (shouldBeDone ? " (Waiting on Server...)" : ""));
|
||||
J.sleep(3000);
|
||||
}
|
||||
});
|
||||
|
||||
world.set(INMS.get().createWorld(wc));
|
||||
done.set(true);
|
||||
});
|
||||
|
||||
return world.get();
|
||||
}
|
||||
}
|
||||
|
@ -169,67 +169,13 @@ public class IrisProject {
|
||||
}
|
||||
});
|
||||
|
||||
String wfp = "iris/" + UUID.randomUUID();
|
||||
|
||||
WorldCreator c = new IrisWorldCreator().dimension(getName())
|
||||
J.a(() -> IrisToolbelt.createWorld()
|
||||
.seed(1337)
|
||||
.name(wfp)
|
||||
.studioMode()
|
||||
.create();
|
||||
|
||||
PlatformChunkGenerator gx = ((PlatformChunkGenerator) c.generator());
|
||||
O<Boolean> done = new O<>();
|
||||
done.set(false);
|
||||
activeProvider = gx;
|
||||
|
||||
J.a(() ->
|
||||
{
|
||||
double last = 0;
|
||||
int req = 400;
|
||||
|
||||
while (gx.getEngine().getGenerated() < req) {
|
||||
assert gx != null;
|
||||
double v = (double) gx.getEngine().getGenerated() / (double) req;
|
||||
|
||||
if (sender.isPlayer()) {
|
||||
sender.sendProgress(v, "Generating");
|
||||
J.sleep(16);
|
||||
} else {
|
||||
sender.sendProgress(v, "Generating");
|
||||
J.sleep(16);
|
||||
}
|
||||
}
|
||||
if (sender.isPlayer()) {
|
||||
sender.player().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(C.WHITE + "Generation Complete"));
|
||||
}
|
||||
});
|
||||
|
||||
//@builder
|
||||
World world = INMS.get().createWorld(c);
|
||||
if (IrisSettings.get().getStudio().isDisableTimeAndWeather()) {
|
||||
world.setGameRule(GameRule.DO_WEATHER_CYCLE, false);
|
||||
world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
|
||||
world.setTime(6000);
|
||||
}
|
||||
Iris.linkMultiverseCore.removeFromConfig(world);
|
||||
|
||||
done.set(true);
|
||||
|
||||
if (sender.isPlayer()) {
|
||||
assert world != null;
|
||||
sender.player().teleport(world.getSpawnLocation());
|
||||
} else {
|
||||
sender.sendAction(C.IRIS + "Generation Complete");
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () ->
|
||||
{
|
||||
if (sender.isPlayer()) {
|
||||
sender.player().setGameMode(GameMode.SPECTATOR);
|
||||
}
|
||||
|
||||
onDone.run();
|
||||
}, 0);
|
||||
.sender(sender)
|
||||
.studio(true)
|
||||
.name("iris/" + UUID.randomUUID())
|
||||
.dimension(d.getLoadKey())
|
||||
.create());
|
||||
}
|
||||
|
||||
public void close() {
|
||||
|
@ -18,8 +18,11 @@
|
||||
|
||||
package com.volmit.iris.core.tools;
|
||||
|
||||
import com.google.common.util.concurrent.AtomicDouble;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.pregenerator.PregenTask;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.object.common.HeadlessWorld;
|
||||
import com.volmit.iris.engine.object.dimensional.IrisDimension;
|
||||
import com.volmit.iris.engine.platform.HeadlessGenerator;
|
||||
@ -36,9 +39,12 @@ import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
@ -73,13 +79,6 @@ public class IrisCreator {
|
||||
*/
|
||||
private String name = "irisworld";
|
||||
|
||||
/**
|
||||
* Headless mode allows Iris to generate / query engine information
|
||||
* without needing an actual world loaded. This is normally only used
|
||||
* for pregeneration purposes but it could be used for mapping.
|
||||
*/
|
||||
private boolean headless = false;
|
||||
|
||||
/**
|
||||
* Studio mode makes the engine hotloadable and uses the dimension in
|
||||
* your Iris/packs folder instead of copying the dimension files into
|
||||
@ -93,33 +92,27 @@ public class IrisCreator {
|
||||
* @return the IrisAccess
|
||||
* @throws IrisException shit happens
|
||||
*/
|
||||
public PlatformChunkGenerator create() throws IrisException {
|
||||
public World create() throws IrisException {
|
||||
if(Bukkit.isPrimaryThread())
|
||||
{
|
||||
throw new IrisException("You cannot invoke create() on the main thread.");
|
||||
}
|
||||
|
||||
IrisDimension d = IrisToolbelt.getDimension(dimension());
|
||||
|
||||
if(d == null)
|
||||
{
|
||||
throw new IrisException("Dimension cannot be found null for id " + dimension());
|
||||
}
|
||||
|
||||
if(!studio())
|
||||
{
|
||||
Iris.proj.installIntoWorld(sender, d.getLoadKey(), new File(name()));
|
||||
}
|
||||
|
||||
PlatformChunkGenerator access = null;
|
||||
Consumer<Double> prog = (pxx) -> {
|
||||
double px = pxx;
|
||||
|
||||
if (pregen != null && !headless) {
|
||||
px = (px / 2) + 0.5;
|
||||
}
|
||||
|
||||
if (sender != null) {
|
||||
if (sender.isPlayer()) {
|
||||
sender.player().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(C.WHITE + "Generating " + Form.pc(px)));
|
||||
} else {
|
||||
sender.sendMessage("Generating " + Form.f(px, 0));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (d == null) {
|
||||
throw new MissingDimensionException("Cannot find dimension '" + dimension() + "'");
|
||||
}
|
||||
|
||||
if (headless) {
|
||||
HeadlessWorld w = new HeadlessWorld(name, d, seed, studio);
|
||||
access = w.generate();
|
||||
} else {
|
||||
AtomicReference<World> world = new AtomicReference<>();
|
||||
AtomicDouble pp = new AtomicDouble(0);
|
||||
O<Boolean> done = new O<>();
|
||||
done.set(false);
|
||||
WorldCreator wc = new IrisWorldCreator()
|
||||
@ -128,94 +121,92 @@ public class IrisCreator {
|
||||
.seed(seed)
|
||||
.studio(studio)
|
||||
.create();
|
||||
|
||||
access = (PlatformChunkGenerator) wc.generator();
|
||||
PlatformChunkGenerator finalAccess1 = access;
|
||||
|
||||
J.a(() ->
|
||||
{
|
||||
int req = 400;
|
||||
int req = 441;
|
||||
|
||||
while (finalAccess1.getEngine().getGenerated() < req && !done.get()) {
|
||||
while (finalAccess1.getEngine().getGenerated() < req) {
|
||||
double v = (double) finalAccess1.getEngine().getGenerated() / (double) req;
|
||||
|
||||
if (pregen != null) {
|
||||
v /= 2;
|
||||
}
|
||||
|
||||
if (sender.isPlayer()) {
|
||||
sender.player().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(C.WHITE + "Generating " + Form.pc(v) + ((C.GRAY + " (" + (req - finalAccess1.getEngine().getGenerated()) + " Left)"))));
|
||||
J.sleep(50);
|
||||
sender.sendProgress(v, "Generating");
|
||||
J.sleep(16);
|
||||
} else {
|
||||
sender.sendMessage(C.WHITE + "Generating " + Form.pc(v) + ((C.GRAY + " (" + (req - finalAccess1.getEngine().getGenerated()) + " Left)")));
|
||||
J.sleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
sender.player().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(C.WHITE + "Generation Complete"));
|
||||
});
|
||||
|
||||
|
||||
try {
|
||||
J.sfut(wc::createWorld).get();
|
||||
J.sfut(() -> {
|
||||
world.set(wc.createWorld());
|
||||
}).get();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (access == null) {
|
||||
throw new IrisException("Access is null. Something bad happened.");
|
||||
}
|
||||
|
||||
CompletableFuture<Boolean> ff = new CompletableFuture<>();
|
||||
done.set(true);
|
||||
|
||||
if(sender.isPlayer())
|
||||
{
|
||||
J.s(() -> {
|
||||
sender.player().teleport(new Location(world.get(), 0, world.get().getHighestBlockYAt(0, 0), 0));
|
||||
});
|
||||
}
|
||||
|
||||
if(studio)
|
||||
{
|
||||
J.s(() -> {
|
||||
Iris.linkMultiverseCore.removeFromConfig(world.get());
|
||||
|
||||
if (IrisSettings.get().getStudio().isDisableTimeAndWeather()) {
|
||||
world.get().setGameRule(GameRule.DO_WEATHER_CYCLE, false);
|
||||
world.get().setGameRule(GameRule.DO_DAYLIGHT_CYCLE, false);
|
||||
world.get().setTime(6000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (pregen != null) {
|
||||
CompletableFuture<Boolean> ff = new CompletableFuture<>();
|
||||
|
||||
IrisToolbelt.pregenerate(pregen, access)
|
||||
.onProgress(prog)
|
||||
.onProgress(pp::set)
|
||||
.whenDone(() -> ff.complete(true));
|
||||
|
||||
try {
|
||||
ff.get();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
AtomicBoolean dx = new AtomicBoolean(false);
|
||||
|
||||
try {
|
||||
|
||||
PlatformChunkGenerator finalAccess = access;
|
||||
J.sfut(() -> {
|
||||
if (headless) {
|
||||
O<Boolean> done = new O<>();
|
||||
done.set(false);
|
||||
|
||||
J.a(() ->
|
||||
J.a(() -> {
|
||||
while(!dx.get())
|
||||
{
|
||||
int req = 400;
|
||||
|
||||
while (finalAccess.getEngine().getGenerated() < req && !done.get()) {
|
||||
double v = (double) finalAccess.getEngine().getGenerated() / (double) req;
|
||||
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.getEngine().getGenerated()) + " Left)"))));
|
||||
J.sleep(50);
|
||||
sender.sendProgress(pp.get(), "Pregenerating");
|
||||
J.sleep(16);
|
||||
} else {
|
||||
sender.sendMessage(C.WHITE + "Generating " + Form.pc(v) + ((C.GRAY + " (" + (req - finalAccess.getEngine().getGenerated()) + " Left)")));
|
||||
sender.sendMessage(C.WHITE + "Pregenerating " + Form.pc(pp.get()));
|
||||
J.sleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
sender.player().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(C.WHITE + "Generation Complete"));
|
||||
});
|
||||
|
||||
((HeadlessGenerator) finalAccess).getWorld().load();
|
||||
done.set(true);
|
||||
}
|
||||
}).get();
|
||||
|
||||
ff.get();
|
||||
dx.set(true);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return access;
|
||||
return world.get();
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,12 @@ public class EngineProvider {
|
||||
engine.set(MultiBurst.burst.completeValue(() -> {
|
||||
IrisData data = new IrisData(dataLocation);
|
||||
IrisDimension realDimension = data.getDimensionLoader().load(dimension);
|
||||
|
||||
if(realDimension == null)
|
||||
{
|
||||
throw new RuntimeException("Cannot find dimension in " + data.getDataFolder().getAbsolutePath() + " with key " + dimension);
|
||||
}
|
||||
|
||||
EngineTarget target = new EngineTarget(world, realDimension, data);
|
||||
Engine engine = new IrisEngine(target, studio);
|
||||
post.accept(engine);
|
||||
|
Loading…
x
Reference in New Issue
Block a user