Place/Breaking/Activation logic separated from BlockAPI

This commit is contained in:
Shoghi Cervantes Pueyo 2013-02-03 18:55:59 +01:00
parent 6156baab85
commit d9c87161ba
37 changed files with 387 additions and 216 deletions

View file

@ -43,11 +43,11 @@ class BigTreeObject extends TreeObject{
private $addLogVines = false;
private $addCocoaPlants = false;
public function canPlaceObject(LevelAPI $level, $x, $y, $z){
public function canPlaceObject(BlockAPI $level, $x, $y, $z){
return false;
}
public function placeObject(LevelAPI $level, $x, $y, $z, $type){
public function placeObject(BlockAPI $level, $x, $y, $z, $type){
$this->trunkHeight = (int) ($this->totalHeight * $this->trunkHeightMultiplier);
$leaves = $this->getLeafGroupPoints($level, $x, $y, $z);

View file

@ -34,7 +34,7 @@ class PineTreeObject extends TreeObject{
private $leavesSizeY = -1;
private $leavesAbsoluteMaxRadius = -1;
public function canPlaceObject(LevelAPI $level, $x, $y, $z){
public function canPlaceObject(BlockAPI $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);
if(!isset($this->overridable[$block[0]])){
if(!isset($this->overridable[$block->getID()])){
return false;
}
}
@ -59,11 +59,11 @@ class PineTreeObject extends TreeObject{
$this->leavesAbsoluteMaxRadius = 2 + mt_rand(0, 2);
}
public function placeObject(LevelAPI $level, $x, $y, $z){
public function placeObject(BlockAPI $level, $x, $y, $z){
if($this->leavesSizeY === -1 or $this->leavesAbsoluteMaxRadius === -1) {
$this->findRandomLeavesSize();
}
$level->setBlock($x, $y - 1, $z, 3, 0);
$level->setBlock(new Vector3($x, $y - 1, $z), 3, 0);
$leavesRadius = mt_rand(0,2);
$leavesMaxRadius = 1;
$leavesBottomY = $this->totalHeight - $this->leavesSizeY;
@ -73,7 +73,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($x + $xx, $y + $yy, $z + $zz, 18, $this->type);
$level->setBlock(New Vector3($x + $xx, $y + $yy, $z + $zz), 18, $this->type);
}
}
}
@ -89,7 +89,7 @@ class PineTreeObject extends TreeObject{
}
$trunkHeightReducer = mt_rand(0,3);
for($yy = 0; $yy < ($this->totalHeight - $trunkHeightReducer); ++$yy){
$level->setBlock($x, $y + $yy, $z, 17, $this->type);
$level->setBlock(new Vector3($x, $y + $yy, $z), 17, $this->type);
}
}

View file

@ -37,7 +37,7 @@ class SmallTreeObject extends TreeObject{
private $addLogVines = false;
private $addCocoaPlants = false;
public function canPlaceObject(LevelAPI $level, $x, $y, $z){
public function canPlaceObject(BlockAPI $level, $x, $y, $z){
$radiusToCheck = $this->radiusIncrease;
for ($yy = 0; $yy < $this->totalHeight + 2; ++$yy) {
if ($yy == 1 or $yy === $this->totalHeight - 1) {
@ -45,8 +45,8 @@ class SmallTreeObject extends TreeObject{
}
for($xx = -$radiusToCheck; $xx < ($radiusToCheck + 1); ++$xx){
for($zz = -$radiusToCheck; $zz < ($radiusToCheck + 1); ++$zz){
$block = $level->getBlock($x + $xx, $y + $yy, $z + $zz);
if(!isset($this->overridable[$block[0]])){
$block = $level->getBlock(new Vector3($x + $xx, $y + $yy, $z + $zz));
if(!isset($this->overridable[$block->getID()])){
return false;
}
}
@ -55,8 +55,8 @@ class SmallTreeObject extends TreeObject{
return true;
}
public function placeObject(LevelAPI $level, $x, $y, $z){
$level->setBlock($x, $y - 1, $z, 3, 0);
public function placeObject(BlockAPI $level, $x, $y, $z){
$level->setBlock(new Vector3($x, $y - 1, $z), 3, 0);
$this->totalHeight += mt_rand(-1, 3);
$this->leavesHeight += mt_rand(0, 1);
for($yy = ($this->totalHeight - $this->leavesHeight); $yy < ($this->totalHeight + 1); ++$yy){
@ -65,13 +65,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($x + $xx, $y + $yy, $z + $zz, 18, $this->type);
$level->setBlock(new Vector3($x + $xx, $y + $yy, $z + $zz), 18, $this->type);
}
}
}
}
for($yy = 0; $yy < ($this->totalHeight - 1); ++$yy){
$level->setBlock($x, $y + $yy, $z, 17, $this->type);
$level->setBlock(new Vector3($x, $y + $yy, $z), 17, $this->type);
}
}

View file

@ -34,7 +34,7 @@ class SpruceTreeObject extends TreeObject{
private $leavesBottomY = -1;
private $leavesMaxRadius = -1;
public function canPlaceObject(LevelAPI $level, $x, $y, $z){
public function canPlaceObject(BlockAPI $level, $x, $y, $z){
$this->findRandomLeavesSize();
$checkRadius = 0;
for($yy = 0; $yy < $this->totalHeight + 2; ++$yy) {
@ -43,8 +43,8 @@ class SpruceTreeObject 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);
if(!isset($this->overridable[$block[0]])){
$block = $level->getBlock(new Vector3($x + $xx, $y + $yy, $z + $zz));
if(!isset($this->overridable[$block->getID()])){
return false;
}
}
@ -59,17 +59,17 @@ class SpruceTreeObject extends TreeObject{
$this->leavesMaxRadius = 1 + mt_rand(0, 1);
}
public function placeObject(LevelAPI $level, $x, $y, $z){
public function placeObject(BlockAPI $level, $x, $y, $z){
if($this->leavesBottomY === -1 or $this->leavesMaxRadius === -1) {
$this->findRandomLeavesSize();
}
$level->setBlock($x, $y - 1, $z, 3, 0);
$level->setBlock(new Vector3($x, $y - 1, $z), 3, 0);
$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($x + $xx, $y + $yy, $z + $zz, 18, $this->type);
$level->setBlock(new Vector3($x + $xx, $y + $yy, $z + $zz), 18, $this->type);
}
}
}
@ -80,7 +80,7 @@ class SpruceTreeObject extends TreeObject{
}
}
for($yy = 0; $yy < ($this->totalHeight - 1); ++$yy){
$level->setBlock($x, $y + $yy, $z, 17, $this->type);
$level->setBlock(new Vector3($x, $y + $yy, $z), 17, $this->type);
}
}

View file

@ -33,7 +33,7 @@ class TreeObject{
17 => true,
18 => true,
);
public static function growTree(LevelAPI $level, Block $block){
public static function growTree(BlockAPI $level, Block $block){
switch($block->getMetadata() & 0x03){
case SaplingBlock::SPRUCE:
if(mt_rand(0,1) == 1){
@ -55,8 +55,8 @@ class TreeObject{
}
break;
}
if($tree->canPlaceObject($level, $block->v->x, $block->v->y, $block->v->z)){
$tree->placeObject($level, $block->v->x, $block->v->y, $block->v->z);
if($tree->canPlaceObject($level, $block->x, $block->y, $block->z)){
$tree->placeObject($level, $block->x, $block->y, $block->z);
}
}
}