diff --git a/src/material/block/plant/CyanFlowerBlock.php b/src/material/block/plant/CyanFlowerBlock.php index b0308bbc..0503b918 100644 --- a/src/material/block/plant/CyanFlowerBlock.php +++ b/src/material/block/plant/CyanFlowerBlock.php @@ -3,6 +3,7 @@ class CyanFlowerBlock extends FlowableBlock{ public function __construct(){ parent::__construct(CYAN_FLOWER, 0, "Cyan Flower"); + $this->isActivable = true; $this->hardness = 0; } @@ -25,4 +26,35 @@ class CyanFlowerBlock extends FlowableBlock{ } return false; } + + public function onActivate(Item $item, Player $player){ + if($item->getID() === DYE and $item->getMetadata() === 0x0F){ + if(($player->gamemode & 0x01) === 0){ + $player->removeItem(DYE,0x0F,1); + } + $random = new Random(); + self::placeFlowers($this->level, new Vector3($this->x, $this->y, $this->z), $random, $random->nextRange(2, 5), 2); + return true; + } + return false; + } + + public static function placeFlowers(Level $level, Vector3 $pos, Random $random, $count, $radius){ + for($c = 0; $c < $count; ++$c){ + $x = $random->nextRange($pos->x - $radius, $pos->x + $radius); + $z = $random->nextRange($pos->z - $radius, $pos->z + $radius); + for($y = $pos->y - 2; $y <= $pos->y + 2; ++$y){ + if($level->level->getBlockID($x, $y + 1, $z) === AIR and $level->level->getBlockID($x, $y, $z) === GRASS){ + $changeFlower = $random->nextRange(1, 7); + if($changeFlower === 1){ + $t = BlockAPI::get(DANDELION, 0); + } else { + $t = BlockAPI::get(CYAN_FLOWER, 0); + } + $level->setBlockRaw(new Vector3($x, $y + 1, $z), $t); + break; + } + } + } + } } \ No newline at end of file diff --git a/src/material/block/plant/DandelionBlock.php b/src/material/block/plant/DandelionBlock.php index 5d352a67..67c09732 100644 --- a/src/material/block/plant/DandelionBlock.php +++ b/src/material/block/plant/DandelionBlock.php @@ -3,6 +3,7 @@ class DandelionBlock extends FlowableBlock{ public function __construct(){ parent::__construct(DANDELION, 0, "Dandelion"); + $this->isActivable = true; $this->hardness = 0; } @@ -25,4 +26,35 @@ class DandelionBlock extends FlowableBlock{ } return false; } + + public function onActivate(Item $item, Player $player){ + if($item->getID() === DYE and $item->getMetadata() === 0x0F){ + if(($player->gamemode & 0x01) === 0){ + $player->removeItem(DYE,0x0F,1); + } + $random = new Random(); + self::placeFlowers($this->level, new Vector3($this->x, $this->y, $this->z), $random, $random->nextRange(2, 5), 2); + return true; + } + return false; + } + + public static function placeFlowers(Level $level, Vector3 $pos, Random $random, $count, $radius){ + for($c = 0; $c < $count; ++$c){ + $x = $random->nextRange($pos->x - $radius, $pos->x + $radius); + $z = $random->nextRange($pos->z - $radius, $pos->z + $radius); + for($y = $pos->y - 2; $y <= $pos->y + 2; ++$y){ + if($level->level->getBlockID($x, $y + 1, $z) === AIR and $level->level->getBlockID($x, $y, $z) === GRASS){ + $changeFlower = $random->nextRange(1, 7); + if($changeFlower === 1){ + $t = BlockAPI::get(CYAN_FLOWER, 0); + } else { + $t = BlockAPI::get(DANDELION, 0); + } + $level->setBlockRaw(new Vector3($x, $y + 1, $z), $t); + break; + } + } + } + } } \ No newline at end of file diff --git a/src/world/generator/object/grass/TallGrassObject.php b/src/world/generator/object/grass/TallGrassObject.php index 527a6373..ba193b55 100644 --- a/src/world/generator/object/grass/TallGrassObject.php +++ b/src/world/generator/object/grass/TallGrassObject.php @@ -2,23 +2,26 @@ class TallGrassObject{ - public static function growGrass(Level $level, Vector3 $pos, Random $random, $count = 15, $radius = 10){ - $arr = [ - BlockAPI::get(DANDELION, 0), - BlockAPI::get(CYAN_FLOWER, 0), - BlockAPI::get(TALL_GRASS, 1), - BlockAPI::get(TALL_GRASS, 1), - BlockAPI::get(TALL_GRASS, 2), - BlockAPI::get(TALL_GRASS, 1) - ]; - $arrC = count($arr) - 1; - for($c = 0; $c < $count; ++$c){ - $x = $random->nextRange($pos->x - $radius, $pos->x + $radius); - $z = $random->nextRange($pos->z - $radius, $pos->z + $radius); - if($level->level->getBlockID($x, $pos->y + 1, $z) === AIR and $level->level->getBlockID($x, $pos->y, $z) === GRASS){ - $t = $arr[$random->nextRange(0, $arrC)]; - $level->setBlockRaw(new Vector3($x, $pos->y + 1, $z), $t); - } - } - } + public static function growGrass(Level $level, Vector3 $pos, Random $random, $count = 15, $radius = 10){ + $arr = [ + BlockAPI::get(DANDELION, 0), + BlockAPI::get(CYAN_FLOWER, 0), + BlockAPI::get(TALL_GRASS, 1), + BlockAPI::get(TALL_GRASS, 1), + BlockAPI::get(TALL_GRASS, 2), + BlockAPI::get(TALL_GRASS, 1) + ]; + $arrC = count($arr) - 1; + for($c = 0; $c < $count; ++$c){ + $x = $random->nextRange($pos->x - $radius, $pos->x + $radius); + $z = $random->nextRange($pos->z - $radius, $pos->z + $radius); + for($y = $pos->y - 2; $y <= $pos->y + 2; ++$y){ + if($level->level->getBlockID($x, $y + 1, $z) === AIR and $level->level->getBlockID($x, $y, $z) === GRASS){ + $t = $arr[$random->nextRange(0, $arrC)]; + $level->setBlockRaw(new Vector3($x, $y + 1, $z), $t); + break; + } + } + } + } } \ No newline at end of file