Skip to content

Instantly share code, notes, and snippets.

@Muqsit
Created April 24, 2024 09:46
Show Gist options
  • Save Muqsit/3fb8521ea5af2ca0748d09855fbaf5c0 to your computer and use it in GitHub Desktop.
Save Muqsit/3fb8521ea5af2ca0748d09855fbaf5c0 to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\math\VoxelRayTrace;
use pocketmine\player\Player;
use pocketmine\scheduler\CancelTaskException;
use pocketmine\scheduler\ClosureTask;
use pocketmine\Server;
use pocketmine\world\ChunkLoader;
use pocketmine\world\format\Chunk;
use pocketmine\world\particle\BlockForceFieldParticle;
use pocketmine\world\World;
$server = Server::getInstance();
assert(isset($sender) && $sender instanceof Player);
$plugin = $server->getPluginManager()->getPlugin("Scripter");
$server->getWorldManager()->loadWorld("dungeon_maps");
$world = $server->getWorldManager()->getWorldByName("dungeon_maps");
$p1 = new Vector3(986, 62, 400);
$p2 = new Vector3(896, 42, 327);
$min = Vector3::minComponents($p1, $p2);
$max = Vector3::maxComponents($p1, $p2);
$origin = new Vector3(982, 54, 370);
$width = 0.6;
$height = 2;
/**
* Builds a mesh of traversable block positions for an entity of size ($width x $height).
* $min and $max vectors constrict the mesh to a definite region.
* $origin is the block position of any traversable point in the mesh (<-- position where the entity would be spawned).
*
* @param World $world
* @param Vector3 $min
* @param Vector3 $max
* @param Vector3 $origin
* @param float $width
* @param float $height
* @return array<int, array{int, int, int}>
*/
$build_mesh = static function(World $world, Vector3 $min, Vector3 $max, Vector3 $origin, float $width, float $height) : array{
/** @var SplQueue<Vector3> $queue */
$queue = new SplQueue();
$queue->push($origin);
$visited = [];
$smoothening_points = [];
$result = [World::blockHash($origin->x, $origin->y, $origin->z) => [$origin->x, $origin->y, $origin->z]];
$bb = new AxisAlignedBB(-$width / 2, 0, -$width / 2, $width / 2, $height, $width / 2);
while(!$queue->isEmpty()){
$current = $queue->dequeue();
// constrict our search to $min, $max
if($current->x <= $min->x || $current->x >= $max->x){
continue;
}
if($current->y <= $min->y || $current->y >= $max->y){
continue;
}
if($current->z <= $min->z || $current->z >= $max->z){
continue;
}
foreach(Facing::HORIZONTAL as $facing){
$block_side = $current->getSide($facing);
$hash = World::blockHash($block_side->x, $block_side->y, $block_side->z);
if(isset($visited[$hash])){
continue;
}
$visited[$hash] = true;
$targets = [];
// determine where we must move ($target) -- forward, ascend, descend, or none.
$move_neighbor = $bb->offsetCopy($block_side->x + 0.5, $block_side->y, $block_side->z + 0.5);
if(count($world->getBlockCollisionBoxes($move_neighbor)) === 0){ // no block is obstructing our path
if(count($world->getBlockCollisionBoxes($move_neighbor->offsetCopy(0, -1, 0))) > 0){ // we have a block to stand on, can proceed forward
$targets[] = $block_side;
}elseif(count($world->getBlockCollisionBoxes($move_neighbor->offsetCopy(0, -2, 0))) > 0){ // no floor but there is a block below floor, can safely descend
$smoothening_points[] = $block_side;
$targets[] = $block_side->down();
}
}elseif(count($world->getBlockCollisionBoxes($move_neighbor->offsetCopy(0, 1, 0))) === 0){ // empty space above for us to jump, can ascend
$smoothening_points[] = $current->up();
$targets[] = $block_side->up();
}
foreach($targets as $target){
$hash = World::blockHash($target->x, $target->y, $target->z);
$queue->enqueue($target);
$result[$hash] = [$target->x, $target->y, $target->z];
}
}
}
foreach($smoothening_points as $target){
$result[World::blockHash($target->x, $target->y, $target->z)] = [$target->x, $target->y, $target->z];
}
return $result;
};
/**
* Finds the geometric median from the given points.
*
* @param list<array{int, int, int}> $points
* @return ($points is empty ? null : array{int, int, int})
*/
$find_center = static function(array $points) : ?array{
$min_dist_sum = INF;
$center_point = null;
foreach($points as $point){
$distance_sum = 0;
foreach($points as $other){
$distance_sum += (($point[0] - $other[0]) ** 2) + (($point[1] - $other[1]) ** 2) + (($point[2] - $other[2]) ** 2);
}
if($distance_sum < $min_dist_sum){
$min_dist_sum = $distance_sum;
$center_point = $point;
}
}
return $center_point;
};
/**
* Creates a list of grids (set of XZ points) from a mesh (set of XYZ points).
*
* @param list<array{int, int, int}> $points
* @param int $max_dist maximum size of each grid -- grids exceeding this size will be divided
* @return list<array<int, array{int, int, int}>>
*/
$mesh_to_grids = static function(array $mesh, int $max_dist = 8) : array{
$grids = [];
$visited = [];
foreach($mesh as $source_hash => [$sx, $sy, $sz]){
if(isset($visited[$source_hash])){
continue;
}
// BFS: find all points touching this point horizontally
$touching = [$source_hash => [$sx, $sy, $sz]];
/** @var SplQueue<int> $queue */
$queue = new SplQueue();
$queue->enqueue($source_hash);
while(!$queue->isEmpty()){
$index = $queue->dequeue();
$visited[$index] = true;
[$cx, $cy, $cz] = $mesh[$index];
if(abs($sx - $cx) > $max_dist || abs($sy - $cy) > $max_dist || abs($sz - $cz) > $max_dist){
continue;
}
foreach(Facing::HORIZONTAL as $side){
[$dx, $dy, $dz] = Facing::OFFSET[$side];
$x = $cx + $dx;
$y = $cy + $dy;
$z = $cz + $dz;
$hash = World::blockHash($x, $y, $z);
if(!isset($mesh[$hash])){
continue;
}
if(isset($neighbors[$hash]) || isset($visited[$hash])){
continue;
}
$touching[$hash] = [$x, $y, $z];
$visited[$hash] = true;
$queue->enqueue($hash);
}
}
if(count($touching) === 0){
continue;
}
$grids[] = $touching;
}
return $grids;
};
/**
* Connects a set of grids and represents them as a graph.
* Returns two arrays -- a list of vertices and an adjacency list
*
* @param list<array<int, array{int, int, int}>> $grids
* @return array{list<array{int, int, int}>, list<array{int, list<int>}>}
*/
$grids_to_graph = static function(array $grids) use($find_center) : array{
$vertices = array_map($find_center, $grids);
$adjacency_list = [];
foreach($vertices as $index => $vertex){
$connections = [];
foreach($vertices as $index2 => $vertex2){
if($index2 >= $index){
continue;
}
foreach(VoxelRayTrace::betweenPoints(new Vector3($vertex[0], $vertex[1], $vertex[2]), new Vector3($vertex2[0], $vertex2[1], $vertex2[2])) as $point){
$connection = false;
foreach([0, -1, 1] as $dy){
$hash = World::blockHash($point->x, $point->y + $dy, $point->z);
if(isset($grids[$index][$hash]) || isset($grids[$index2][$hash])){
$connection = true;
break;
}
}
if(!$connection){
continue 2;
}
}
$connections[] = $index2;
}
$adjacency_list[] = [$index, $connections];
}
return [$vertices, $adjacency_list];
};
$loader = new class implements ChunkLoader{};
for($x = ($min->x >> Chunk::COORD_BIT_SIZE); $x <= ($max->x >> Chunk::COORD_BIT_SIZE); $x++){
for($z = ($min->z >> Chunk::COORD_BIT_SIZE); $z <= ($max->z >> Chunk::COORD_BIT_SIZE); $z++){
$world->registerChunkLoader($loader, $x, $z);
}
}
try{
$mesh = $build_mesh($world, $min, $max, $origin, $width, $height);
$grids = $mesh_to_grids($mesh, 4);
[$vertices, $adjacency_list] = $grids_to_graph($grids);
}finally{
for($x = ($min->x >> Chunk::COORD_BIT_SIZE); $x <= ($max->x >> Chunk::COORD_BIT_SIZE); $x++){
for($z = ($min->z >> Chunk::COORD_BIT_SIZE); $z <= ($max->z >> Chunk::COORD_BIT_SIZE); $z++){
$world->unregisterChunkLoader($loader, $x, $z);
}
}
}
$particles = [];
$display_layers = ["edge", "vertex"]; // "mesh", "plane", "edge", "vertex"
foreach($display_layers as $option){
if($option === "mesh"){
$colors = ColorUtils::getXkcdColors(); // {"cloudy_blue":[172,194,217],"dark_pastel_green":[86,174,87],"dust":[178,153,110],"electric_lime":[168,255,4],"fresh_green":[105,216,79],"light_eggplant":[137,69,133],"nasty_green":[112,178,63],"really_light_blue":[212,255,255],"tea":[101,171,124],"warm_purple":[149,46,143],"yellowish_tan":[252,252,129],"cement":[165,163,145],"dark_grass_green":[56,128,4],"dusty_teal":[76,144,133],"grey_teal":[94,155,138],"macaroni_and_cheese":[239,180,53],"pinkish_tan":[217,155,130],"spruce":[10,95,56],"strong_blue":[12,6,247],"toxic_green":[97,222,42],"windows_blue":[55,120,191],"blue_blue":[34,66,199],"blue_with_a_hint_of_purple":[83,60,198],"booger":[155,181,60],"bright_sea_green":[5,255,166],"dark_green_blue":[31,99,87],"deep_turquoise":[1,115,116],"green_teal":[12,181,119],"strong_pink":[255,7,137],"bland":[175,168,139],"deep_aqua":[8,120,127],"lavender_pink":[221,133,215],"light_moss_green":[166,200,117],"light_seafoam_green":[167,255,181],"olive_yellow":[194,183,9],"pig_pink":[231,142,165],"deep_lilac":[150,110,189],"desert":[204,173,96],"dusty_lavender":[172,134,168],"purpley_grey":[148,126,148],"purply":[152,63,178],"candy_pink":[255,99,233],"light_pastel_green":[178,251,165],"boring_green":[99,179,101],"kiwi_green":[142,229,63],"light_grey_green":[183,225,161],"orange_pink":[255,111,82],"tea_green":[189,248,163],"very_light_brown":[211,182,131],"egg_shell":[255,252,196],"eggplant_purple":[67,5,65],"powder_pink":[255,178,208],"reddish_grey":[153,117,112],"baby_shit_brown":[173,144,13],"liliac":[196,142,253],"stormy_blue":[80,123,156],"ugly_brown":[125,113,3],"custard":[255,253,120],"darkish_pink":[218,70,125],"deep_brown":[65,2,0],"greenish_beige":[201,209,121],"manilla":[255,250,134],"off_blue":[86,132,174],"battleship_grey":[107,124,133],"browny_green":[111,108,10],"bruise":[126,64,113],"kelley_green":[0,147,55],"sickly_yellow":[208,228,41],"sunny_yellow":[255,249,23],"azul":[29,93,236],"darkgreen":[5,73,7],"green\/yellow":[181,206,8],"lichen":[143,182,123],"light_light_green":[200,255,176],"pale_gold":[253,222,108],"sun_yellow":[255,223,34],"tan_green":[169,190,112],"burple":[104,50,227],"butterscotch":[253,177,71],"toupe":[199,172,125],"dark_cream":[255,243,154],"indian_red":[133,14,4],"light_lavendar":[239,192,254],"poison_green":[64,253,20],"baby_puke_green":[182,196,6],"bright_yellow_green":[157,255,0],"charcoal_grey":[60,65,66],"squash":[242,171,21],"cinnamon":[172,79,6],"light_pea_green":[196,254,130],"radioactive_green":[44,250,31],"raw_sienna":[154,98,0],"baby_purple":[202,155,247],"cocoa":[135,95,66],"light_royal_blue":[58,46,254],"orangeish":[253,141,73],"rust_brown":[139,49,3],"sand_brown":[203,165,96],"swamp":[105,131,57],"tealish_green":[12,220,115],"burnt_siena":[183,82,3],"camo":[127,143,78],"dusk_blue":[38,83,141],"fern":[99,169,80],"old_rose":[200,127,137],"pale_light_green":[177,252,153],"peachy_pink":[255,154,138],"rosy_pink":[246,104,142],"light_bluish_green":[118,253,168],"light_bright_green":[83,254,92],"light_neon_green":[78,253,84],"light_seafoam":[160,254,191],"tiffany_blue":[123,242,218],"washed_out_green":[188,245,166],"browny_orange":[202,107,2],"nice_blue":[16,122,176],"sapphire":[33,56,171],"greyish_teal":[113,159,145],"orangey_yellow":[253,185,21],"parchment":[254,252,175],"straw":[252,246,121],"very_dark_brown":[29,2,0],"terracota":[203,104,67],"ugly_blue":[49,102,138],"clear_blue":[36,122,253],"creme":[255,255,182],"foam_green":[144,253,169],"grey\/green":[134,161,125],"light_gold":[253,220,92],"seafoam_blue":[120,209,182],"topaz":[19,187,175],"violet_pink":[251,95,252],"wintergreen":[32,249,134],"yellow_tan":[255,227,110],"dark_fuchsia":[157,7,89],"indigo_blue":[58,24,177],"light_yellowish_green":[194,255,137],"pale_magenta":[215,103,173],"rich_purple":[114,0,88],"sunflower_yellow":[255,218,3],"green\/blue":[1,192,141],"leather":[172,116,52],"racing_green":[1,70,0],"vivid_purple":[153,0,250],"dark_royal_blue":[2,6,111],"hazel":[142,118,24],"muted_pink":[209,118,143],"booger_green":[150,180,3],"canary":[253,255,99],"cool_grey":[149,163,166],"dark_taupe":[127,104,78],"darkish_purple":[117,25,115],"true_green":[8,148,4],"coral_pink":[255,97,99],"dark_sage":[89,133,86],"dark_slate_blue":[33,71,97],"flat_blue":[60,115,168],"mushroom":[186,158,136],"rich_blue":[2,27,249],"dirty_purple":[115,74,101],"greenblue":[35,196,139],"icky_green":[143,174,34],"light_khaki":[230,242,162],"warm_blue":[75,87,219],"dark_hot_pink":[217,1,102],"deep_sea_blue":[1,84,130],"carmine":[157,2,22],"dark_yellow_green":[114,143,2],"pale_peach":[255,229,173],"plum_purple":[78,5,80],"golden_rod":[249,188,8],"neon_red":[255,7,58],"old_pink":[199,121,134],"very_pale_blue":[214,255,254],"blood_orange":[254,75,3],"grapefruit":[253,89,86],"sand_yellow":[252,225,102],"clay_brown":[178,113,61],"dark_blue_grey":[31,59,77],"flat_green":[105,157,76],"light_green_blue":[86,252,162],"warm_pink":[251,85,129],"dodger_blue":[62,130,252],"gross_green":[160,191,22],"ice":[214,255,250],"metallic_blue":[79,115,142],"pale_salmon":[255,177,154],"sap_green":[92,139,21],"algae":[84,172,104],"bluey_grey":[137,160,176],"greeny_grey":[126,160,122],"highlighter_green":[27,252,6],"light_light_blue":[202,255,251],"light_mint":[182,255,187],"raw_umber":[167,94,9],"vivid_blue":[21,46,255],"deep_lavender":[141,94,183],"dull_teal":[95,158,143],"light_greenish_blue":[99,247,180],"mud_green":[96,102,2],"pinky":[252,134,170],"red_wine":[140,0,52],"shit_green":[117,128,0],"tan_brown":[171,126,76],"darkblue":[3,7,100],"rosa":[254,134,164],"lipstick":[213,23,78],"pale_mauve":[254,208,252],"claret":[104,0,24],"dandelion":[254,223,8],"orangered":[254,66,15],"poop_green":[111,124,0],"ruby":[202,1,71],"dark":[27,36,49],"greenish_turquoise":[0,251,176],"pastel_red":[219,88,86],"piss_yellow":[221,214,24],"bright_cyan":[65,253,254],"dark_coral":[207,82,78],"algae_green":[33,195,111],"darkish_red":[169,3,8],"reddy_brown":[110,16,5],"blush_pink":[254,130,140],"camouflage_green":[75,97,19],"lawn_green":[77,164,9],"putty":[190,174,138],"vibrant_blue":[3,57,248],"dark_sand":[168,143,89],"purple\/blue":[93,33,208],"saffron":[254,178,9],"twilight":[78,81,139],"warm_brown":[150,78,2],"bluegrey":[133,163,178],"bubble_gum_pink":[255,105,175],"duck_egg_blue":[195,251,244],"greenish_cyan":[42,254,183],"petrol":[0,95,106],"royal":[12,23,147],"butter":[255,255,129],"dusty_orange":[240,131,58],"off_yellow":[241,243,63],"pale_olive_green":[177,210,123],"orangish":[252,130,74],"leaf":[113,170,52],"light_blue_grey":[183,201,226],"dried_blood":[75,1,1],"lightish_purple":[165,82,230],"rusty_red":[175,47,13],"lavender_blue":[139,136,248],"light_grass_green":[154,247,100],"light_mint_green":[166,251,178],"sunflower":[255,197,18],"velvet":[117,8,81],"brick_orange":[193,74,9],"lightish_red":[254,47,74],"pure_blue":[2,3,226],"twilight_blue":[10,67,122],"violet_red":[165,0,85],"yellowy_brown":[174,139,12],"carnation":[253,121,143],"muddy_yellow":[191,172,5],"dark_seafoam_green":[62,175,118],"deep_rose":[199,71,103],"dusty_red":[185,72,78],"grey\/blue":[100,125,142],"lemon_lime":[191,254,40],"purple\/pink":[215,37,222],"brown_yellow":[178,151,5],"purple_brown":[103,58,63],"wisteria":[168,125,194],"banana_yellow":[250,254,75],"lipstick_red":[192,2,47],"water_blue":[14,135,204],"brown_grey":[141,132,104],"vibrant_purple":[173,3,222],"baby_green":[140,255,158],"barf_green":[148,172,2],"eggshell_blue":[196,255,247],"sandy_yellow":[253,238,115],"cool_green":[51,184,100],"pale":[255,249,208],"blue\/grey":[117,141,163],"hot_magenta":[245,4,201],"greyblue":[119,161,181],"purpley":[135,86,228],"baby_shit_green":[136,151,23],"brownish_pink":[194,126,121],"dark_aquamarine":[1,115,113],"diarrhea":[159,131,3],"light_mustard":[247,213,96],"pale_sky_blue":[189,246,254],"turtle_green":[117,184,79],"bright_olive":[156,187,4],"dark_grey_blue":[41,70,91],"greeny_brown":[105,96,6],"lemon_green":[173,248,2],"light_periwinkle":[193,198,252],"seaweed_green":[53,173,107],"sunshine_yellow":[255,253,55],"ugly_purple":[164,66,160],"medium_pink":[243,97,150],"puke_brown":[148,119,6],"very_light_pink":[255,244,242],"viridian":[30,145,103],"bile":[181,195,6],"faded_yellow":[254,255,127],"very_pale_green":[207,253,188],"vibrant_green":[10,221,8],"bright_lime":[135,253,5],"spearmint":[30,248,118],"light_aquamarine":[123,253,199],"light_sage":[188,236,172],"yellowgreen":[187,249,15],"baby_poo":[171,144,4],"dark_seafoam":[31,181,122],"deep_teal":[0,85,90],"heather":[164,132,172],"rust_orange":[196,85,8],"dirty_blue":[63,130,157],"fern_green":[84,141,68],"bright_lilac":[201,94,251],"weird_green":[58,229,127],"peacock_blue":[1,103,149],"avocado_green":[135,169,34],"faded_orange":[240,148,77],"grape_purple":[93,20,81],"hot_green":[37,255,41],"lime_yellow":[208,254,29],"mango":[255,166,43],"shamrock":[1,180,76],"bubblegum":[255,108,181],"purplish_brown":[107,66,71],"vomit_yellow":[199,193,12],"pale_cyan":[183,255,250],"key_lime":[174,255,110],"tomato_red":[236,45,1],"lightgreen":[118,255,123],"merlot":[115,0,57],"night_blue":[4,3,72],"purpleish_pink":[223,78,200],"apple":[110,203,60],"baby_poop_green":[143,152,5],"green_apple":[94,220,31],"heliotrope":[217,79,245],"yellow\/green":[200,253,61],"almost_black":[7,13,13],"cool_blue":[73,132,184],"leafy_green":[81,183,59],"mustard_brown":[172,126,4],"dusk":[78,84,129],"dull_brown":[135,110,75],"frog_green":[88,188,8],"vivid_green":[47,239,16],"bright_light_green":[45,254,84],"fluro_green":[10,255,2],"kiwi":[156,239,67],"seaweed":[24,209,123],"navy_green":[53,83,10],"ultramarine_blue":[24,5,219],"iris":[98,88,196],"pastel_orange":[255,150,79],"yellowish_orange":[255,171,15],"perrywinkle":[143,140,231],"tealish":[36,188,168],"dark_plum":[63,1,44],"pear":[203,248,95],"pinkish_orange":[255,114,76],"midnight_purple":[40,1,55],"light_urple":[179,111,246],"dark_mint":[72,192,114],"greenish_tan":[188,203,122],"light_burgundy":[168,65,91],"turquoise_blue":[6,177,196],"ugly_pink":[205,117,132],"sandy":[241,218,122],"electric_pink":[255,4,144],"muted_purple":[128,91,135],"mid_green":[80,167,71],"greyish":[168,164,149],"neon_yellow":[207,255,4],"banana":[255,255,126],"carnation_pink":[255,127,167],"tomato":[239,64,38],"sea":[60,153,146],"muddy_brown":[136,104,6],"turquoise_green":[4,244,137],"buff":[254,246,158],"fawn":[207,175,123],"muted_blue":[59,113,159],"pale_rose":[253,193,197],"dark_mint_green":[32,192,115],"amethyst":[155,95,192],"blue\/green":[15,155,142],"chestnut":[116,40,2],"sick_green":[157,185,44],"pea":[164,191,32],"rusty_orange":[205,89,9],"stone":[173,165,135],"rose_red":[190,1,60],"pale_aqua":[184,255,235],"deep_orange":[220,77,1],"earth":[162,101,62],"mossy_green":[99,139,39],"grassy_green":[65,156,3],"pale_lime_green":[177,255,101],"light_grey_blue":[157,188,212],"pale_grey":[253,253,254],"asparagus":[119,171,86],"blueberry":[70,65,150],"purple_red":[153,1,71],"pale_lime":[190,253,115],"greenish_teal":[50,191,132],"caramel":[175,111,9],"deep_magenta":[160,2,92],"light_peach":[255,216,177],"milk_chocolate":[127,78,30],"ocher":[191,155,12],"off_green":[107,163,83],"purply_pink":[240,117,230],"lightblue":[123,200,246],"dusky_blue":[71,95,148],"golden":[245,191,3],"light_beige":[255,254,182],"butter_yellow":[255,253,116],"dusky_purple":[137,91,123],"french_blue":[67,107,173],"ugly_yellow":[208,193,1],"greeny_yellow":[198,248,8],"orangish_red":[244,54,5],"shamrock_green":[2,193,77],"orangish_brown":[178,95,3],"tree_green":[42,126,25],"deep_violet":[73,6,72],"gunmetal":[83,98,103],"blue\/purple":[90,6,239],"cherry":[207,2,52],"sandy_brown":[196,166,97],"warm_grey":[151,138,132],"dark_indigo":[31,9,84],"midnight":[3,1,45],"bluey_green":[43,177,121],"grey_pink":[195,144,155],"soft_purple":[166,111,181],"blood":[119,0,1],"brown_red":[146,43,5],"medium_grey":[125,127,124],"berry":[153,15,75],"poo":[143,115,3],"purpley_pink":[200,60,185],"light_salmon":[254,169,147],"snot":[172,187,13],"easter_purple":[192,113,254],"light_yellow_green":[204,253,127],"dark_navy_blue":[0,2,46],"drab":[130,131,68],"light_rose":[255,197,203],"rouge":[171,18,57],"purplish_red":[176,5,75],"slime_green":[153,204,4],"baby_poop":[147,124,0],"irish_green":[1,149,41],"pink\/purple":[239,29,231],"dark_navy":[0,4,53],"greeny_blue":[66,179,149],"light_plum":[157,87,131],"pinkish_grey":[200,172,169],"dirty_orange":[200,118,6],"rust_red":[170,39,4],"pale_lilac":[228,203,255],"orangey_red":[250,66,36],"primary_blue":[8,4,249],"kermit_green":[92,178,0],"brownish_purple":[118,66,78],"murky_green":[108,122,14],"wheat":[251,221,126],"very_dark_purple":[42,1,52],"bottle_green":[4,74,5],"watermelon":[253,70,89],"deep_sky_blue":[13,117,248],"fire_engine_red":[254,0,2],"yellow_ochre":[203,157,6],"pumpkin_orange":[251,125,7],"pale_olive":[185,204,129],"light_lilac":[237,200,255],"lightish_green":[97,225,96],"carolina_blue":[138,184,254],"mulberry":[146,10,78],"shocking_pink":[254,2,162],"auburn":[154,48,1],"bright_lime_green":[101,254,8],"celadon":[190,253,183],"pinkish_brown":[177,114,97],"poo_brown":[136,95,1],"bright_sky_blue":[2,204,254],"celery":[193,253,149],"dirt_brown":[131,101,57],"strawberry":[251,41,67],"dark_lime":[132,183,1],"copper":[182,99,37],"medium_brown":[127,81,18],"muted_green":[95,160,82],"robin's_egg":[109,237,253],"bright_aqua":[11,249,234],"bright_lavender":[199,96,255],"ivory":[255,255,203],"very_light_purple":[246,206,252],"light_navy":[21,80,132],"pink_red":[245,5,79],"olive_brown":[100,84,3],"poop_brown":[122,89,1],"mustard_green":[168,181,4],"ocean_green":[61,153,115],"very_dark_blue":[0,1,51],"dusty_green":[118,169,115],"light_navy_blue":[46,90,136],"minty_green":[11,247,125],"adobe":[189,108,72],"barney":[172,29,184],"jade_green":[43,175,106],"bright_light_blue":[38,247,253],"light_lime":[174,253,108],"dark_khaki":[155,143,85],"orange_yellow":[255,173,1],"ocre":[198,156,4],"maize":[244,208,84],"faded_pink":[222,157,172],"british_racing_green":[5,72,13],"sandstone":[201,174,116],"mud_brown":[96,70,15],"light_sea_green":[152,246,176],"robin_egg_blue":[138,241,254],"aqua_marine":[46,232,187],"dark_sea_green":[17,135,93],"soft_pink":[253,176,192],"orangey_brown":[177,96,2],"cherry_red":[247,2,42],"burnt_yellow":[213,171,9],"brownish_grey":[134,119,95],"camel":[198,159,89],"purplish_grey":[122,104,127],"marine":[4,46,96],"greyish_pink":[200,141,148],"pale_turquoise":[165,251,213],"pastel_yellow":[255,254,113],"bluey_purple":[98,65,199],"canary_yellow":[255,254,64],"faded_red":[211,73,78],"sepia":[152,94,43],"coffee":[166,129,76],"bright_magenta":[255,8,232],"mocha":[157,118,81],"ecru":[254,255,202],"purpleish":[152,86,141],"cranberry":[158,0,58],"darkish_green":[40,124,55],"brown_orange":[185,105,2],"dusky_rose":[186,104,115],"melon":[255,120,85],"sickly_green":[148,178,28],"silver":[197,201,199],"purply_blue":[102,26,238],"purpleish_blue":[97,64,239],"hospital_green":[155,229,170],"shit_brown":[123,88,4],"mid_blue":[39,106,179],"amber":[254,179,8],"easter_green":[140,253,126],"soft_blue":[100,136,234],"cerulean_blue":[5,110,238],"golden_brown":[178,122,1],"bright_turquoise":[15,254,249],"red_pink":[250,42,85],"red_purple":[130,7,71],"greyish_brown":[122,106,79],"vermillion":[244,50,12],"russet":[161,57,5],"steel_grey":[111,130,138],"lighter_purple":[165,90,244],"bright_violet":[173,10,253],"prussian_blue":[0,69,119],"slate_green":[101,141,109],"dirty_pink":[202,123,128],"dark_blue_green":[0,82,73],"pine":[43,93,52],"yellowy_green":[191,241,40],"dark_gold":[181,148,16],"bluish":[41,118,187],"darkish_blue":[1,65,130],"dull_red":[187,63,63],"pinky_red":[252,38,71],"bronze":[168,121,0],"pale_teal":[130,203,178],"military_green":[102,124,62],"barbie_pink":[254,70,165],"bubblegum_pink":[254,131,204],"pea_soup_green":[148,166,23],"dark_mustard":[168,137,5],"shit":[127,95,0],"medium_purple":[158,67,162],"very_dark_green":[6,46,3],"dirt":[138,110,69],"dusky_pink":[204,122,139],"red_violet":[158,1,104],"lemon_yellow":[253,255,56],"pistachio":[192,250,139],"dull_yellow":[238,220,91],"dark_lime_green":[126,189,1],"denim_blue":[59,91,146],"teal_blue":[1,136,159],"lightish_blue":[61,122,253],"purpley_blue":[95,52,231],"light_indigo":[109,90,207],"swamp_green":[116,133,0],"brown_green":[112,108,17],"dark_maroon":[60,0,8],"hot_purple":[203,0,245],"dark_forest_green":[0,45,4],"faded_blue":[101,140,187],"drab_green":[116,149,81],"light_lime_green":[185,255,102],"snot_green":[157,193,0],"yellowish":[250,238,102],"light_blue_green":[126,251,179],"bordeaux":[123,0,44],"light_mauve":[194,146,161],"ocean":[1,123,146],"marigold":[252,192,6],"muddy_green":[101,116,50],"dull_orange":[216,134,59],"steel":[115,133,149],"electric_purple":[170,35,255],"fluorescent_green":[8,255,8],"yellowish_brown":[155,122,1],"blush":[242,158,142],"soft_green":[111,194,118],"bright_orange":[255,91,0],"lemon":[253,255,82],"purple_grey":[134,111,133],"acid_green":[143,254,9],"pale_lavender":[238,207,254],"violet_blue":[81,10,201],"light_forest_green":[79,145,83],"burnt_red":[159,35,5],"khaki_green":[114,134,57],"cerise":[222,12,98],"faded_purple":[145,110,153],"apricot":[255,177,109],"dark_olive_green":[60,77,3],"grey_brown":[127,112,83],"green_grey":[119,146,111],"true_blue":[1,15,204],"pale_violet":[206,174,250],"periwinkle_blue":[143,153,251],"light_sky_blue":[198,252,255],"blurple":[85,57,204],"green_brown":[84,78,3],"bluegreen":[1,122,121],"bright_teal":[1,249,198],"brownish_yellow":[201,176,3],"pea_soup":[146,153,1],"forest":[11,85,9],"barney_purple":[160,4,152],"ultramarine":[32,0,177],"purplish":[148,86,140],"puke_yellow":[194,190,14],"bluish_grey":[116,139,151],"dark_periwinkle":[102,95,209],"dark_lilac":[156,109,165],"reddish":[196,66,64],"light_maroon":[162,72,87],"dusty_purple":[130,95,135],"terra_cotta":[201,100,59],"avocado":[144,177,52],"marine_blue":[1,56,106],"teal_green":[37,163,111],"slate_grey":[89,101,109],"lighter_green":[117,253,99],"electric_green":[33,252,13],"dusty_blue":[90,134,173],"golden_yellow":[254,198,21],"bright_yellow":[255,253,1],"light_lavender":[223,197,254],"umber":[178,100,0],"poop":[127,94,0],"dark_peach":[222,126,93],"jungle_green":[4,130,67],"eggshell":[255,255,212],"denim":[59,99,140],"yellow_brown":[183,148,0],"dull_purple":[132,89,126],"chocolate_brown":[65,25,0],"wine_red":[123,3,35],"neon_blue":[4,217,255],"dirty_green":[102,126,44],"light_tan":[251,238,172],"ice_blue":[215,255,254],"cadet_blue":[78,116,150],"dark_mauve":[135,76,98],"very_light_blue":[213,255,255],"grey_purple":[130,109,140],"pastel_pink":[255,186,205],"very_light_green":[209,255,189],"dark_sky_blue":[68,142,228],"evergreen":[5,71,42],"dull_pink":[213,134,157],"aubergine":[61,7,52],"mahogany":[74,1,0],"reddish_orange":[248,72,28],"deep_green":[2,89,15],"vomit_green":[137,162,3],"purple_pink":[224,63,216],"dusty_pink":[213,138,148],"faded_green":[123,178,116],"camo_green":[82,101,37],"pinky_purple":[201,76,190],"pink_purple":[219,75,218],"brownish_red":[158,54,35],"dark_rose":[181,72,93],"mud":[115,92,18],"brownish":[156,109,87],"emerald_green":[2,143,30],"pale_brown":[177,145,110],"dull_blue":[73,117,156],"burnt_umber":[160,69,14],"medium_green":[57,173,72],"clay":[182,106,80],"light_aqua":[140,255,219],"light_olive_green":[164,190,92],"brownish_orange":[203,119,35],"dark_aqua":[5,105,107],"purplish_pink":[206,93,174],"dark_salmon":[200,90,83],"greenish_grey":[150,174,141],"jade":[31,167,116],"ugly_green":[122,151,3],"dark_beige":[172,147,98],"emerald":[1,160,73],"pale_red":[217,84,77],"light_magenta":[250,95,247],"sky":[130,202,252],"light_cyan":[172,255,252],"yellow_orange":[252,176,1],"reddish_purple":[145,9,81],"reddish_pink":[254,44,84],"orchid":[200,117,196],"dirty_yellow":[205,197,10],"orange_red":[253,65,30],"deep_red":[154,2,0],"orange_brown":[190,100,0],"cobalt_blue":[3,10,167],"neon_pink":[254,1,154],"rose_pink":[247,135,154],"greyish_purple":[136,113,145],"raspberry":[176,1,73],"aqua_green":[18,225,147],"salmon_pink":[254,123,124],"tangerine":[255,148,8],"brownish_green":[106,110,9],"red_brown":[139,46,22],"greenish_brown":[105,97,18],"pumpkin":[225,119,1],"pine_green":[10,72,30],"charcoal":[52,56,55],"baby_pink":[255,183,206],"cornflower":[106,121,247],"blue_violet":[93,6,233],"chocolate":[61,28,2],"greyish_green":[130,166,125],"scarlet":[190,1,25],"green_yellow":[201,255,39],"dark_olive":[55,62,2],"sienna":[169,86,30],"pastel_purple":[202,160,255],"terracotta":[202,102,65],"aqua_blue":[2,216,233],"sage_green":[136,179,120],"blood_red":[152,0,2],"deep_pink":[203,1,98],"grass":[92,172,45],"moss":[118,153,88],"pastel_blue":[162,191,254],"bluish_green":[16,166,116],"green_blue":[6,180,139],"dark_tan":[175,136,74],"greenish_blue":[11,139,135],"pale_orange":[255,167,86],"vomit":[162,164,21],"forrest_green":[21,68,6],"dark_lavender":[133,103,152],"dark_violet":[52,1,63],"purple_blue":[99,45,233],"dark_cyan":[10,136,138],"olive_drab":[111,118,50],"pinkish":[212,106,126],"cobalt":[30,72,143],"neon_purple":[188,19,254],"light_turquoise":[126,244,204],"apple_green":[118,205,38],"dull_green":[116,166,98],"wine":[128,1,63],"powder_blue":[177,209,252],"off_white":[255,255,228],"electric_blue":[6,82,255],"dark_turquoise":[4,92,90],"blue_purple":[87,41,206],"azure":[6,154,243],"bright_red":[255,0,13],"pinkish_red":[241,12,69],"cornflower_blue":[81,112,215],"light_olive":[172,191,105],"grape":[108,52,97],"greyish_blue":[94,129,157],"purplish_blue":[96,30,249],"yellowish_green":[176,221,22],"greenish_yellow":[205,253,2],"medium_blue":[44,111,187],"dusty_rose":[192,115,122],"light_violet":[214,180,252],"midnight_blue":[2,0,53],"bluish_purple":[112,59,231],"red_orange":[253,60,6],"dark_magenta":[150,0,86],"greenish":[64,163,104],"ocean_blue":[3,113,156],"coral":[252,90,80],"cream":[255,255,194],"reddish_brown":[127,43,10],"burnt_sienna":[176,78,15],"brick":[160,54,35],"sage":[135,174,115],"grey_green":[120,155,115],"white":[255,255,255],"robin's_egg_blue":[152,239,249],"moss_green":[101,139,56],"steel_blue":[90,125,154],"eggplant":[56,8,53],"light_yellow":[255,254,122],"leaf_green":[92,169,4],"light_grey":[216,220,214],"puke":[165,165,2],"pinkish_purple":[214,72,215],"sea_blue":[4,116,149],"pale_purple":[183,144,212],"slate_blue":[91,124,153],"blue_grey":[96,124,142],"hunter_green":[11,64,8],"fuchsia":[237,13,217],"crimson":[140,0,15],"pale_yellow":[255,255,132],"ochre":[191,144,5],"mustard_yellow":[210,189,10],"light_red":[255,71,76],"cerulean":[4,133,209],"pale_pink":[255,207,220],"deep_blue":[4,2,115],"rust":[168,60,9],"light_teal":[144,228,193],"slate":[81,101,114],"goldenrod":[250,194,5],"dark_yellow":[213,182,10],"dark_grey":[54,55,55],"army_green":[75,93,22],"grey_blue":[107,139,164],"seafoam":[128,249,173],"puce":[165,126,82],"spring_green":[169,249,113],"dark_orange":[198,81,2],"sand":[226,202,118],"pastel_green":[176,255,157],"mint":[159,254,176],"light_orange":[253,170,72],"bright_pink":[254,1,177],"chartreuse":[193,248,10],"deep_purple":[54,1,63],"dark_brown":[52,28,2],"taupe":[185,162,129],"pea_green":[142,171,18],"puke_green":[154,174,7],"kelly_green":[2,171,46],"seafoam_green":[122,249,171],"blue_green":[19,126,109],"khaki":[170,166,98],"burgundy":[97,0,35],"dark_teal":[1,77,78],"brick_red":[143,20,2],"royal_purple":[75,0,110],"plum":[88,15,65],"mint_green":[143,255,159],"gold":[219,180,12],"baby_blue":[162,207,254],"yellow_green":[192,251,45],"bright_purple":[190,3,253],"dark_red":[132,0,0],"pale_blue":[208,254,254],"grass_green":[63,155,11],"navy":[1,21,62],"aquamarine":[4,216,178],"burnt_orange":[192,78,1],"neon_green":[12,255,12],"bright_blue":[1,101,252],"rose":[207,98,117],"light_pink":[255,209,223],"mustard":[206,179,1],"indigo":[56,2,130],"lime":[170,255,50],"sea_green":[83,252,161],"periwinkle":[142,130,254],"dark_pink":[203,65,107],"olive_green":[103,122,4],"peach":[255,176,124],"pale_green":[199,253,181],"light_brown":[173,129,80],"hot_pink":[255,2,141],"black":[0,0,0],"lilac":[206,162,253],"navy_blue":[0,17,70],"royal_blue":[5,4,170],"beige":[230,218,166],"salmon":[255,121,108],"olive":[110,117,14],"maroon":[101,0,33],"bright_green":[1,255,7],"dark_purple":[53,6,62],"mauve":[174,113,129],"forest_green":[6,71,12],"aqua":[19,234,201],"cyan":[0,255,255],"tan":[209,178,111],"dark_blue":[0,3,91],"lavender":[199,159,239],"turquoise":[6,194,172],"dark_green":[3,53,0],"violet":[154,14,234],"light_purple":[191,119,246],"lime_green":[137,254,5],"grey":[146,149,145],"sky_blue":[117,187,253],"yellow":[255,255,20],"magenta":[194,0,120],"light_green":[150,249,123],"orange":[249,115,6],"teal":[2,147,134],"light_blue":[149,208,252],"red":[229,0,0],"brown":[101,55,0],"pink":[255,129,192],"blue":[3,67,223],"green":[21,176,26],"purple":[126,30,156]}
$i = 0;
foreach($mesh as [$x, $y, $z]){
[$r, $g, $b] = current($colors);
if(next($colors) === false){
reset($colors);
}
$particle = GenericEffectParticle::flatBlock($world, 1, $r / 255, $g / 255, $b / 255);
$particles[] = [new Vector3($x + 0.5, $y + 0.0625, $z + 0.5), $particle];
}
}elseif($option === "plane"){
$colors = ColorUtils::getXkcdColors();
foreach($grids as $plane){
[$r, $g, $b] = $colors[$index = array_rand($colors)];
unset($colors[$index]);
$particle = GenericEffectParticle::flatBlock($world, 1, $r / 255, $g / 255, $b / 255);
foreach($plane as [$x, $y, $z]){
$particles[] = [new Vector3($x + 0.5, $y + 0.0625, $z + 0.5), $particle];
}
}
}elseif($option === "edge"){
foreach($adjacency_list as [$source, $destinations]){
[$sx, $sy, $sz] = $vertices[$source];
$src_vec = new Vector3($sx + 0.5, $sy + 0.5, $sz + 0.5);
foreach($destinations as $destination){
[$dx, $dy, $dz] = $vertices[$destination];
$dst_vec = new Vector3($dx + 0.5, $dy + 0.5, $dz + 0.5);
$dv = $dst_vec->subtractVector($src_vec)->normalize();
$size = $dst_vec->distance($src_vec);
$particles[] = [$src_vec, GenericEffectParticle::laserBeam($world, $dv->x, $dv->y, $dv->z, $size, 15, 0, 1, 0)];
}
}
}elseif($option === "vertex"){
foreach($adjacency_list as [$source, $destinations]){
[$sx, $sy, $sz] = $vertices[$source];
$src_vec = new Vector3($sx + 0.5, $sy + 0.5, $sz + 0.5);
$particles[] = [$src_vec, new BlockForceFieldParticle(65535)];
}
}else{
throw new RuntimeException();
}
}
$duration1 = 30;
$plugin->getScheduler()->scheduleRepeatingTask(new ClosureTask(function() use(&$duration1, $particles, $origin, $world) : void{
--$duration1 > 0 || throw new CancelTaskException();
foreach($particles as [$pos, $particle]){
$world->addParticle($pos, $particle);
}
}), 10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment