From 3f532d419cef4739a040c574d41a04c9bb22816a Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Wed, 15 May 2013 22:06:38 +0200 Subject: [PATCH] Saplings --- src/material/block/plant/Sapling.php | 19 ++++++++----------- src/world/Level.php | 2 +- .../generator/object/tree/BigTreeObject.php | 4 ++-- .../generator/object/tree/PineTreeObject.php | 12 ++++++------ .../generator/object/tree/SmallTreeObject.php | 10 +++++----- .../object/tree/SpruceTreeObject.php | 10 +++++----- .../generator/object/tree/TreeObject.php | 2 +- 7 files changed, 28 insertions(+), 31 deletions(-) diff --git a/src/material/block/plant/Sapling.php b/src/material/block/plant/Sapling.php index 4a767656d..fee962242 100644 --- a/src/material/block/plant/Sapling.php +++ b/src/material/block/plant/Sapling.php @@ -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; } diff --git a/src/world/Level.php b/src/world/Level.php index af11c1643..64fb44366 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -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(); diff --git a/src/world/generator/object/tree/BigTreeObject.php b/src/world/generator/object/tree/BigTreeObject.php index 4f5fd29a6..28a99dab6 100644 --- a/src/world/generator/object/tree/BigTreeObject.php +++ b/src/world/generator/object/tree/BigTreeObject.php @@ -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); diff --git a/src/world/generator/object/tree/PineTreeObject.php b/src/world/generator/object/tree/PineTreeObject.php index 11cb30c0a..c70f70c76 100644 --- a/src/world/generator/object/tree/PineTreeObject.php +++ b/src/world/generator/object/tree/PineTreeObject.php @@ -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)); } } diff --git a/src/world/generator/object/tree/SmallTreeObject.php b/src/world/generator/object/tree/SmallTreeObject.php index 665b14faa..08020f5f6 100644 --- a/src/world/generator/object/tree/SmallTreeObject.php +++ b/src/world/generator/object/tree/SmallTreeObject.php @@ -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)); } } diff --git a/src/world/generator/object/tree/SpruceTreeObject.php b/src/world/generator/object/tree/SpruceTreeObject.php index 1837989e0..ecd81d8f4 100644 --- a/src/world/generator/object/tree/SpruceTreeObject.php +++ b/src/world/generator/object/tree/SpruceTreeObject.php @@ -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)); } } diff --git a/src/world/generator/object/tree/TreeObject.php b/src/world/generator/object/tree/TreeObject.php index 3ebd4586d..7351c25ad 100644 --- a/src/world/generator/object/tree/TreeObject.php +++ b/src/world/generator/object/tree/TreeObject.php @@ -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){