This commit is contained in:
Daniel Mills 2020-10-21 10:03:15 -04:00
parent 0a0617c5fc
commit ccdb136b9a
17 changed files with 807 additions and 26 deletions

View File

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

View File

@ -89,7 +89,7 @@ public abstract class ContextualTerrainProvider implements TerrainProvider, List
tickLatch = new ChronoLatch(650);
perSecond = new ChronoLatch(1000);
hlast = M.ms();
cache = new AtomicMulticache((IrisTerrainProvider) this);
cache = new AtomicMulticache((SkyTerrainProvider) this);
CNG.creates = 0;
generated = 0;
ticks = 0;
@ -470,7 +470,6 @@ public abstract class ContextualTerrainProvider implements TerrainProvider, List
Iris.instance.imsg(i, C.DARK_RED + "Iris Generator has crashed!");
Iris.instance.imsg(i, C.RED + "- Check the console for the error.");
Iris.instance.imsg(i, C.RED + "- To Regen, use /iris std open <dim>");
Iris.instance.imsg(i, C.RED + "- To Retry the chunk, use /iris world retry");
}
});

View File

@ -26,6 +26,7 @@ import lombok.EqualsAndHashCode;
public abstract class DimensionalTerrainProvider extends ContextualTerrainProvider
{
private String dimensionName;
private IrisDimension forceDimension;
protected static final FastBlockData AIR = FastBlockData.of(Material.AIR);
protected static final FastBlockData CAVE_AIR = B.get("CAVE_AIR");
protected static final FastBlockData BEDROCK = FastBlockData.of(Material.BEDROCK);
@ -35,6 +36,7 @@ public abstract class DimensionalTerrainProvider extends ContextualTerrainProvid
{
super(t);
setDimensionName(dimensionName);
setForceDimension(null);
if(getDimensionName().isEmpty())
{
@ -99,6 +101,11 @@ public abstract class DimensionalTerrainProvider extends ContextualTerrainProvid
}
}
protected void forceDimension(IrisDimension sky)
{
setForceDimension(sky);
}
protected void useDefaultDimensionSetupNOW()
{
@ -124,6 +131,11 @@ public abstract class DimensionalTerrainProvider extends ContextualTerrainProvid
public IrisDimension getDimension()
{
if(forceDimension != null)
{
return forceDimension;
}
IrisDimension d = loadDimension(getDimensionName());
return d;

View File

@ -253,6 +253,7 @@ public class IrisTerrainProvider extends SkyTerrainProvider implements IrisConte
getData().dump();
getCache().drop();
onHotload();
skyHotload();
Iris.proj.updateWorkspace();
}

View File

@ -1,5 +1,20 @@
package com.volmit.iris.gen;
import java.util.function.Function;
import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
import org.bukkit.generator.ChunkGenerator.ChunkData;
import org.bukkit.material.MaterialData;
import org.bukkit.util.BlockVector;
import com.volmit.iris.Iris;
import com.volmit.iris.gen.scaffold.GeneratedChunk;
import com.volmit.iris.gen.scaffold.TerrainChunk;
import com.volmit.iris.gen.scaffold.TerrainTarget;
@ -7,14 +22,232 @@ import com.volmit.iris.util.RNG;
public abstract class SkyTerrainProvider extends PostBlockTerrainProvider
{
private IrisTerrainProvider actualSky;
public SkyTerrainProvider(TerrainTarget t, String dimensionName, int threads)
{
super(t, dimensionName, threads);
}
public void skyHotload()
{
if(actualSky != null)
{
actualSky.onHotloaded();
}
}
@Override
protected GeneratedChunk onGenerate(RNG random, int x, int z, TerrainChunk terrain)
{
return super.onGenerate(random, x, z, terrain);
GeneratedChunk gc = super.onGenerate(random, x, z, terrain);
if(getDimension().hasSky())
{
getDimension().getSky().setSkyDimension(true);
if(actualSky == null)
{
actualSky = new IrisTerrainProvider(getTarget(), "...", getThreads())
{
@Override
public boolean shouldGenerateVanillaStructures()
{
return false;
}
@Override
public boolean shouldGenerateMobs()
{
return false;
}
@Override
public boolean shouldGenerateDecorations()
{
return false;
}
@Override
public boolean shouldGenerateCaves()
{
return getDimension().getSky().isVanillaCaves();
}
@Override
public BlockVector computeSpawn(Function<BlockVector, Boolean> allowed)
{
return null;
}
@Override
public boolean canSpawn(int x, int z)
{
return false;
}
@Override
protected void onSpawn(EntitySpawnEvent e)
{
}
@Override
protected void onPlayerJoin(Player p)
{
}
@Override
protected void onFailure(Throwable e)
{
}
@Override
protected void onChunkUnloaded(Chunk c)
{
}
@Override
protected void onChunkLoaded(Chunk c)
{
}
@Override
protected void handleDrops(BlockDropItemEvent e)
{
}
};
actualSky.changeThreadCount(getThreads());
actualSky.forceDimension(getDimension().getSky());
actualSky.setMasterRandom(new RNG(getMasterRandom().nextParallelRNG(299455).nextLong()));
Iris.info("Created Sky Dimension Provider");
}
try
{
actualSky.onGenerate(random, x, z, new TerrainChunk()
{
@Override
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, BlockData blockData)
{
}
@Override
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, MaterialData material)
{
}
@Override
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, Material material)
{
}
@Override
public void setBlock(int x, int y, int z, MaterialData material)
{
gc.getTerrain().setBlock(x, 255 - y, z, material);
}
@Override
public void setBlock(int x, int y, int z, Material material)
{
gc.getTerrain().setBlock(x, 255 - y, z, material);
}
@Override
public MaterialData getTypeAndData(int x, int y, int z)
{
return gc.getTerrain().getTypeAndData(x, 255 - y, z);
}
@Override
public Material getType(int x, int y, int z)
{
return gc.getTerrain().getType(x, 255 - y, z);
}
@Override
public byte getData(int x, int y, int z)
{
return 0;
}
@Override
public void setRaw(ChunkData data)
{
}
@Override
public void setBlock(int x, int y, int z, BlockData blockData)
{
gc.getTerrain().setBlock(x, 255 - y, z, blockData);
}
@Override
public void setBiome(int x, int y, int z, Biome bio)
{
gc.getTerrain().setBiome(x, 255 - y, z, bio);
}
@Override
public void setBiome(int x, int z, Biome bio)
{
}
@Override
public void inject(BiomeGrid biome)
{
}
@Override
public ChunkData getRaw()
{
return null;
}
@Override
public int getMaxHeight()
{
return gc.getTerrain().getMaxHeight();
}
@Override
public BlockData getBlockData(int x, int y, int z)
{
return gc.getTerrain().getBlockData(x, 255 - y, z);
}
@Override
public Biome getBiome(int x, int y, int z)
{
return gc.getTerrain().getBiome(x, 255 - y, z);
}
@Override
public Biome getBiome(int x, int z)
{
return Biome.THE_VOID;
}
});
}
catch(Throwable e)
{
}
}
return gc;
}
}

View File

@ -3,7 +3,7 @@ package com.volmit.iris.gen.atomics;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.volmit.iris.IrisSettings;
import com.volmit.iris.gen.IrisTerrainProvider;
import com.volmit.iris.gen.SkyTerrainProvider;
import com.volmit.iris.object.IrisBiome;
import com.volmit.iris.object.IrisRegion;
import com.volmit.iris.util.ChunkPosition;
@ -18,7 +18,7 @@ public class AtomicMulticache
private final LoadingCache<ChunkPosition, IrisBiome> rawBiome;
private final LoadingCache<ChunkPosition, IrisRegion> region;
public AtomicMulticache(IrisTerrainProvider gen)
public AtomicMulticache(SkyTerrainProvider gen)
{
height = Caffeine.newBuilder().maximumSize(getLimit()).build((c) -> gen.getNoiseHeight(c.getX(), c.getZ()) + gen.getFluidHeight());
carvedHeight = Caffeine.newBuilder().maximumSize(getLimit()).build((c) ->

View File

@ -417,6 +417,8 @@ public class NMSChunkGenerator16_2_PAPER extends ChunkGenerator implements Provi
for(int xx = 0; xx < 16; xx++)
{
for(int zz = 0; zz < 16; zz++)
{
try
{
int y = gc.getHeight().getHeight(xx, zz);
if(y < getSeaLevel())
@ -425,6 +427,12 @@ public class NMSChunkGenerator16_2_PAPER extends ChunkGenerator implements Provi
}
heightmap1.a(xx, Math.max(y, getSeaLevel()), zz, Blocks.STONE.getBlockData());
}
catch(Throwable e)
{
}
}
}
}

View File

@ -0,0 +1,6 @@
package com.volmit.iris.generator;
public class IrisTerrainProvider
{
}

View File

@ -0,0 +1,218 @@
package com.volmit.iris.generator.atomics;
import org.bouncycastle.util.Arrays;
import lombok.Data;
@Data
public class Hunk<T>
{
protected final int w;
protected final int h;
protected final int d;
protected final T[] data;
@SuppressWarnings("unchecked")
public Hunk(int w, int h, int d)
{
this.w = w;
this.h = h;
this.d = d;
data = (T[]) new Object[w * h * d];
}
/**
* Create a new hunk from a section of this hunk.
*
*
* @param x1
* The min x (inclusive)
* @param y1
* The min y (inclusive)
* @param z1
* The min z (inclusive)
* @param x2
* The max x (exclusive)
* @param y2
* The max y (exclusive)
* @param z2
* The max z (exclusive)
* @return the new hunk (x2-x1, y2-y1, z2-z1)
*/
public Hunk<T> crop(int x1, int y1, int z1, int x2, int y2, int z2)
{
Hunk<T> h = new Hunk<T>(x2 - x1, y2 - y1, z2 - z1);
for(int i = x1; i < x2; i++)
{
for(int j = y1; j < y2; j++)
{
for(int k = z1; k < z2; k++)
{
h.set(i - x1, j - y1, k - z1, get(i, j, k));
}
}
}
return h;
}
/**
* Insert a hunk into this one with an offset 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
*/
public void insert(int offX, int offY, int offZ, Hunk<T> hunk)
{
insert(offX, offY, offZ, hunk, false);
}
/**
* Insert a hunk into this one
*
* @param hunk
* the hunk to insert
*/
public void insert(Hunk<T> hunk)
{
insert(0, 0, 0, hunk, false);
}
/**
* Insert a hunk into this one
*
* @param hunk
* the hunk to insert
* @param inverted
* invert the inserted hunk or not
*/
public void insert(Hunk<T> hunk, boolean inverted)
{
insert(0, 0, 0, hunk, inverted);
}
/**
* 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
* 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
*/
public void insert(int offX, int offY, int offZ, Hunk<T> hunk, boolean invertY)
{
if(offX + (hunk.getW() - 1) >= w || offY + (hunk.getH() - 1) >= h || offZ + (hunk.getD() - 1) >= d || offX < 0 || offY < 0 || offZ < 0)
{
throw new RuntimeException("Cannot insert hunk " + hunk.getW() + "," + hunk.getH() + "," + hunk.getD() + " into Hunk " + w + "," + h + "," + d + " with offset " + offZ + "," + offY + "," + offZ);
}
for(int i = offX; i < offX + hunk.getW(); i++)
{
for(int j = offY; j < offY + hunk.getH(); j++)
{
for(int k = offZ; k < offZ + hunk.getD(); k++)
{
set(i, j, k, hunk.get(i - offX, j - offY, k - offZ));
}
}
}
}
public void set(int x, int y, int z, T t)
{
data[index(x, y, z)] = t;
}
public T get(int x, int y, int z)
{
return data[index(x, y, z)];
}
public void setInvertedY(int x, int y, int z, T t)
{
data[index(x, h - y, z)] = t;
}
public T getInvertedY(int x, int y, int z)
{
return data[index(x, h - y, z)];
}
protected int index(int x, int y, int z)
{
if(x >= w || y >= h || z >= d)
{
throw new RuntimeException(x + " " + y + " " + z + " is out of the bounds 0,0,0 - " + (w - 1) + "," + (h - 1) + "," + (d - 1));
}
return (z * w * h) + (y * w) + x;
}
public void fill(T t)
{
Arrays.fill(data, t);
}
@SafeVarargs
public static <T> Hunk<T> combined(T defaultNode, Hunk<T>... hunks)
{
int w = 0;
int h = 0;
int d = 0;
for(Hunk<T> i : hunks)
{
w = Math.max(w, i.getW());
h = Math.max(h, i.getH());
d = Math.max(d, i.getD());
}
Hunk<T> b = new Hunk<T>(w, h, d);
b.fill(defaultNode);
for(Hunk<T> i : hunks)
{
b.insert(i);
}
return b;
}
@SafeVarargs
public static <T> Hunk<T> combined(Hunk<T>... hunks)
{
int w = 0;
int h = 0;
int d = 0;
for(Hunk<T> i : hunks)
{
w = Math.max(w, i.getW());
h = Math.max(h, i.getH());
d = Math.max(d, i.getD());
}
Hunk<T> b = new Hunk<T>(w, h, d);
for(Hunk<T> i : hunks)
{
b.insert(i);
}
return b;
}
}

View File

@ -0,0 +1,204 @@
package com.volmit.iris.generator.atomics;
import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.block.data.BlockData;
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
import org.bukkit.generator.ChunkGenerator.ChunkData;
import org.bukkit.material.MaterialData;
@SuppressWarnings("deprecation")
public class TerrainHunk extends Hunk<TerrainNode> implements BiomeGrid, ChunkData
{
public TerrainHunk(int w, int h, int d)
{
super(w, h, d);
}
@Override
public int getMaxHeight()
{
return getH();
}
private void set(int x, int y, int z, BlockData block)
{
TerrainNode n = get(x, y, z);
if(n == null)
{
n = new TerrainNode(Biome.THE_VOID, block);
}
else
{
n = n.setBlockData(block);
}
set(x, y, z, n);
}
private void set(int x, int y, int z, Biome biome)
{
TerrainNode n = get(x, y, z);
if(n == null)
{
n = new TerrainNode(biome, Material.AIR.createBlockData());
}
else
{
n = n.setBiome(biome);
}
set(x, y, z, n);
}
@Override
public void setBlock(int x, int y, int z, Material material)
{
set(x, y, z, material.createBlockData());
}
@Override
public void setBlock(int x, int y, int z, MaterialData material)
{
set(x, y, z, material.getItemType().createBlockData());
}
@Override
public void setBlock(int x, int y, int z, BlockData blockData)
{
set(x, y, z, blockData);
}
@Override
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, Material material)
{
throw new RuntimeException("Not Supported");
}
@Override
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, MaterialData material)
{
throw new RuntimeException("Not Supported");
}
@Override
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, BlockData blockData)
{
throw new RuntimeException("Not Supported");
}
@Override
public Material getType(int x, int y, int z)
{
return getBlockData(x, y, z).getMaterial();
}
@Override
public MaterialData getTypeAndData(int x, int y, int z)
{
return new MaterialData(getBlockData(x, y, z).getMaterial());
}
@Override
public BlockData getBlockData(int x, int y, int z)
{
TerrainNode n = get(x, y, z);
if(n == null)
{
return Material.STONE.createBlockData();
}
return n.getBlockData();
}
@Override
public byte getData(int x, int y, int z)
{
throw new RuntimeException("Not Supported");
}
@Override
public Biome getBiome(int x, int z)
{
throw new RuntimeException("Not Supported");
}
@Override
public Biome getBiome(int x, int y, int z)
{
TerrainNode n = get(x, y, z);
if(n == null)
{
return Biome.THE_VOID;
}
return n.getBiome();
}
@Override
public void setBiome(int x, int z, Biome bio)
{
throw new RuntimeException("Not Supported");
}
@Override
public void setBiome(int x, int y, int z, Biome bio)
{
set(x, y, z, bio);
}
@SafeVarargs
public static TerrainHunk combined(TerrainNode defaultNode, TerrainHunk... hunks)
{
int w = 0;
int h = 0;
int d = 0;
for(TerrainHunk i : hunks)
{
w = Math.max(w, i.getW());
h = Math.max(h, i.getH());
d = Math.max(d, i.getD());
}
TerrainHunk b = new TerrainHunk(w, h, d);
b.fill(defaultNode);
for(TerrainHunk i : hunks)
{
b.insert(i);
}
return b;
}
@SafeVarargs
public static TerrainHunk combined(TerrainHunk... hunks)
{
int w = 0;
int h = 0;
int d = 0;
for(TerrainHunk i : hunks)
{
w = Math.max(w, i.getW());
h = Math.max(h, i.getH());
d = Math.max(d, i.getD());
}
TerrainHunk b = new TerrainHunk(w, h, d);
for(TerrainHunk i : hunks)
{
b.insert(i);
}
return b;
}
}

View File

@ -0,0 +1,61 @@
package com.volmit.iris.generator.atomics;
import org.bukkit.block.Biome;
import org.bukkit.block.data.BlockData;
import com.volmit.iris.util.KList;
public class TerrainNode
{
private static final KList<BlockData> blockDataPalette = new KList<BlockData>();
private final byte biome;
private final short block;
private TerrainNode(byte biome, short block)
{
this.biome = biome;
this.block = block;
}
public TerrainNode(Biome biome, BlockData block)
{
this((byte) (biome.ordinal() + Byte.MIN_VALUE), (short) (paletteOf(block) + Short.MIN_VALUE));
}
public TerrainNode setBlockData(BlockData block)
{
return new TerrainNode(biome, (short) (paletteOf(block) + Short.MIN_VALUE));
}
public TerrainNode setBiome(Biome biome)
{
return new TerrainNode((byte) (biome.ordinal() + Byte.MIN_VALUE), block);
}
public BlockData getBlockData()
{
return blockDataPalette.get(block);
}
public Biome getBiome()
{
return Biome.values()[biome];
}
private static int paletteOf(BlockData b)
{
synchronized(blockDataPalette)
{
int v = blockDataPalette.indexOf(b);
if(v >= 0)
{
return v;
}
blockDataPalette.add(b);
return blockDataPalette.size() - 1;
}
}
}

View File

@ -0,0 +1,18 @@
package com.volmit.iris.generator.scaffold;
import com.volmit.iris.generator.atomics.TerrainHunk;
public class IrisTerrainStream implements TerrainStream
{
@Override
public TerrainHunk generate(int x1, int z1, int x2, int z2)
{
return null;
}
@Override
public TerrainHunk generate(int x, int z)
{
return null;
}
}

View File

@ -0,0 +1,10 @@
package com.volmit.iris.generator.scaffold;
import com.volmit.iris.generator.atomics.TerrainHunk;
public interface TerrainStream
{
public TerrainHunk generate(int x1, int z1, int x2, int z2);
public TerrainHunk generate(int x, int z);
}

View File

@ -238,7 +238,7 @@ public class IrisProject
return new File(path, getName() + ".code-workspace");
}
public void updateWorkspace()
public boolean updateWorkspace()
{
getPath().mkdirs();
File ws = getCodeWorkspaceFile();
@ -251,6 +251,7 @@ public class IrisProject
IO.writeAll(ws, j.toString(4));
p.end();
Iris.info("Updated Workspace: " + ws.getPath() + " in " + Form.duration(p.getMilliseconds(), 2));
return true;
}
catch(Throwable e)
@ -267,6 +268,8 @@ public class IrisProject
e1.printStackTrace();
}
}
return false;
}
public JSONObject createCodeWorkspaceConfig()

View File

@ -91,7 +91,7 @@ public class ProjectManager
catch(IOException e)
{
e.printStackTrace();
}
}

View File

@ -154,6 +154,8 @@ public class WandManager implements Listener
@EventHandler
public void on(PlayerInteractEvent e)
{
try
{
if(e.getHand().equals(EquipmentSlot.HAND) && isWand(e.getPlayer().getInventory().getItemInMainHand()))
{
@ -175,6 +177,12 @@ public class WandManager implements Listener
}
}
catch(Throwable ex)
{
}
}
public static void pasteSchematic(IrisObject s, Location at)
{
s.place(at);

View File

@ -26,7 +26,7 @@ public class IrisCaveFluid
@MaxNumber(255)
@MinNumber(0)
@DontObfuscate
@Desc("The cave zoom. Higher values makes caves spread out further and branch less often, but are thicker.")
@Desc("The fluid height of the cave")
private int fluidHeight = 35;
@DontObfuscate