level = $level; if ($random->nextBoundedInt ( 1000 ) > 25) return; // ~1 chance / 1000 due to building limitations. $well = new Well (); $x = $random->nextRange ( $chunkX << 4, ($chunkX << 4) + 15 ); $z = $random->nextRange ( $chunkZ << 4, ($chunkZ << 4) + 15 ); $y = $this->getHighestWorkableBlock ( $x, $z ) - 1; if ($well->canPlaceObject ( $level, $x, $y, $z, $random )) $well->placeObject ( $level, $x, $y, $z, $random ); } /* * Gets the top block (y) on an x and z axes * @param $x int * @param $z int */ protected function getHighestWorkableBlock($x, $z) { for($y = 127; $y > 0; -- $y) { $b = $this->level->getBlockIdAt ( $x, $y, $z ); if ($b === Block::SAND) { break; } } return ++ $y; } }