use of org.terasology.world.chunks.CoreChunk in project Terasology by MovingBlocks.
the class FloraRasterizer method generateChunk.
@Override
public void generateChunk(CoreChunk chunk, Region chunkRegion) {
FloraFacet facet = chunkRegion.getFacet(FloraFacet.class);
WhiteNoise noise = new WhiteNoise(chunk.getPosition().hashCode());
Map<BaseVector3i, FloraType> entries = facet.getRelativeEntries();
// check if some other rasterizer has already placed something here
entries.keySet().stream().filter(pos -> chunk.getBlock(pos).equals(air)).forEach(pos -> {
FloraType type = entries.get(pos);
List<Block> list = flora.get(type);
int blockIdx = Math.abs(noise.intNoise(pos.x(), pos.y(), pos.z())) % list.size();
Block block = list.get(blockIdx);
chunk.setBlock(pos, block);
});
}
use of org.terasology.world.chunks.CoreChunk in project Terasology by MovingBlocks.
the class WorldProviderCoreImpl method getLiquid.
@Override
public LiquidData getLiquid(int x, int y, int z) {
Vector3i chunkPos = ChunkMath.calcChunkPos(x, y, z);
CoreChunk chunk = chunkProvider.getChunk(chunkPos);
if (chunk != null) {
Vector3i blockPos = ChunkMath.calcBlockPos(x, y, z);
return chunk.getLiquid(blockPos);
}
return new LiquidData();
}
use of org.terasology.world.chunks.CoreChunk in project Terasology by MovingBlocks.
the class WorldProviderCoreImpl method setLiquid.
@Override
public boolean setLiquid(int x, int y, int z, LiquidData newState, LiquidData oldState) {
Vector3i chunkPos = ChunkMath.calcChunkPos(x, y, z);
CoreChunk chunk = chunkProvider.getChunk(chunkPos);
if (chunk != null) {
Vector3i blockPos = ChunkMath.calcBlockPos(x, y, z);
LiquidData liquidState = chunk.getLiquid(blockPos);
if (liquidState.equals(oldState)) {
chunk.setLiquid(blockPos, newState);
return true;
}
}
return false;
}
use of org.terasology.world.chunks.CoreChunk in project Terasology by MovingBlocks.
the class WorldProviderCoreImpl method setBlock.
@Override
public Block setBlock(Vector3i worldPos, Block type) {
/*
* Hint: This method has a benchmark available in the BenchmarkScreen, The screen can be opened ingame via the
* command "showSCreen BenchmarkScreen".
*/
Vector3i chunkPos = ChunkMath.calcChunkPos(worldPos);
CoreChunk chunk = chunkProvider.getChunk(chunkPos);
if (chunk != null) {
Vector3i blockPos = ChunkMath.calcBlockPos(worldPos);
Block oldBlockType = chunk.setBlock(blockPos, type);
if (oldBlockType != type) {
BlockChange oldChange = blockChanges.get(worldPos);
if (oldChange == null) {
blockChanges.put(worldPos, new BlockChange(worldPos, oldBlockType, type));
} else {
oldChange.setTo(type);
}
for (Vector3i pos : ChunkMath.getChunkRegionAroundWorldPos(worldPos, 1)) {
RenderableChunk dirtiedChunk = chunkProvider.getChunk(pos);
if (dirtiedChunk != null) {
dirtiedChunk.setDirty(true);
}
}
notifyBlockChanged(worldPos, type, oldBlockType);
}
return oldBlockType;
}
return null;
}
use of org.terasology.world.chunks.CoreChunk in project Terasology by MovingBlocks.
the class WorldProviderCoreImpl method setBiome.
@Override
public Biome setBiome(Vector3i worldPos, Biome biome) {
Vector3i chunkPos = ChunkMath.calcChunkPos(worldPos);
CoreChunk chunk = chunkProvider.getChunk(chunkPos);
if (chunk != null) {
Vector3i blockPos = ChunkMath.calcBlockPos(worldPos);
Biome oldBiomeType = chunk.setBiome(blockPos.x, blockPos.y, blockPos.z, biome);
if (oldBiomeType != biome) {
BiomeChange oldChange = biomeChanges.get(worldPos);
if (oldChange == null) {
biomeChanges.put(worldPos, new BiomeChange(worldPos, oldBiomeType, biome));
} else {
oldChange.setTo(biome);
}
for (Vector3i pos : ChunkMath.getChunkRegionAroundWorldPos(worldPos, 1)) {
RenderableChunk dirtiedChunk = chunkProvider.getChunk(pos);
if (dirtiedChunk != null) {
dirtiedChunk.setDirty(true);
}
}
notifyBiomeChanged(worldPos, biome, oldBiomeType);
}
return oldBiomeType;
}
return null;
}
Aggregations