diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index 9f570ead..4cadc27f 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -138,6 +138,7 @@ class ServerAPI{ "enable-mob-ai" => true, "abort-reading-after-N-packets" => PocketMinecraftServer::$PACKET_READING_LIMIT, "ticking-mode" => "legacy", + "mushroom-spread" => Block::$mushroomSpread ], comments: [ "level-type" => [ "Alowed types:", @@ -178,8 +179,12 @@ class ServerAPI{ " decoration(treecount= grasscount=) - sets amount of decorations", "Preset example:", "2;7,59x1,3x3,2;1;spawn(radius=10 block=89),decoration(treecount=80 grasscount=45)" + ], + "mushroom-spread" => [ + "Enable or disable mushroom spreading" ] ]); + Block::$mushroomSpread = $this->getProperty("mushroom-spread", Block::$mushroomSpread); Entity::$allowFly = $this->getProperty("allow-flight", true); if(!Entity::$allowFly){ ConsoleAPI::warn("Fly checking is enabled! Players may experience issues with kicking while not flying!"); diff --git a/src/material/Block.php b/src/material/Block.php index 34209442..b26c2b6b 100755 --- a/src/material/Block.php +++ b/src/material/Block.php @@ -1,6 +1,8 @@ "AirBlock", STONE => "StoneBlock", diff --git a/src/material/block/plant/BaseMushroomBlock.php b/src/material/block/plant/BaseMushroomBlock.php new file mode 100644 index 00000000..a7e18958 --- /dev/null +++ b/src/material/block/plant/BaseMushroomBlock.php @@ -0,0 +1,56 @@ +hardness = 0; + $this->breakTime = 0; + $this->material = Material::$plant; + } + + public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ + if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method + ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(static::$blockID, 0, 1)); + $level->fastSetBlockUpdate($x, $y, $z, 0, 0); + } + } + + public static function onRandomTick(Level $level, $x, $y, $z){ + if(Block::$mushroomSpread/* && mt_rand(0, 24) == 0*/){ + $maxcnt = 5; + for($xx = $x-4; $xx <= $x+4; ++$xx){ + for($zz = $z-4; $zz <= $z+4; ++$zz){ + for($yy = $y-1; $yy <= $y+1; ++$yy){ + if($level->level->getBlockID($xx, $yy, $zz) == static::$blockID){ + if(--$maxcnt <= 0) return; + } + } + } + } + + for($att = 0; $att < 4; ++$att){ + $nx = $x + mt_rand(-1, 1); + $ny = $y + mt_rand(-1, 1); + $nz = $z + mt_rand(-1, 1); + if($ny < 127 && $ny > 0 && $level->level->getBlockID($nx, $ny, $nz) == 0){ + $idb = $level->level->getBlockID($nx, $ny-1, $nz); + if(!StaticBlock::getIsTransparent($idb)){ //TODO better canSurvive check + if($level->getRawBrightness($nx, $ny, $nz) <= 12){ + $level->fastSetBlockUpdate($nx, $ny, $nz, static::$blockID, 0); + return; + } + } + } + } + } + } + + public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ + $down = $this->getSide(0); + if($down->isTransparent === false){ + $this->level->setBlock($block, $this, true, false, true); + return true; + } + return false; + } +} \ No newline at end of file diff --git a/src/material/block/plant/BrownMushroomBlock.php b/src/material/block/plant/BrownMushroomBlock.php index e252640c..6cf2ebe1 100644 --- a/src/material/block/plant/BrownMushroomBlock.php +++ b/src/material/block/plant/BrownMushroomBlock.php @@ -1,28 +1,9 @@ hardness = 0; - $this->breakTime = 0; - $this->material = Material::$plant; $this->lightEmission = 1; } - - public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ - if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method - ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(BROWN_MUSHROOM)); - $level->fastSetBlockUpdate($x, $y, $z, 0, 0); - } - } - - public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - $down = $this->getSide(0); - if($down->isTransparent === false){ - $this->level->setBlock($block, $this, true, false, true); - return true; - } - return false; - } } \ No newline at end of file diff --git a/src/material/block/plant/RedMushroomBlock.php b/src/material/block/plant/RedMushroomBlock.php index a3507380..d2564bb6 100644 --- a/src/material/block/plant/RedMushroomBlock.php +++ b/src/material/block/plant/RedMushroomBlock.php @@ -1,27 +1,9 @@ hardness = 0; - $this->breakTime = 0; - $this->material = Material::$plant; } - - public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ - if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method - ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(RED_MUSHROOM)); - $level->fastSetBlockUpdate($x, $y, $z, 0, 0); - } - } - - public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ - $down = $this->getSide(0); - if($down->isTransparent === false){ - $this->level->setBlock($block, $this, true, false, true); - return true; - } - return false; - } } \ No newline at end of file diff --git a/src/world/Level.php b/src/world/Level.php index b14f7dc6..779afa59 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -45,7 +45,9 @@ class Level{ GRASS => true, LEAVES => true, SNOW_LAYER => true, - ICE => true + ICE => true, + RED_MUSHROOM => true, + BROWN_MUSHROOM => true ]; public function __construct(PMFLevel $level, Config $entities, Config $tiles, Config $blockUpdates, $name){