mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
added mushroom spreading
This commit is contained in:
parent
a6d96c4ac7
commit
f81c8b17bf
6 changed files with 70 additions and 42 deletions
|
|
@ -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=<N> grasscount=<M>) - 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!");
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
|
||||
abstract class Block extends Position{
|
||||
public static $mushroomSpread = true;
|
||||
|
||||
public static $class = array(
|
||||
AIR => "AirBlock",
|
||||
STONE => "StoneBlock",
|
||||
|
|
|
|||
56
src/material/block/plant/BaseMushroomBlock.php
Normal file
56
src/material/block/plant/BaseMushroomBlock.php
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
class BaseMushroomBlock extends FlowableBlock{
|
||||
public function __construct($id, $meta, $name){
|
||||
parent::__construct($id, $meta, $name);
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +1,9 @@
|
|||
<?php
|
||||
|
||||
class BrownMushroomBlock extends FlowableBlock{
|
||||
require_once("BaseMushroomBlock.php");
|
||||
class BrownMushroomBlock extends BaseMushroomBlock{
|
||||
public static $blockID;
|
||||
public function __construct(){
|
||||
parent::__construct(BROWN_MUSHROOM, 0, "Brown Mushroom");
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +1,9 @@
|
|||
<?php
|
||||
require_once("BaseMushroomBlock.php");
|
||||
|
||||
class RedMushroomBlock extends FlowableBlock{
|
||||
class RedMushroomBlock extends BaseMushroomBlock{
|
||||
public static $blockID;
|
||||
public function __construct(){
|
||||
parent::__construct(RED_MUSHROOM, 0, "Red Mushroom");
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue