예제 #1
0
파일: generators.py 프로젝트: driax/bravo
    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)
예제 #2
0
파일: generators.py 프로젝트: tazjel/bravo
    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)
예제 #3
0
 def test_second_full(self):
     self.assertEqual(morton2(0x0, 0xffff), 0xaaaaaaaa)
예제 #4
0
 def test_first_full(self):
     self.assertEqual(morton2(0xffff, 0x0), 0x55555555)
예제 #5
0
 def test_second(self):
     self.assertEqual(morton2(0, 1), 2)
예제 #6
0
 def test_first(self):
     self.assertEqual(morton2(1, 0), 1)
예제 #7
0
 def test_zero(self):
     self.assertEqual(morton2(0, 0), 0)
예제 #8
0
파일: test_maths.py 프로젝트: JDShu/bravo
 def test_first(self):
     self.assertEqual(morton2(1, 0), 1)
예제 #9
0
파일: test_maths.py 프로젝트: JDShu/bravo
 def test_zero(self):
     self.assertEqual(morton2(0, 0), 0)
예제 #10
0
파일: test_maths.py 프로젝트: JDShu/bravo
 def test_second_full(self):
     self.assertEqual(morton2(0x0, 0xffff), 0xaaaaaaaa)
예제 #11
0
파일: test_maths.py 프로젝트: JDShu/bravo
 def test_first_full(self):
     self.assertEqual(morton2(0xffff, 0x0), 0x55555555)
예제 #12
0
파일: test_maths.py 프로젝트: JDShu/bravo
 def test_second(self):
     self.assertEqual(morton2(0, 1), 2)