Tree growing!

This commit is contained in:
Shoghi Cervantes Pueyo 2012-12-27 01:08:26 +01:00
parent 8f6ed22158
commit 2353457b5b
10 changed files with 163 additions and 5 deletions

View File

@ -15,7 +15,7 @@ __Check Milestones [here](https://github.com/shoghicp/PocketMine-MP/issues/miles
* Done!
### Alpha v1.1
* Tree growing!
## Beta (Survival)
- Random Chunk Updates

View File

@ -176,6 +176,10 @@ class BlockAPI{
if(isset(Material::$activable[$target[0]])){
switch($target[0]){
case 6:
if($data["block"] === 351 and $data["meta"] === 0x0F){ //Bonemeal
Sapling::growTree($this->server->api->level, $target, $target[1] & 0x03);
$cancelPlace = true;
}
break;
case 2:
case 3:

View File

@ -153,7 +153,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
if($this->getProperty("generator") !== false and class_exists($this->getProperty("generator"))){
$generator = $this->getProperty("generator");
}
$this->gen = new Generator($generator, $this->server->seed);
$this->gen = new WorldGenerator($generator, $this->server->seed);
if($this->getProperty("generator-settings") !== false and trim($this->getProperty("generator-settings")) != ""){
$this->gen->set("preset", $this->getProperty("generator-settings"));
}

View File

@ -25,8 +25,7 @@ the Free Software Foundation, either version 3 of the License, or
*/
class Generator{
class WorldGenerator{
private $gen, $seed, $raw;
public function __construct($genName, $seed){
$this->seed = (int) $seed;

View File

@ -35,7 +35,7 @@ define("BIG_ENDIAN", 0x00);
define("LITTLE_ENDIAN", 0x01);
define("ENDIANNESS", (pack("d", 1) === "\77\360\0\0\0\0\0\0" ? BIG_ENDIAN:LITTLE_ENDIAN));
class Utils{
abstract class Utils{
public static function getOS(){
$uname = strtoupper(php_uname("s"));

View File

@ -69,6 +69,7 @@ if($errors > 0){
}
require_once("classes/Data.class.php");
require_once("classes/Player.class.php");
require_once("classes/Generator.class.php");
@ -84,5 +85,6 @@ require_once("classes/SerializedPacketHandler.class.php");
require_once("classes/CustomPacketHandler.class.php");
require_once("classes/MinecraftInterface.class.php");
require_once("classes/BigInteger.class.php");
require_all("misc/");
?>

View File

@ -26,6 +26,21 @@ the Free Software Foundation, either version 3 of the License, or
*/
function require_all($path, &$count = 0){
$dir = dir($path."/");
while(false !== ($file = $dir->read())){
if($file !== "." and $file !== ".."){
if(!is_dir($path.$file) and strtolower(substr($file, -3)) === "php"){
require_once($path.$file);
++$count;
}elseif(is_dir($path.$file)){
require_all($path.$file."/", $count);
}
}
}
}
function hard_unset(&$var){
if(is_object($var)){
$unset = new ReflectionClass($var);

View File

@ -0,0 +1,38 @@
<?php
/*
-
/ \
/ \
/ PocketMine \
/ MP \
|\ @shoghicp /|
|. \ / .|
| .. \ / .. |
| .. | .. |
| .. | .. |
\ | /
\ | /
\ | /
\ | /
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.
*/
class Sapling{
const OAK = 0;
const SPRUCE = 1;
const BIRCH = 2;
const BURN_TIME = 5;
public static function growTree(LevelAPI $level, $block, $type){
$type = $type & 0x03;
TreeObject::growTree($level, $block, $type);
}
}

View File

@ -0,0 +1,60 @@
<?php
/*
-
/ \
/ \
/ PocketMine \
/ MP \
|\ @shoghicp /|
|. \ / .|
| .. \ / .. |
| .. | .. |
| .. | .. |
\ | /
\ | /
\ | /
\ | /
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.
*/
require_once("misc/world/generator/object/tree/TreeObject.php");
class SmallTreeObject extends TreeObject{
private $totalHeight = 6;
private $leavesHeight = 3;
protected $radiusIncrease = 0;
private $addLeavesVines = false;
private $addLogVines = false;
private $addCocoaPlants = false;
public function placeObject(LevelAPI $level, $x, $y, $z, $type){
$level->setBlock($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){
$yRadius = ($yy - $this->totalHeight);
$xzRadius = (int) (($this->radiusIncrease + 1) - $yRadius / 2);
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, $type);
}
}
}
}
for($yy = 0; $yy < ($this->totalHeight - 1); ++$yy){
$level->setBlock($x, $y + $yy, $z, 17, $type);
}
}
}

View File

@ -0,0 +1,40 @@
<?php
/*
-
/ \
/ \
/ PocketMine \
/ MP \
|\ @shoghicp /|
|. \ / .|
| .. \ / .. |
| .. | .. |
| .. | .. |
\ | /
\ | /
\ | /
\ | /
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.
*/
class TreeObject{
public static function growTree(LevelAPI $level, $block, $type){
switch($type){
default:
case Sapling::OAK:
$tree = new SmallTreeObject();
break;
}
$tree->placeObject($level, $block[2][0], $block[2][1], $block[2][2], $type);
}
}