use of cn.nukkit.level.format.generic.BaseFullChunk in project Nukkit by Nukkit.
the class GenerationTask method onCompletion.
@Override
public void onCompletion(Server server) {
Level level = server.getLevel(this.levelId);
if (level != null) {
if (!this.state) {
level.registerGenerator();
return;
}
BaseFullChunk chunk = this.chunk.clone();
if (chunk == null) {
return;
}
level.generateChunkCallback(chunk.getX(), chunk.getZ(), chunk);
}
}
use of cn.nukkit.level.format.generic.BaseFullChunk in project Nukkit by Nukkit.
the class GenerationTask method onRun.
@Override
public void onRun() {
Generator generator = GeneratorPool.get(this.levelId);
if (generator == null) {
this.state = false;
return;
}
SimpleChunkManager manager = (SimpleChunkManager) generator.getChunkManager();
if (manager == null) {
this.state = false;
return;
}
synchronized (manager) {
BaseFullChunk chunk = this.chunk.clone();
if (chunk == null) {
return;
}
manager.setChunk(chunk.getX(), chunk.getZ(), chunk);
generator.generateChunk(chunk.getX(), chunk.getZ());
chunk = manager.getChunk(chunk.getX(), chunk.getZ());
chunk.setGenerated();
this.chunk = chunk.clone();
manager.setChunk(chunk.getX(), chunk.getZ(), null);
}
}
use of cn.nukkit.level.format.generic.BaseFullChunk in project Nukkit by Nukkit.
the class LightPopulationTask method onCompletion.
@Override
public void onCompletion(Server server) {
Level level = server.getLevel(this.levelId);
BaseFullChunk chunk = this.chunk.clone();
if (level != null) {
if (chunk == null) {
return;
}
level.generateChunkCallback(chunk.getX(), chunk.getZ(), chunk);
}
}
use of cn.nukkit.level.format.generic.BaseFullChunk in project Nukkit by Nukkit.
the class PopulationTask method onRun.
@Override
public void onRun() {
Generator generator = GeneratorPool.get(this.levelId);
if (generator == null) {
this.state = false;
return;
}
SimpleChunkManager manager = (SimpleChunkManager) generator.getChunkManager();
if (manager == null) {
this.state = false;
return;
}
synchronized (generator.getChunkManager()) {
BaseFullChunk[] chunks = new BaseFullChunk[9];
BaseFullChunk chunk = this.chunk.clone();
if (chunk == null) {
return;
}
for (int i = 0; i < 9; i++) {
if (i == 4) {
continue;
}
int xx = -1 + i % 3;
int zz = -1 + (i / 3);
BaseFullChunk ck = this.chunks[i];
if (ck == null) {
try {
chunks[i] = (BaseFullChunk) this.chunk.getClass().getMethod("getEmptyChunk", int.class, int.class).invoke(null, chunk.getX() + xx, chunk.getZ() + zz);
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
chunks[i] = ck.clone();
}
}
manager.setChunk(chunk.getX(), chunk.getZ(), chunk);
if (!chunk.isGenerated()) {
generator.generateChunk(chunk.getX(), chunk.getZ());
chunk.setGenerated();
}
for (BaseFullChunk c : chunks) {
if (c != null) {
manager.setChunk(c.getX(), c.getZ(), c);
if (!c.isGenerated()) {
generator.generateChunk(c.getX(), c.getZ());
c = manager.getChunk(c.getX(), c.getZ());
c.setGenerated();
manager.setChunk(c.getX(), c.getZ(), c);
}
}
}
generator.populateChunk(chunk.getX(), chunk.getZ());
chunk = manager.getChunk(chunk.getX(), chunk.getZ());
chunk.recalculateHeightMap();
chunk.populateSkyLight();
chunk.setLightPopulated();
chunk.setPopulated();
this.chunk = chunk.clone();
manager.setChunk(chunk.getX(), chunk.getZ(), null);
for (int i = 0; i < chunks.length; i++) {
if (i == 4) {
continue;
}
BaseFullChunk c = chunks[i];
if (c != null) {
c = chunks[i] = manager.getChunk(c.getX(), c.getZ());
if (!c.hasChanged()) {
chunks[i] = null;
}
}
}
manager.cleanChunks();
for (int i = 0; i < 9; i++) {
if (i == 4) {
continue;
}
this.chunks[i] = chunks[i] != null ? chunks[i].clone() : null;
}
}
}
use of cn.nukkit.level.format.generic.BaseFullChunk in project Nukkit by Nukkit.
the class PopulatorGlowStone method populate.
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
this.level = level;
BaseFullChunk chunk = level.getChunk(chunkX, chunkZ);
int bx = chunkX << 4;
int bz = chunkZ << 4;
int tx = bx + 15;
int tz = bz + 15;
ObjectOre ore = new ObjectOre(random, type, Block.AIR);
for (int i = 0; i < ore.type.clusterCount; ++i) {
int x = random.nextRange(0, 15);
int z = random.nextRange(0, 15);
int y = this.getHighestWorkableBlock(chunk, x, z);
if (y != -1) {
ore.placeObject(level, bx + x, y, bz + z);
}
}
}
Aggregations