当前位置: 首页>>代码示例>>Python>>正文


Python Chunk.get_block方法代码示例

本文整理汇总了Python中bravo.chunk.Chunk.get_block方法的典型用法代码示例。如果您正苦于以下问题:Python Chunk.get_block方法的具体用法?Python Chunk.get_block怎么用?Python Chunk.get_block使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bravo.chunk.Chunk的用法示例。


在下文中一共展示了Chunk.get_block方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestAlphaSandGravelDig

# 需要导入模块: from bravo.chunk import Chunk [as 别名]
# 或者: from bravo.chunk.Chunk import get_block [as 别名]
class TestAlphaSandGravelDig(unittest.TestCase):

    def setUp(self):
        self.f = FallablesMockFactory()
        self.p = retrieve_plugins(IDigHook, parameters={"factory": self.f})

        if "alpha_sand_gravel" not in self.p:
            raise unittest.SkipTest("Plugin not present")

        self.hook = self.p["alpha_sand_gravel"]
        self.c = Chunk(0, 0)

    def test_trivial(self):
        pass

    def test_floating_sand(self):
        """
        Sand placed in midair should fall down to the ground.
        """

        self.c.set_block((0, 1, 0), blocks["sand"].slot)

        self.hook.dig_hook(self.c, 0, 0, 0, blocks["air"].slot)

        self.assertEqual(self.c.get_block((0, 1, 0)), blocks["air"].slot)
        self.assertEqual(self.c.get_block((0, 0, 0)), blocks["sand"].slot)

    def test_sand_on_snow(self):
        """
        Sand placed on snow should replace the snow.

        Test for #298.
        """

        self.c.set_block((0, 1, 0), blocks["sand"].slot)
        self.c.set_block((0, 0, 0), blocks["snow"].slot)

        self.hook.dig_hook(self.c, 0, 2, 0, blocks["snow"].slot)

        self.assertEqual(self.c.get_block((0, 1, 0)), blocks["air"].slot)
        self.assertEqual(self.c.get_block((0, 0, 0)), blocks["sand"].slot)

    def test_sand_on_water(self):
        """
        Sand placed on water should replace the water.

        Test for #317.
        """

        self.c.set_block((0, 1, 0), blocks["sand"].slot)
        self.c.set_block((0, 0, 0), blocks["spring"].slot)

        self.hook.dig_hook(self.c, 0, 2, 0, blocks["spring"].slot)

        self.assertEqual(self.c.get_block((0, 1, 0)), blocks["air"].slot)
        self.assertEqual(self.c.get_block((0, 0, 0)), blocks["sand"].slot)
开发者ID:JDShu,项目名称:bravo,代码行数:58,代码来源:test_fallables.py

示例2: TestGenerators

# 需要导入模块: from bravo.chunk import Chunk [as 别名]
# 或者: from bravo.chunk.Chunk import get_block [as 别名]
class TestGenerators(unittest.TestCase):

    def setUp(self):
        self.chunk = Chunk(0, 0)

        self.p = bravo.plugin.retrieve_plugins(bravo.ibravo.ITerrainGenerator)

    def test_trivial(self):
        pass

    def test_boring(self):
        if "boring" not in self.p:
            raise unittest.SkipTest("plugin not present")

        plugin = self.p["boring"]

        plugin.populate(self.chunk, 0)
        for x, z, y in iterchunk():
            if y < CHUNK_HEIGHT // 2:
                self.assertEqual(self.chunk.get_block((x, y, z)),
                    bravo.blocks.blocks["stone"].slot)
            else:
                self.assertEqual(self.chunk.get_block((x, y, z)),
                    bravo.blocks.blocks["air"].slot)

    def test_beaches_range(self):
        if "beaches" not in self.p:
            raise unittest.SkipTest("plugin not present")

        plugin = self.p["beaches"]

        # Prepare chunk.
        for i in range(5):
            self.chunk.set_block((i, 61 + i, i),
                                 bravo.blocks.blocks["dirt"].slot)

        plugin.populate(self.chunk, 0)
        for i in range(5):
            self.assertEqual(self.chunk.get_block((i, 61 + i, i)),
                bravo.blocks.blocks["sand"].slot,
                "%d, %d, %d is wrong" % (i, 61 + i, i))

    def test_beaches_immersed(self):
        """
        Test that beaches still generate properly around pre-existing water
        tables.

        This test is meant to ensure that the order of beaches and watertable
        does not matter.
        """

        if "beaches" not in self.p:
            raise unittest.SkipTest("plugin not present")

        plugin = self.p["beaches"]

        # Prepare chunk.
        for x, z, y in product(xrange(16), xrange(16), xrange(60, 64)):
            self.chunk.set_block((x, y, z),
                                 bravo.blocks.blocks["spring"].slot)
        for i in range(5):
            self.chunk.set_block((i, 61 + i, i),
                                 bravo.blocks.blocks["dirt"].slot)

        plugin.populate(self.chunk, 0)
        for i in range(5):
            self.assertEqual(self.chunk.get_block((i, 61 + i, i)),
                bravo.blocks.blocks["sand"].slot,
                "%d, %d, %d is wrong" % (i, 61 + i, i))
开发者ID:KingPsychopath,项目名称:bravo,代码行数:71,代码来源:test_generators.py

示例3: TestChunkBlocks

# 需要导入模块: from bravo.chunk import Chunk [as 别名]
# 或者: from bravo.chunk.Chunk import get_block [as 别名]
class TestChunkBlocks(unittest.TestCase):

    def setUp(self):
        self.c = Chunk(0, 0)

    def test_trivial(self):
        pass

    def test_set_block(self):
        self.assertEqual(self.c.blocks[0], 0)
        self.c.set_block((0, 0, 0), 1)
        self.assertEqual(self.c.blocks[0], 1)

    def test_set_block_xyz_xzy(self):
        """
        Test that set_block swizzles correctly.
        """

        self.c.set_block((1, 0, 0), 1)
        self.c.set_block((0, 1, 0), 2)
        self.c.set_block((0, 0, 1), 3)
        self.assertEqual(self.c.blocks[2048], 1)
        self.assertEqual(self.c.blocks[1], 2)
        self.assertEqual(self.c.blocks[128], 3)

    def test_destroy(self):
        """
        Test block destruction.
        """

        self.c.set_block((0, 0, 0), 1)
        self.c.set_metadata((0, 0, 0), 1)
        self.c.destroy((0, 0, 0))
        self.assertEqual(self.c.blocks[0], 0)
        self.assertEqual(self.c.metadata[0], 0)

    def test_sed(self):
        """
        ``sed()`` should work.
        """

        self.c.set_block((1, 1, 1), 1)
        self.c.set_block((2, 2, 2), 2)
        self.c.set_block((3, 3, 3), 3)

        self.c.sed(1, 3)

        self.assertEqual(self.c.get_block((1, 1, 1)), 3)
        self.assertEqual(self.c.get_block((2, 2, 2)), 2)
        self.assertEqual(self.c.get_block((3, 3, 3)), 3)

    def test_single_block_damage_packet(self):
        chunk = Chunk(2, 1)
        chunk.populated = True
        chunk.set_block((2, 4, 8), 1)
        chunk.set_metadata((2, 4, 8), 2)
        packet = chunk.get_damage_packet()
        self.assertEqual(packet, '\x35\x00\x00\x00\x22\x04\x00\x00\x00\x18\x01\x02')

    def test_set_block_correct_heightmap(self):
        """
        Test heightmap update for a single column.
        """

        self.c.populated = True

        self.assertEqual(self.c.heightmap[0], 0)
        self.c.set_block((0, 20, 0), 1)
        self.assertEqual(self.c.heightmap[0], 20)

        self.c.set_block((0, 10, 0), 1)
        self.assertEqual(self.c.heightmap[0], 20)

        self.c.set_block((0, 30, 0), 1)
        self.assertEqual(self.c.heightmap[0], 30)

        self.c.destroy((0, 10, 0))
        self.assertEqual(self.c.heightmap[0], 30)

        self.c.destroy((0, 30, 0))
        self.assertEqual(self.c.heightmap[0], 20)
开发者ID:miea,项目名称:bravo,代码行数:83,代码来源:test_chunk.py

示例4: TestWinter

# 需要导入模块: from bravo.chunk import Chunk [as 别名]
# 或者: from bravo.chunk.Chunk import get_block [as 别名]
class TestWinter(unittest.TestCase):

    def setUp(self):
        self.hook = Winter()
        self.c = Chunk(0, 0)

    def test_trivial(self):
        pass

    def test_spring_to_ice(self):
        self.c.set_block((0, 0, 0), blocks["spring"].slot)
        self.hook.transform(self.c)
        self.assertEqual(self.c.get_block((0, 0, 0)), blocks["ice"].slot)

    def test_snow_on_stone(self):
        self.c.set_block((0, 0, 0), blocks["stone"].slot)
        self.hook.transform(self.c)
        self.assertEqual(self.c.get_block((0, 1, 0)), blocks["snow"].slot)

    def test_no_snow_on_snow(self):
        """
        Test whether snow is spawned on top of other snow.
        """

        self.c.set_block((0, 0, 0), blocks["snow"].slot)
        self.hook.transform(self.c)
        self.assertNotEqual(self.c.get_block((0, 1, 0)), blocks["snow"].slot)

    def test_no_floating_snow(self):
        """
        Test whether snow is spawned in the correct y-level over populated
        chunks.
        """

        self.c.set_block((0, 0, 0), blocks["grass"].slot)
        self.c.populated = True
        self.c.dirty = False
        self.c.clear_damage()
        self.hook.transform(self.c)
        self.assertEqual(self.c.get_block((0, 1, 0)), blocks["snow"].slot)
        self.assertNotEqual(self.c.get_block((0, 2, 0)), blocks["snow"].slot)

    def test_bad_heightmap_floating_snow(self):
        """
        Test whether snow is spawned in the correct y-level over populated
        chunks, if the heightmap is incorrect.
        """

        self.c.set_block((0, 0, 0), blocks["grass"].slot)
        self.c.populated = True
        self.c.dirty = False
        self.c.clear_damage()
        self.c.heightmap[0 * 16 + 0] = 2
        self.hook.transform(self.c)
        self.assertEqual(self.c.get_block((0, 1, 0)), blocks["snow"].slot)
        self.assertNotEqual(self.c.get_block((0, 2, 0)), blocks["snow"].slot)

    def test_top_of_world_snow(self):
        """
        Blocks at the top of the world should not cause exceptions when snow
        is placed on them.
        """

        self.c.set_block((0, 127, 0), blocks["stone"].slot)
        self.hook.transform(self.c)
开发者ID:dkkline,项目名称:bravo,代码行数:67,代码来源:test_seasons.py

示例5: TestChunkBlocks

# 需要导入模块: from bravo.chunk import Chunk [as 别名]
# 或者: from bravo.chunk.Chunk import get_block [as 别名]
class TestChunkBlocks(unittest.TestCase):

    def setUp(self):
        self.c = Chunk(0, 0)

    def test_trivial(self):
        pass

    def test_destroy(self):
        """
        Test block destruction.
        """

        self.c.set_block((0, 0, 0), 1)
        self.c.set_metadata((0, 0, 0), 1)
        self.c.destroy((0, 0, 0))
        self.assertEqual(self.c.get_block((0, 0, 0)), 0)
        self.assertEqual(self.c.get_metadata((0, 0, 0)), 0)

    def test_sed(self):
        """
        ``sed()`` should work.
        """

        self.c.set_block((1, 1, 1), 1)
        self.c.set_block((2, 2, 2), 2)
        self.c.set_block((3, 3, 3), 3)

        self.c.sed(1, 3)

        self.assertEqual(self.c.get_block((1, 1, 1)), 3)
        self.assertEqual(self.c.get_block((2, 2, 2)), 2)
        self.assertEqual(self.c.get_block((3, 3, 3)), 3)

    def test_set_block_heightmap(self):
        """
        Heightmaps work.
        """

        self.c.populated = True

        self.c.set_block((0, 20, 0), 1)
        self.assertEqual(self.c.heightmap[0], 20)

    def test_set_block_heightmap_underneath(self):
        """
        A block placed underneath the highest block will not alter the
        heightmap.
        """

        self.c.populated = True

        self.c.set_block((0, 20, 0), 1)
        self.assertEqual(self.c.heightmap[0], 20)

        self.c.set_block((0, 10, 0), 1)
        self.assertEqual(self.c.heightmap[0], 20)

    def test_set_block_heightmap_destroyed(self):
        """
        Upon destruction of the highest block, the heightmap will point at the
        next-highest block.
        """

        self.c.populated = True

        self.c.set_block((0, 30, 0), 1)
        self.c.set_block((0, 10, 0), 1)
        self.c.destroy((0, 30, 0))
        self.assertEqual(self.c.heightmap[0], 10)
开发者ID:MartysTardis,项目名称:bravo,代码行数:72,代码来源:test_chunk.py


注:本文中的bravo.chunk.Chunk.get_block方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。