diff --git a/src/material/block/solid/MyceliumBlock.php b/src/material/block/solid/MyceliumBlock.php index 6472cf15..05384769 100644 --- a/src/material/block/solid/MyceliumBlock.php +++ b/src/material/block/solid/MyceliumBlock.php @@ -15,10 +15,7 @@ class MyceliumBlock extends SolidBlock{ } public function onActivate(Item $item, Player $player){ //uwu - /*$f = Utils::randomFloat(); - if($f <= 0.33) VillageLibraryStructure::buildStructure($this->level, $this->getX(), $this->getY(), $this->getZ()); - elseif($f <= 0.67) SmallHouseStructure::buildStructure($this->level, $this->getX(), $this->getY(), $this->getZ()); - else WoodHutStructure::buildStructure($this->level, $this->getX(), $this->getY(), $this->getZ());*/ + //(new VillageLibraryStructure())::build($this->level, $this->getX(), $this->getY(), $this->getZ()); } public function getDrops(Item $item, Player $player){ diff --git a/src/structure/Structure.php b/src/structure/Structure.php index 2be51bd2..bf5e3971 100644 --- a/src/structure/Structure.php +++ b/src/structure/Structure.php @@ -8,61 +8,60 @@ abstract class Structure{ const MAP_NO_KEY = -255; const LEVEL_RSV1 = 1; - private $structure; + private static $structure, $tmpStructure; public $api, $pm; - public $mapSymToID, $width, $radius; + public static $map, $width, $lenght; - public function __construct($struct, $width, $symToID = []){ - $this->structure = $struct; - $this->mapSymToID = $symToID; + public function __construct($width, $lenght, $charToBlock = []){ $this->pm = ServerAPI::request(); $this->api = $this->pm->api; - $this->width = $width; - $this->radius = $width / 2; - + self::$width = $width; + self::$lenght = $lenght; + self::$map = $charToBlock; + /*foreach($charToBlock as $char => $array){ + $this->addMapping($char, , isset($array) ? $array[1] : 0); + }*/ } - public function addMapping($sym, $id){ - $this->mapSymToID[$sym] = $id; + public function addMapping($char, $blockClass, $meta){ + self::$map[$char] = new $blockClass($meta); } - public function getMappingFor($sym){ - return isset($this->mapSymToID[$sym]) ? $this->mapSymToID[$sym] : Structure::MAP_NO_KEY; + + public static function getMappingFor($char){ + return isset(self::$map[$char]) ? self::$map[$char] : Structure::MAP_NO_KEY; } - protected function placeBlock($level, $sym, &$tv){ - //console("@@@"); + protected static function placeBlock($level, $char, &$vector){ + if($char == "") return; if($level instanceof Level){ - $idm = $this->getMappingFor($sym); - if(!isset($idm[1])) $idm[1] = 0; - //var_dump($idm); - if($idm === Structure::MAP_NO_KEY){ + $blockClass = is_array(self::$map[$char]) ? self::$map[$char][0] : self::$map[$char]; + $block = new $blockClass(isset(self::$map[$char]) ? self::$map[$char][1] : 0, isset(self::$map[$char][2]) ? self::$map[$char][2] : 0); + //var_dump($block); + /*if($block === Structure::MAP_NO_KEY){ //console("Failed to receive id"); return false; - } - $block = $this->api->block->get($idm[0], $idm[1], $tv); //TODO: meta - //console($block); - $level->setBlock($tv, $block, true, false, true); + }*/ + $level->setBlock($vector, $block, true, false, true); } - } - public function build($level, $centerX, $centerY, $centerZ){ + public static function build($level, $centerX, $centerY, $centerZ, $structure){ //console("b"); - $tempVector = new Vector3(0,0,0); - $x = $centerX - $this->radius; - $z = $centerZ - $this->radius; - foreach($this->structure as $offsetY => $blocksXZ){ + $offsetX = 0; + $offsetZ = 0; + foreach($structure as $offsetY => $blocksXZ){ foreach($blocksXZ as $blocks){ + $blocks = rtrim($blocks); foreach(str_split($blocks) as $block){ - $tempVector->setXYZ($x, $centerY + $offsetY, $z); - //console("6#&_+7$:373-"); - $this->placeBlock($level, $block, $tempVector); - ++$x; + $vector = new Vector3($centerX - floor(self::$width / 2) + $offsetX, $centerY + $offsetY, $centerZ + $offsetZ); + //$tempVector->setXYZ($x, $centerY + $offsetY, $z); + self::placeBlock($level, $block, $vector); + ++$offsetX; } - ++$z; - $x = $centerX - $this->radius; + ++$offsetZ; + $offsetX = 0; } - $z = $centerZ - $this->radius; + $offsetZ = 0; } } diff --git a/src/structure/village/SmallHouseStructure.php b/src/structure/village/SmallHouseStructure.php index 578782aa..1a49b356 100644 --- a/src/structure/village/SmallHouseStructure.php +++ b/src/structure/village/SmallHouseStructure.php @@ -1,6 +1,6 @@ "CobbleStoneBlock", + "P" => "PlanksBlock", + "W" => "WoodBlock", + "D" => "DirtBlock", + "G" => "GlassPaneBlock", + "L" => ["LadderBlock", 2], + "F" => "FenceBlock", + " " => "AirBlock" + ]; + + public function __construct($width = 0, $lenght = 0, $charToBlock = []){ + parent::__construct(self::$width, self::$lenght, self::$map); + } + public static function generateFence(){ self::$tmpStructure = self::$structure; if(Utils::chance(50)){ @@ -59,52 +74,9 @@ class SmallHouseStructure{ } } - public static function buildStructure($level, $x, $y, $z){ /*use CENTER positions*/ + public static function build($level, $x, $y, $z, $structure = []){ self::generateFence(); - $offsetX = 0; - $offsetZ = 0; - foreach(self::$tmpStructure as $layerCount => $layer){ - foreach($layer as $line){ - $line = rtrim($line); //remove useless spaces(only from right) - foreach(str_split($line) as $char){ - $vector = new Vector3($x - floor(self::$width / 2) + $offsetX, $y + $layerCount, $z + $offsetZ); - switch($char){ - case "C": - $level->setBlockRaw($vector, new CobbleStoneBlock()); - break; - case "P": - $level->setBlockRaw($vector, new PlanksBlock()); - break; - case "W": - $level->setBlockRaw($vector, new WoodBlock()); - break; - case "D": - $level->setBlockRaw($vector, new DirtBlock()); - break; - case "G": - $level->setBlockRaw($vector, new GlassPaneBlock()); - break; - case "L": - $level->setBlockRaw($vector, new LadderBlock(2)); - break; - case "F": - $level->setBlockRaw($vector, new FenceBlock()); - break; - case " ": - $block = $level->getBlock($vector)->getID(); - if($block === AIR){ - break; - } - $level->setBlockRaw($vector, new AirBlock()); - break; - } - ++$offsetX; - } - ++$offsetZ; - $offsetX = 0; - } - $offsetZ = 0; - } + parent::build($level, $x, $y, $z, self::$tmpStructure); } } \ No newline at end of file diff --git a/src/structure/village/VillageLibraryStructure.php b/src/structure/village/VillageLibraryStructure.php index 0b709f85..2e80f947 100644 --- a/src/structure/village/VillageLibraryStructure.php +++ b/src/structure/village/VillageLibraryStructure.php @@ -1,6 +1,6 @@ [ "", - "CdPPGGGPC", + "C8PPGGGPC", "P P", "G G", "G c c G", @@ -96,69 +96,29 @@ class VillageLibraryStructure{ ] ]; - public static function buildStructure($level, $x, $y, $z){ /*use CENTER positions*/ - $offsetX = 0; - $offsetZ = 0; - foreach(self::$structure as $layerCount => $layer){ - foreach($layer as $line){ - $line = rtrim($line); //remove useless spaces(only from right) - foreach(str_split($line) as $char){ - $vector = new Vector3($x - floor(self::$width / 2) + $offsetX, $y + $layerCount, $z + $offsetZ); - switch($char){ - case "S": - $level->setBlockRaw($vector, new CobbleStoneStairsBlock(2)); - break; - case "C": - $level->setBlockRaw($vector, new CobbleStoneBlock()); - break; - case "P": - $level->setBlockRaw($vector, new PlanksBlock()); - break; - case "W": - $level->setBlockRaw($vector, new WoodBlock()); - break; - case "d": - if($layerCount == 1) $level->setBlockRaw($vector, new DoorBlock(64)); - else $level->setBlockRaw($vector, new DoorBlock(64, 0x08)); - break; - case "G": - $level->setBlockRaw($vector, new GlassPaneBlock()); - break; - case "B": - $level->setBlockRaw($vector, new BookshelfBlock()); - break; - case "F": - $level->setBlockRaw($vector, new FenceBlock()); - break; - case "c": - $level->setBlockRaw($vector, new CarpetBlock(12)); - break; - case "1": - $level->setBlockRaw($vector, new WoodStairsBlock(1)); - break; - case "2": - $level->setBlockRaw($vector, new WoodStairsBlock(2)); - break; - case "3": - $level->setBlockRaw($vector, new WoodStairsBlock(3)); - break; - case "T": - $level->setBlockRaw($vector, new WorkbenchBlock()); - break; - case " ": - $block = $level->getBlock($vector)->getID(); - if($block === AIR){ - break; - } - $level->setBlockRaw($vector, new AirBlock()); - break; - } - ++$offsetX; - } - ++$offsetZ; - $offsetX = 0; - } - $offsetZ = 0; - } + public static $map = [ + "S" => ["CobbleStoneStairsBlock", 2], + "C" => "CobbleStoneBlock", + "P" => "PlanksBlock", + "W" => "WoodBlock", + "d" => ["DoorBlock", 64], + "8" => ["DoorBlock", 64, 0x08], + "G" => "GlassPaneBlock", + "B" => "BookshelfBlock", + "F" => "FenceBlock", + "c" => ["CarpetBlock", 12], + "1" => ["WoodStairsBlock", 1], + "2" => ["WoodStairsBlock", 2], + "3" => ["WoodStairsBlock", 3], + "T" => "WorkbenchBlock", + " " => "AirBlock" + ]; + + public function __construct($width = 0, $lenght = 0, $charToBlock = []){ + parent::__construct(self::$width, self::$lenght, self::$map); + } + + public static function build($level, $x, $y, $z, $structure = 0){ + parent::build($level, $x, $y, $z, self::$structure); } } \ No newline at end of file