use of org.terasology.engine.world.block.Block in project Terasology by MovingBlocks.
the class StandardBatchPropagator method purge.
/**
* Reset a position to only it's fixed values
*
* @param pos The position to reset
* @param oldValue The value present before reset
*/
private void purge(Vector3ic pos, byte oldValue) {
increaseQueues[rules.getMaxValue() - oldValue].remove(pos);
/* Clear the value and re-propagate it if it's a positive value */
Block block = world.getBlockAt(pos);
byte fixedValue = rules.getFixedValue(block, pos);
if (fixedValue > 0) {
increase(pos, fixedValue);
} else {
world.setValueAt(pos, NO_VALUE);
}
Vector3i adjPos = new Vector3i();
for (Side side : Side.values()) {
/* Handle this value being reset to the default by updating sides as needed */
byte expectedValue = rules.propagateValue(oldValue, side, block, scale);
if (rules.canSpreadOutOf(block, side)) {
side.getAdjacentPos(pos, adjPos);
byte adjValue = world.getValueAt(adjPos);
if (adjValue == expectedValue) {
Block adjBlock = world.getBlockAt(adjPos);
if (rules.canSpreadInto(adjBlock, side.reverse())) {
reduce(adjPos, expectedValue);
}
} else if (adjValue > 0) {
queueSpreadValue(adjPos, adjValue);
}
}
}
}
use of org.terasology.engine.world.block.Block in project Terasology by MovingBlocks.
the class WorldProviderCoreImpl method setBlock.
@Override
public Block setBlock(Vector3ic 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 = Chunks.toChunkPos(worldPos, new Vector3i());
Chunk chunk = chunkProvider.getChunk(chunkPos);
if (chunk != null) {
Vector3i blockPos = Chunks.toRelative(worldPos, new Vector3i());
Block oldBlockType = chunk.setBlock(blockPos, type);
if (oldBlockType != type) {
BlockChange oldChange = blockChanges.get(worldPos);
if (oldChange == null) {
blockChanges.put(new Vector3i(worldPos), new BlockChange(worldPos, oldBlockType, type));
} else {
oldChange.setTo(type);
}
setDirtyChunksNear(worldPos);
notifyBlockChanged(worldPos, type, oldBlockType);
}
return oldBlockType;
}
return null;
}
use of org.terasology.engine.world.block.Block in project Terasology by MovingBlocks.
the class InternalLightProcessor method populateSunlight.
/**
* Propagate the initial sunlight values out
*
* @param chunk The chunk to set in
*/
private static void populateSunlight(Chunk chunk, int scale) {
PropagationRules sunlightRules = new SunlightPropagationRules(chunk);
BatchPropagator lightPropagator = new StandardBatchPropagator(sunlightRules, new SingleChunkView(sunlightRules, chunk), scale);
Vector3i pos = new Vector3i();
for (int x = 0; x < Chunks.SIZE_X; x++) {
for (int z = 0; z < Chunks.SIZE_Z; z++) {
/* Start at the bottom of the chunk and then move up until the max sunlight level */
for (int y = 0; y < Chunks.SIZE_Y; y++) {
pos.set(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.engine.world.block.Block in project Terasology by MovingBlocks.
the class InternalLightProcessor method populateLight.
/**
* Propagate out light from the initial luminous blocks
*
* @param chunk The chunk to populate through
*/
private static void populateLight(Chunk chunk, int scale) {
BatchPropagator lightPropagator = new StandardBatchPropagator(LIGHT_RULES, new SingleChunkView(LIGHT_RULES, chunk), scale);
Vector3i pos = new Vector3i();
for (int x = 0; x < Chunks.SIZE_X; x++) {
for (int z = 0; z < Chunks.SIZE_Z; z++) {
for (int y = 0; y < Chunks.SIZE_Y; y++) {
Block block = chunk.getBlock(x, y, z);
if (block.getLuminance() > 0) {
chunk.setLight(x, y, z, block.getLuminance());
lightPropagator.propagateFrom(pos.set(x, y, z), block.getLuminance());
}
}
}
}
lightPropagator.process();
}
Aggregations