mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-06 07:46:08 +00:00
Fixes
This commit is contained in:
1305
src/main/java/com/volmit/iris/util/HeightedFakeWorld.java
Normal file
1305
src/main/java/com/volmit/iris/util/HeightedFakeWorld.java
Normal file
File diff suppressed because it is too large
Load Diff
75
src/main/java/com/volmit/iris/util/IrisBiomeStorage.java
Normal file
75
src/main/java/com/volmit/iris/util/IrisBiomeStorage.java
Normal file
@@ -0,0 +1,75 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
229
src/main/java/com/volmit/iris/util/LinkedTerrainChunk.java
Normal file
229
src/main/java/com/volmit/iris/util/LinkedTerrainChunk.java
Normal file
@@ -0,0 +1,229 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
138
src/main/java/com/volmit/iris/util/TerrainChunk.java
Normal file
138
src/main/java/com/volmit/iris/util/TerrainChunk.java
Normal file
@@ -0,0 +1,138 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user