def test_fill_operation(self): subbox_1 = SelectionBox((1, 70, 3), (5, 71, 5)) selection = SelectionGroup((subbox_1, )) # Start sanity check self.assertEqual( "universal_minecraft:stone", self.world.get_block(1, 70, 3, OVERWORLD).blockstate, ) self.assertEqual( "universal_minecraft:granite[polished=false]", self.world.get_block(1, 70, 5, OVERWORLD).blockstate, ) # End sanity check generator_unpacker( fill( self.world, OVERWORLD, selection, Block.from_string_blockstate("universal_minecraft:stone"), )) self.world.create_undo_point() for x, y, z in selection.blocks: self.assertEqual( "universal_minecraft:stone", self.world.get_block(x, y, z, OVERWORLD).blockstate, f"Failed at coordinate ({x},{y},{z})", ) self.world.undo() self.assertEqual( "universal_minecraft:stone", self.world.get_block(1, 70, 3, OVERWORLD).blockstate, ) self.assertEqual( "universal_minecraft:granite[polished=false]", self.world.get_block(1, 70, 5, OVERWORLD).blockstate, ) self.world.redo() for x, y, z in selection.blocks: self.assertEqual( "universal_minecraft:stone", self.world.get_block(x, y, z, OVERWORLD).blockstate, f"Failed at coordinate ({x},{y},{z})", )
def test_delete_chunk(self): subbox1 = SelectionBox((1, 1, 1), (5, 5, 5)) box1 = SelectionGroup((subbox1, )) self.assertEqual( "universal_minecraft:stone", self.world.get_block(1, 70, 3, OVERWORLD).blockstate, ) self.assertEqual( "universal_minecraft:granite[polished=false]", self.world.get_block(1, 70, 5, OVERWORLD).blockstate, ) generator_unpacker(delete_chunk(self.world, OVERWORLD, box1)) self.world.create_undo_point() with self.assertRaises(ChunkDoesNotExist): _ = self.world.get_block(1, 70, 3, OVERWORLD).blockstate self.assertEqual( 0, len([ x for x in self.world.get_chunk_slice_box( OVERWORLD, subbox1) ]), ) self.world.undo() self.assertEqual( "universal_minecraft:stone", self.world.get_block(1, 70, 3, OVERWORLD).blockstate, ) self.assertEqual( "universal_minecraft:granite[polished=false]", self.world.get_block(1, 70, 5, OVERWORLD).blockstate, ) self.world.redo() with self.assertRaises(ChunkDoesNotExist): _ = self.world.get_block(1, 70, 3, OVERWORLD).blockstate self.assertEqual( 0, len([ x for x in self.world.get_chunk_slice_box( OVERWORLD, subbox1) ]), )
def create_undo_point(self) -> bool: """ Find what has changed since the last undo point and optionally create a new undo point. :return: Was an undo point created. If there were no changes no snapshot will be created. """ return generator_unpacker(self.create_undo_point_iter())
def from_level(cls, level: BaseLevel, selection: SelectionGroup, dimension: Dimension): """ Extract a section of the level into an :class:`ImmutableStructure` class. :param level: The level to extract the area from. :param selection: The selection to extract. :param dimension: The dimension to extract from. :return: The created instance of :class:`ImmutableStructure` """ return generator_unpacker( cls.from_level_iter(level, selection, dimension))
def run_operation(self, operation: OperationType, dimension: Dimension, *args, create_undo=True) -> Any: try: out = operation(self, dimension, *args) if inspect.isgenerator(out): out: Generator out = generator_unpacker(out) except Exception as e: self.restore_last_undo_point() raise e if create_undo: self.create_undo_point() return out
def paste( self, src_structure: "BaseLevel", src_dimension: Dimension, src_selection: SelectionGroup, dst_dimension: Dimension, location: BlockCoordinates, scale: FloatTriplet = (1.0, 1.0, 1.0), rotation: FloatTriplet = (0.0, 0.0, 0.0), include_blocks: bool = True, include_entities: bool = True, skip_blocks: Tuple[Block, ...] = (), copy_chunk_not_exist: bool = False, ): """Paste a level into this level at the given location. Note this command may change in the future. :param src_structure: The structure to paste into this structure. :param src_dimension: The dimension of the source structure to copy from. :param src_selection: The selection to copy from the source structure. :param dst_dimension: The dimension to paste the structure into. :param location: The location where the centre of the structure will be in the level :param scale: The scale in the x, y and z axis. These can be negative to mirror. :param rotation: The rotation in degrees around each of the axis. :param include_blocks: Include blocks when pasting the structure. :param include_entities: Include entities when pasting the structure. :param skip_blocks: If a block matches a block in this list it will not be copied. :param copy_chunk_not_exist: If a chunk does not exist in the source should it be copied over as air. Always False where level is a World. :return: """ return generator_unpacker( self.paste_iter( src_structure, src_dimension, src_selection, dst_dimension, location, scale, rotation, include_blocks, include_entities, skip_blocks, copy_chunk_not_exist, ))
def create_undo_point(self, world=True, non_world=True) -> bool: return generator_unpacker(self.create_undo_point_iter( world, non_world))