diff --git a/src/classes/material/Block.php b/src/classes/material/Block.php new file mode 100644 index 000000000..fd314ae94 --- /dev/null +++ b/src/classes/material/Block.php @@ -0,0 +1,83 @@ + "GenericBlock", + + );*/ + + protected $id; + protected $meta; + protected $shortname = ""; + protected $name = ""; + public $isActivable = false; + public $isBreakable = true; + public $isFlowable = false; + public $isTransparent = false; + public $isReplaceable = false; + public $isPlaceable = true; + public $inWorld = false; + public $hasPhysics = false; + public $v = false; + + public function __construct($id, $meta = 0, $name = "Unknown"){ + $this->id = (int) $id; + $this->meta = (int) $meta; + $this->name = $name; + $this->shortname = strtolower(str_replace(" ", "_", $name)); + } + + final public function getID(){ + return $id; + } + + final public function getMetadata(){ + return $meta & 0x0F; + } + + final public function position(Vector3 $v){ + $this->inWorld = true; + $this->position = new Vector3((int) $v->x, (int) $v->y, (int) $v->z); + } + + public function getDrops(Item $item, Player $player){ + return array( + array($this->id, $this->meta, 1), + ); + } + + abstract function onActivate(LevelAPI $level, Item $item, Player $player); + + abstract function onUpdate(LevelAPI $level, $type); +} + +require_once("block/GenericBlock.php"); +require_once("block/SolidBlock.php"); +require_once("block/TransparentBlock.php"); +require_once("block/FallableBlock.php"); \ No newline at end of file diff --git a/src/classes/material/IDs.php b/src/classes/material/IDs.php new file mode 100644 index 000000000..dca5879e4 --- /dev/null +++ b/src/classes/material/IDs.php @@ -0,0 +1,162 @@ +id = (int) $id; + $this->meta = (int) $meta; } - public function setMaxStackSize($size = 64){ - $this->maxStackSize = (int) $size; - } - public function getDestroySpeed(Item $item, Entity $entity){ - return 1; - } public function getMaxStackSize(){ return $this->maxStackSize; } + public function getDestroySpeed(Item $item, Player $player){ + return 1; + } + } \ No newline at end of file diff --git a/src/classes/block/plant/Sapling.php b/src/classes/material/block/FallableBlock.php similarity index 71% rename from src/classes/block/plant/Sapling.php rename to src/classes/material/block/FallableBlock.php index 320835dc5..992bacb4d 100644 --- a/src/classes/block/plant/Sapling.php +++ b/src/classes/material/block/FallableBlock.php @@ -25,14 +25,9 @@ the Free Software Foundation, either version 3 of the License, or */ -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); +class FallableBlock extends GenericBlock{ + public function __construct($id, $meta = 0, $name = "Unknown"){ + parent::__construct($id, $meta, $name); + $this->hasPhysics = true; } } \ No newline at end of file diff --git a/src/classes/material/block/FlowableBlock.php b/src/classes/material/block/FlowableBlock.php new file mode 100644 index 000000000..8f8524efb --- /dev/null +++ b/src/classes/material/block/FlowableBlock.php @@ -0,0 +1,33 @@ +isFlowable = true; + } +} \ No newline at end of file diff --git a/src/classes/material/block/GenericBlock.php b/src/classes/material/block/GenericBlock.php new file mode 100644 index 000000000..59e232127 --- /dev/null +++ b/src/classes/material/block/GenericBlock.php @@ -0,0 +1,36 @@ +isActivable = false; + $this->isBreakable = true; + $this->isFlowable = false; + $this->isTransparent = true; + $this->isReplaceable = false; + $this->isPlaceable = true; + } +} \ No newline at end of file diff --git a/src/classes/material/block/misc/Bed.php b/src/classes/material/block/misc/Bed.php new file mode 100644 index 000000000..8f61626d2 --- /dev/null +++ b/src/classes/material/block/misc/Bed.php @@ -0,0 +1,34 @@ +isActivable = true; + } + +} \ No newline at end of file diff --git a/src/classes/material/block/ore/CoalOre.php b/src/classes/material/block/ore/CoalOre.php new file mode 100644 index 000000000..ec13e6302 --- /dev/null +++ b/src/classes/material/block/ore/CoalOre.php @@ -0,0 +1,39 @@ +isFlowable = true; + } + +} \ No newline at end of file diff --git a/src/classes/material/block/plant/CyanFlower.php b/src/classes/material/block/plant/CyanFlower.php new file mode 100644 index 000000000..0810b937c --- /dev/null +++ b/src/classes/material/block/plant/CyanFlower.php @@ -0,0 +1,34 @@ +isFlowable = true; + } + +} \ No newline at end of file diff --git a/src/classes/material/block/plant/Dandelion.php b/src/classes/material/block/plant/Dandelion.php new file mode 100644 index 000000000..fdb46f464 --- /dev/null +++ b/src/classes/material/block/plant/Dandelion.php @@ -0,0 +1,34 @@ +isFlowable = true; + } + +} \ No newline at end of file diff --git a/src/classes/material/block/plant/DeadBush.php b/src/classes/material/block/plant/DeadBush.php new file mode 100644 index 000000000..d75599119 --- /dev/null +++ b/src/classes/material/block/plant/DeadBush.php @@ -0,0 +1,35 @@ +isFlowable = true; + $this->isReplaceable = true; + } + +} \ No newline at end of file diff --git a/src/classes/material/block/plant/RedMushroom.php b/src/classes/material/block/plant/RedMushroom.php new file mode 100644 index 000000000..eea6dc3ed --- /dev/null +++ b/src/classes/material/block/plant/RedMushroom.php @@ -0,0 +1,34 @@ +isFlowable = true; + } + +} \ No newline at end of file diff --git a/src/classes/material/block/plant/Sapling.php b/src/classes/material/block/plant/Sapling.php new file mode 100644 index 000000000..a0b56c112 --- /dev/null +++ b/src/classes/material/block/plant/Sapling.php @@ -0,0 +1,65 @@ +isActivable = true; + $this->isFlowable = true; + $names = array( + 0 => "Oak Sapling", + 1 => "Spruce Sapling", + 2 => "Birch Sapling", + ); + $this->name = $names[$this->type & 0x03]; + } + + public function onActivate(LevelAPI $level, Item $item, Player $player){ + TreeObject::growTree($level, $this); + } + + public function onUpdate(LevelAPI $level, $type){ + if($this->inWorld !== true){ + return false; + } + if($type === BLOCK_UPDATE_RANDOM and mt_rand(0,2) === 0){ //Growth + if(($this->meta & 0x08) === 0x08){ + TreeObject::growTree($level, $this); + }else{ + $this->meta |= 0x08; + $this->level->setBlock($this->x, $this->y, $this->z, $this->id, $this->meta); + } + return true; + } + return false; + } +} \ No newline at end of file diff --git a/src/classes/material/block/plant/TallGrass.php b/src/classes/material/block/plant/TallGrass.php new file mode 100644 index 000000000..be507038b --- /dev/null +++ b/src/classes/material/block/plant/TallGrass.php @@ -0,0 +1,41 @@ +isFlowable = true; + $this->isReplaceable = true; + $names = array( + 0 => "Dead Shrub", + 1 => "Tall Grass", + 2 => "Fern", + ); + $this->name = $names[$this->type & 0x03]; + } + +} \ No newline at end of file diff --git a/src/classes/material/block/solid/Bedrock.php b/src/classes/material/block/solid/Bedrock.php new file mode 100644 index 000000000..ffd925bf2 --- /dev/null +++ b/src/classes/material/block/solid/Bedrock.php @@ -0,0 +1,34 @@ +isBreakable = false; + } + +} \ No newline at end of file diff --git a/src/classes/material/block/solid/Cobblestone.php b/src/classes/material/block/solid/Cobblestone.php new file mode 100644 index 000000000..98c0c4668 --- /dev/null +++ b/src/classes/material/block/solid/Cobblestone.php @@ -0,0 +1,33 @@ +isFlowable = true; + } + +} \ No newline at end of file diff --git a/src/classes/material/block/solid/Dirt.php b/src/classes/material/block/solid/Dirt.php new file mode 100644 index 000000000..d05415ffc --- /dev/null +++ b/src/classes/material/block/solid/Dirt.php @@ -0,0 +1,33 @@ + "Oak Leaves", + 1 => "Spruce Leaves", + 2 => "Birch Leaves", + ); + $this->name = $names[$this->type & 0x03]; + } + +} \ No newline at end of file diff --git a/src/classes/material/block/solid/Planks.php b/src/classes/material/block/solid/Planks.php new file mode 100644 index 000000000..d41c3d3ff --- /dev/null +++ b/src/classes/material/block/solid/Planks.php @@ -0,0 +1,33 @@ + "Sandstone", + 1 => "Chiseled Sandstone", + 2 => "Smooth Sandstone", + ); + $this->name = $names[$this->type & 0x03]; + } + +} \ No newline at end of file diff --git a/src/classes/material/block/solid/Stone.php b/src/classes/material/block/solid/Stone.php new file mode 100644 index 000000000..d45b72b36 --- /dev/null +++ b/src/classes/material/block/solid/Stone.php @@ -0,0 +1,33 @@ + "Oak Wood", + 1 => "Spruce Wood", + 2 => "Birch Wood", + ); + $this->name = $names[$this->type & 0x03]; + } + +} \ No newline at end of file diff --git a/src/classes/world/generator/object/tree/TreeObject.php b/src/classes/world/generator/object/tree/TreeObject.php index 52b0e6f29..a9afba782 100644 --- a/src/classes/world/generator/object/tree/TreeObject.php +++ b/src/classes/world/generator/object/tree/TreeObject.php @@ -33,8 +33,8 @@ class TreeObject{ 17 => true, 18 => true, ); - public static function growTree(LevelAPI $level, $block, $type){ - switch($type){ + public static function growTree(LevelAPI $level, Block $block){ + switch($block->getMetadata() & 0x03){ case Sapling::SPRUCE: if(mt_rand(0,1) == 1){ $tree = new SpruceTreeObject(); @@ -55,8 +55,8 @@ class TreeObject{ } break; } - if($tree->canPlaceObject($level, $block[2][0], $block[2][1], $block[2][2])){ - $tree->placeObject($level, $block[2][0], $block[2][1], $block[2][2]); + if($tree->canPlaceObject($level, $block->position->x, $block->position->y, $block->position->z)){ + $tree->placeObject($level, $block->position->x, $block->position->y, $block->position->z); } } } \ No newline at end of file diff --git a/src/common/functions.php b/src/common/functions.php index 70a955021..6d763b380 100644 --- a/src/common/functions.php +++ b/src/common/functions.php @@ -46,16 +46,20 @@ function kill($pid){ function require_all($path, &$count = 0){ $dir = dir($path."/"); + $dirs = array(); 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); + $dirs[] = $path.$file."/"; } } } + foreach($dirs as $dir){ + require_all($dir, $count); + } }