Tilling Dirt & Grass, tall gras growth

This commit is contained in:
Shoghi Cervantes Pueyo 2013-02-04 18:54:48 +01:00
parent a718294a08
commit fee04cd0d9
6 changed files with 61 additions and 10 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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;
}
}