@@ -181,4 +181,103 @@ private static function validateBlocks($blocks): void {
181181 }
182182 }
183183 }
184+
185+ /**
186+ * Get the volume of the area defined by two positions.
187+ * @param Position $pos1
188+ * @param Position $pos2
189+ * @return int The volume of the area.
190+ */
191+ public static function getVolume (Position $ pos1 , Position $ pos2 ): int {
192+ self ::validatePositions ($ pos1 , $ pos2 );
193+
194+ $ minX = min ($ pos1 ->getX (), $ pos2 ->getX ());
195+ $ maxX = max ($ pos1 ->getX (), $ pos2 ->getX ());
196+ $ minY = min ($ pos1 ->getY (), $ pos2 ->getY ());
197+ $ maxY = max ($ pos1 ->getY (), $ pos2 ->getY ());
198+ $ minZ = min ($ pos1 ->getZ (), $ pos2 ->getZ ());
199+ $ maxZ = max ($ pos1 ->getZ (), $ pos2 ->getZ ());
200+
201+ $ width = $ maxX - $ minX + 1 ;
202+ $ height = $ maxY - $ minY + 1 ;
203+ $ depth = $ maxZ - $ minZ + 1 ;
204+
205+ return $ width * $ height * $ depth ;
206+ }
207+
208+ /**
209+ * Get the border blocks of the area defined by two positions.
210+ * @param Position $pos1
211+ * @param Position $pos2
212+ * @return Block[] The border blocks.
213+ */
214+ public static function getBorder (Position $ pos1 , Position $ pos2 ): array {
215+ self ::validatePositions ($ pos1 , $ pos2 );
216+
217+ $ world = $ pos1 ->getWorld ();
218+ $ borderBlocks = [];
219+
220+ $ minX = min ($ pos1 ->getX (), $ pos2 ->getX ());
221+ $ maxX = max ($ pos1 ->getX (), $ pos2 ->getX ());
222+ $ minY = min ($ pos1 ->getY (), $ pos2 ->getY ());
223+ $ maxY = max ($ pos1 ->getY (), $ pos2 ->getY ());
224+ $ minZ = min ($ pos1 ->getZ (), $ pos2 ->getZ ());
225+ $ maxZ = max ($ pos1 ->getZ (), $ pos2 ->getZ ());
226+
227+ // Top and bottom faces
228+ for ($ x = $ minX ; $ x <= $ maxX ; $ x ++) {
229+ for ($ z = $ minZ ; $ z <= $ maxZ ; $ z ++) {
230+ $ borderBlocks [] = $ world ->getBlockAt ($ x , $ minY , $ z ); // Bottom
231+ $ borderBlocks [] = $ world ->getBlockAt ($ x , $ maxY , $ z ); // Top
232+ }
233+ }
234+
235+ // Front and back faces (excluding edges already added)
236+ for ($ x = $ minX ; $ x <= $ maxX ; $ x ++) {
237+ for ($ y = $ minY + 1 ; $ y <= $ maxY - 1 ; $ y ++) {
238+ $ borderBlocks [] = $ world ->getBlockAt ($ x , $ y , $ minZ ); // Front
239+ $ borderBlocks [] = $ world ->getBlockAt ($ x , $ y , $ maxZ ); // Back
240+ }
241+ }
242+
243+ // Left and right faces (excluding edges already added)
244+ for ($ z = $ minZ + 1 ; $ z <= $ maxZ - 1 ; $ z ++) {
245+ for ($ y = $ minY + 1 ; $ y <= $ maxY - 1 ; $ y ++) {
246+ $ borderBlocks [] = $ world ->getBlockAt ($ minX , $ y , $ z ); // Left
247+ $ borderBlocks [] = $ world ->getBlockAt ($ maxX , $ y , $ z ); // Right
248+ }
249+ }
250+
251+ return $ borderBlocks ;
252+ }
253+
254+ /**
255+ * Check if a position is inside the area defined by two positions.
256+ * @param Position $pos The position to check.
257+ * @param Position $areaPos1 The first position defining the area.
258+ * @param Position $areaPos2 The second position defining the area.
259+ * @return bool True if the position is inside the area.
260+ */
261+ public static function isPositionInside (Position $ pos , Position $ areaPos1 , Position $ areaPos2 ): bool {
262+ self ::validatePositions ($ areaPos1 , $ areaPos2 );
263+
264+ if ($ pos ->getWorld ()->getFolderName () !== $ areaPos1 ->getWorld ()->getFolderName ()) {
265+ return false ;
266+ }
267+
268+ $ minX = min ($ areaPos1 ->getX (), $ areaPos2 ->getX ());
269+ $ maxX = max ($ areaPos1 ->getX (), $ areaPos2 ->getX ());
270+ $ minY = min ($ areaPos1 ->getY (), $ areaPos2 ->getY ());
271+ $ maxY = max ($ areaPos1 ->getY (), $ areaPos2 ->getY ());
272+ $ minZ = min ($ areaPos1 ->getZ (), $ areaPos2 ->getZ ());
273+ $ maxZ = max ($ areaPos1 ->getZ (), $ areaPos2 ->getZ ());
274+
275+ $ x = $ pos ->getX ();
276+ $ y = $ pos ->getY ();
277+ $ z = $ pos ->getZ ();
278+
279+ return $ x >= $ minX && $ x <= $ maxX &&
280+ $ y >= $ minY && $ y <= $ maxY &&
281+ $ z >= $ minZ && $ z <= $ maxZ ;
282+ }
184283}
0 commit comments