Class: RubyCraft::ChunkCube

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rubycraft/region.rb

Instance Method Summary collapse

Constructor Details

#initialize(region, initialPos, width, length, height) ⇒ ChunkCube

width corresponds do z, length to x, and height to y.



217
218
219
220
221
222
223
# File 'lib/rubycraft/region.rb', line 217

def initialize(region, initialPos, width, length, height)
  @region = region
  @initialPos = initialPos
  @width = width || 1
  @length = length || 1
  @height = height || 1
end

Instance Method Details

#each(&block) ⇒ Object



225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/rubycraft/region.rb', line 225

def each(&block)
  z, x, y = @initialPos
  firstChunkX = x / chunkSide
  firstChunkZ = z / chunkSide
  lastChunkX = (x + @length - 1) / chunkSide
  lastChunkZ = (z + @width - 1) / chunkSide
  for j in firstChunkZ..lastChunkZ
    for i in firstChunkX..lastChunkX
      iterateOverChunk j, i, &block
    end
  end
end