getOppositeSide() public static method

public static getOppositeSide ( $side )
示例#1
0
 public function onUpdate($type)
 {
     if ($type === Level::BLOCK_UPDATE_NORMAL) {
         $faces = array_flip(array(2 => 2, 3 => 4, 4 => 5, 5 => 3));
         if ($this->getSide(Vector3::getOppositeSide($faces[$this->meta % 4 + 2]))->isTransparent() === true) {
             $this->getLevel()->useBreakOn($this);
             return Level::BLOCK_UPDATE_NORMAL;
         }
     } elseif ($type === Level::BLOCK_UPDATE_RANDOM) {
         if (mt_rand(0, 2) === 1) {
             if ($this->meta < 8) {
                 $block = clone $this;
                 $block->meta += 4;
                 Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block));
                 if (!$ev->isCancelled()) {
                     $this->getLevel()->setBlock($this, $ev->getNewState(), true, true);
                 } else {
                     return Level::BLOCK_UPDATE_RANDOM;
                 }
             }
         } else {
             return Level::BLOCK_UPDATE_RANDOM;
         }
     }
     return false;
 }
示例#2
0
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     if ($face !== 0 && $face !== 1) {
         $faces = [3 => 3, 2 => 4, 4 => 2, 5 => 1];
         $this->meta = $faces[$face];
         if ($this->getSide(Vector3::getOppositeSide($face))->getId() === Block::TRIPWIRE) {
             $this->meta & 0x1;
         }
         $this->getLevel()->setBlock($block, Block::get(Block::TRIPWIRE_HOOK, $this->meta), true);
         return true;
     }
     return false;
 }
示例#3
0
 public function __construct(Level $level, Vector3 $start, Vector3 $direction, $yOffset = 0, $maxDistance = 0)
 {
     $this->level = $level;
     $this->maxDistance = (int) $maxDistance;
     $this->blockQueue = new \SplFixedArray(3);
     $startClone = new Vector3($start->x, $start->y, $start->z);
     $startClone->y += $yOffset;
     $this->currentDistance = 0;
     $mainDirection = 0;
     $secondDirection = 0;
     $thirdDirection = 0;
     $mainPosition = 0;
     $secondPosition = 0;
     $thirdPosition = 0;
     $pos = new Vector3($startClone->x, $startClone->y, $startClone->z);
     $startBlock = $this->level->getBlock(new Vector3(floor($pos->x), floor($pos->y), floor($pos->z)));
     if ($this->getXLength($direction) > $mainDirection) {
         $this->mainFace = $this->getXFace($direction);
         $mainDirection = $this->getXLength($direction);
         $mainPosition = $this->getXPosition($direction, $startClone, $startBlock);
         $this->secondFace = $this->getYFace($direction);
         $secondDirection = $this->getYLength($direction);
         $secondPosition = $this->getYPosition($direction, $startClone, $startBlock);
         $this->thirdFace = $this->getZFace($direction);
         $thirdDirection = $this->getZLength($direction);
         $thirdPosition = $this->getZPosition($direction, $startClone, $startBlock);
     }
     if ($this->getYLength($direction) > $mainDirection) {
         $this->mainFace = $this->getYFace($direction);
         $mainDirection = $this->getYLength($direction);
         $mainPosition = $this->getYPosition($direction, $startClone, $startBlock);
         $this->secondFace = $this->getZFace($direction);
         $secondDirection = $this->getZLength($direction);
         $secondPosition = $this->getZPosition($direction, $startClone, $startBlock);
         $this->thirdFace = $this->getXFace($direction);
         $thirdDirection = $this->getXLength($direction);
         $thirdPosition = $this->getXPosition($direction, $startClone, $startBlock);
     }
     if ($this->getZLength($direction) > $mainDirection) {
         $this->mainFace = $this->getZFace($direction);
         $mainDirection = $this->getZLength($direction);
         $mainPosition = $this->getZPosition($direction, $startClone, $startBlock);
         $this->secondFace = $this->getXFace($direction);
         $secondDirection = $this->getXLength($direction);
         $secondPosition = $this->getXPosition($direction, $startClone, $startBlock);
         $this->thirdFace = $this->getYFace($direction);
         $thirdDirection = $this->getYLength($direction);
         $thirdPosition = $this->getYPosition($direction, $startClone, $startBlock);
     }
     $d = $mainPosition / $mainDirection;
     $secondd = $secondPosition - $secondDirection * $d;
     $thirdd = $thirdPosition - $thirdDirection * $d;
     $this->secondError = floor($secondd * self::$gridSize);
     $this->secondStep = round($secondDirection / $mainDirection * self::$gridSize);
     $this->thirdError = floor($thirdd * self::$gridSize);
     $this->thirdStep = round($thirdDirection / $mainDirection * self::$gridSize);
     if ($this->secondError + $this->secondStep <= 0) {
         $this->secondError = -$this->secondStep + 1;
     }
     if ($this->thirdError + $this->thirdStep <= 0) {
         $this->thirdError = -$this->thirdStep + 1;
     }
     $lastBlock = $startBlock->getSide(Vector3::getOppositeSide($this->mainFace));
     if ($this->secondError < 0) {
         $this->secondError += self::$gridSize;
         $lastBlock = $lastBlock->getSide(Vector3::getOppositeSide($this->secondFace));
     }
     if ($this->thirdError < 0) {
         $this->thirdError += self::$gridSize;
         $lastBlock = $lastBlock->getSide(Vector3::getOppositeSide($this->thirdFace));
     }
     $this->secondError -= self::$gridSize;
     $this->thirdError -= self::$gridSize;
     $this->blockQueue[0] = $lastBlock;
     $this->currentBlock = -1;
     $this->scan();
     $startBlockFound = false;
     for ($cnt = $this->currentBlock; $cnt >= 0; --$cnt) {
         if ($this->blockEquals($this->blockQueue[$cnt], $startBlock)) {
             $this->currentBlock = $cnt;
             $startBlockFound = true;
             break;
         }
     }
     if (!$startBlockFound) {
         throw new \InvalidStateException("Start block missed in BlockIterator");
     }
     $this->maxDistanceInt = round($maxDistance / (sqrt($mainDirection ** 2 + $secondDirection ** 2 + $thirdDirection ** 2) / $mainDirection));
 }
示例#4
0
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     $this->meta = Vector3::getOppositeSide($face);
     $this->getLevel()->setBlock($block, $this, true, true);
     return true;
 }
示例#5
0
 public function getAttachedFace()
 {
     return Vector3::getOppositeSide($this->getFacing());
 }