/** * @param gries\MControl\Builder\BlockTypeColorMapping $blockTypeColorMapping */ function it_creates_multiple_levels_of_the_image_depending_on_the_given_heigh(BlockTypeColorMapping $blockTypeColorMapping) { $blackBlockType = new BlockType(array('name' => 'coal_block')); $blockTypeColorMapping->getBlockTypeForRgbColor(255, 255, 255)->willReturn($blackBlockType); $whiteBlockType = new BlockType(array('name' => 'iron_block', 'meta' => 2)); $blockTypeColorMapping->getBlockTypeForRgbColor(0, 0, 0)->willReturn($whiteBlockType); $this->beConstructedWith($blockTypeColorMapping); $expectedStructure = new Structure(); $expectedStructure->createBlock('coal_block', array('x' => 1, 'y' => 1, 'z' => 1)); $expectedStructure->createBlock('coal_block', array('x' => 1, 'y' => 1, 'z' => 2)); $expectedStructure->createBlock('iron_block', array('x' => 2, 'y' => 1, 'z' => 1), 2); $expectedStructure->createBlock('iron_block', array('x' => 2, 'y' => 1, 'z' => 2), 2); $expectedStructure->createBlock('coal_block', array('x' => 1, 'y' => 2, 'z' => 1)); $expectedStructure->createBlock('coal_block', array('x' => 1, 'y' => 2, 'z' => 2)); $expectedStructure->createBlock('iron_block', array('x' => 2, 'y' => 2, 'z' => 1), 2); $expectedStructure->createBlock('iron_block', array('x' => 2, 'y' => 2, 'z' => 2), 2); // returns a 2x2 image with 2 black and 2 white pixels $image = $this->getImage(); $this->convert($image, 2)->shouldBeLike($expectedStructure); }
public function scan(array $coordinates, $width, $length, $height) { $structure = new Structure(); // go through the height for ($y = 1; $y <= $height; $y++) { // go through the length for ($z = 1; $z <= $length; $z++) { // go through the width for ($x = 1; $x <= $width; $x++) { $currentX = $coordinates['x'] + $x; $currentY = $coordinates['y'] + $y; $currentZ = $coordinates['z'] + $z; $currentCoordinates = array('x' => $currentX, 'y' => $currentY, 'z' => $currentZ); $type = $this->scanner->detectBlockType($currentCoordinates); // default to air if (!$type) { $type = new BlockType(array('name' => 'air', 'meta' => 0)); } $structure->createBlock($type->getName(), array('x' => $x, 'y' => $y, 'z' => $z), $type->getMeta()); } } } return $structure; }
/** * @param gries\MControl\Server\BlockTypeScanner $scanner */ function it_should_scan_a_structure_block_by_block_for_given_coordinates(BlockTypeScanner $scanner) { $scanner->detectBlockType(array('x' => 6, 'y' => 6, 'z' => 6))->shouldBeCalled()->willReturn(new BlockType(array('name' => 'iron', 'meta' => 0))); $scanner->detectBlockType(array('x' => 7, 'y' => 6, 'z' => 6))->shouldBeCalled()->willReturn(new BlockType(array('name' => 'iron', 'meta' => 0))); $scanner->detectBlockType(array('x' => 8, 'y' => 6, 'z' => 6))->shouldBeCalled()->willReturn(new BlockType(array('name' => 'iron', 'meta' => 0))); $scanner->detectBlockType(array('x' => 6, 'y' => 6, 'z' => 7))->shouldBeCalled()->willReturn(new BlockType(array('name' => 'air', 'meta' => 1))); $scanner->detectBlockType(array('x' => 7, 'y' => 6, 'z' => 7))->shouldBeCalled()->willReturn(new BlockType(array('name' => 'iron', 'meta' => 0))); $scanner->detectBlockType(array('x' => 8, 'y' => 6, 'z' => 7))->shouldBeCalled()->willReturn(new BlockType(array('name' => 'iron', 'meta' => 0))); $expectedStructure = new Structure(); $expectedStructure->createBlock('iron', array('x' => 1, 'y' => 1, 'z' => 1), 0); $expectedStructure->createBlock('iron', array('x' => 2, 'y' => 1, 'z' => 1), 0); $expectedStructure->createBlock('iron', array('x' => 3, 'y' => 1, 'z' => 1), 0); $expectedStructure->createBlock('air', array('x' => 1, 'y' => 1, 'z' => 2), 1); $expectedStructure->createBlock('iron', array('x' => 2, 'y' => 1, 'z' => 2), 0); $expectedStructure->createBlock('iron', array('x' => 3, 'y' => 1, 'z' => 2), 0); $coordinates = array('x' => 5, 'y' => 5, 'z' => 5); $width = 3; $height = 1; $length = 2; $this->scan($coordinates, $width, $length, $height)->shouldBeLike($expectedStructure); }