Exemplo n.º 1
0
 public function onActivate(Item $item, Player $player)
 {
     if ($item->getID() === DYE and $item->getMetadata() === 0xf) {
         if (($player->gamemode & 0x1) === 0) {
             $item->count--;
         }
         TallGrassObject::growGrass($this->level, $this, new Random(), 8, 2);
         return true;
     } elseif ($item->isHoe()) {
         if (($player->gamemode & 0x1) === 0) {
             $item->useOn($this);
         }
         $this->level->setBlock($this, new FarmlandBlock());
         return true;
     }
     return false;
 }
Exemplo n.º 2
0
 public function populateLevel()
 {
     $this->random->setSeed($this->level->getSeed());
     if (isset($this->options["spawn"])) {
         $spawn = array(10, new SandstoneBlock());
         if (isset($this->options["spawn"]["radius"])) {
             $spawn[0] = intval($this->options["spawn"]["radius"]);
         }
         if (isset($this->options["spawn"]["block"])) {
             $spawn[1] = BlockAPI::fromString($this->options["spawn"]["block"])->getBlock();
             if (!$spawn[1] instanceof Block) {
                 $spawn[1] = new SandstoneBlock();
             }
         }
         $start = 128 - $spawn[0];
         $end = 128 + $spawn[0];
         for ($x = $start; $x <= $end; ++$x) {
             for ($z = $start; $z <= $end; ++$z) {
                 if (floor(sqrt(pow($x - 128, 2) + pow($z - 128, 2))) <= $spawn[0]) {
                     $this->level->setBlockRaw(new Vector3($x, $this->floorLevel - 1, $z), $spawn[1], null);
                 }
             }
         }
     }
     if (isset($this->options["decoration"])) {
         $treecount = 80;
         $grasscount = 120;
         if (isset($this->options["spawn"]["treecount"])) {
             $treecount = intval($this->options["spawn"]["treecount"]);
         }
         if (isset($this->options["spawn"]["grasscount"])) {
             $grasscount = intval($this->options["spawn"]["grasscount"]);
         }
         for ($t = 0; $t < $treecount; ++$t) {
             $centerX = $this->random->nextRange(0, 255);
             $centerZ = $this->random->nextRange(0, 255);
             $down = $this->level->level->getBlockID($centerX, $this->floorLevel - 1, $centerZ);
             if ($down === DIRT or $down === GRASS or $down === FARMLAND) {
                 TreeObject::growTree($this->level, new Vector3($centerX, $this->floorLevel, $centerZ), $this->random, $this->random->nextRange(0, 3));
             }
         }
         for ($t = 0; $t < $grasscount; ++$t) {
             $centerX = $this->random->nextRange(0, 255);
             $centerZ = $this->random->nextRange(0, 255);
             $down = $this->level->level->getBlockID($centerX, $this->floorLevel - 1, $centerZ);
             if ($down === GRASS) {
                 TallGrassObject::growGrass($this->level, new Vector3($centerX, $this->floorLevel - 1, $centerZ), $this->random, $this->random->nextRange(8, 40));
             }
         }
     }
 }