use of org.spongepowered.common.util.gen.ObjectArrayMutableBiomeBuffer in project SpongeCommon by SpongePowered.
the class CustomBiomeProvider method getBiomes.
@Override
public Biome[] getBiomes(Biome[] biomeArray, int startX, int startZ, int sizeX, int sizeZ) {
if (biomeArray == null || biomeArray.length < sizeX * sizeZ) {
biomeArray = new Biome[sizeX * sizeZ];
} else {
// Biome generators don't have to set every position. If we set
// all positions to ocean first, every position not set will be
// ocean, and not some random biome from the last time this array
// was used
Arrays.fill(biomeArray, Biomes.OCEAN);
}
ObjectArrayMutableBiomeBuffer biomeArea = new ObjectArrayMutableBiomeBuffer(new Vector3i(startX, 0, startZ), new Vector3i(sizeX, 1, sizeZ));
this.biomeGenerator.generateBiomes(biomeArea);
biomeArea.fill(biomeArray);
return biomeArray;
}
use of org.spongepowered.common.util.gen.ObjectArrayMutableBiomeBuffer in project SpongeCommon by SpongePowered.
the class CustomBiomeProvider method findBiomePosition.
@Override
public BlockPos findBiomePosition(int xCenter, int zCenter, int range, List<Biome> biomes, Random random) {
IntCache.resetIntCache();
int xStartSegment = xCenter - range;
int zStartSegment = zCenter - range;
int xMaxSegment = xCenter + range;
int zMaxSegment = zCenter + range;
int xSizeSegments = xMaxSegment - xStartSegment + 1;
int zSizeSegments = zMaxSegment - zStartSegment + 1;
ObjectArrayMutableBiomeBuffer buffer = getBiomeBuffer(xStartSegment, zStartSegment, xSizeSegments, zSizeSegments);
this.biomeGenerator.generateBiomes(buffer);
BlockPos blockpos = null;
int attempts = 0;
for (int x = xStartSegment; x < xMaxSegment; x++) {
for (int z = zStartSegment; z < zMaxSegment; z++) {
Biome type = buffer.getNativeBiome(x, 0, z);
if (biomes.contains(type) && (blockpos == null || random.nextInt(attempts + 1) == 0)) {
blockpos = new BlockPos(x, 0, z);
++attempts;
}
}
}
return blockpos;
}
use of org.spongepowered.common.util.gen.ObjectArrayMutableBiomeBuffer in project SpongeCommon by SpongePowered.
the class MixinChunkGeneratorOverworld method getBiomesFromGenerator.
private Biome[] getBiomesFromGenerator(int x, int z) {
if (this.biomegen instanceof BiomeProvider) {
return ((BiomeProvider) this.biomegen).getBiomesForGeneration(this.biomesForGeneration, x * 4 - 2, z * 4 - 2, 10, 10);
}
// If its not a WorldChunkManager then we have to perform a reverse of
// the voronoi zoom biome generation layer to get a zoomed out version
// of the biomes that the terrain generator expects. While not an exact
// reverse of the algorithm this should be accurate 99.997% of the time
// (based on testing).
ObjectArrayMutableBiomeBuffer buffer = new ObjectArrayMutableBiomeBuffer(new Vector3i(x * 16 - 6, 0, z * 16 - 6), new Vector3i(37, 1, 37));
this.biomegen.generateBiomes(buffer);
if (this.biomesForGeneration == null || this.biomesForGeneration.length < 100) {
this.biomesForGeneration = new Biome[100];
}
for (int bx = 0; bx < 40; bx += 4) {
int absX = bx + x * 16 - 6;
for (int bz = 0; bz < 40; bz += 4) {
int absZ = bz + z * 16 - 6;
Biome type = buffer.getNativeBiome(absX, 0, absZ);
this.biomesForGeneration[(bx / 4) + (bz / 4) * 10] = type;
}
}
return this.biomesForGeneration;
}
use of org.spongepowered.common.util.gen.ObjectArrayMutableBiomeBuffer in project SpongeCommon by SpongePowered.
the class CustomBiomeProvider method getBiomesForGeneration.
@Override
public Biome[] getBiomesForGeneration(Biome[] biomeArrayZoomedOut, int xStart, int zStart, int xSize, int zSize) {
if (biomeArrayZoomedOut == null || biomeArrayZoomedOut.length < xSize * zSize) {
biomeArrayZoomedOut = new Biome[xSize * zSize];
}
// Transform to normal scale
int xStartBlock = (xStart + 2) * 4;
int zStartBlock = (zStart + 2) * 4;
int xSizeBlock = xSize * 4;
int zSizeBlock = zSize * 4;
// Get biomes
ObjectArrayMutableBiomeBuffer buffer = getBiomeBuffer(xStartBlock, zStartBlock, xSizeBlock, zSizeBlock);
this.biomeGenerator.generateBiomes(buffer);
// Downscale
for (int i = 0; i < biomeArrayZoomedOut.length; i++) {
int x = i % xSize;
int z = i / xSize;
Biome type = buffer.getNativeBiome(x * 4, 0, z * 4);
biomeArrayZoomedOut[i] = type;
}
return biomeArrayZoomedOut;
}
use of org.spongepowered.common.util.gen.ObjectArrayMutableBiomeBuffer in project SpongeCommon by SpongePowered.
the class CustomBiomeProvider method areBiomesViable.
@Override
public boolean areBiomesViable(int xCenter, int zCenter, int range, @SuppressWarnings("rawtypes") List searchingForBiomes) {
IntCache.resetIntCache();
int xStartSegment = xCenter - range;
int zStartSegment = zCenter - range;
int xMaxSegment = xCenter + range;
int zMaxSegment = zCenter + range;
int xSizeSegments = xMaxSegment - xStartSegment + 1;
int zSizeSegments = zMaxSegment - zStartSegment + 1;
ObjectArrayMutableBiomeBuffer buffer = getBiomeBuffer(xStartSegment, zStartSegment, xSizeSegments, zSizeSegments);
this.biomeGenerator.generateBiomes(buffer);
for (int x = xStartSegment; x < xMaxSegment; x++) {
for (int z = zStartSegment; z < zMaxSegment; z++) {
Biome type = buffer.getNativeBiome(x, 0, z);
if (!searchingForBiomes.contains(type)) {
return false;
}
}
}
return true;
}
Aggregations