def populate(self, chunk, seed): """ Place saplings. The algorithm used to pick locations for the saplings is quite simple, although slightly involved. The basic technique is to calculate a Morton number for every xz-column in the chunk, and then use coprime offsets to sprinkle selected points fairly evenly throughout the chunk. Saplings are only placed on dirt and grass blocks. """ R.seed(seed) factors = R.choice(list(combinations(self.primes, 3))) for x, z in product(xrange(16), repeat=2): # Make a Morton number. morton = morton2(chunk.x * 16 + x, chunk.z * 16 + z) if not all(morton % factor for factor in factors): # Plant a sapling. y = chunk.height_at(x, z) if chunk.get_block((x, y, z)) in self.ground: chunk.set_block((x, y + 1, z), blocks["sapling"].slot)
def populate(self, chunk, seed): """ Place saplings. The algorithm used to pick locations for the saplings is quite simple, although slightly involved. The basic technique is to calculate a Morton number for every xz-column in the chunk, and then use coprime offsets to sprinkle selected points fairly evenly throughout the chunk. Saplings are only placed on dirt and grass blocks. """ R.seed(seed) factors = R.choice(list(combinations(self.primes, 3))) for x, z in XZ: # Make a Morton number. morton = morton2(chunk.x * 16 + x, chunk.z * 16 + z) if not all(morton % factor for factor in factors): # Magic number is how many tree types are available species = morton % 4 # Plant a sapling. y = chunk.height_at(x, z) if chunk.get_block((x, y, z)) in self.ground: chunk.set_block((x, y + 1, z), blocks["sapling"].slot) chunk.set_metadata((x, y + 1, z), species)
def test_second_full(self): self.assertEqual(morton2(0x0, 0xffff), 0xaaaaaaaa)
def test_first_full(self): self.assertEqual(morton2(0xffff, 0x0), 0x55555555)
def test_second(self): self.assertEqual(morton2(0, 1), 2)
def test_first(self): self.assertEqual(morton2(1, 0), 1)
def test_zero(self): self.assertEqual(morton2(0, 0), 0)
def test_first(self): self.assertEqual(morton2(1, 0), 1)
def test_zero(self): self.assertEqual(morton2(0, 0), 0)
def test_second_full(self): self.assertEqual(morton2(0x0, 0xffff), 0xaaaaaaaa)
def test_first_full(self): self.assertEqual(morton2(0xffff, 0x0), 0x55555555)
def test_second(self): self.assertEqual(morton2(0, 1), 2)