From a07a3ed486671b6c1bca4d75aa62c975d1ab1fe1 Mon Sep 17 00:00:00 2001 From: ArkQuark <74979909+ArkQuark@users.noreply.github.com> Date: Sat, 4 Mar 2023 22:44:32 +0300 Subject: [PATCH] Some structure fixes --- src/material/block/solid/MyceliumBlock.php | 10 ++++++---- src/structure/Structure.php | 8 ++++++-- src/structure/village/SmallFarmStructure.php | 5 ++--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/material/block/solid/MyceliumBlock.php b/src/material/block/solid/MyceliumBlock.php index 1831c4d7..b533d05f 100644 --- a/src/material/block/solid/MyceliumBlock.php +++ b/src/material/block/solid/MyceliumBlock.php @@ -15,11 +15,13 @@ class MyceliumBlock extends SolidBlock{ } public function onActivate(Item $item, Player $player){ //uwu - /*if(mt_rand(0, 1) === 0){ - Structures::$SMALLFARM_VILLAGE->rotate90deg($this->level, $this->x, $this->y, $this->z)->build($this->level, $this->x, $this->y, $this->z); + /*$oldtime = microtime(1); + if(mt_rand(0, 1) === 0){ + $time = Structures::$SMALLFARM_VILLAGE->rotate90deg($this->level, $this->x, $this->y, $this->z)->build($this->level, $this->x, $this->y, $this->z); }else{ - Structures::$SMALLFARM_VILLAGE->build($this->level, $this->x, $this->y, $this->z); - }*/ + $time = Structures::$SMALLFARM_VILLAGE->build($this->level, $this->x, $this->y, $this->z); + } + console("builded in ".($time - $oldtime));*/ //(new WoodHutStructure())->build($this->level, $this->getX(), $this->getY(), $this->getZ()); } diff --git a/src/structure/Structure.php b/src/structure/Structure.php index 6a7bdd8f..d0c6a09b 100644 --- a/src/structure/Structure.php +++ b/src/structure/Structure.php @@ -30,7 +30,7 @@ abstract class Structure{ if($char === "" || (($mk = $this->getMappingFor($char)) === self::MAP_NO_KEY)) return; $id = is_array($mk) ? $mk[0] : $mk; $meta = is_array($mk) ? $mk[1] : 0; - return $level->setBlock($vector, BlockAPI::get($id, $meta)); + return $level->setBlockRaw($vector, BlockAPI::get($id, $meta)); } protected function init(){} @@ -38,6 +38,7 @@ abstract class Structure{ protected function getFinalStructure(Level $level, $x, $y, $z){ return $this->structure; } + public function rotate90deg(Level $level, $x, $y, $z){ $str = $this->getFinalStructure($level, $x, $y, $z); foreach($str as &$arr){ @@ -52,13 +53,15 @@ abstract class Structure{ } return (clone $this)->setStructure($str, $this->length, $this->width); } + private function setStructure($struct, $width, $length){ $this->structure = $struct; $this->width = $width; $this->length = $length; - console("Modifed"); + //console("Modifed"); return $this; } + public function build(Level $level, $centerX, $centerY, $centerZ){ $offsetX = $offsetZ = 0; $centWidth = floor($this->width / 2); @@ -76,6 +79,7 @@ abstract class Structure{ } $offsetZ = 0; } + return microtime(1); } } \ No newline at end of file diff --git a/src/structure/village/SmallFarmStructure.php b/src/structure/village/SmallFarmStructure.php index f9d74084..c48b05e8 100644 --- a/src/structure/village/SmallFarmStructure.php +++ b/src/structure/village/SmallFarmStructure.php @@ -36,8 +36,8 @@ class SmallFarmStructure extends Structure{ " " => 0, "D" => DIRT ]; - protected function getFinalStructure(Level $level, $x, $y, $z) - { + + protected function getFinalStructure(Level $level, $x, $y, $z){ if(!$level->getBlockWithoutVector($x, $y - 1, $z)->isSolid){ $structCopy = $this->structure; $structCopy[-1] = array_fill(0, $this->length, str_repeat("D", $this->width)); //TODO sand or clay, check for the whole row of water? @@ -46,7 +46,6 @@ class SmallFarmStructure extends Structure{ return parent::getFinalStructure($level, $x, $y, $z); } - protected function getMappingFor($char){ if($char === "R"){ $f = Utils::randomFloat();