mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-20 15:41:33 +00:00
Plant growth & scheduled updates!
This commit is contained in:
@@ -35,7 +35,7 @@ class GlowingRedstoneOreBlock extends SolidBlock{
|
||||
$this->level->setBlock($this, BlockAPI::get(REDSTONE_ORE, $this->meta), false);
|
||||
return BLOCK_UPDATE_WEAK;
|
||||
}else{
|
||||
$this->level->scheduleBlockUpdate($this, mt_rand(45, 100));
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@@ -33,7 +33,7 @@ class RedstoneOreBlock extends SolidBlock{
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL or $type === BLOCK_UPDATE_TOUCH){
|
||||
$this->level->setBlock($this, BlockAPI::get(GLOWING_REDSTONE_ORE, $this->meta), false);
|
||||
$this->level->scheduleBlockUpdate($this, mt_rand(45, 100));
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
return BLOCK_UPDATE_WEAK;
|
||||
}
|
||||
return false;
|
||||
|
@@ -26,19 +26,37 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
*/
|
||||
|
||||
class CactusBlock extends TransparentBlock{
|
||||
public function __construct(){
|
||||
parent::__construct(CACTUS, 0, "Cactus");
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(CACTUS, $meta, "Cactus");
|
||||
$this->isFullBlock = false;
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
$down = $this->getSide(0)->getID();
|
||||
if($down !== SAND and $down !== CACTUS){ //Replace wit common break method
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() !== SAND and $down->getID() !== CACTUS){ //Replace wit common break method
|
||||
$this->level->setBlock($this, new AirBlock(), false);
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}elseif($type === BLOCK_UPDATE_RANDOM){
|
||||
if($this->getSide(0)->getID() !== CACTUS){
|
||||
if($this->meta == 0x0F){
|
||||
for($y = 1; $y < 3; ++$y){
|
||||
$b = $this->level->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
|
||||
if($b->getID() === AIR){
|
||||
$this->level->setBlock($b, new CactusBlock());
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->meta = 0;
|
||||
$this->level->setBlock($this, $this);
|
||||
}else{
|
||||
++$this->meta;
|
||||
$this->level->setBlock($this, $this);
|
||||
}
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -51,11 +69,17 @@ class CactusBlock extends TransparentBlock{
|
||||
$block2 = $this->getSide(4);
|
||||
$block3 = $this->getSide(5);
|
||||
if($block0->isTransparent === true and $block1->isTransparent === true and $block2->isTransparent === true and $block3->isTransparent === true){
|
||||
$this->level->setBlock($block, $this);
|
||||
$this->level->setBlock($this, $this);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
return array(
|
||||
array($this->id, 0, 1),
|
||||
);
|
||||
}
|
||||
}
|
@@ -34,6 +34,7 @@ class MelonStemBlock extends FlowableBlock{
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === FARMLAND){
|
||||
$this->level->setBlock($block, $this);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -46,6 +47,27 @@ class MelonStemBlock extends FlowableBlock{
|
||||
$this->level->setBlock($this, new AirBlock(), false);
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}elseif($type === BLOCK_UPDATE_RANDOM){
|
||||
if(mt_rand(0, 2) == 1){
|
||||
if($this->meta < 0x07){
|
||||
++$this->meta;
|
||||
$this->level->setBlock($this, $this);
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}else{
|
||||
for($side = 2; $side <= 5; ++$side){
|
||||
$b = $this->getSide($side);
|
||||
if($b->getID() === MELON_BLOCK){
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
}
|
||||
$side = $this->getSide(mt_rand(2,5));
|
||||
$d = $side->getSide(0);
|
||||
if($side->getID() === AIR and ($d->getID() === FARMLAND or $d->getID() === GRASS or $d->getID() === DIRT)){
|
||||
$this->level->setBlock($side, new MelonBlock());
|
||||
}
|
||||
}
|
||||
}
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@@ -46,6 +46,7 @@ class SaplingBlock extends FlowableBlock{
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === FARMLAND){
|
||||
$this->level->setBlock($block, $this);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -65,12 +66,17 @@ class SaplingBlock extends FlowableBlock{
|
||||
$this->level->setBlock($this, new AirBlock(), false);
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}elseif($type === BLOCK_UPDATE_RANDOM and mt_rand(0,2) === 0){ //Growth
|
||||
if(($this->meta & 0x08) === 0x08){
|
||||
TreeObject::growTree($this->level, $this, new Random(), $this->meta & 0x03);
|
||||
}elseif($type === BLOCK_UPDATE_RANDOM){ //Growth
|
||||
if(mt_rand(1,7) === 1){
|
||||
if(($this->meta & 0x08) === 0x08){
|
||||
TreeObject::growTree($this->level, $this, new Random(), $this->meta & 0x03);
|
||||
}else{
|
||||
$this->meta |= 0x08;
|
||||
$this->level->setBlock($this, $this);
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
}else{
|
||||
$this->meta |= 0x08;
|
||||
$this->level->setBlock($this, $this);
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@@ -26,8 +26,8 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
*/
|
||||
|
||||
class SugarcaneBlock extends FlowableBlock{
|
||||
public function __construct(){
|
||||
parent::__construct(SUGARCANE_BLOCK, 0, "Sugarcane");
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(SUGARCANE_BLOCK, $meta, "Sugarcane");
|
||||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
@@ -38,11 +38,30 @@ class SugarcaneBlock extends FlowableBlock{
|
||||
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->isTransparent === true){ //Replace wit common break method
|
||||
$down = $this->getSide(0);
|
||||
if($down->isTransparent === true and $down->getID() !== SUGARCANE_BLOCK){ //Replace wit common break method
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SUGARCANE));
|
||||
$this->level->setBlock($this, new AirBlock(), false);
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}elseif($type === BLOCK_UPDATE_RANDOM){
|
||||
if($this->getSide(0)->getID() !== SUGARCANE_BLOCK){
|
||||
if($this->meta === 0x0F){
|
||||
for($y = 1; $y < 3; ++$y){
|
||||
$b = $this->level->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
|
||||
if($b->getID() === AIR){
|
||||
$this->level->setBlock($b, new SugarcaneBlock());
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->meta = 0;
|
||||
$this->level->setBlock($this, $this);
|
||||
}else{
|
||||
++$this->meta;
|
||||
$this->level->setBlock($this, $this);
|
||||
}
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -53,19 +72,19 @@ class SugarcaneBlock extends FlowableBlock{
|
||||
$this->level->setBlock($block, new SugarcaneBlock());
|
||||
return true;
|
||||
}elseif($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === SAND){
|
||||
$block0 = $this->getSide(2);
|
||||
$block1 = $this->getSide(3);
|
||||
$block2 = $this->getSide(4);
|
||||
$block3 = $this->getSide(5);
|
||||
if($block0->getID() === WATER or $block0->getID() === STILL_WATER
|
||||
or $block1->getID() === WATER or $block1->getID() === STILL_WATER
|
||||
or $block2->getID() === WATER or $block2->getID() === STILL_WATER
|
||||
or $block3->getID() === WATER or $block3->getID() === STILL_WATER){
|
||||
$block0 = $down->getSide(2);
|
||||
$block1 = $down->getSide(3);
|
||||
$block2 = $down->getSide(4);
|
||||
$block3 = $down->getSide(5);
|
||||
if(($block0 instanceof WaterBlock)
|
||||
or ($block1 instanceof WaterBlock)
|
||||
or ($block2 instanceof WaterBlock)
|
||||
or ($block3 instanceof WaterBlock)){
|
||||
$this->level->setBlock($block, new SugarcaneBlock());
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@@ -35,6 +35,7 @@ class WheatBlock extends FlowableBlock{
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === FARMLAND){
|
||||
$this->level->setBlock($block, $this);
|
||||
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -56,6 +57,16 @@ class WheatBlock extends FlowableBlock{
|
||||
$this->level->setBlock($this, new AirBlock(), false);
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}elseif($type === BLOCK_UPDATE_RANDOM){
|
||||
if(mt_rand(0, 2) == 1){
|
||||
if($this->meta < 0x07){
|
||||
++$this->meta;
|
||||
$this->level->setBlock($this, $this);
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
}else{
|
||||
return BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user