69 $this->level = $level;
70 $this->maxDistance = (int) $maxDistance;
71 $this->blockQueue = new \SplFixedArray(3);
73 $startClone =
new Vector3($start->x, $start->y, $start->z);
74 $startClone->y += $yOffset;
76 $this->currentDistance = 0;
86 $pos =
new Vector3($startClone->x, $startClone->y, $startClone->z);
87 $startBlock = $this->level->getBlock(
new Vector3(floor($pos->x), floor($pos->y), floor($pos->z)));
89 if($this->getXLength($direction) > $mainDirection){
90 $this->mainFace = $this->getXFace($direction);
91 $mainDirection = $this->getXLength($direction);
92 $mainPosition = $this->getXPosition($direction, $startClone, $startBlock);
94 $this->secondFace = $this->getYFace($direction);
95 $secondDirection = $this->getYLength($direction);
96 $secondPosition = $this->getYPosition($direction, $startClone, $startBlock);
98 $this->thirdFace = $this->getZFace($direction);
99 $thirdDirection = $this->getZLength($direction);
100 $thirdPosition = $this->getZPosition($direction, $startClone, $startBlock);
102 if($this->getYLength($direction) > $mainDirection){
103 $this->mainFace = $this->getYFace($direction);
104 $mainDirection = $this->getYLength($direction);
105 $mainPosition = $this->getYPosition($direction, $startClone, $startBlock);
107 $this->secondFace = $this->getZFace($direction);
108 $secondDirection = $this->getZLength($direction);
109 $secondPosition = $this->getZPosition($direction, $startClone, $startBlock);
111 $this->thirdFace = $this->getXFace($direction);
112 $thirdDirection = $this->getXLength($direction);
113 $thirdPosition = $this->getXPosition($direction, $startClone, $startBlock);
115 if($this->getZLength($direction) > $mainDirection){
116 $this->mainFace = $this->getZFace($direction);
117 $mainDirection = $this->getZLength($direction);
118 $mainPosition = $this->getZPosition($direction, $startClone, $startBlock);
120 $this->secondFace = $this->getXFace($direction);
121 $secondDirection = $this->getXLength($direction);
122 $secondPosition = $this->getXPosition($direction, $startClone, $startBlock);
124 $this->thirdFace = $this->getYFace($direction);
125 $thirdDirection = $this->getYLength($direction);
126 $thirdPosition = $this->getYPosition($direction, $startClone, $startBlock);
129 $d = $mainPosition / $mainDirection;
130 $secondd = $secondPosition - $secondDirection * $d;
131 $thirdd = $thirdPosition - $thirdDirection * $d;
133 $this->secondError = floor($secondd * self::$gridSize);
134 $this->secondStep = round($secondDirection / $mainDirection * self::$gridSize);
135 $this->thirdError = floor($thirdd * self::$gridSize);
136 $this->thirdStep = round($thirdDirection / $mainDirection * self::$gridSize);
138 if($this->secondError + $this->secondStep <= 0){
139 $this->secondError = -$this->secondStep + 1;
142 if($this->thirdError + $this->thirdStep <= 0){
143 $this->thirdError = -$this->thirdStep + 1;
148 if($this->secondError < 0){
149 $this->secondError += self::$gridSize;
153 if($this->thirdError < 0){
154 $this->thirdError += self::$gridSize;
158 $this->secondError -= self::$gridSize;
159 $this->thirdError -= self::$gridSize;
161 $this->blockQueue[0] = $lastBlock;
163 $this->currentBlock = -1;
167 $startBlockFound =
false;
169 for($cnt = $this->currentBlock; $cnt >= 0; --$cnt){
170 if($this->blockEquals($this->blockQueue[$cnt], $startBlock)){
171 $this->currentBlock = $cnt;
172 $startBlockFound =
true;
177 if(!$startBlockFound){
178 throw new \InvalidStateException(
"Start block missed in BlockIterator");
181 $this->maxDistanceInt = round($maxDistance / (sqrt($mainDirection ** 2 + $secondDirection ** 2 + $thirdDirection ** 2) / $mainDirection));