Skip to content

ImprovedNoise 5.46.0 ​

final class · pocketmine\world\generator\vanilla\noise\ImprovedNoise · source

One octave of 3D gradient ("Perlin") noise with a random permutation and offset (ported from misode/deepslate GradientNoise/PerlinNoise, MIT).

The permutation table is stored pre-multiplied into gradient tables so that sampling only needs flat int/float array reads: $p is the permutation (values 0-255), $gx/$gy/$gz the gradient vector selected by p[i] & 15.

Constants ​

GRADIENT_X ​

php
public const GRADIENT_X = [1, -1, 1, -1, 1, -1, 1, -1, 0, 0, 0, 0, 1, 0, -1, 0]

Vanilla gradient table (16 entries, the last four repeat earlier ones).

GRADIENT_Y ​

php
public const GRADIENT_Y = [1, 1, -1, -1, 0, 0, 0, 0, 1, -1, 1, -1, 1, -1, 1, -1]

GRADIENT_Z ​

php
public const GRADIENT_Z = [0, 0, 0, 0, 1, 1, -1, -1, 1, 1, -1, -1, 0, 1, 0, -1]

Properties ​

$gx ​

php
public array $gx

$gy ​

php
public array $gy

$gz ​

php
public array $gz

$p ​

php
public array $p

$xo ​

php
public float $xo

$yo ​

php
public float $yo

$zo ​

php
public float $zo

Methods ​

__construct() ​

php
public function __construct(\pocketmine\world\generator\vanilla\random\RandomSource $random)

sample() ​

php
public function sample(float $x, float $y, float $z) : float

Samples the octave. x/y/z must already be scaled by the octave frequency; wrapping and offsets are applied here.

sampleRaw() ​

php
public static function sampleRaw(array $p, array $gx, array $gy, array $gz, float $x, float $y, float $z) : float

sampleSmearedRaw() ​

php
public static function sampleSmearedRaw(array $p, array $gx, array $gy, array $gz, float $x, float $y, float $z, float $originalY, float $fudgeScale) : float

Y-smeared variant used by the blended noise: the gradient y offset is snapped to multiples of $fudgeScale (computed from the unwrapped scaled coordinate $originalY) while the interpolation uses the real offset. Coordinates must already be wrapped and offset.

wrap() ​

php
public static function wrap(float $x) : float

Coordinates are wrapped to avoid precision loss far from the origin.

VanillaMine is a fork of PocketMine-MP, maintained by Luxury Nodes. Not affiliated with the PMMP team or Mojang.