示例#1
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $targetBlock = Block::get($this->meta);
     if ($targetBlock instanceof Air) {
         if ($target instanceof Liquid and $target->getDamage() === 0) {
             $result = clone $this;
             $result->setDamage($target->getId());
             $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
             if (!$ev->isCancelled()) {
                 $player->getLevel()->setBlock($target, new Air(), true, true);
                 if ($player->isSurvival()) {
                     $player->getInventory()->setItemInHand($ev->getItem(), $player);
                 }
                 return true;
             } else {
                 $player->getInventory()->sendContents($player);
             }
         }
     } elseif ($targetBlock instanceof Liquid) {
         $result = clone $this;
         $result->setDamage(0);
         $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
         if (!$ev->isCancelled()) {
             $player->getLevel()->setBlock($block, $targetBlock, true, true);
             if ($player->isSurvival()) {
                 $player->getInventory()->setItemInHand($ev->getItem(), $player);
             }
             return true;
         } else {
             $player->getInventory()->sendContents($player);
         }
     }
     return false;
 }
示例#2
0
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     $this->meta &= 0x7;
     if ($face === 0) {
         if ($target->getId() === self::SLAB and ($target->getDamage() & 0x8) === 0x8 and ($target->getDamage() & 0x7) === ($this->meta & 0x7)) {
             $this->getLevel()->setBlock($target, Block::get(Item::DOUBLE_SLAB, $this->meta), true);
             return true;
         } elseif ($block->getId() === self::SLAB and ($block->getDamage() & 0x7) === ($this->meta & 0x7)) {
             $this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true);
             return true;
         } else {
             $this->meta |= 0x8;
         }
     } elseif ($face === 1) {
         if ($target->getId() === self::SLAB and ($target->getDamage() & 0x8) === 0 and ($target->getDamage() & 0x7) === ($this->meta & 0x7)) {
             $this->getLevel()->setBlock($target, Block::get(Item::DOUBLE_SLAB, $this->meta), true);
             return true;
         } elseif ($block->getId() === self::SLAB and ($block->getDamage() & 0x7) === ($this->meta & 0x7)) {
             $this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true);
             return true;
         }
         //TODO: check for collision
     } else {
         if ($block->getId() === self::SLAB) {
             if (($block->getDamage() & 0x7) === ($this->meta & 0x7)) {
                 $this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true);
                 return true;
             }
             return false;
         } else {
             if ($fy > 0.5) {
                 $this->meta |= 0x8;
             }
         }
     }
     if ($block->getId() === self::SLAB and ($target->getDamage() & 0x7) !== ($this->meta & 0x7)) {
         return false;
     }
     $this->getLevel()->setBlock($block, $this, true, true);
     return true;
 }
示例#3
0
 /**
  * Sets on Vector3 the data from a Block object,
  * does block updates and puts the changes to the send queue.
  *
  * If $direct is true, it'll send changes directly to players. if false, it'll be queued
  * and the best way to send queued changes will be done in the next tick.
  * This way big changes can be sent on a single chunk update packet instead of thousands of packets.
  *
  * If $update is true, it'll get the neighbour blocks (6 sides) and update them.
  * If you are doing big changes, you might want to set this to false, then update manually.
  *
  * @param Vector3 $pos
  * @param Block   $block
  * @param bool    $direct @deprecated
  * @param bool    $update
  *
  * @return bool Whether the block has been updated or not
  */
 public function setBlock(Vector3 $pos, Block $block, $direct = false, $update = true)
 {
     if ($pos->y < 0 or $pos->y >= 128) {
         return false;
     }
     if ($this->getChunk($pos->x >> 4, $pos->z >> 4, true)->setBlock($pos->x & 0xf, $pos->y & 0x7f, $pos->z & 0xf, $block->getId(), $block->getDamage())) {
         if (!$pos instanceof Position) {
             $pos = $this->temporalPosition->setComponents($pos->x, $pos->y, $pos->z);
         }
         $block->position($pos);
         unset($this->blockCache[Level::blockHash($pos->x, $pos->y, $pos->z)]);
         $index = Level::chunkHash($pos->x >> 4, $pos->z >> 4);
         if ($direct === true) {
             $this->sendBlocks($this->getChunkPlayers($pos->x >> 4, $pos->z >> 4), [$block], UpdateBlockPacket::FLAG_ALL_PRIORITY);
             unset($this->chunkCache[$index]);
         } else {
             if (!isset($this->changedBlocks[$index])) {
                 $this->changedBlocks[$index] = [];
             }
             $this->changedBlocks[$index][Level::blockHash($block->x, $block->y, $block->z)] = clone $block;
         }
         foreach ($this->getChunkLoaders($pos->x >> 4, $pos->z >> 4) as $loader) {
             $loader->onBlockChanged($block);
         }
         if ($update === true) {
             $this->updateAllLight($block);
             $this->server->getPluginManager()->callEvent($ev = new BlockUpdateEvent($block));
             if (!$ev->isCancelled()) {
                 foreach ($this->getNearbyEntities(new AxisAlignedBB($block->x - 1, $block->y - 1, $block->z - 1, $block->x + 1, $block->y + 1, $block->z + 1)) as $entity) {
                     $entity->scheduleUpdate();
                 }
                 $ev->getBlock()->onUpdate(self::BLOCK_UPDATE_NORMAL);
             }
             $this->updateAround($pos);
         }
         return true;
     }
     return false;
 }
示例#4
0
 public function __construct(Block $block, $meta = 0, $count = 1)
 {
     $this->block = $block;
     parent::__construct($block->getId(), $block->getDamage(), $count, $block->getName());
 }
示例#5
0
 public function __construct(Vector3 $pos, Block $b)
 {
     parent::__construct($pos, Particle::TYPE_TERRAIN, $b->getDamage() << 8 | $b->getId());
 }
 public function __construct(Vector3 $pos, Block $b)
 {
     parent::__construct($pos->x, $pos->y, $pos->z);
     $this->data = $b->getId() + ($b->getDamage() << 12);
 }