Skip to content

Instantly share code, notes, and snippets.

@MakStashkevich
Last active August 1, 2020 11:37
Show Gist options
  • Save MakStashkevich/6033173af56717a22c2252271bf26f87 to your computer and use it in GitHub Desktop.
Save MakStashkevich/6033173af56717a22c2252271bf26f87 to your computer and use it in GitHub Desktop.
Paint min\max x\z on chunks
<?php
function paint($minX, $maxX, $minZ, $maxZ)
{
$fromX = $minX >> 4;
$toX = $maxX >> 4;
$fromZ = $minZ >> 4;
$toZ = $maxZ >> 4;
$paper = array_fill(0, 16 + 2, '');
$tube = [];
$tubeId = 0;
for ($chunkX = $fromX; $chunkX <= $toX; $chunkX++) {
for ($chunkZ = $fromZ; $chunkZ <= $toZ; $chunkZ++) {
$paint = array_fill(0, 16, array_fill(0, 16, str_repeat('#', 3)));
$fX = max(0, $minX - ($chunkX << 4)) & 0xf;
$tX = min(15, $maxX - ($chunkX << 4)) + 1;
$fZ = max(0, $minZ - ($chunkZ << 4)) & 0xf;
$tZ = min(15, $maxZ - ($chunkZ << 4)) + 1;
for ($x = $fX; $x < $tX; $x++) {
for ($z = $fZ; $z < $tZ; $z++) {
$paint[$x][$z] = str_repeat('*', 3);
}
}
$paper[0] .= str_pad('Chunk(X:' . $chunkX . ', Z:' . $chunkZ . ')', (16 << 1) + (3 << 3), str_repeat(' ', 3), STR_PAD_BOTH);
foreach ($paint as $x => $lineZ) {
$paper[$x + 1] .= ($x < 10 ? "0$x" : $x) . ' ' . implode('', $lineZ) . str_repeat(' ', 3);
}
$numbersZ = str_repeat(' ', 3);
for ($z = 0; $z < 16; $z++) {
$numbersZ .= ($z < 10 ? "0$z" : $z) . str_repeat(' ', 1);
}
$paper[$x + 2] .= $numbersZ . str_repeat(' ', 3);
if ($chunkZ === $toZ) {
$tube[$tubeId] = $paper;
$paper = array_fill(0, 16 + 2, '');
$tubeId++;
}
}
}
foreach ($tube as $paper) {
foreach ($paper as $id => $line) {
echo $line . PHP_EOL;
}
echo str_repeat(PHP_EOL, 2);
}
}
paint(-10, 10, -10, 10);
Chunk(X:-1, Z:-1) Chunk(X:-1, Z:0)
00 ################################################ 00 ################################################
01 ################################################ 01 ################################################
02 ################################################ 02 ################################################
03 ################################################ 03 ################################################
04 ################################################ 04 ################################################
05 ################################################ 05 ################################################
06 ##################****************************** 06 *********************************###############
07 ##################****************************** 07 *********************************###############
08 ##################****************************** 08 *********************************###############
09 ##################****************************** 09 *********************************###############
10 ##################****************************** 10 *********************************###############
11 ##################****************************** 11 *********************************###############
12 ##################****************************** 12 *********************************###############
13 ##################****************************** 13 *********************************###############
14 ##################****************************** 14 *********************************###############
15 ##################****************************** 15 *********************************###############
00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
Chunk(X:0, Z:-1) Chunk(X:0, Z:0)
00 ##################****************************** 00 *********************************###############
01 ##################****************************** 01 *********************************###############
02 ##################****************************** 02 *********************************###############
03 ##################****************************** 03 *********************************###############
04 ##################****************************** 04 *********************************###############
05 ##################****************************** 05 *********************************###############
06 ##################****************************** 06 *********************************###############
07 ##################****************************** 07 *********************************###############
08 ##################****************************** 08 *********************************###############
09 ##################****************************** 09 *********************************###############
10 ##################****************************** 10 *********************************###############
11 ################################################ 11 ################################################
12 ################################################ 12 ################################################
13 ################################################ 13 ################################################
14 ################################################ 14 ################################################
15 ################################################ 15 ################################################
00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment