mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 10:43:14 +00:00
Fixes & merge
This commit is contained in:
parent
99022055cf
commit
5a6f6fba2e
@ -1,4 +1,4 @@
|
||||
package com.volmit.iris.generator.atomics;
|
||||
package com.volmit.iris.gen.atomics;
|
||||
|
||||
public class HeightHunk extends Hunk<Byte>
|
||||
{
|
@ -1,7 +1,8 @@
|
||||
package com.volmit.iris.generator.atomics;
|
||||
package com.volmit.iris.gen.atomics;
|
||||
|
||||
import org.bouncycastle.util.Arrays;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.Function3;
|
||||
import com.volmit.iris.util.Supplier2;
|
||||
import com.volmit.iris.util.Supplier3;
|
||||
@ -19,6 +20,11 @@ public class Hunk<T>
|
||||
@SuppressWarnings("unchecked")
|
||||
public Hunk(int w, int h, int d)
|
||||
{
|
||||
if(w * h * d < 0)
|
||||
{
|
||||
Iris.error(w + " " + h + " " + d + " is not valid!");
|
||||
}
|
||||
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
this.d = d;
|
||||
@ -138,7 +144,10 @@ public class Hunk<T>
|
||||
|
||||
public void set(int x, int z, int y1, int y2, T t)
|
||||
{
|
||||
set(x, x, y1, y2, z, z, t);
|
||||
for(int i = y1; i <= y2; i++)
|
||||
{
|
||||
set(x, i, z, t);
|
||||
}
|
||||
}
|
||||
|
||||
public void set(int x1, int y1, int z1, int x2, int y2, int z2, T t)
|
||||
@ -165,6 +174,21 @@ public class Hunk<T>
|
||||
return data[index(x, y, z)];
|
||||
}
|
||||
|
||||
public T get(int x, int y, int z, T oob)
|
||||
{
|
||||
if(x >= w || y >= h || z >= d)
|
||||
{
|
||||
return oob;
|
||||
}
|
||||
|
||||
return data[index(x, y, z)];
|
||||
}
|
||||
|
||||
public T getClosest(int x, int y, int z)
|
||||
{
|
||||
return data[index(x >= w ? w - 1 : x, y >= h ? h - 1 : y, z >= d ? d - 1 : z)];
|
||||
}
|
||||
|
||||
public void setInvertedY(int x, int y, int z, T t)
|
||||
{
|
||||
data[index(x, h - y, z)] = t;
|
||||
@ -277,4 +301,17 @@ public class Hunk<T>
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
public int highestNonNull(int x, int z)
|
||||
{
|
||||
for(int i = h - 1; i >= 0; i--)
|
||||
{
|
||||
if(get(x, i, z) != null)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.volmit.iris.generator.atomics;
|
||||
package com.volmit.iris.gen.atomics;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Biome;
|
||||
@ -28,11 +28,19 @@ public class TerrainHunk extends Hunk<TerrainNode> implements BiomeGrid, ChunkDa
|
||||
this.biome = new Hunk<IrisBiome>(w, h, d);
|
||||
}
|
||||
|
||||
public TerrainHunk(int w, int h, int d, HeightHunk hh)
|
||||
public TerrainHunk(int w, int h, int d, Hunk<Double> noise)
|
||||
{
|
||||
super(w, h, d);
|
||||
this.height = hh;
|
||||
this.height = new HeightHunk(w, d);
|
||||
this.biome = new Hunk<IrisBiome>(w, h, d);
|
||||
|
||||
for(int i = 0; i < w; i++)
|
||||
{
|
||||
for(int j = 0; j < d; j++)
|
||||
{
|
||||
height.setHeight(i, noise.highestNonNull(i, j), j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -136,6 +144,18 @@ public class TerrainHunk extends Hunk<TerrainNode> implements BiomeGrid, ChunkDa
|
||||
return n.getBlockData();
|
||||
}
|
||||
|
||||
public BlockData getBlockDataOrNull(int x, int y, int z)
|
||||
{
|
||||
TerrainNode n = get(x, y, z);
|
||||
|
||||
if(n == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return n.getBlockData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getData(int x, int y, int z)
|
||||
{
|
||||
@ -238,4 +258,26 @@ public class TerrainHunk extends Hunk<TerrainNode> implements BiomeGrid, ChunkDa
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
public void into(ChunkData c)
|
||||
{
|
||||
|
||||
for(int i = 0; i < w; i++)
|
||||
{
|
||||
for(int j = 0; j < h; j++)
|
||||
{
|
||||
for(int k = 0; k < d; k++)
|
||||
{
|
||||
BlockData n = getBlockData(i, j, k);
|
||||
|
||||
if(n == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
c.setBlock(i, j, k, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.volmit.iris.generator.atomics;
|
||||
package com.volmit.iris.gen.atomics;
|
||||
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
@ -1,131 +0,0 @@
|
||||
package com.volmit.iris.generator;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import com.volmit.iris.generator.atomics.HeightHunk;
|
||||
import com.volmit.iris.generator.atomics.TerrainHunk;
|
||||
import com.volmit.iris.generator.scaffold.TerrainStream;
|
||||
import com.volmit.iris.noise.CNG;
|
||||
import com.volmit.iris.object.NoiseStyle;
|
||||
import com.volmit.iris.util.RNG;
|
||||
|
||||
public class IrisTerrainStream implements TerrainStream
|
||||
{
|
||||
private CNG cng = NoiseStyle.IRIS_DOUBLE.create(new RNG(1234)).scale(0.5);
|
||||
private static final BlockData STONE = Material.STONE.createBlockData();
|
||||
|
||||
@Override
|
||||
public long getSeed()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight()
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNoise(int x, int z)
|
||||
{
|
||||
return (int) Math.round(cng.fitDouble(0, getHeight() - 1, (double) x, (double) z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public HeightHunk genNoise(int x1, int z1, int x2, int z2)
|
||||
{
|
||||
HeightHunk b = new HeightHunk(x2 - x1, z2 - z1);
|
||||
|
||||
for(int i = 0; i < b.getW(); i++)
|
||||
{
|
||||
for(int j = 0; j < b.getD(); j++)
|
||||
{
|
||||
b.setHeight(i, getNoise(i + x1, j + z1), j);
|
||||
}
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerrainHunk genCarving(int x1, int z1, int x2, int z2, HeightHunk noise)
|
||||
{
|
||||
TerrainHunk t = new TerrainHunk(noise.getW(), getHeight(), noise.getD(), noise);
|
||||
|
||||
for(int i = 0; i < t.getW(); i++)
|
||||
{
|
||||
for(int k = 0; k < t.getD(); k++)
|
||||
{
|
||||
int height = t.getHeight().getHeight(i, k);
|
||||
|
||||
for(int j = 0; j <= height; j++)
|
||||
{
|
||||
t.setBlock(i, j, k, STONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerrainHunk genTerrain(int x1, int z1, int x2, int z2, TerrainHunk t)
|
||||
{
|
||||
boolean hard = false;
|
||||
int lastHard = 255;
|
||||
|
||||
for(int i = 0; i < t.getW(); i++)
|
||||
{
|
||||
for(int k = 0; k < t.getW(); k++)
|
||||
{
|
||||
int height = t.getHeight().getHeight(i, k);
|
||||
|
||||
for(int j = height; j >= 0; j--)
|
||||
{
|
||||
boolean _hard = !t.getBlockData(i, j, k).getMaterial().equals(Material.VOID_AIR);
|
||||
|
||||
if(!hard && _hard)
|
||||
{
|
||||
lastHard = j;
|
||||
hard = true;
|
||||
}
|
||||
|
||||
else if(hard && (!_hard || j == 0))
|
||||
{
|
||||
generateSurface(x1, z1, i, lastHard, k, lastHard - j, t);
|
||||
hard = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
protected void generateSurface(int ox, int oz, int x, int y, int z, int depth, TerrainHunk t)
|
||||
{
|
||||
for(int i = y; i <= (y + depth); i++)
|
||||
{
|
||||
if(i == y)
|
||||
{
|
||||
t.setBlock(x, i, z, Material.GRASS_BLOCK.createBlockData());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerrainHunk genDecorations(int x1, int z1, int x2, int z2, TerrainHunk hunk)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return hunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerrainHunk genParallax(int x1, int z1, int x2, int z2, TerrainHunk hunk)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return hunk;
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.volmit.iris.generator.scaffold;
|
||||
|
||||
import com.volmit.iris.generator.atomics.HeightHunk;
|
||||
import com.volmit.iris.generator.atomics.TerrainHunk;
|
||||
|
||||
public interface TerrainStream
|
||||
{
|
||||
public long getSeed();
|
||||
|
||||
public int getHeight();
|
||||
|
||||
public int getNoise(int x, int z);
|
||||
|
||||
public HeightHunk genNoise(int x1, int z1, int x2, int z2);
|
||||
|
||||
public TerrainHunk genTerrain(int x1, int z1, int x2, int z2, TerrainHunk noise);
|
||||
|
||||
public TerrainHunk genCarving(int x1, int z1, int x2, int z2, HeightHunk noise);
|
||||
|
||||
public TerrainHunk genDecorations(int x1, int z1, int x2, int z2, TerrainHunk hunk);
|
||||
|
||||
public TerrainHunk genParallax(int x1, int z1, int x2, int z2, TerrainHunk hunk);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user