use of org.terasology.engine.world.propagation.BlockChange 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;
}
use of org.terasology.engine.world.propagation.BlockChange 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;
}
Aggregations