示例#1
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if ($this->meta === AIR) {
         if ($target instanceof LiquidBlock) {
             $level->setBlock($target, new AirBlock(), true, false, true);
             if (($player->gamemode & 0x1) === 0) {
                 $this->meta = $target instanceof WaterBlock ? WATER : LAVA;
             }
             return true;
         }
     } elseif ($this->meta === WATER) {
         //Support Make Non-Support Water to Support Water
         if ($block->getID() === AIR || $block instanceof WaterBlock && ($block->getMetadata() & 0x7) != 0x0) {
             $water = new WaterBlock();
             $level->setBlock($block, $water, true, false, true);
             $water->place(clone $this, $player, $block, $target, $face, $fx, $fy, $fz);
             if (($player->gamemode & 0x1) === 0) {
                 $this->meta = 0;
             }
             return true;
         }
     } elseif ($this->meta === LAVA) {
         if ($block->getID() === AIR) {
             $level->setBlock($block, new LavaBlock(), true, false, true);
             if (($player->gamemode & 0x1) === 0) {
                 $this->meta = 0;
             }
             return true;
         }
     }
     return false;
 }
示例#2
0
 public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $this->meta &= 0x7;
     if ($face === 0) {
         if ($target->getID() === WOOD_SLAB and ($target->getMetadata() & 0x8) === 0x8 and ($target->getMetadata() & 0x7) === ($this->meta & 0x7)) {
             $this->level->setBlock($target, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
             return true;
         } elseif ($block->getID() === WOOD_SLAB and ($block->getMetadata() & 0x7) === ($this->meta & 0x7)) {
             $this->level->setBlock($block, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
             return true;
         } else {
             $this->meta |= 0x8;
         }
     } elseif ($face === 1) {
         if ($target->getID() === WOOD_SLAB and ($target->getMetadata() & 0x8) === 0 and ($target->getMetadata() & 0x7) === ($this->meta & 0x7)) {
             $this->level->setBlock($target, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
             return true;
         } elseif ($block->getID() === WOOD_SLAB and ($block->getMetadata() & 0x7) === ($this->meta & 0x7)) {
             $this->level->setBlock($block, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
             return true;
         }
     } elseif (!$player->entity->inBlock($block)) {
         if ($block->getID() === WOOD_SLAB) {
             if (($block->getMetadata() & 0x7) === ($this->meta & 0x7)) {
                 $this->level->setBlock($block, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
                 return true;
             }
             return false;
         } else {
             if ($fy > 0.5) {
                 $this->meta |= 0x8;
             }
         }
     } else {
         return false;
     }
     if ($block->getID() === WOOD_SLAB and ($target->getMetadata() & 0x7) !== ($this->meta & 0x7)) {
         return false;
     }
     $this->level->setBlock($block, $this, true, false, true);
     return true;
 }
示例#3
0
 public function setBlock(Vector3 $pos, Block $block, $update = true, $tiles = false, $direct = false)
 {
     if (!isset($this->level) or $pos instanceof Position and $pos->level !== $this or $pos->x < 0 or $pos->y < 0 or $pos->z < 0) {
         return false;
     }
     $ret = $this->level->setBlock($pos->x, $pos->y, $pos->z, $block->getID(), $block->getMetadata());
     if ($ret === true) {
         if (!$pos instanceof Position) {
             $pos = new Position($pos->x, $pos->y, $pos->z, $this);
         }
         $block->position($pos);
         if ($direct === true) {
             $pk = new UpdateBlockPacket();
             $pk->x = $pos->x;
             $pk->y = $pos->y;
             $pk->z = $pos->z;
             $pk->block = $block->getID();
             $pk->meta = $block->getMetadata();
             $this->server->api->player->broadcastPacket($this->players, $pk);
         } else {
             $i = ($pos->x >> 4) . ":" . ($pos->y >> 4) . ":" . ($pos->z >> 4);
             if (!isset($this->changedBlocks[$i])) {
                 $this->changedBlocks[$i] = array();
                 $this->changedCount[$i] = 0;
             }
             if (ADVANCED_CACHE == true) {
                 Cache::remove("world:{$this->name}:" . ($pos->x >> 4) . ":" . ($pos->z >> 4));
             }
             $this->changedBlocks[$i][] = clone $block;
             ++$this->changedCount[$i];
         }
         if ($update === true) {
             $this->server->api->block->blockUpdateAround($pos, BLOCK_UPDATE_NORMAL, 1);
             $this->server->api->entity->updateRadius($pos, 3);
         }
         if ($tiles === true) {
             if (($t = $this->server->api->tile->get($pos)) !== false) {
                 $t->close();
             }
         }
     }
     return $ret;
 }
示例#4
0
 private function cancelAction(Block $block, Player $player, $send = true)
 {
     $pk = new UpdateBlockPacket();
     $pk->x = $block->x;
     $pk->y = $block->y;
     $pk->z = $block->z;
     $pk->block = $block->getID();
     $pk->meta = $block->getMetadata();
     $player->dataPacket($pk);
     if ($send === true) {
         $player->sendInventorySlot($player->slot);
     }
     return false;
 }