This commit is contained in:
Daniel Mills
2020-11-14 15:08:11 -05:00
parent 468448ff6e
commit 6b8610b72d
12 changed files with 6 additions and 446 deletions

View File

@@ -1,84 +0,0 @@
package com.volmit.iris.generator.legacy.scaffold;
import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.bukkit.generator.ChunkGenerator.ChunkData;
import org.bukkit.material.MaterialData;
@SuppressWarnings("deprecation")
public class ChunkWrapper implements ChunkData
{
private final Chunk chunk;
public ChunkWrapper(Chunk chunk)
{
this.chunk = chunk;
}
@Override
public int getMaxHeight()
{
return chunk.getWorld().getMaxHeight();
}
@Override
public void setBlock(int x, int y, int z, Material material)
{
chunk.getBlock(x, y, z).setType(material, false);
}
@Override
public void setBlock(int x, int y, int z, MaterialData material)
{
throw new UnsupportedOperationException();
}
@Override
public void setBlock(int x, int y, int z, BlockData blockData)
{
chunk.getBlock(x, y, z).setBlockData(blockData, false);
}
@Override
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, Material material)
{
throw new UnsupportedOperationException();
}
@Override
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, MaterialData material)
{
throw new UnsupportedOperationException();
}
@Override
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, BlockData blockData)
{
throw new UnsupportedOperationException();
}
@Override
public Material getType(int x, int y, int z)
{
return chunk.getBlock(x, y, z).getType();
}
@Override
public MaterialData getTypeAndData(int x, int y, int z)
{
throw new UnsupportedOperationException();
}
@Override
public BlockData getBlockData(int x, int y, int z)
{
return chunk.getBlock(x, y, z).getBlockData();
}
@Override
public byte getData(int x, int y, int z)
{
throw new UnsupportedOperationException();
}
}

View File

@@ -1,77 +0,0 @@
package com.volmit.iris.generator.legacy.scaffold;
import org.bukkit.block.Biome;
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
import com.volmit.iris.util.IrisMathHelper;
public class IrisBiomeStorage
{
private static final int e;
private static final int f;
public static final int a;
public static final int b;
public static final int c;
private final Biome[] g;
static
{
e = (int) Math.round(Math.log(16.0) / Math.log(2.0)) - 2;
f = (int) Math.round(Math.log(256.0) / Math.log(2.0)) - 2;
a = 1 << IrisBiomeStorage.e + IrisBiomeStorage.e + IrisBiomeStorage.f;
b = (1 << IrisBiomeStorage.e) - 1;
c = (1 << IrisBiomeStorage.f) - 1;
}
public IrisBiomeStorage(final Biome[] aBiome)
{
this.g = aBiome;
}
public IrisBiomeStorage()
{
this(new Biome[IrisBiomeStorage.a]);
}
public IrisBiomeStorage b()
{
return new IrisBiomeStorage(this.g.clone());
}
public void inject(BiomeGrid grid)
{
for(int i = 0; i < 256; i++)
{
for(int j = 0; j < 16; j++)
{
for(int k = 0; k < 16; k++)
{
Biome b = getBiome(j, i, k);
if(b == null || b.equals(Biome.THE_VOID))
{
continue;
}
grid.setBiome(j, i, k, b);
}
}
}
}
public Biome getBiome(final int x, final int y, final int z)
{
final int l = x & IrisBiomeStorage.b;
final int i2 = IrisMathHelper.clamp(y, 0, IrisBiomeStorage.c);
final int j2 = z & IrisBiomeStorage.b;
return this.g[i2 << IrisBiomeStorage.e + IrisBiomeStorage.e | j2 << IrisBiomeStorage.e | l];
}
public void setBiome(final int x, final int y, final int z, final Biome biome)
{
final int l = x & IrisBiomeStorage.b;
final int i2 = IrisMathHelper.clamp(y, 0, IrisBiomeStorage.c);
final int j2 = z & IrisBiomeStorage.b;
this.g[i2 << IrisBiomeStorage.e + IrisBiomeStorage.e | j2 << IrisBiomeStorage.e | l] = biome;
}
}

View File

@@ -1,35 +0,0 @@
package com.volmit.iris.generator.legacy.scaffold;
import com.volmit.iris.object.IrisBiome;
import com.volmit.iris.object.IrisDimension;
import com.volmit.iris.object.IrisRegion;
import com.volmit.iris.util.KMap;
public interface IrisContext
{
static KMap<TerrainTarget, IrisContext> contexts = new KMap<>();
public static void pushContext(IrisContext context)
{
contexts.put(context.getTarget(), context);
}
public static IrisContext of(TerrainTarget world)
{
return contexts.get(world);
}
public TerrainTarget getTarget();
public IrisBiome getBiome(int x, int z);
public IrisDimension getDimension();
public IrisRegion getRegion(int x, int z);
public IrisMetrics getMetrics();
public int getHeight(int x, int z);
public void onHotloaded();
}

View File

@@ -1,38 +0,0 @@
package com.volmit.iris.generator.legacy.scaffold;
import com.volmit.iris.Iris;
import com.volmit.iris.util.RollingSequence;
import lombok.Data;
@Data
public class IrisMetrics
{
private final RollingSequence parallax;
private final RollingSequence terrain;
private final RollingSequence post;
private final RollingSequence update;
private final RollingSequence deposits;
private final RollingSequence spawns;
private final RollingSequence total;
private final RollingSequence perSecond;
public int generators = 0;
public int noiseHits = 0;
public IrisMetrics(int memory)
{
parallax = new RollingSequence(memory);
spawns = new RollingSequence(memory);
terrain = new RollingSequence(memory);
post = new RollingSequence(memory);
update = new RollingSequence(memory);
deposits = new RollingSequence(memory);
total = new RollingSequence(memory);
perSecond = new RollingSequence(5);
}
public double getSpeed()
{
return (double) Iris.board.hits.getAverage() / (double) total.getAverage();
}
}

View File

@@ -1,229 +0,0 @@
package com.volmit.iris.generator.legacy.scaffold;
import org.bukkit.Bukkit;
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;
import com.volmit.iris.Iris;
@SuppressWarnings("deprecation")
public class LinkedTerrainChunk implements TerrainChunk
{
private final Biome[] biome2D;
private final IrisBiomeStorage biome3D;
private ChunkData rawChunkData;
private final BiomeGrid storage;
public LinkedTerrainChunk(int maxHeight)
{
this(null, maxHeight);
}
public LinkedTerrainChunk(BiomeGrid storage, ChunkData data)
{
this.storage = storage;
rawChunkData = data;
biome2D = storage != null ? null : Iris.biome3d ? null : new Biome[256];
biome3D = storage != null ? null : Iris.biome3d ? new IrisBiomeStorage() : null;
}
public LinkedTerrainChunk(BiomeGrid storage, int maxHeight)
{
this.storage = storage;
rawChunkData = createChunkData(maxHeight);
biome2D = storage != null ? null : Iris.biome3d ? null : new Biome[256];
biome3D = storage != null ? null : Iris.biome3d ? new IrisBiomeStorage() : null;
}
private ChunkData createChunkData(int maxHeight)
{
try
{
return Bukkit.createChunkData(new HeightedFakeWorld(maxHeight));
}
catch(Throwable e)
{
e.printStackTrace();
}
return null;
}
@Override
public Biome getBiome(int x, int z)
{
if(storage != null)
{
return storage.getBiome(x, z);
}
if(biome2D != null)
{
return biome2D[(z << 4) | x];
}
return biome3D.getBiome(x, 0, z);
}
@Override
public Biome getBiome(int x, int y, int z)
{
if(storage != null)
{
return storage.getBiome(x, y, z);
}
if(biome2D != null)
{
return biome2D[(z << 4) | x];
}
return biome3D.getBiome(x, y, z);
}
@Override
public void setBiome(int x, int z, Biome bio)
{
if(storage != null)
{
storage.setBiome(x, z, bio);
return;
}
if(biome2D != null)
{
biome2D[(z << 4) | x] = bio;
return;
}
biome3D.setBiome(x, 0, z, bio);
}
@Override
public void setBiome(int x, int y, int z, Biome bio)
{
if(storage != null)
{
storage.setBiome(x, y, z, bio);
return;
}
if(biome2D != null)
{
biome2D[(z << 4) | x] = bio;
return;
}
biome3D.setBiome(x, y, z, bio);
}
@Override
public int getMaxHeight()
{
return rawChunkData.getMaxHeight();
}
@Override
public void setBlock(int x, int y, int z, BlockData blockData)
{
rawChunkData.setBlock(x, y, z, blockData);
}
@Override
public BlockData getBlockData(int x, int y, int z)
{
return rawChunkData.getBlockData(x, y, z);
}
@Deprecated
@Override
public void setBlock(int x, int y, int z, Material material)
{
rawChunkData.setBlock(x, y, z, material);
}
@Deprecated
@Override
public void setBlock(int x, int y, int z, MaterialData material)
{
rawChunkData.setBlock(x, y, z, material);
}
@Deprecated
@Override
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, Material material)
{
rawChunkData.setRegion(xMin, yMin, zMin, xMax, yMax, zMax, material);
}
@Deprecated
@Override
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, MaterialData material)
{
rawChunkData.setRegion(xMin, yMin, zMin, xMax, yMax, zMax, material);
}
@Override
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, BlockData blockData)
{
rawChunkData.setRegion(xMin, yMin, zMin, xMax, yMax, zMax, blockData);
}
@Deprecated
@Override
public Material getType(int x, int y, int z)
{
return rawChunkData.getType(x, y, z);
}
@Deprecated
@Override
public MaterialData getTypeAndData(int x, int y, int z)
{
return rawChunkData.getTypeAndData(x, y, z);
}
@Deprecated
@Override
public byte getData(int x, int y, int z)
{
return rawChunkData.getData(x, y, z);
}
@Override
public ChunkData getRaw()
{
return rawChunkData;
}
@Override
public void setRaw(ChunkData data)
{
rawChunkData = data;
}
@Override
public void inject(BiomeGrid biome)
{
if(biome2D != null)
{
for(int i = 0; i < 16; i++)
{
for(int j = 0; j < 16; j++)
{
biome.setBiome(i, j, getBiome(i, j));
}
}
}
else if(biome3D != null)
{
biome3D.inject(biome);
}
}
}

View File

@@ -1,138 +0,0 @@
package com.volmit.iris.generator.legacy.scaffold;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.block.data.BlockData;
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
import org.bukkit.generator.ChunkGenerator.ChunkData;
public interface TerrainChunk extends BiomeGrid, ChunkData
{
public static TerrainChunk create(World world)
{
return create(world.getMaxHeight());
}
public static TerrainChunk create(int maxHeight)
{
return new LinkedTerrainChunk(maxHeight);
}
public static TerrainChunk create(World world, BiomeGrid grid)
{
return create(world.getMaxHeight(), grid);
}
public static TerrainChunk create(ChunkData raw, BiomeGrid grid)
{
return new LinkedTerrainChunk(grid, raw);
}
public static TerrainChunk create(int maxHeight, BiomeGrid grid)
{
return new LinkedTerrainChunk(grid, maxHeight);
}
public void setRaw(ChunkData data);
/**
* Get biome at x, z within chunk being generated
*
* @param x
* - 0-15
* @param z
* - 0-15
* @return Biome value
* @deprecated biomes are now 3-dimensional
*/
@Deprecated
Biome getBiome(int x, int z);
/**
* Get biome at x, z within chunk being generated
*
* @param x
* - 0-15
* @param y
* - 0-255
* @param z
* - 0-15
* @return Biome value
*/
Biome getBiome(int x, int y, int z);
/**
* Set biome at x, z within chunk being generated
*
* @param x
* - 0-15
* @param z
* - 0-15
* @param bio
* - Biome value
* @deprecated biomes are now 3-dimensional
*/
@Deprecated
void setBiome(int x, int z, Biome bio);
/**
* Set biome at x, z within chunk being generated
*
* @param x
* - 0-15
* @param y
* - 0-255
* @param z
* - 0-15
* @param bio
* - Biome value
*/
void setBiome(int x, int y, int z, Biome bio);
/**
* Get the maximum height for the chunk.
*
* Setting blocks at or above this height will do nothing.
*
* @return the maximum height
*/
public int getMaxHeight();
/**
* Set the block at x,y,z in the chunk data to material.
*
* Setting blocks outside the chunk's bounds does nothing.
*
* @param x
* the x location in the chunk from 0-15 inclusive
* @param y
* the y location in the chunk from 0 (inclusive) - maxHeight
* (exclusive)
* @param z
* the z location in the chunk from 0-15 inclusive
* @param blockData
* the type to set the block to
*/
public void setBlock(int x, int y, int z, BlockData blockData);
/**
* Get the type and data of the block at x, y, z.
*
* Getting blocks outside the chunk's bounds returns air.
*
* @param x
* the x location in the chunk from 0-15 inclusive
* @param y
* the y location in the chunk from 0 (inclusive) - maxHeight
* (exclusive)
* @param z
* the z location in the chunk from 0-15 inclusive
* @return the data of the block or the BlockData for air if x, y or z are
* outside the chunk's bounds
*/
public BlockData getBlockData(int x, int y, int z);
public ChunkData getRaw();
public void inject(BiomeGrid biome);
}

View File

@@ -1,97 +0,0 @@
package com.volmit.iris.generator.legacy.scaffold;
import java.io.File;
import java.util.List;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.entity.Player;
import com.volmit.iris.util.KList;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
public class TerrainTarget
{
private long seed;
private Environment environment;
private String name;
private File folder;
private static final KList<Player> emptyPlayers = new KList<>();
private World realWorld;
public void setRealWorld(World realWorld)
{
if(this.realWorld == null || realWorld != this.realWorld)
{
this.realWorld = realWorld;
this.seed = realWorld.getSeed();
this.folder = realWorld.getWorldFolder();
this.environment = realWorld.getEnvironment();
this.name = realWorld.getName();
}
}
public static TerrainTarget from(World world)
{
// @NoArgsConstructor
return new TerrainTargetBuilder().environment(world.getEnvironment()).seed(world.getSeed()).folder(world.getWorldFolder()).name(world.getName()).realWorld(world).build();
//@done
}
public List<Player> getPlayers()
{
return realWorld != null ? realWorld.getPlayers() : emptyPlayers;
}
public boolean isWorld(World world)
{
return world.getName().equals(getName()) && world.getSeed() == getSeed() && getEnvironment().equals(world.getEnvironment()) && world.getWorldFolder().equals(getFolder());
}
@Override
public boolean equals(Object obj)
{
if(this == obj)
return true;
if(obj == null)
return false;
if(getClass() != obj.getClass())
return false;
TerrainTarget other = (TerrainTarget) obj;
if(environment != other.environment)
return false;
if(folder == null)
{
if(other.folder != null)
return false;
}
else if(!folder.equals(other.folder))
return false;
if(name == null)
{
if(other.name != null)
return false;
}
else if(!name.equals(other.name))
return false;
if(seed != other.seed)
return false;
return true;
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((environment == null) ? 0 : environment.hashCode());
result = prime * result + ((folder == null) ? 0 : folder.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + (int) (seed ^ (seed >>> 32));
return result;
}
}