src/falkirks/minereset/task/ResetTask.php
/**
	 * Actions to execute when run
	 *
	 * @return void
	 */
Actions to execute when run
@return void
Actions to execute when run @return void
public function onRun(): void {
		$chunkClass = $this->chunkClass;
		$chunks = unserialize($this->chunks);
		foreach ($chunks as $hash => $binary) {
			$chunks[$hash] = FastChunkSerializer::deserializeTerrain($binary);
		}
		$sum = [];
		$id = array_map([$this->parserClass, "parse"], array_keys(unserialize($this->ratioData)));
		$m = array_values(unserialize($this->ratioData));
		$sum[0] = $m[0];
		for ($l = 1, $mCount = count($m); $l < $mCount; $l++)
			$sum[$l] = $sum[$l - 1] + $m[$l];
		$sumCount = count($sum);
		$posA = $this->a;
		$posB = $this->b;
		$totalBlocks = ($posB->x - $posA->x + 1) * ($posB->y - $posA->y + 1) * ($posB->z - $posA->z + 1);
		$interval = $totalBlocks / 8; 
		$lastUpdate = 0;
		$currentBlocks = 0;
		$currentChunkX = $posA->x >> 4;
		$currentChunkZ = $posA->z >> 4;
		$currentChunkY = $posA->y >> 4;
		$currentChunk = null;
		$currentSubChunk = null;
		for ($x = $posA->getX(), $x2 = $posB->getX(); $x <= $x2; $x++) {
			$chunkX = $x >> 4;
			for ($z = $posA->getZ(), $z2 = $posB->getZ(); $z <= $z2; $z++) {
				$chunkZ = $z >> 4;
				if ($currentChunk === null or $chunkX !== $currentChunkX or $chunkZ !== $currentChunkZ) {
					$currentChunkX = $chunkX;
					$currentChunkZ = $chunkZ;
					$currentSubChunk = null;
					$hash = World::chunkHash($chunkX, $chunkZ);
					$currentChunk = $chunks[$hash];
					if ($currentChunk === null) {
						continue;
					}
				}
				for ($y = $posA->getY(), $y2 = $posB->getY(); $y <= $y2; $y++) {
					$chunkY = $y >> 4;
					if ($currentSubChunk === null or $chunkY !== $currentChunkY) {
						$currentChunkY = $chunkY;
						$currentSubChunk = $currentChunk->getSubChunk($chunkY);
						if ($currentSubChunk === null) {
							continue;
						}
					}
					$a = rand(0, end($sum));
					for ($l = 0; $l < $sumCount; $l++) {
						if ($a <= $sum[$l]) {
							$currentSubChunk->setFullBlock($x & 0x0f, $y & 0x0f, $z & 0x0f, $id[$l][0] << Block::INTERNAL_METADATA_BITS | $id[$l][1] & 0xff);
							$currentBlocks++;
							if ($lastUpdate + $interval <= $currentBlocks) {
								if (method_exists($this, 'publishProgress')) {
									$this->publishProgress(round(($currentBlocks / $totalBlocks) * 100) . "%");
								}
								$lastUpdate = $currentBlocks;
							}
							break;
						}
					}
				}
			}
		}
		$this->setResult($chunks);
	}
public function onRun ( ) : void { $ chunkClass = $ this -> chunkClass ; $ chunks = unserialize ( $ this -> chunks ) ; foreach ( $ chunks as $ hash => $ binary ) { $ chunks [ $ hash ] = FastChunkSerializer :: deserializeTerrain ( $ binary ) ; } $ sum = [ ] ; $ id = array_map ( [ $ this -> parserClass , " parse " ] , array_keys ( unserialize ( $ this -> ratioData ) ) ) ; $ m = array_values ( unserialize ( $ this -> ratioData ) ) ; $ sum [ 0 ] = $ m [ 0 ] ; for ( $ l = 1 , $ mCount = count ( $ m ) ; $ l < $ mCount ; $ l ++ ) $ sum [ $ l ] = $ sum [ $ l - 1 ] + $ m [ $ l ] ; $ sumCount = count ( $ sum ) ; $ posA = $ this -> a ; $ posB = $ this -> b ; $ totalBlocks = ( $ posB -> x - $ posA -> x + 1 ) * ( $ posB -> y - $ posA -> y + 1 ) * ( $ posB -> z - $ posA -> z + 1 ) ; $ interval = $ totalBlocks / 8 ; $ lastUpdate = 0 ; $ currentBlocks = 0 ; $ currentChunkX = $ posA -> x >> 4 ; $ currentChunkZ = $ posA -> z >> 4 ; $ currentChunkY = $ posA -> y >> 4 ; $ currentChunk = null ; $ currentSubChunk = null ; for ( $ x = $ posA -> getX ( ) , $ x2 = $ posB -> getX ( ) ; $ x <= $ x2 ; $ x ++ ) { $ chunkX = $ x >> 4 ; for ( $ z = $ posA -> getZ ( ) , $ z2 = $ posB -> getZ ( ) ; $ z <= $ z2 ; $ z ++ ) { $ chunkZ = $ z >> 4 ; if ( $ currentChunk === null or $ chunkX !== $ currentChunkX or $ chunkZ !== $ currentChunkZ ) { $ currentChunkX = $ chunkX ; $ currentChunkZ = $ chunkZ ; $ currentSubChunk = null ; $ hash = World :: chunkHash ( $ chunkX , $ chunkZ ) ; $ currentChunk = $ chunks [ $ hash ] ; if ( $ currentChunk === null ) { continue ; } } for ( $ y = $ posA -> getY ( ) , $ y2 = $ posB -> getY ( ) ; $ y <= $ y2 ; $ y ++ ) { $ chunkY = $ y >> 4 ; if ( $ currentSubChunk === null or $ chunkY !== $ currentChunkY ) { $ currentChunkY = $ chunkY ; $ currentSubChunk = $ currentChunk -> getSubChunk ( $ chunkY ) ; if ( $ currentSubChunk === null ) { continue ; } } $ a = rand ( 0 , end ( $ sum ) ) ; for ( $ l = 0 ; $ l < $ sumCount ; $ l ++ ) { if ( $ a <= $ sum [ $ l ] ) { $ currentSubChunk -> setFullBlock ( $ x & 0x0f , $ y & 0x0f , $ z & 0x0f , $ id [ $ l ] [ 0 ] << Block :: INTERNAL_METADATA_BITS | $ id [ $ l ] [ 1 ] & 0xff ) ; $ currentBlocks ++ ; if ( $ lastUpdate + $ interval <= $ currentBlocks ) { if ( method_exists ( $ this , 'publishProgress' ) ) { $ this -> publishProgress ( round ( ( $ currentBlocks / $ totalBlocks ) * 100 ) . " % " ) ; } $ lastUpdate = $ currentBlocks ; } break ; } } } } } $ this -> setResult ( $ chunks ) ; }
Actions to execute when run
 @return void
Actions to execute when run @return void
//Get these as local variables so they don't keep getting serialized/unserialized every single access //TODO determine the interval programmatically