Skip to content

Instantly share code, notes, and snippets.

@MakStashkevich
Created June 13, 2020 09:15
Show Gist options
  • Save MakStashkevich/e9d413a11cbfe0d6e6eb0622453a14d2 to your computer and use it in GitHub Desktop.
Save MakStashkevich/e9d413a11cbfe0d6e6eb0622453a14d2 to your computer and use it in GitHub Desktop.
Convert XYZ to subchunks
<?php
class LevelUtils
{
/**
* @param Vector3 $pos1
* @param Vector3 $pos2
*/
static function printRegions(array $pos1, array $pos2)
{
$min = self::minVector($pos1, $pos2);
$max = self::maxVector($pos1, $pos2);
for ($x = $min[0]; $x <= $max[0]; $x++) {
for ($z = $min[2]; $z <= $max[2]; $z++) {
echo "r.$x.$z.mca" . PHP_EOL;
}
}
}
/**
* @param Vector3 $v1
* @param Vector3 $v2
* @return Vector3
*/
static function minVector(array $v1, array $v2)
{
return [min($v1[0], $v2[0]) >> 9, 0, min($v1[2], $v2[2]) >> 9];
}
/**
* @param Vector3 $v1
* @param Vector3 $v2
* @return Vector3
*/
static function maxVector(array $v1, array $v2)
{
return [max($v1[0], $v2[0]) >> 9, 0, max($v1[2], $v2[2]) >> 9];
}
}
LevelUtils::printRegions([-32, 64, -1137], [242, 162, -853]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment