mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Tree growing!
This commit is contained in:
parent
8f6ed22158
commit
2353457b5b
2
TODO.md
2
TODO.md
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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"));
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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"));
|
||||
|
@ -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/");
|
||||
|
||||
?>
|
@ -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);
|
||||
|
38
misc/block/plant/Sapling.php
Normal file
38
misc/block/plant/Sapling.php
Normal 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);
|
||||
}
|
||||
}
|
60
misc/world/generator/object/tree/SmallTreeObject.php
Normal file
60
misc/world/generator/object/tree/SmallTreeObject.php
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
40
misc/world/generator/object/tree/TreeObject.php
Normal file
40
misc/world/generator/object/tree/TreeObject.php
Normal 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);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user