@@ -143,7 +143,7 @@ public class World {
143
143
chunk. setBlockId ( at: position. relativeToChunk, to: state)
144
144
lightingEngine. updateLighting ( at: position, in: self )
145
145
146
- eventBus. dispatch ( Event . SetBlock (
146
+ eventBus. dispatch ( Event . SingleBlockUpdate (
147
147
position: position,
148
148
newState: state
149
149
) )
@@ -157,27 +157,36 @@ public class World {
157
157
/// Using this method is preferred over just using setBlockId within a for loop because it
158
158
/// processes lighting updates in batch which is much more efficient.
159
159
/// - Parameters:
160
- /// - chunk: The position of the chunk that all of the updates are in.
161
160
/// - updates: The positions and new states of affected blocks.
162
- public func processMultiBlockChange(
163
- at chunkPosition: ChunkPosition ,
164
- _ updates: [ ( position: BlockPosition , state: Int ) ]
161
+ /// - chunkPosition: If all updates occur within a single chunk provide this parameter for more
162
+ /// efficient batching.
163
+ public func processMultiBlockUpdate(
164
+ _ updates: [ Event . SingleBlockUpdate ] ,
165
+ inChunkAt chunkPosition: ChunkPosition ? = nil
165
166
) {
166
- if let chunk = chunk ( at: chunkPosition) {
167
- for (position, state) in updates {
168
- chunk. setBlockId ( at: position. relativeToChunk, to: state)
169
- }
170
- lightingEngine. updateLighting ( at: updates. map ( \. position) , in: self )
171
-
172
- for (position, state) in updates {
173
- eventBus. dispatch ( Event . SetBlock (
174
- position: position,
175
- newState: state
176
- ) )
167
+ if let chunkPosition = chunkPosition {
168
+ if let chunk = chunk ( at: chunkPosition) {
169
+ for update in updates {
170
+ chunk. setBlockId ( at: update. position. relativeToChunk, to: update. newState)
171
+ }
172
+ lightingEngine. updateLighting ( at: updates. map ( \. position) , in: self )
173
+ } else {
174
+ log. warning ( " Cannot handle multi-block change in non-existent chunk, chunkPosition= \( chunkPosition) " )
175
+ return
177
176
}
178
177
} else {
179
- log. warning ( " Cannot handle multi-block change in non-existent chunk, chunkPosition= \( chunkPosition) " )
178
+ for update in updates {
179
+ if let chunk = chunk ( at: update. position. chunk) {
180
+ chunk. setBlockId ( at: update. position. relativeToChunk, to: update. newState)
181
+ } else {
182
+ log. warning ( " Cannot handle multi-block change in non-existent chunk, chunkPosition= \( update. position. chunk) " )
183
+ return
184
+ }
185
+ }
186
+ lightingEngine. updateLighting ( at: updates. map ( \. position) , in: self )
180
187
}
188
+
189
+ eventBus. dispatch ( Event . MultiBlockUpdate ( updates: updates) )
181
190
}
182
191
183
192
/// Get the block id of the block at the specified position.
0 commit comments