예제 #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)
 {
     if (($target->isTransparent() === false or $target->getId() === self::SLAB) and $face !== 0 and $face !== 1) {
         $faces = [2 => 0, 3 => 1, 4 => 2, 5 => 3];
         $this->meta = $faces[$face] & 0x3;
         if ($fy > 0.5) {
             $this->meta |= 0x8;
         }
         $this->getLevel()->setBlock($block, $this, true, true);
         return true;
     }
     return false;
 }
예제 #3
0
 /**
  * TODO: Move this to each item
  *
  * @param Entity|Block $object
  *
  * @return bool
  */
 public function useOn($object)
 {
     if ($this->isUnbreakable()) {
         return true;
     }
     if ($object instanceof Block) {
         if ($object->getToolType() === Tool::TYPE_PICKAXE and $this->isPickaxe() or $object->getToolType() === Tool::TYPE_SHOVEL and $this->isShovel() or $object->getToolType() === Tool::TYPE_AXE and $this->isAxe() or $object->getToolType() === Tool::TYPE_SWORD and $this->isSword() or $object->getToolType() === Tool::TYPE_SHEARS and $this->isShears()) {
             $this->meta++;
         } elseif (!$this->isShears() and $object->getBreakTime($this) > 0) {
             $this->meta += 2;
         }
     } elseif ($this->isHoe()) {
         if ($object instanceof Block and ($object->getId() === self::GRASS or $object->getId() === self::DIRT)) {
             $this->meta++;
         }
     } elseif ($object instanceof Entity and !$this->isSword()) {
         $this->meta += 2;
     } else {
         $this->meta++;
     }
     return true;
 }
예제 #4
0
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     $down = $this->getSide(0);
     if ($face !== 0 && $fy > 0.5 && $target->getId() !== self::SKULL_BLOCK && !$down instanceof SkullBlock) {
         $this->getLevel()->setBlock($block, Block::get(Block::SKULL_BLOCK, 0), true, true);
         if ($face === 1) {
             $rot = new Byte("Rot", floor($player->yaw * 16 / 360 + 0.5) & 0xf);
         } else {
             $rot = new Byte("Rot", 0);
         }
         $nbt = new Compound("", [new String("id", Tile::SKULL), new Int("x", $block->x), new Int("y", $block->y), new Int("z", $block->z), new Byte("SkullType", $item->getDamage()), $rot]);
         $chunk = $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4);
         $pot = Tile::createTile("Skull", $chunk, $nbt);
         $this->getLevel()->setBlock($block, Block::get(Block::SKULL_BLOCK, $face), true, true);
         return true;
     }
     return false;
 }
예제 #5
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;
 }
예제 #6
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;
 }
예제 #7
0
 private function findLog(Block $pos, array $visited, $distance, &$check, $fromSide = null)
 {
     ++$check;
     $index = $pos->x . "." . $pos->y . "." . $pos->z;
     if (isset($visited[$index])) {
         return false;
     }
     if ($pos->getId() === self::WOOD2) {
         return true;
     } elseif ($pos->getId() === self::LEAVES2 and $distance < 3) {
         $visited[$index] = true;
         $down = $pos->getSide(0)->getId();
         if ($down === Item::WOOD2) {
             return true;
         }
         if ($fromSide === null) {
             for ($side = 2; $side <= 5; ++$side) {
                 if ($this->findLog($pos->getSide($side), $visited, $distance + 1, $check, $side) === true) {
                     return true;
                 }
             }
         } else {
             //No more loops
             switch ($fromSide) {
                 case 2:
                     if ($this->findLog($pos->getSide(2), $visited, $distance + 1, $check, $fromSide) === true) {
                         return true;
                     } elseif ($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true) {
                         return true;
                     } elseif ($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true) {
                         return true;
                     }
                     break;
                 case 3:
                     if ($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true) {
                         return true;
                     } elseif ($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true) {
                         return true;
                     } elseif ($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true) {
                         return true;
                     }
                     break;
                 case 4:
                     if ($this->findLog($pos->getSide(2), $visited, $distance + 1, $check, $fromSide) === true) {
                         return true;
                     } elseif ($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true) {
                         return true;
                     } elseif ($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true) {
                         return true;
                     }
                     break;
                 case 5:
                     if ($this->findLog($pos->getSide(2), $visited, $distance + 1, $check, $fromSide) === true) {
                         return true;
                     } elseif ($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true) {
                         return true;
                     } elseif ($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true) {
                         return true;
                     }
                     break;
             }
         }
     }
     return false;
 }
예제 #8
0
 public function __construct(Block $block, $meta = 0, $count = 1)
 {
     $this->block = $block;
     parent::__construct($block->getId(), $block->getDamage(), $count, $block->getName());
 }
예제 #9
0
 public function __construct(Vector3 $pos, Block $b)
 {
     parent::__construct($pos, Particle::TYPE_TERRAIN, $b->getDamage() << 8 | $b->getId());
 }
예제 #10
0
 public function canConnect(Block $block)
 {
     return ($block->getId() !== self::COBBLE_WALL and $block->getId() !== self::FENCE_GATE) ? $block->isSolid() and !$block->isTransparent() : true;
 }
예제 #11
0
 public function __construct(Vector3 $pos, Block $b)
 {
     parent::__construct($pos->x, $pos->y, $pos->z);
     $this->data = $b->getId() + ($b->getDamage() << 12);
 }
예제 #12
0
 private function flowIntoBlock(Block $block, $newFlowDecay)
 {
     if ($block->canBeFlowedInto()) {
         if ($block->getId() > 0) {
             $this->getLevel()->useBreakOn($block);
         }
         $this->getLevel()->setBlock($block, Block::get($this->getId(), $newFlowDecay), true);
         $this->getLevel()->scheduleUpdate($block, $this->tickRate());
     }
 }
예제 #13
0
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     if ((!$target->isTransparent() and $target->isSolid()) || $target->getId() === Block::LEAVES || $target->getId() === Block::LEAVES2) {
         $faces = [0 => 0, 1 => 0, 2 => 1, 3 => 4, 4 => 8, 5 => 2];
         if (isset($faces[$face])) {
             $this->meta = $faces[$face];
             $this->getLevel()->setBlock($block, $this, true, true);
             return true;
         }
     }
     return false;
 }
예제 #14
0
 public function canConnect(Block $block)
 {
     return $block->isSolid() or $block->getId() === $this->getId() or $block->getId() === self::GLASS_PANE or $block->getId() === self::GLASS;
 }