mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
Improved trees, improved inventory transactions, improved snowball/bow usage
This commit is contained in:
47
src/pocketmine/level/generator/object/BirchTree.php
Normal file
47
src/pocketmine/level/generator/object/BirchTree.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\level\generator\object;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\Wood;
|
||||
use pocketmine\level\ChunkManager;
|
||||
use pocketmine\utils\Random;
|
||||
|
||||
class BirchTree extends Tree{
|
||||
|
||||
protected $superBirch = false;
|
||||
|
||||
public function __construct($superBirch = false){
|
||||
$this->trunkBlock = Block::LOG;
|
||||
$this->leafBlock = Block::LEAVES;
|
||||
$this->type = Wood::BIRCH;
|
||||
$this->superBirch = (bool) $superBirch;
|
||||
}
|
||||
|
||||
public function placeObject(ChunkManager $level, $x, $y, $z, Random $random){
|
||||
$this->treeHeight = $random->nextBoundedInt(3) + 5;
|
||||
if($this->superBirch){
|
||||
$this->treeHeight += 5;
|
||||
}
|
||||
parent::placeObject($level, $x, $y, $z, $random);
|
||||
}
|
||||
}
|
35
src/pocketmine/level/generator/object/JungleTree.php
Normal file
35
src/pocketmine/level/generator/object/JungleTree.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\level\generator\object;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\Wood;
|
||||
|
||||
class JungleTree extends Tree{
|
||||
|
||||
public function __construct(){
|
||||
$this->trunkBlock = Block::LOG;
|
||||
$this->leafBlock = Block::LEAVES;
|
||||
$this->type = Wood::JUNGLE;
|
||||
$this->treeHeight = 8;
|
||||
}
|
||||
}
|
41
src/pocketmine/level/generator/object/OakTree.php
Normal file
41
src/pocketmine/level/generator/object/OakTree.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\level\generator\object;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\Wood;
|
||||
use pocketmine\level\ChunkManager;
|
||||
use pocketmine\utils\Random;
|
||||
|
||||
class OakTree extends Tree{
|
||||
|
||||
public function __construct(){
|
||||
$this->trunkBlock = Block::LOG;
|
||||
$this->leafBlock = Block::LEAVES;
|
||||
$this->type = Wood::OAK;
|
||||
}
|
||||
|
||||
public function placeObject(ChunkManager $level, $x, $y, $z, Random $random){
|
||||
$this->treeHeight = $random->nextBoundedInt(3) + 4;
|
||||
parent::placeObject($level, $x, $y, $z, $random);
|
||||
}
|
||||
}
|
@ -50,8 +50,8 @@ class Ore{
|
||||
$x2 = $x + 8 - $offset->x;
|
||||
$z1 = $z + 8 + $offset->y;
|
||||
$z2 = $z + 8 - $offset->y;
|
||||
$y1 = $y + $this->random->nextRange(0, 3) + 2;
|
||||
$y2 = $y + $this->random->nextRange(0, 3) + 2;
|
||||
$y1 = $y + $this->random->nextBoundedInt(3) + 2;
|
||||
$y2 = $y + $this->random->nextBoundedInt(3) + 2;
|
||||
for($count = 0; $count <= $clusterSize; ++$count){
|
||||
$seedX = $x1 + ($x2 - $x1) * $count / $clusterSize;
|
||||
$seedY = $y1 + ($y2 - $y1) * $count / $clusterSize;
|
||||
|
@ -1,96 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\level\generator\object;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\level\ChunkManager;
|
||||
use pocketmine\utils\Random;
|
||||
|
||||
class PineTree extends Tree{
|
||||
var $type = 1;
|
||||
private $totalHeight = 8;
|
||||
private $leavesSizeY = -1;
|
||||
private $leavesAbsoluteMaxRadius = -1;
|
||||
|
||||
public function canPlaceObject(ChunkManager $level, $x, $y, $z, Random $random){
|
||||
$this->findRandomLeavesSize($random);
|
||||
$checkRadius = 0;
|
||||
for($yy = 0; $yy < $this->totalHeight; ++$yy){
|
||||
if($yy === $this->leavesSizeY){
|
||||
$checkRadius = $this->leavesAbsoluteMaxRadius;
|
||||
}
|
||||
for($xx = -$checkRadius; $xx < ($checkRadius + 1); ++$xx){
|
||||
for($zz = -$checkRadius; $zz < ($checkRadius + 1); ++$zz){
|
||||
if(!isset($this->overridable[$level->getBlockIdAt($x + $xx, $y + $yy, $z + $zz)])){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function findRandomLeavesSize(Random $random){
|
||||
$this->totalHeight += $random->nextRange(-1, 2);
|
||||
$this->leavesSizeY = 1 + $random->nextRange(0, 2);
|
||||
$this->leavesAbsoluteMaxRadius = 2 + $random->nextRange(0, 1);
|
||||
}
|
||||
|
||||
public function placeObject(ChunkManager $level, $x, $y, $z, Random $random){
|
||||
if($this->leavesSizeY === -1 or $this->leavesAbsoluteMaxRadius === -1){
|
||||
$this->findRandomLeavesSize($random);
|
||||
}
|
||||
$level->setBlockIdAt($x, $y - 1, $z, Block::DIRT);
|
||||
$leavesRadius = 0;
|
||||
$leavesMaxRadius = 1;
|
||||
$leavesBottomY = $this->totalHeight - $this->leavesSizeY;
|
||||
$firstMaxedRadius = false;
|
||||
for($leavesY = 0; $leavesY <= $leavesBottomY; ++$leavesY){
|
||||
$yy = $this->totalHeight - $leavesY;
|
||||
for($xx = -$leavesRadius; $xx <= $leavesRadius; ++$xx){
|
||||
for($zz = -$leavesRadius; $zz <= $leavesRadius; ++$zz){
|
||||
if(abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0){
|
||||
$level->setBlockIdAt($x + $xx, $y + $yy, $z + $zz, Block::LEAVES);
|
||||
$level->setBlockDataAt($x + $xx, $y + $yy, $z + $zz, $this->type);
|
||||
}
|
||||
}
|
||||
}
|
||||
if($leavesRadius >= $leavesMaxRadius){
|
||||
$leavesRadius = $firstMaxedRadius ? 1 : 0;
|
||||
$firstMaxedRadius = true;
|
||||
if(++$leavesMaxRadius > $this->leavesAbsoluteMaxRadius){
|
||||
$leavesMaxRadius = $this->leavesAbsoluteMaxRadius;
|
||||
}
|
||||
}else{
|
||||
++$leavesRadius;
|
||||
}
|
||||
}
|
||||
$trunkHeightReducer = $random->nextRange(0, 3);
|
||||
for($yy = 0; $yy < ($this->totalHeight - $trunkHeightReducer); ++$yy){
|
||||
$level->setBlockIdAt($x, $y + $yy, $z, Block::TRUNK);
|
||||
$level->setBlockDataAt($x, $y + $yy, $z, $this->type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\level\generator\object;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\level\ChunkManager;
|
||||
use pocketmine\utils\Random;
|
||||
|
||||
class SmallTree extends Tree{
|
||||
public $type = 0;
|
||||
private $trunkHeight = 5;
|
||||
private static $leavesHeight = 4; // All trees appear to be 4 tall
|
||||
private static $leafRadii = [1, 1.41, 2.83, 2.24];
|
||||
|
||||
private $addLeavesVines = false;
|
||||
private $addLogVines = false;
|
||||
private $addCocoaPlants = false;
|
||||
|
||||
public function canPlaceObject(ChunkManager $level, $x, $y, $z, Random $random){
|
||||
$radiusToCheck = 0;
|
||||
for($yy = 0; $yy < $this->trunkHeight + 3; ++$yy){
|
||||
if($yy == 1 or $yy === $this->trunkHeight){
|
||||
++$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){
|
||||
// The base dirt block
|
||||
$level->setBlockIdAt($x, $y, $z, Block::DIRT);
|
||||
|
||||
// Adjust the tree trunk's height randomly
|
||||
// plot [-14:11] int( x / 8 ) + 5
|
||||
// - min=4 (all leaves are 4 tall, some trunk must show)
|
||||
// - max=6 (top leaves are within ground-level whacking range
|
||||
// on all small trees)
|
||||
$heightPre = $random->nextRange(-14, 11);
|
||||
$this->trunkHeight = intval($heightPre / 8) + 5;
|
||||
|
||||
// Adjust the starting leaf density using the trunk height as a
|
||||
// starting position (tall trees with skimpy leaves don't look
|
||||
// too good)
|
||||
$leafPre = $random->nextRange($this->trunkHeight, 10) / 20; // (TODO: seed may apply)
|
||||
|
||||
// Now build the tree (from the top down)
|
||||
$leaflevel = 0;
|
||||
for($yy = ($this->trunkHeight + 1); $yy >= 0; --$yy){
|
||||
if($leaflevel < self::$leavesHeight){
|
||||
// The size is a slight variation on the trunkheight
|
||||
$radius = self::$leafRadii[$leaflevel] + $leafPre;
|
||||
$bRadius = 3;
|
||||
for($xx = -$bRadius; $xx <= $bRadius; ++$xx){
|
||||
for($zz = -$bRadius; $zz <= $bRadius; ++$zz){
|
||||
if(sqrt($xx ** 2 + $zz ** 2) <= $radius){
|
||||
$level->setBlockIdAt($x + $xx, $y + $yy, $z + $zz, Block::LEAVES);
|
||||
$level->setBlockDataAt($x + $xx, $y + $yy, $z + $zz, $this->type);
|
||||
}
|
||||
}
|
||||
}
|
||||
$leaflevel++;
|
||||
}
|
||||
|
||||
// Place the trunk last
|
||||
if($leaflevel > 1){
|
||||
$level->setBlockIdAt($x, $y + $yy, $z, Block::TRUNK);
|
||||
$level->setBlockDataAt($x, $y + $yy, $z, $this->type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -22,64 +22,56 @@
|
||||
namespace pocketmine\level\generator\object;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\Wood;
|
||||
use pocketmine\level\ChunkManager;
|
||||
use pocketmine\utils\Random;
|
||||
|
||||
class SpruceTree extends Tree{
|
||||
var $type = 1;
|
||||
private $totalHeight = 8;
|
||||
private $leavesBottomY = -1;
|
||||
private $leavesMaxRadius = -1;
|
||||
|
||||
public function canPlaceObject(ChunkManager $level, $x, $y, $z, Random $random){
|
||||
$this->findRandomLeavesSize($random);
|
||||
$checkRadius = 0;
|
||||
for($yy = 0; $yy < $this->totalHeight + 2; ++$yy){
|
||||
if($yy === $this->leavesBottomY){
|
||||
$checkRadius = $this->leavesMaxRadius;
|
||||
}
|
||||
for($xx = -$checkRadius; $xx < ($checkRadius + 1); ++$xx){
|
||||
for($zz = -$checkRadius; $zz < ($checkRadius + 1); ++$zz){
|
||||
if(!isset($this->overridable[$level->getBlockIdAt($x + $xx, $y + $yy, $z + $zz)])){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function findRandomLeavesSize(Random $random){
|
||||
$this->totalHeight += $random->nextRange(-1, 2);
|
||||
$this->leavesBottomY = (int) ($this->totalHeight - $random->nextRange(1, 2) - 3);
|
||||
$this->leavesMaxRadius = 1 + $random->nextRange(0, 1);
|
||||
public function __construct(){
|
||||
$this->trunkBlock = Block::LOG;
|
||||
$this->leafBlock = Block::LEAVES;
|
||||
$this->type = Wood::SPRUCE;
|
||||
$this->treeHeight = 10;
|
||||
}
|
||||
|
||||
public function placeObject(ChunkManager $level, $x, $y, $z, Random $random){
|
||||
if($this->leavesBottomY === -1 or $this->leavesMaxRadius === -1){
|
||||
$this->findRandomLeavesSize($random);
|
||||
}
|
||||
$level->setBlockIdAt($x, $y - 1, $z, Block::DIRT);
|
||||
$leavesRadius = 0;
|
||||
for($yy = $this->totalHeight; $yy >= $this->leavesBottomY; --$yy){
|
||||
for($xx = -$leavesRadius; $xx <= $leavesRadius; ++$xx){
|
||||
for($zz = -$leavesRadius; $zz <= $leavesRadius; ++$zz){
|
||||
if(abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0){
|
||||
$level->setBlockIdAt($x + $xx, $y + $yy, $z + $zz, Block::LEAVES);
|
||||
$level->setBlockDataAt($x + $xx, $y + $yy, $z + $zz, $this->type);
|
||||
$this->treeHeight = $random->nextBoundedInt(4) + 6;
|
||||
|
||||
$topSize = $this->treeHeight - (1 + $random->nextBoundedInt(2));
|
||||
$lRadius = 2 + $random->nextBoundedInt(2);
|
||||
|
||||
$this->placeTrunk($level, $x, $y, $z, $random, $this->treeHeight - $random->nextBoundedInt(3));
|
||||
|
||||
$radius = $random->nextBoundedInt(2);
|
||||
$maxR = 1;
|
||||
$minR = 0;
|
||||
|
||||
for($yy = 0; $yy <= $topSize; ++$yy){
|
||||
$yyy = $y + $this->treeHeight - $yy;
|
||||
|
||||
for($xx = $x - $radius; $xx <= $x + $radius; ++$xx){
|
||||
$xOff = $xx - $x;
|
||||
for($zz = $z - $radius; $zz <= $z + $radius; ++$zz){
|
||||
$zOff = $zz - $z;
|
||||
if(abs($xOff) === $radius and abs($zOff) === $radius and $radius > 0){
|
||||
continue;
|
||||
}
|
||||
|
||||
$level->setBlockIdAt($xx, $yyy, $zz, $this->leafBlock);
|
||||
$level->setBlockDataAt($xx, $yyy, $zz, $this->type);
|
||||
}
|
||||
}
|
||||
|
||||
if($radius >= $maxR){
|
||||
$radius = $minR;
|
||||
$minR = 1;
|
||||
if(++$maxR > $lRadius){
|
||||
$maxR = $lRadius;
|
||||
}
|
||||
}else{
|
||||
++$radius;
|
||||
}
|
||||
if($leavesRadius > 0 and $yy === ($y + $this->leavesBottomY + 1)){
|
||||
--$leavesRadius;
|
||||
}elseif($leavesRadius < $this->leavesMaxRadius){
|
||||
++$leavesRadius;
|
||||
}
|
||||
}
|
||||
for($yy = 0; $yy < ($this->totalHeight - 1); ++$yy){
|
||||
$level->setBlockIdAt($x, $y + $yy, $z, Block::TRUNK);
|
||||
$level->setBlockDataAt($x, $y + $yy, $z, $this->type);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user