mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 16:51:42 +00:00
Saplings
This commit is contained in:
parent
6f59e2eaad
commit
3f532d419c
@ -44,32 +44,29 @@ class SaplingBlock extends TransparentBlock{
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
console("SAPLING SAPLING SAPLING");return false; //Placeholder
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === FARMLAND){
|
||||
$level->setBlock($block, $this->id, $this->getMetadata());
|
||||
return true;
|
||||
}
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === FARMLAND){
|
||||
$this->level->setBlock($block, $this);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function onActivate(Item $item, Player $player){
|
||||
console("SAPLING SAPLING SAPLING");return false; //Placeholder
|
||||
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
||||
TreeObject::growTree($level, $this);
|
||||
TreeObject::growTree($this->level, $this);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
console("SAPLING SAPLING SAPLING");return false; //Placeholder
|
||||
if($type === BLOCK_UPDATE_RANDOM and mt_rand(0,2) === 0){ //Growth
|
||||
if(($this->meta & 0x08) === 0x08){
|
||||
TreeObject::growTree($level, $this);
|
||||
TreeObject::growTree($this->level, $this);
|
||||
}else{
|
||||
$this->meta |= 0x08;
|
||||
$this->level->setBlock($this->x, $this->y, $this->z, $this->id, $this->meta);
|
||||
$this->level->setBlock($this, $this);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
|
||||
class Level{
|
||||
public $entities, $tileEntities;
|
||||
private $level, $time, $startCheck, $startTime, $server, $name;
|
||||
private $level, $time, $startCheck, $startTime, $server, $name, $usedChunks;
|
||||
|
||||
public function __construct(PMFLevel $level, Config $entities, Config $tileEntities, $name){
|
||||
$this->server = ServerAPI::request();
|
||||
|
@ -44,11 +44,11 @@ class BigTreeObject extends TreeObject{
|
||||
private $addLogVines = false;
|
||||
private $addCocoaPlants = false;
|
||||
|
||||
public function canPlaceObject(BlockAPI $level, $x, $y, $z){
|
||||
public function canPlaceObject(Level $level, $x, $y, $z){
|
||||
return false;
|
||||
}
|
||||
|
||||
public function placeObject(BlockAPI $level, $x, $y, $z, $type){
|
||||
public function placeObject(Level $level, $x, $y, $z, $type){
|
||||
|
||||
$this->trunkHeight = (int) ($this->totalHeight * $this->trunkHeightMultiplier);
|
||||
$leaves = $this->getLeafGroupPoints($level, $x, $y, $z);
|
||||
|
@ -35,7 +35,7 @@ class PineTreeObject extends TreeObject{
|
||||
private $leavesSizeY = -1;
|
||||
private $leavesAbsoluteMaxRadius = -1;
|
||||
|
||||
public function canPlaceObject(BlockAPI $level, $x, $y, $z){
|
||||
public function canPlaceObject(Level $level, $x, $y, $z){
|
||||
$this->findRandomLeavesSize();
|
||||
$checkRadius = 0;
|
||||
for($yy = 0; $yy < $this->totalHeight; ++$yy) {
|
||||
@ -44,7 +44,7 @@ class PineTreeObject extends TreeObject{
|
||||
}
|
||||
for($xx = -$checkRadius; $xx < ($checkRadius + 1); ++$xx){
|
||||
for($zz = -$checkRadius; $zz < ($checkRadius + 1); ++$zz){
|
||||
$block = $level->getBlock($x + $xx, $y + $yy, $z + $zz);
|
||||
$block = $level->getBlock(new Vector3($x + $xx, $y + $yy, $z + $zz));
|
||||
if(!isset($this->overridable[$block->getID()])){
|
||||
return false;
|
||||
}
|
||||
@ -60,11 +60,11 @@ class PineTreeObject extends TreeObject{
|
||||
$this->leavesAbsoluteMaxRadius = 2 + mt_rand(0, 2);
|
||||
}
|
||||
|
||||
public function placeObject(BlockAPI $level, $x, $y, $z){
|
||||
public function placeObject(Level $level, $x, $y, $z){
|
||||
if($this->leavesSizeY === -1 or $this->leavesAbsoluteMaxRadius === -1) {
|
||||
$this->findRandomLeavesSize();
|
||||
}
|
||||
$level->setBlock(new Vector3($x, $y - 1, $z), 3, 0);
|
||||
$level->setBlock(new Vector3($x, $y - 1, $z), new DirtBlock());
|
||||
$leavesRadius = mt_rand(0,2);
|
||||
$leavesMaxRadius = 1;
|
||||
$leavesBottomY = $this->totalHeight - $this->leavesSizeY;
|
||||
@ -74,7 +74,7 @@ class PineTreeObject extends TreeObject{
|
||||
for ($xx = -$leavesRadius; $xx < ($leavesRadius + 1); ++$xx) {
|
||||
for ($zz = -$leavesRadius; $zz < ($leavesRadius + 1); ++$zz) {
|
||||
if (abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0) {
|
||||
$level->setBlock(New Vector3($x + $xx, $y + $yy, $z + $zz), 18, $this->type);
|
||||
$level->setBlock(new Vector3($x + $xx, $y + $yy, $z + $zz), new LeavesBlock($this->type));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -90,7 +90,7 @@ class PineTreeObject extends TreeObject{
|
||||
}
|
||||
$trunkHeightReducer = mt_rand(0,3);
|
||||
for($yy = 0; $yy < ($this->totalHeight - $trunkHeightReducer); ++$yy){
|
||||
$level->setBlock(new Vector3($x, $y + $yy, $z), 17, $this->type);
|
||||
$level->setBlock(new Vector3($x, $y + $yy, $z), new WoodBlock($this->type));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ class SmallTreeObject extends TreeObject{
|
||||
private $addLogVines = false;
|
||||
private $addCocoaPlants = false;
|
||||
|
||||
public function canPlaceObject(BlockAPI $level, $x, $y, $z){
|
||||
public function canPlaceObject(Level $level, $x, $y, $z){
|
||||
$radiusToCheck = $this->radiusIncrease;
|
||||
for ($yy = 0; $yy < $this->totalHeight + 2; ++$yy) {
|
||||
if ($yy == 1 or $yy === $this->totalHeight - 1) {
|
||||
@ -56,8 +56,8 @@ class SmallTreeObject extends TreeObject{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function placeObject(BlockAPI $level, $x, $y, $z){
|
||||
$level->setBlock(new Vector3($x, $y - 1, $z), 3, 0);
|
||||
public function placeObject(Level $level, $x, $y, $z){
|
||||
$level->setBlock(new Vector3($x, $y - 1, $z), new DirtBlock());
|
||||
$this->totalHeight += mt_rand(-1, 3);
|
||||
$this->leavesHeight += mt_rand(0, 1);
|
||||
for($yy = ($this->totalHeight - $this->leavesHeight); $yy < ($this->totalHeight + 1); ++$yy){
|
||||
@ -66,13 +66,13 @@ class SmallTreeObject extends TreeObject{
|
||||
for($xx = -$xzRadius; $xx < ($xzRadius + 1); ++$xx){
|
||||
for($zz = -$xzRadius; $zz < ($xzRadius + 1); ++$zz){
|
||||
if((abs($xx) != $xzRadius or abs($zz) != $xzRadius) and $yRadius != 0){
|
||||
$level->setBlock(new Vector3($x + $xx, $y + $yy, $z + $zz), 18, $this->type);
|
||||
$level->setBlock(new Vector3($x + $xx, $y + $yy, $z + $zz), new LeavesBlck($this->type));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for($yy = 0; $yy < ($this->totalHeight - 1); ++$yy){
|
||||
$level->setBlock(new Vector3($x, $y + $yy, $z), 17, $this->type);
|
||||
$level->setBlock(new Vector3($x, $y + $yy, $z), new WoodBlock($this->type));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ class SpruceTreeObject extends TreeObject{
|
||||
private $leavesBottomY = -1;
|
||||
private $leavesMaxRadius = -1;
|
||||
|
||||
public function canPlaceObject(BlockAPI $level, $x, $y, $z){
|
||||
public function canPlaceObject(Level $level, $x, $y, $z){
|
||||
$this->findRandomLeavesSize();
|
||||
$checkRadius = 0;
|
||||
for($yy = 0; $yy < $this->totalHeight + 2; ++$yy) {
|
||||
@ -60,17 +60,17 @@ class SpruceTreeObject extends TreeObject{
|
||||
$this->leavesMaxRadius = 1 + mt_rand(0, 1);
|
||||
}
|
||||
|
||||
public function placeObject(BlockAPI $level, $x, $y, $z){
|
||||
public function placeObject(Level $level, $x, $y, $z){
|
||||
if($this->leavesBottomY === -1 or $this->leavesMaxRadius === -1) {
|
||||
$this->findRandomLeavesSize();
|
||||
}
|
||||
$level->setBlock(new Vector3($x, $y - 1, $z), 3, 0);
|
||||
$level->setBlock(new Vector3($x, $y - 1, $z), new DirtBlock());
|
||||
$leavesRadius = 0;
|
||||
for($yy = $this->totalHeight; $yy >= $this->leavesBottomY; --$yy){
|
||||
for ($xx = -$leavesRadius; $xx < ($leavesRadius + 1); ++$xx) {
|
||||
for ($zz = -$leavesRadius; $zz < ($leavesRadius + 1); ++$zz) {
|
||||
if (abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0) {
|
||||
$level->setBlock(new Vector3($x + $xx, $y + $yy, $z + $zz), 18, $this->type);
|
||||
$level->setBlock(new Vector3($x + $xx, $y + $yy, $z + $zz), new LeavesBLock($this->type));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -81,7 +81,7 @@ class SpruceTreeObject extends TreeObject{
|
||||
}
|
||||
}
|
||||
for($yy = 0; $yy < ($this->totalHeight - 1); ++$yy){
|
||||
$level->setBlock(new Vector3($x, $y + $yy, $z), 17, $this->type);
|
||||
$level->setBlock(new Vector3($x, $y + $yy, $z), new WoodBlock($this->type));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ class TreeObject{
|
||||
17 => true,
|
||||
18 => true,
|
||||
);
|
||||
public static function growTree(BlockAPI $level, Block $block){
|
||||
public static function growTree(Level $level, Block $block){
|
||||
switch($block->getMetadata() & 0x03){
|
||||
case SaplingBlock::SPRUCE:
|
||||
if(mt_rand(0,1) == 1){
|
||||
|
Loading…
x
Reference in New Issue
Block a user