use of org.terasology.engine.world.block.Block in project Terasology by MovingBlocks.
the class SunlightRegenBatchPropagator method push.
private void push(Vector3ic pos, byte value) {
byte regenValue = value;
Block block = regenWorld.getBlockAt(pos);
Vector3i position = new Vector3i(pos);
while (regenRules.canSpreadOutOf(block, Side.BOTTOM)) {
regenValue = regenRules.propagateValue(regenValue, Side.BOTTOM, block, 1);
position.y -= 1;
byte adjValue = regenWorld.getValueAt(position);
if (adjValue < regenValue && adjValue != PropagatorWorldView.UNAVAILABLE) {
block = regenWorld.getBlockAt(position);
if (regenRules.canSpreadInto(block, Side.TOP)) {
regenWorld.setValueAt(position, regenValue);
reduceQueues[adjValue].remove(position);
byte sunlightValue = (byte) (regenValue - Chunks.SUNLIGHT_REGEN_THRESHOLD);
if (sunlightValue > 0) {
byte prevValue = sunlightWorld.getValueAt(position);
if (prevValue < sunlightValue) {
sunlightWorld.setValueAt(position, sunlightValue);
sunlightPropagator.propagateFrom(new Vector3i(position), sunlightValue);
}
}
} else {
break;
}
} else {
break;
}
}
}
use of org.terasology.engine.world.block.Block in project Terasology by MovingBlocks.
the class StandardBatchPropagator method propagateSide.
private void propagateSide(Chunk chunk, Chunk adjChunk, Side side, Function<Vector3ic, Integer> indexProvider, BlockRegionc edgeRegion, int[] depths) {
Vector3i adjPos = new Vector3i();
for (Vector3ic pos : edgeRegion) {
byte expectedValue = (byte) (rules.getValue(chunk, pos) - 1);
if (expectedValue < 1) {
continue;
}
pos.add(chunkEdgeDeltas.get(side), adjPos);
int depthIndex = indexProvider.apply(pos);
int depth = 0;
Block lastBlock = chunk.getBlock(pos);
byte adjValue = rules.getValue(adjChunk, adjPos);
while (expectedValue > adjValue && adjValue != PropagatorWorldView.UNAVAILABLE && rules.canSpreadOutOf(lastBlock, side)) {
lastBlock = adjChunk.getBlock(adjPos);
if (rules.canSpreadInto(lastBlock, side.reverse())) {
rules.setValue(adjChunk, adjPos, expectedValue);
adjPos.add(side.direction());
depth++;
expectedValue--;
adjValue = rules.getValue(adjChunk, adjPos);
} else {
break;
}
}
depths[depthIndex] = depth;
}
}
use of org.terasology.engine.world.block.Block in project Terasology by MovingBlocks.
the class StandardBatchPropagator method push.
/**
* Propagates a value from a position out into all adjacent blocks.
* <p>
* If the value spreading into a block is larger than the current value there, set it and queue it for propagating
* again If the value is smaller than the current value, do nothing
*
* @param pos The initial position
* @param value The value to propagate
*/
private void push(Vector3ic pos, byte value) {
Block block = world.getBlockAt(pos);
Vector3i adjPos = new Vector3i();
for (Side side : Side.values()) {
byte propagatedValue = rules.propagateValue(value, side, block, scale);
if (rules.canSpreadOutOf(block, side)) {
side.getAdjacentPos(pos, adjPos);
byte adjValue = world.getValueAt(adjPos);
if (adjValue < propagatedValue && adjValue != PropagatorWorldView.UNAVAILABLE) {
Block adjBlock = world.getBlockAt(adjPos);
if (rules.canSpreadInto(adjBlock, side.reverse())) {
increase(adjPos, propagatedValue);
}
}
}
}
}
use of org.terasology.engine.world.block.Block in project Terasology by MovingBlocks.
the class InternalLightProcessor method populateSunlightRegen.
/**
* Sets the initial values for the sunlight regeneration
*
* @param chunk The chunk to populate the regeneration values through
*/
private static void populateSunlightRegen(Chunk chunk, int scale) {
int top = Chunks.SIZE_Y - 1;
/* Scan through each column in the chunk & propagate light from the top down */
for (int x = 0; x < Chunks.SIZE_X; x++) {
for (int z = 0; z < Chunks.SIZE_Z; z++) {
byte regen = chunk.getSunlightRegen(x, top, z);
Block lastBlock = chunk.getBlock(x, top, z);
for (int y = top - 1; y >= 0; y--) {
Block block = chunk.getBlock(x, y, z);
/* If the regeneration can propagate down into this block */
if (SUNLIGHT_REGEN_RULES.canSpreadOutOf(lastBlock, Side.BOTTOM) && SUNLIGHT_REGEN_RULES.canSpreadInto(block, Side.TOP)) {
regen = SUNLIGHT_REGEN_RULES.propagateValue(regen, Side.BOTTOM, lastBlock, scale);
chunk.setSunlightRegen(x, y, z, regen);
} else {
regen = 0;
}
lastBlock = block;
}
}
}
}
use of org.terasology.engine.world.block.Block in project Terasology by MovingBlocks.
the class WorldProviderCoreImpl method setBlocks.
@Override
public Map<Vector3ic, Block> setBlocks(Map<? extends Vector3ic, Block> blocks) {
/*
* Hint: This method has a benchmark available in the BenchmarkScreen, The screen can be opened ingame via the
* command "showSCreen BenchmarkScreen".
*/
Set<BlockChange> changedBlocks = new HashSet<>();
Map<Vector3ic, Block> result = new HashMap<>(blocks.size());
Vector3i chunkPos = new Vector3i();
Vector3i relativePos = new Vector3i();
for (Map.Entry<? extends Vector3ic, Block> entry : blocks.entrySet()) {
Vector3ic worldPos = entry.getKey();
Chunks.toChunkPos(worldPos, chunkPos);
Chunk chunk = chunkProvider.getChunk(chunkPos);
if (chunk != null) {
Block type = entry.getValue();
Chunks.toRelative(worldPos, relativePos);
Block oldBlockType = chunk.setBlock(relativePos, 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);
changedBlocks.add(new BlockChange(worldPos, oldBlockType, type));
}
result.put(worldPos, oldBlockType);
} else {
result.put(worldPos, null);
}
}
for (BlockChange change : changedBlocks) {
notifyBlockChanged(change.getPosition(), change.getTo(), change.getFrom());
}
return result;
}
Aggregations