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;
 }
示例#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::WOOD_SLAB and ($target->getDamage() & 0x8) === 0x8 and ($target->getDamage() & 0x7) === ($this->meta & 0x7)) {
             $this->getLevel()->setBlock($target, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true);
             return true;
         } elseif ($block->getId() === self::WOOD_SLAB and ($block->getDamage() & 0x7) === ($this->meta & 0x7)) {
             $this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true);
             return true;
         } else {
             $this->meta |= 0x8;
         }
     } elseif ($face === 1) {
         if ($target->getId() === self::WOOD_SLAB and ($target->getDamage() & 0x8) === 0 and ($target->getDamage() & 0x7) === ($this->meta & 0x7)) {
             $this->getLevel()->setBlock($target, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true);
             return true;
         } elseif ($block->getId() === self::WOOD_SLAB and ($block->getDamage() & 0x7) === ($this->meta & 0x7)) {
             $this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true);
             return true;
         }
     } else {
         //TODO: collision
         if ($block->getId() === self::WOOD_SLAB) {
             if (($block->getDamage() & 0x7) === ($this->meta & 0x7)) {
                 $this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true);
                 return true;
             }
             return false;
         } else {
             if ($fy > 0.5) {
                 $this->meta |= 0x8;
             }
         }
     }
     if ($block->getId() === self::WOOD_SLAB and ($target->getDamage() & 0x7) !== ($this->meta & 0x7)) {
         return false;
     }
     $this->getLevel()->setBlock($block, $this, true, true);
     return true;
 }
 public function canConnect(Block $block)
 {
     return ($block->getId() !== self::COBBLE_WALL and $block->getId() !== self::FENCE_GATE) ? $block->isSolid() and !$block->isTransparent() : true;
 }
示例#4
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::WOOD) {
         return true;
     } elseif ($pos->getId() === self::LEAVES and $distance < 3) {
         $visited[$index] = true;
         $down = $pos->getSide(0)->getId();
         if ($down === Item::WOOD) {
             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;
 }
示例#5
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;
 }
示例#6
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());
     }
 }