This commit is contained in:
Daniel Mills 2020-10-06 16:54:36 -04:00
parent 4f7d659700
commit 843b5d7154
8 changed files with 206 additions and 116 deletions

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>bytecode.ninja</groupId> <groupId>bytecode.ninja</groupId>
<artifactId>Iris</artifactId> <artifactId>Iris</artifactId>
<version>1.0.3</version> <version>1.0.5</version>
<name>Iris</name> <name>Iris</name>
<properties> <properties>
<skip.copy>false</skip.copy> <skip.copy>false</skip.copy>

View File

@ -7,6 +7,7 @@ import com.google.gson.Gson;
import com.volmit.iris.util.Desc; import com.volmit.iris.util.Desc;
import com.volmit.iris.util.DontObfuscate; import com.volmit.iris.util.DontObfuscate;
import com.volmit.iris.util.IO; import com.volmit.iris.util.IO;
import com.volmit.iris.util.J;
import com.volmit.iris.util.JSONException; import com.volmit.iris.util.JSONException;
import com.volmit.iris.util.JSONObject; import com.volmit.iris.util.JSONObject;
@ -21,6 +22,10 @@ public class IrisSettings
@Desc("Iris generator threads (must be 2 or higher). Threads in iris are not a perfect scale for performance as a lot of data has to be shared. 16 Threads is a good rule of thumb. Use 8 threads on a quad core processor.") @Desc("Iris generator threads (must be 2 or higher). Threads in iris are not a perfect scale for performance as a lot of data has to be shared. 16 Threads is a good rule of thumb. Use 8 threads on a quad core processor.")
public int threads = 16; public int threads = 16;
@DontObfuscate
@Desc("The default world type incase iris doesnt have a dimension to use.")
public String defaultWorldType = "overworld";
@DontObfuscate @DontObfuscate
@Desc("Iris uses a lot of caching to speed up chunk generation. Setting this higher uses more memory, but may improve performance. Anything past 8,000 should be avoided because there is little benefit past this value.") @Desc("Iris uses a lot of caching to speed up chunk generation. Setting this higher uses more memory, but may improve performance. Anything past 8,000 should be avoided because there is little benefit past this value.")
public int atomicCacheSize = 3000; public int atomicCacheSize = 3000;
@ -65,12 +70,18 @@ public class IrisSettings
@Desc("Collects anonymous metrics for bstats") @Desc("Collects anonymous metrics for bstats")
public boolean metrics = true; public boolean metrics = true;
@DontObfuscate
@Desc("Skips preparing spawn by using nms to hijack the world init phase")
public boolean skipPrepareSpawnNMS = true;
@DontObfuscate @DontObfuscate
@Desc("Used to activate Iris") @Desc("Used to activate Iris")
public String activationCode = ""; public String activationCode = "";
public static IrisSettings get() public static IrisSettings get()
{ {
IrisSettings defaults = new IrisSettings();
JSONObject def = new JSONObject(new Gson().toJson(defaults));
if(settings == null) if(settings == null)
{ {
settings = new IrisSettings(); settings = new IrisSettings();
@ -94,7 +105,37 @@ public class IrisSettings
{ {
try try
{ {
settings = new Gson().fromJson(IO.readAll(s), IrisSettings.class); String ss = IO.readAll(s);
settings = new Gson().fromJson(ss, IrisSettings.class);
J.a(() ->
{
JSONObject j = new JSONObject(ss);
boolean u = false;
for(String i : def.keySet())
{
if(!j.has(i))
{
u = true;
j.put(i, def.get(i));
Iris.verbose("Adding new config key: " + i);
}
}
if(u)
{
try
{
IO.writeAll(s, j.toString(4));
Iris.info("Updated Configuration Files");
}
catch(Throwable e)
{
}
}
});
} }
catch(JSONException | IOException e) catch(JSONException | IOException e)

View File

@ -1,14 +1,11 @@
package com.volmit.iris.command; package com.volmit.iris.command;
import java.io.File; import java.io.File;
import java.io.IOException;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.WorldCreator; import org.bukkit.WorldCreator;
import org.bukkit.WorldType; import org.bukkit.WorldType;
import org.zeroturnaround.zip.ZipUtil;
import org.zeroturnaround.zip.commons.FileUtils;
import com.volmit.iris.Iris; import com.volmit.iris.Iris;
import com.volmit.iris.IrisSettings; import com.volmit.iris.IrisSettings;
@ -17,11 +14,8 @@ import com.volmit.iris.gen.nms.NMSCreator;
import com.volmit.iris.gen.provisions.ProvisionBukkit; import com.volmit.iris.gen.provisions.ProvisionBukkit;
import com.volmit.iris.gen.scaffold.IrisGenConfiguration; import com.volmit.iris.gen.scaffold.IrisGenConfiguration;
import com.volmit.iris.gen.scaffold.TerrainTarget; import com.volmit.iris.gen.scaffold.TerrainTarget;
import com.volmit.iris.manager.IrisDataManager;
import com.volmit.iris.manager.ProjectManager;
import com.volmit.iris.object.IrisDimension; import com.volmit.iris.object.IrisDimension;
import com.volmit.iris.util.Form; import com.volmit.iris.util.Form;
import com.volmit.iris.util.IO;
import com.volmit.iris.util.J; import com.volmit.iris.util.J;
import com.volmit.iris.util.MortarCommand; import com.volmit.iris.util.MortarCommand;
import com.volmit.iris.util.MortarSender; import com.volmit.iris.util.MortarSender;
@ -63,86 +57,8 @@ public class CommandIrisCreate extends MortarCommand
pregen = i.startsWith("pregen=") ? Integer.parseInt(i.split("\\Q=\\E")[1]) : pregen; pregen = i.startsWith("pregen=") ? Integer.parseInt(i.split("\\Q=\\E")[1]) : pregen;
} }
sender.sendMessage("Looking for Package: " + type); IrisDimension dim = Iris.proj.installIntoWorld(sender, type, folder);
IrisDimension dim = Iris.globaldata.getDimensionLoader().load(type);
if(dim == null)
{
for(File i : Iris.proj.getWorkspaceFolder().listFiles())
{
if(i.isFile() && i.getName().equals(type + ".iris"))
{
sender.sendMessage("Found " + type + ".iris in " + ProjectManager.workspaceName + " folder");
ZipUtil.unpack(i, iris);
break;
}
}
}
else
{
sender.sendMessage("Foind " + type + " dimension in " + ProjectManager.workspaceName + " folder. Repackaging");
ZipUtil.unpack(Iris.proj.compilePackage(sender, type, true, true), iris);
}
File dimf = new File(iris, "dimensions/" + type + ".json");
if(!dimf.exists() || !dimf.isFile())
{
Iris.globaldata.dump();
Iris.globaldata.preferFolder(null);
Iris.proj.downloadSearch(sender, type, false);
File downloaded = Iris.proj.getWorkspaceFolder(type);
for(File i : downloaded.listFiles())
{
if(i.isFile())
{
try
{
FileUtils.copyFile(i, new File(iris, i.getName()));
}
catch(IOException e)
{
e.printStackTrace();
}
}
else
{
try
{
FileUtils.copyDirectory(i, new File(iris, i.getName()));
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
IO.delete(downloaded);
}
if(!dimf.exists() || !dimf.isFile())
{
sender.sendMessage("Can't find the " + dimf.getName() + " in the dimensions folder of this pack! Failed!");
return true;
}
IrisDataManager dm = new IrisDataManager(folder);
dim = dm.getDimensionLoader().load(type);
if(dim == null)
{
sender.sendMessage("Can't load the dimension! Failed!");
return true;
}
sender.sendMessage(worldName + " type installed. Generating Spawn Area...");
//@builder //@builder
ProvisionBukkit gen = Iris.instance.createProvisionBukkit( ProvisionBukkit gen = Iris.instance.createProvisionBukkit(
IrisGenConfiguration.builder() IrisGenConfiguration.builder()
@ -191,7 +107,6 @@ public class CommandIrisCreate extends MortarCommand
World world = NMSCreator.createWorld(wc, false); World world = NMSCreator.createWorld(wc, false);
done.set(true); done.set(true);
sender.sendMessage(worldName + " Spawn Area generated."); sender.sendMessage(worldName + " Spawn Area generated.");

View File

@ -2,17 +2,20 @@ package com.volmit.iris.gen;
import java.io.File; import java.io.File;
import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.volmit.iris.Iris; import com.volmit.iris.Iris;
import com.volmit.iris.IrisSettings;
import com.volmit.iris.gen.scaffold.TerrainTarget; import com.volmit.iris.gen.scaffold.TerrainTarget;
import com.volmit.iris.object.InferredType; import com.volmit.iris.object.InferredType;
import com.volmit.iris.object.IrisBiome; import com.volmit.iris.object.IrisBiome;
import com.volmit.iris.object.IrisDimension; import com.volmit.iris.object.IrisDimension;
import com.volmit.iris.object.IrisRegion; import com.volmit.iris.object.IrisRegion;
import com.volmit.iris.util.B; import com.volmit.iris.util.B;
import com.volmit.iris.util.MortarSender;
import com.volmit.iris.util.RNG; import com.volmit.iris.util.RNG;
import lombok.Data; import lombok.Data;
@ -40,7 +43,23 @@ public abstract class DimensionalTerrainProvider extends ContextualTerrainProvid
if(!folder.exists()) if(!folder.exists())
{ {
Iris.error("Missing World iris/dimensions folder! (" + folder.getAbsolutePath() + ")"); Iris.error("Missing World iris/dimensions folder! (" + folder.getAbsolutePath() + ")");
setDimensionName("error-missing-dimension"); setDimensionName(IrisSettings.get().getDefaultWorldType());
Iris.proj.installIntoWorld(new MortarSender(Bukkit.getConsoleSender()), getDimensionName(), getTarget().getFolder());
return;
}
if(!folder.exists())
{
Iris.error("Missing World iris/dimensions folder! (" + folder.getAbsolutePath() + ")");
try
{
throw new RuntimeException("Cant find dimension data!");
}
catch(Throwable e)
{
fail(e);
}
return; return;
} }
@ -53,9 +72,20 @@ public abstract class DimensionalTerrainProvider extends ContextualTerrainProvid
} }
} }
Iris.error("Missing World iris/dimensions/<dimension-name>.json file. Assuming overworld!"); if(!folder.exists())
setDimensionName("error-missing-dimension"); {
fail(new RuntimeException("Missing dimension folder/file in " + folder.getAbsolutePath())); Iris.error("Missing World iris/dimensions folder! (" + folder.getAbsolutePath() + ")");
try
{
throw new RuntimeException("Cant find dimension data!");
}
catch(Throwable e)
{
fail(e);
}
return;
}
} }
try try
@ -69,6 +99,11 @@ public abstract class DimensionalTerrainProvider extends ContextualTerrainProvid
} }
} }
protected void useDefaultDimensionSetupNOW()
{
}
public void onPlayerLeft(Player p) public void onPlayerLeft(Player p)
{ {

View File

@ -542,12 +542,22 @@ public class IrisTerrainProvider extends SkyTerrainProvider implements IrisConte
@Override @Override
public boolean shouldGenerateCaves() public boolean shouldGenerateCaves()
{ {
if(getDimension() == null)
{
return false;
}
return getDimension().isVanillaCaves(); return getDimension().isVanillaCaves();
} }
@Override @Override
public boolean shouldGenerateVanillaStructures() public boolean shouldGenerateVanillaStructures()
{ {
if(getDimension() == null)
{
return false;
}
return getDimension().isVanillaStructures(); return getDimension().isVanillaStructures();
} }

View File

@ -5,6 +5,7 @@ import org.bukkit.World;
import org.bukkit.WorldCreator; import org.bukkit.WorldCreator;
import com.volmit.iris.Iris; import com.volmit.iris.Iris;
import com.volmit.iris.IrisSettings;
public class NMSCreator public class NMSCreator
{ {
@ -14,6 +15,8 @@ public class NMSCreator
} }
public static World createWorld(WorldCreator creator, boolean loadSpawn) public static World createWorld(WorldCreator creator, boolean loadSpawn)
{
if(IrisSettings.get().isSkipPrepareSpawnNMS())
{ {
try try
{ {
@ -41,6 +44,7 @@ public class NMSCreator
{ {
} }
}
return Bukkit.createWorld(creator); return Bukkit.createWorld(creator);
} }

View File

@ -66,6 +66,91 @@ public class ProjectManager
} }
} }
public IrisDimension installIntoWorld(MortarSender sender, String type, File folder)
{
sender.sendMessage("Looking for Package: " + type);
File iris = new File(folder, "iris");
IrisDimension dim = Iris.globaldata.getDimensionLoader().load(type);
if(dim == null)
{
for(File i : Iris.proj.getWorkspaceFolder().listFiles())
{
if(i.isFile() && i.getName().equals(type + ".iris"))
{
sender.sendMessage("Found " + type + ".iris in " + ProjectManager.workspaceName + " folder");
ZipUtil.unpack(i, iris);
break;
}
}
}
else
{
sender.sendMessage("Found " + type + " dimension in " + ProjectManager.workspaceName + " folder. Repackaging");
ZipUtil.unpack(Iris.proj.compilePackage(sender, type, true, true), iris);
}
File dimf = new File(iris, "dimensions/" + type + ".json");
if(!dimf.exists() || !dimf.isFile())
{
Iris.globaldata.dump();
Iris.globaldata.preferFolder(null);
Iris.proj.downloadSearch(sender, type, false);
File downloaded = Iris.proj.getWorkspaceFolder(type);
for(File i : downloaded.listFiles())
{
if(i.isFile())
{
try
{
FileUtils.copyFile(i, new File(iris, i.getName()));
}
catch(IOException e)
{
e.printStackTrace();
}
}
else
{
try
{
FileUtils.copyDirectory(i, new File(iris, i.getName()));
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
IO.delete(downloaded);
}
if(!dimf.exists() || !dimf.isFile())
{
sender.sendMessage("Can't find the " + dimf.getName() + " in the dimensions folder of this pack! Failed!");
return null;
}
IrisDataManager dm = new IrisDataManager(folder);
dim = dm.getDimensionLoader().load(type);
if(dim == null)
{
sender.sendMessage("Can't load the dimension! Failed!");
return null;
}
sender.sendMessage(folder.getName() + " type installed. ");
return dim;
}
public void downloadSearch(MortarSender sender, String key, boolean trim) public void downloadSearch(MortarSender sender, String key, boolean trim)
{ {
String repo = getListing(false).get(key); String repo = getListing(false).get(key);

View File

@ -182,7 +182,7 @@ public class PregenJob implements Listener
{ {
chunkSpiraler.next(); chunkSpiraler.next();
if(isChunkWithin(chunkX, chunkZ)) if(isChunkWithin(chunkX, chunkZ) && consumer != null)
{ {
consumer.accept(new ChunkPosition(chunkX, chunkZ), Color.BLUE.darker().darker()); consumer.accept(new ChunkPosition(chunkX, chunkZ), Color.BLUE.darker().darker());
} }