diff --git a/src/classes/material/Item.php b/src/classes/material/Item.php index 92b78a33c..d8246fd1a 100644 --- a/src/classes/material/Item.php +++ b/src/classes/material/Item.php @@ -84,19 +84,32 @@ class Item{ switch($this->id){ case IRON_PICKAXE: return 3; - case 270: //Wood + case WOODEN_PICKAXE: return 1; - case 274: //Stone + case STONE_PICKAXE: return 2; - case 278: //Diamond + case DIAMOND_PICKAXE: return 4; - case 285: //Gold + case GOLD_PICKAXE: return 3; default: return false; } } + public function isHoe(){ + switch($this->id){ + case IRON_HOE: + case WOODEN_HOE: + case STONE_HOE: + case DIAMOND_HOE: + case GOLD_HOE: + return true; + default: + return false; + } + } + public function getDestroySpeed(Block $block, Player $player){ return 1; } diff --git a/src/classes/material/block/plant/MelonStem.php b/src/classes/material/block/plant/MelonStem.php index 271c7cbc7..9f8f69248 100644 --- a/src/classes/material/block/plant/MelonStem.php +++ b/src/classes/material/block/plant/MelonStem.php @@ -32,7 +32,7 @@ class MelonStemBlock extends TransparentBlock{ public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ if($block->inWorld === true){ $down = $level->getBlockFace($block, 0); - if($down->getID() === 60){ + if($down->getID() === FARMLAND){ $level->setBlock($block, $this->id, $this->getMetadata()); return true; } diff --git a/src/classes/material/block/plant/Sapling.php b/src/classes/material/block/plant/Sapling.php index 82ffdef3c..7a36526dd 100644 --- a/src/classes/material/block/plant/Sapling.php +++ b/src/classes/material/block/plant/Sapling.php @@ -46,7 +46,7 @@ class SaplingBlock extends TransparentBlock{ public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ if($block->inWorld === true){ $down = $level->getBlockFace($block, 0); - if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){ + if($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === FARMLAND){ $level->setBlock($block, $this->id, $this->getMetadata()); return true; } @@ -55,7 +55,7 @@ class SaplingBlock extends TransparentBlock{ } public function onActivate(BlockAPI $level, Item $item, Player $player){ - if($item->getID() === 351 and $item->getMetadata() === 0x0F){ //Bonemeal + if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal TreeObject::growTree($level, $this); return true; } diff --git a/src/classes/material/block/plant/Wheat.php b/src/classes/material/block/plant/Wheat.php index d27fb7708..19f601004 100644 --- a/src/classes/material/block/plant/Wheat.php +++ b/src/classes/material/block/plant/Wheat.php @@ -33,7 +33,7 @@ class WheatBlock extends FlowableBlock{ public function place(BlockAPI $level, Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ if($block->inWorld === true){ $down = $level->getBlockFace($block, 0); - if($down->getID() === 60){ + if($down->getID() === FARMLAND){ $level->setBlock($block, $this->id, $this->getMetadata()); return true; } diff --git a/src/classes/material/block/solid/Dirt.php b/src/classes/material/block/solid/Dirt.php index d05415ffc..9d8b0662c 100644 --- a/src/classes/material/block/solid/Dirt.php +++ b/src/classes/material/block/solid/Dirt.php @@ -28,6 +28,14 @@ the Free Software Foundation, either version 3 of the License, or class DirtBlock extends SolidBlock{ public function __construct(){ parent::__construct(DIRT, 0, "Dirt"); + $this->isActivable = true; + } + + public function onActivate(BlockAPI $level, Item $item, Player $player){ + if($item->isHoe()){ + $level->setBlock($this, FARMLAND, 0); + return true; + } + return false; } - } \ No newline at end of file diff --git a/src/classes/material/block/solid/Grass.php b/src/classes/material/block/solid/Grass.php index 82c5b9add..9c8f8a5ef 100644 --- a/src/classes/material/block/solid/Grass.php +++ b/src/classes/material/block/solid/Grass.php @@ -28,10 +28,40 @@ the Free Software Foundation, either version 3 of the License, or class GrassBlock extends SolidBlock{ public function __construct(){ parent::__construct(GRASS, 0, "Grass"); + $this->isActivable = true; } public function getDrops(Item $item, Player $player){ return array( array(DIRT, 0, 1), ); - } + } + + public function onActivate(BlockAPI $level, Item $item, Player $player){ + if($item->getID() === DYE and $item->getMetadata() === 0x0F){ + for($c = 0; $c < 15; ++$c){ + $x = mt_rand($this->x - 2, $this->x + 2); + $z = mt_rand($this->z - 2, $this->z + 2); + $b = $level->getBlock(new Vector3($x, $this->y + 1, $z)); + $d = $level->getBlock(new Vector3($x, $this->y, $z)); + if($b->getID() === AIR and $d->getID() === GRASS){ + $arr = array( + array(DANDELION, 0), + array(CYAN_FLOWER, 0), + array(TALL_GRASS, 1), + array(TALL_GRASS, 1), + array(TALL_GRASS, 1), + array(TALL_GRASS, 1), + array(AIR, 0), + ); + $t = $arr[mt_rand(0, count($arr) - 1)]; + $level->setBlock($b, $t[0], $t[1]); + } + } + return true; + }elseif($item->isHoe()){ + $level->setBlock($this, FARMLAND, 0); + return true; + } + return false; + } } \ No newline at end of file