use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class SunlightRegenBatchPropagator method propagateSweep.
private void propagateSweep(LitChunk fromChunk, LitChunk toChunk, int[] depth, int[] startingRegen) {
Vector3i pos = new Vector3i();
for (int z = 0; z < ChunkConstants.SIZE_Z; ++z) {
for (int x = 0; x < ChunkConstants.SIZE_X; ++x) {
int depthIndex = x + ChunkConstants.SIZE_X * z;
startingRegen[depthIndex] = regenRules.getValue(fromChunk, new Vector3i(x, 0, z));
byte expectedValue = (byte) Math.min(startingRegen[depthIndex] + 1, ChunkConstants.MAX_SUNLIGHT_REGEN);
Block fromBlock = fromChunk.getBlock(x, 0, z);
Block toBlock = toChunk.getBlock(x, ChunkConstants.SIZE_Y - 1, z);
if (!(regenRules.canSpreadOutOf(fromBlock, Side.BOTTOM) && regenRules.canSpreadInto(toBlock, Side.TOP))) {
continue;
}
byte predictedValue = 0;
pos.set(x, ChunkConstants.SIZE_Y - 1, z);
int currentValue = regenRules.getValue(toChunk, pos);
while (currentValue == predictedValue && expectedValue > currentValue) {
regenRules.setValue(toChunk, pos, expectedValue);
depth[depthIndex]++;
byte sunlight = (byte) (expectedValue - ChunkConstants.SUNLIGHT_REGEN_THRESHOLD);
if (sunlight > 0 && sunlight > toChunk.getSunlight(pos)) {
toChunk.setSunlight(pos, sunlight);
}
if (expectedValue < ChunkConstants.MAX_SUNLIGHT_REGEN) {
expectedValue++;
}
predictedValue++;
pos.y--;
currentValue = regenRules.getValue(toChunk, pos);
}
}
}
}
use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class InternalLightProcessor method populateSunlight.
private static void populateSunlight(LitChunk chunk) {
PropagationRules sunlightRules = new SunlightPropagationRules(chunk);
BatchPropagator lightPropagator = new StandardBatchPropagator(sunlightRules, new SingleChunkView(sunlightRules, chunk));
for (int x = 0; x < ChunkConstants.SIZE_X; x++) {
for (int z = 0; z < ChunkConstants.SIZE_Z; z++) {
for (int y = 0; y < ChunkConstants.MAX_SUNLIGHT; ++y) {
Vector3i pos = new Vector3i(x, y, z);
Block block = chunk.getBlock(x, y, z);
byte light = sunlightRules.getFixedValue(block, pos);
if (light > 0) {
chunk.setSunlight(x, y, z, light);
lightPropagator.propagateFrom(pos, light);
}
}
}
}
lightPropagator.process();
}
use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class InternalLightProcessor method populateLight.
private static void populateLight(LitChunk chunk) {
BatchPropagator lightPropagator = new StandardBatchPropagator(LIGHT_RULES, new SingleChunkView(LIGHT_RULES, chunk));
for (int x = 0; x < ChunkConstants.SIZE_X; x++) {
for (int z = 0; z < ChunkConstants.SIZE_Z; z++) {
for (int y = 0; y < ChunkConstants.SIZE_Y; y++) {
Block block = chunk.getBlock(x, y, z);
if (block.getLuminance() > 0) {
chunk.setLight(x, y, z, block.getLuminance());
lightPropagator.propagateFrom(new Vector3i(x, y, z), block.getLuminance());
}
}
}
}
lightPropagator.process();
}
use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class Zone method generateChunk.
/**
* Generate the chunk for this zone, based on the rasterizers and nested zones that have been added.
*
* This will only change blocks for which {@link #containsBlock(int, int, int, Region)} returns true.
*
* @see WorldRasterizer#generateChunk(CoreChunk, Region)
*/
@Override
public void generateChunk(CoreChunk chunk, Region chunkRegion) {
Block[][][] savedBlocks = new Block[SIZE_X][SIZE_Y][SIZE_Z];
boolean changeAllBlocks = true;
boolean saveAllBlocks = true;
int offsetX = chunk.getChunkWorldOffsetX();
int offsetY = chunk.getChunkWorldOffsetY();
int offsetZ = chunk.getChunkWorldOffsetZ();
// Save the blocks that aren't in the zone
for (int x = 0; x < SIZE_X; x++) {
for (int y = 0; y < SIZE_Y; y++) {
for (int z = 0; z < SIZE_Z; z++) {
if (!containsBlock(x + offsetX, y + offsetY, z + offsetZ, chunkRegion)) {
savedBlocks[x][y][z] = chunk.getBlock(x, y, z);
changeAllBlocks = false;
} else {
saveAllBlocks = false;
}
}
}
}
// If none of the blocks are in the zone, it doesn't need to be rasterized
if (!saveAllBlocks) {
// Rasterize the zone
rasterizers.forEach(r -> r.generateChunk(chunk, chunkRegion));
// Replace any blocks that aren't in the zone
if (!changeAllBlocks) {
for (int x = 0; x < SIZE_X; x++) {
for (int y = 0; y < SIZE_Y; y++) {
for (int z = 0; z < SIZE_Z; z++) {
Block block = savedBlocks[x][y][z];
if (block != null) {
chunk.setBlock(x, y, z, block);
}
}
}
}
}
}
}
use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class NetClient method sendRegisteredBlocks.
private void sendRegisteredBlocks(NetData.NetMessage.Builder message) {
synchronized (newlyRegisteredFamilies) {
for (BlockFamily family : newlyRegisteredFamilies) {
NetData.BlockFamilyRegisteredMessage.Builder blockRegMessage = NetData.BlockFamilyRegisteredMessage.newBuilder();
for (Block block : family.getBlocks()) {
blockRegMessage.addBlockUri(block.getURI().toString());
blockRegMessage.addBlockId(block.getId());
}
message.addBlockFamilyRegistered(blockRegMessage);
}
newlyRegisteredFamilies.clear();
}
}
Aggregations