mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-09 17:26:22 +00:00
VANILLA STRUCTURES
This commit is contained in:
@@ -48,7 +48,7 @@ public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootPro
|
||||
|
||||
public double modifyZ(double z);
|
||||
|
||||
public void generate(int x, int z, Hunk<BlockData> blocks, Hunk<Biome> biomes);
|
||||
public void generate(int x, int z, Hunk<BlockData> blocks, Hunk<BlockData> postblocks, Hunk<Biome> biomes);
|
||||
|
||||
public EngineMetrics getMetrics();
|
||||
|
||||
|
||||
@@ -163,6 +163,81 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce
|
||||
return dim;
|
||||
}
|
||||
|
||||
private synchronized IrisDimension getDimension(String world) {
|
||||
String hint = dimensionHint;
|
||||
IrisDimension dim = null;
|
||||
|
||||
if (hint == null) {
|
||||
File iris = new File(world +"/iris");
|
||||
|
||||
if(iris.exists() && iris.isDirectory())
|
||||
{
|
||||
searching:
|
||||
for (File i : iris.listFiles()) {
|
||||
// Look for v1 location
|
||||
if (i.isDirectory() && i.getName().equals("dimensions")) {
|
||||
for (File j : i.listFiles()) {
|
||||
if (j.isFile() && j.getName().endsWith(".json")) {
|
||||
hint = j.getName().replaceAll("\\Q.json\\E", "");
|
||||
Iris.error("Found v1 install. Please create a new world, this will cause chunks to change in your existing iris worlds!");
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Look for v2 location
|
||||
else if (i.isFile() && i.getName().equals("engine-metadata.json")) {
|
||||
EngineData metadata = EngineData.load(i);
|
||||
hint = metadata.getDimension();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hint == null) {
|
||||
Iris.error("Cannot find iris dimension data for world: " + world + "! Assuming overworld!");
|
||||
hint = "overworld";
|
||||
}
|
||||
|
||||
dim = IrisDataManager.loadAnyDimension(hint);
|
||||
|
||||
if (dim == null) {
|
||||
Iris.proj.downloadSearch(new MortarSender(Bukkit.getConsoleSender(), Iris.instance.getTag()), hint, false);
|
||||
dim = IrisDataManager.loadAnyDimension(hint);
|
||||
|
||||
if(dim == null)
|
||||
{
|
||||
throw new RuntimeException("Cannot find dimension: " + hint);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Iris.info("Download pack: " + hint);
|
||||
}
|
||||
}
|
||||
|
||||
if (production) {
|
||||
IrisDimension od = dim;
|
||||
dim = new IrisDataManager(getDataFolder(world)).getDimensionLoader().load(od.getLoadKey());
|
||||
|
||||
if (dim == null) {
|
||||
Iris.info("Installing Iris pack " + od.getName() + " into world " + world + "...");
|
||||
Iris.proj.installIntoWorld(new MortarSender(Bukkit.getConsoleSender(), Iris.instance.getTag()), od.getLoadKey(), new File(world));
|
||||
dim = new IrisDataManager(getDataFolder(world)).getDimensionLoader().load(od.getLoadKey());
|
||||
|
||||
if(dim == null)
|
||||
{
|
||||
throw new RuntimeException("Cannot find dimension: " + hint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Iris.info(world + " is configured to generate " + dim.getName() + "!");
|
||||
|
||||
return dim;
|
||||
}
|
||||
|
||||
private synchronized void initialize(World world) {
|
||||
if (initialized.get()) {
|
||||
return;
|
||||
@@ -182,22 +257,28 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce
|
||||
return new File(world.getWorldFolder(), "iris/pack");
|
||||
}
|
||||
|
||||
private File getDataFolder(String world) {
|
||||
return new File(world + "/iris/pack");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ChunkData generateChunkData(@NotNull World world, @NotNull Random ignored, int x, int z, @NotNull BiomeGrid biome) {
|
||||
TerrainChunk tc = TerrainChunk.create(world, biome);
|
||||
generateChunkRawData(world, x, z, tc);
|
||||
generateChunkRawData(world, x, z, tc).run();
|
||||
return tc.getRaw();
|
||||
}
|
||||
|
||||
public void generateChunkRawData(World world, int x, int z, TerrainChunk tc)
|
||||
public Runnable generateChunkRawData(World world, int x, int z, TerrainChunk tc)
|
||||
{
|
||||
initialize(world);
|
||||
Hunk<BlockData> blocks = Hunk.view((ChunkData) tc);
|
||||
Hunk<Biome> biomes = Hunk.view((BiomeGrid) tc);
|
||||
long m = M.ms();
|
||||
compound.generate(x * 16, z * 16, blocks, biomes);
|
||||
Hunk<BlockData> post = Hunk.newAtomicHunk(biomes.getWidth(), biomes.getHeight(), biomes.getDepth());
|
||||
compound.generate(x * 16, z * 16, blocks, post, biomes);
|
||||
generated++;
|
||||
|
||||
return () -> blocks.insertSoftly(0,0,0,post, (b) -> b == null || B.isAir(b));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -451,7 +532,14 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce
|
||||
|
||||
@Override
|
||||
public boolean isClosed() {
|
||||
return getComposite().getEngine(0).isClosed();
|
||||
try
|
||||
{
|
||||
return getComposite().getEngine(0).isClosed();
|
||||
}
|
||||
catch(Throwable e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -473,4 +561,36 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce
|
||||
public boolean isStudio() {
|
||||
return !production;
|
||||
}
|
||||
|
||||
public boolean isVanillaCaves() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public KList<IrisBiome> getAllBiomes(String worldName) {
|
||||
if(getComposite() != null)
|
||||
{
|
||||
return getComposite().getAllBiomes();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
KMap<String, IrisBiome> v = new KMap<>();
|
||||
IrisDimension dim = getDimension(worldName);
|
||||
dim.getAllAnyBiomes().forEach((i) -> v.put(i.getLoadKey(), i));
|
||||
|
||||
try
|
||||
{
|
||||
dim.getDimensionalComposite().forEach((m) -> IrisDataManager.loadAnyDimension(m.getDimension()).getAllAnyBiomes().forEach((i) -> v.put(i.getLoadKey(), i)));
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Iris.info("Injecting " + v.size() + " biomes into the NMS World Chunk Provider (Iris)");
|
||||
|
||||
return v.v();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.volmit.iris.scaffold.engine;
|
||||
|
||||
import com.volmit.iris.manager.IrisDataManager;
|
||||
import com.volmit.iris.object.IrisBiome;
|
||||
import com.volmit.iris.object.IrisDimension;
|
||||
import com.volmit.iris.scaffold.data.DataProvider;
|
||||
import com.volmit.iris.scaffold.hunk.Hunk;
|
||||
import com.volmit.iris.scaffold.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.KList;
|
||||
import com.volmit.iris.util.KMap;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@@ -12,11 +15,11 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
|
||||
public interface EngineCompound extends Listener, Hotloadable
|
||||
public interface EngineCompound extends Listener, Hotloadable, DataProvider
|
||||
{
|
||||
public IrisDimension getRootDimension();
|
||||
|
||||
public void generate(int x, int z, Hunk<BlockData> blocks, Hunk<Biome> biomes);
|
||||
public void generate(int x, int z, Hunk<BlockData> blocks, Hunk<BlockData> postblocks, Hunk<Biome> biomes);
|
||||
|
||||
public World getWorld();
|
||||
|
||||
@@ -105,4 +108,26 @@ public interface EngineCompound extends Listener, Hotloadable
|
||||
getEngine(i).clean();
|
||||
}
|
||||
}
|
||||
|
||||
public Engine getDefaultEngine();
|
||||
|
||||
public default KList<IrisBiome> getAllBiomes()
|
||||
{
|
||||
KMap<String, IrisBiome> v = new KMap<>();
|
||||
|
||||
IrisDimension dim = getRootDimension();
|
||||
dim.getAllBiomes(this).forEach((i) -> v.put(i.getLoadKey(), i));
|
||||
|
||||
try
|
||||
{
|
||||
dim.getDimensionalComposite().forEach((m) -> getData().getDimensionLoader().load(m.getDimension()).getAllBiomes(this).forEach((i) -> v.put(i.getLoadKey(), i)));
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return v.v();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,11 @@ public interface Hunk<T>
|
||||
return new BiomeGridHunkView(biome);
|
||||
}
|
||||
|
||||
public static <T> Hunk<T> fringe(Hunk<T> i, Hunk<T> o)
|
||||
{
|
||||
return new FringedHunkView<>(i, o);
|
||||
}
|
||||
|
||||
public static Hunk<BlockData> view(ChunkData src)
|
||||
{
|
||||
return new ChunkDataHunkView(src);
|
||||
@@ -1309,6 +1314,11 @@ public interface Hunk<T>
|
||||
insert(offX, offY, offZ, hunk, false);
|
||||
}
|
||||
|
||||
default void insertSoftly(int offX, int offY, int offZ, Hunk<T> hunk, Predicate<T> shouldOverwrite)
|
||||
{
|
||||
insertSoftly(offX, offY, offZ, hunk, false, shouldOverwrite);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a hunk into this one
|
||||
*
|
||||
@@ -1348,7 +1358,7 @@ public interface Hunk<T>
|
||||
/**
|
||||
* Insert a hunk into this one with an offset and possibly inverting the y of
|
||||
* the inserted hunk
|
||||
*
|
||||
*
|
||||
* @param offX
|
||||
* the offset from zero for x
|
||||
* @param offY
|
||||
@@ -1375,4 +1385,38 @@ public interface Hunk<T>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a hunk into this one with an offset and possibly inverting the y of. Will never insert a node if its already used
|
||||
* the inserted hunk
|
||||
*
|
||||
* @param offX
|
||||
* the offset from zero for x
|
||||
* @param offY
|
||||
* the offset from zero for y
|
||||
* @param offZ
|
||||
* the offset from zero for z
|
||||
* @param hunk
|
||||
* the hunk to insert
|
||||
* @param invertY
|
||||
* should the inserted hunk be inverted
|
||||
*/
|
||||
default void insertSoftly(int offX, int offY, int offZ, Hunk<T> hunk, boolean invertY, Predicate<T> shouldOverwrite)
|
||||
{
|
||||
enforceBounds(offX, offY, offZ, hunk.getWidth(), hunk.getHeight(), hunk.getDepth());
|
||||
|
||||
for(int i = offX; i < offX + hunk.getWidth(); i++)
|
||||
{
|
||||
for(int j = offY; j < offY + hunk.getHeight(); j++)
|
||||
{
|
||||
for(int k = offZ; k < offZ + hunk.getDepth(); k++)
|
||||
{
|
||||
if(shouldOverwrite.test(getRaw(i, j, k)))
|
||||
{
|
||||
setRaw(i, j, k, hunk.getRaw(i - offX, j - offY, k - offZ));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.volmit.iris.scaffold.hunk.view;
|
||||
|
||||
import com.volmit.iris.scaffold.hunk.Hunk;
|
||||
|
||||
public class FringedHunkView<T> implements Hunk<T> {
|
||||
private final Hunk<T> src;
|
||||
private final Hunk<T> out;
|
||||
|
||||
public FringedHunkView(Hunk<T> src, Hunk<T> out)
|
||||
{
|
||||
this.src = src;
|
||||
this.out = out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t)
|
||||
{
|
||||
out.setRaw(x,y,z,t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getRaw(int x, int y, int z)
|
||||
{
|
||||
return src.getRaw(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth()
|
||||
{
|
||||
return src.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight()
|
||||
{
|
||||
return src.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDepth()
|
||||
{
|
||||
return src.getDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hunk<T> getSource()
|
||||
{
|
||||
return src;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user