Improved trees, improved inventory transactions, improved snowball/bow usage

This commit is contained in:
Shoghi Cervantes
2015-03-28 16:59:15 +01:00
parent 47de616ac5
commit 0a85ad0d1f
22 changed files with 363 additions and 360 deletions

View File

@ -26,11 +26,9 @@ use pocketmine\block\Sapling;
use pocketmine\level\ChunkManager;
use pocketmine\utils\Random;
class Tree{
abstract class Tree{
public $overridable = [
0 => true,
2 => true,
3 => true,
Block::AIR => true,
6 => true,
17 => true,
18 => true,
@ -39,29 +37,33 @@ class Tree{
Block::LEAVES2 => true
];
public $type = 0;
public $trunkBlock = Block::LOG;
public $leafBlock = Block::LEAVES;
public $treeHeight = 7;
public static function growTree(ChunkManager $level, $x, $y, $z, Random $random, $type = 0){
switch($type & 0x03){
switch($type){
case Sapling::SPRUCE:
if($random->nextRange(0, 1) === 1){
$tree = new SpruceTree();
}else{
$tree = new PineTree();
}
$tree = new SpruceTree();
break;
case Sapling::BIRCH:
$tree = new SmallTree();
$tree->type = Sapling::BIRCH;
if($random->nextBoundedInt(39) === 0){
$tree = new BirchTree(true);
}else{
$tree = new BirchTree();
}
break;
case Sapling::JUNGLE:
$tree = new SmallTree();
$tree->type = Sapling::JUNGLE;
$tree = new JungleTree();
break;
case Sapling::OAK:
default:
$tree = new OakTree();
/*if($random->nextRange(0, 9) === 0){
$tree = new BigTree();
}else{*/
$tree = new SmallTree();
//}
break;
}
@ -69,4 +71,57 @@ class Tree{
$tree->placeObject($level, $x, $y, $z, $random);
}
}
public function canPlaceObject(ChunkManager $level, $x, $y, $z, Random $random){
$radiusToCheck = 0;
for($yy = 0; $yy < $this->treeHeight + 3; ++$yy){
if($yy == 1 or $yy === $this->treeHeight){
++$radiusToCheck;
}
for($xx = -$radiusToCheck; $xx < ($radiusToCheck + 1); ++$xx){
for($zz = -$radiusToCheck; $zz < ($radiusToCheck + 1); ++$zz){
if(!isset($this->overridable[$level->getBlockIdAt($x + $xx, $y + $yy, $z + $zz)])){
return false;
}
}
}
}
return true;
}
public function placeObject(ChunkManager $level, $x, $y, $z, Random $random){
$this->placeTrunk($level, $x, $y, $z, $random, $this->treeHeight - 1);
for($yy = $y - 3 + $this->treeHeight; $yy <= $y + $this->treeHeight; ++$yy){
$yOff = $yy - ($y + $this->treeHeight);
$mid = (int) (1 - $yOff / 2);
for($xx = $x - $mid; $xx <= $x + $mid; ++$xx){
$xOff = $xx - $x;
for($zz = $z - $mid; $zz <= $z + $mid; ++$zz){
$zOff = $zz - $z;
if(abs($xOff) === $mid and abs($zOff) === $mid and ($yOff === 0 or $random->nextBoundedInt(2) === 0)){
continue;
}
$level->setBlockIdAt($xx, $yy, $zz, $this->leafBlock);
$level->setBlockDataAt($xx, $yy, $zz, $this->type);
}
}
}
}
protected function placeTrunk(ChunkManager $level, $x, $y, $z, Random $random, $trunkHeight){
// The base dirt block
$level->setBlockIdAt($x, $y - 1, $z, Block::DIRT);
for($yy = 0; $yy <= $trunkHeight; ++$yy){
$blockId = $level->getBlockIdAt($x, $y + $yy, $z);
if(isset($this->overridable[$blockId])){
$level->setBlockIdAt($x, $y + $yy, $z, $this->trunkBlock);
$level->setBlockDataAt($x, $y + $yy, $z, $this->type);
}
}
}
}