diff --git a/src/block/DragonEgg.php b/src/block/DragonEgg.php index 17546b3f2..5ea065759 100644 --- a/src/block/DragonEgg.php +++ b/src/block/DragonEgg.php @@ -65,7 +65,7 @@ class DragonEgg extends Transparent implements Fallable{ for($tries = 0; $tries < 16; ++$tries){ $block = $this->pos->getWorld()->getBlockAt( $this->pos->x + mt_rand(-16, 16), - max(0, min(World::Y_MAX - 1, $this->pos->y + mt_rand(-8, 8))), + max(World::Y_MIN, min(World::Y_MAX - 1, $this->pos->y + mt_rand(-8, 8))), $this->pos->z + mt_rand(-16, 16) ); if($block instanceof Air){ diff --git a/src/command/defaults/ParticleCommand.php b/src/command/defaults/ParticleCommand.php index 0296b148b..1420f5d3c 100644 --- a/src/command/defaults/ParticleCommand.php +++ b/src/command/defaults/ParticleCommand.php @@ -97,7 +97,7 @@ class ParticleCommand extends VanillaCommand{ $world = $senderPos->getWorld(); $pos = new Vector3( $this->getRelativeDouble($senderPos->getX(), $sender, $args[1]), - $this->getRelativeDouble($senderPos->getY(), $sender, $args[2], 0, World::Y_MAX), + $this->getRelativeDouble($senderPos->getY(), $sender, $args[2], World::Y_MIN, World::Y_MAX), $this->getRelativeDouble($senderPos->getZ(), $sender, $args[3]) ); }else{ diff --git a/src/command/defaults/SpawnpointCommand.php b/src/command/defaults/SpawnpointCommand.php index 3fe453844..3c5cf4f0c 100644 --- a/src/command/defaults/SpawnpointCommand.php +++ b/src/command/defaults/SpawnpointCommand.php @@ -73,7 +73,7 @@ class SpawnpointCommand extends VanillaCommand{ $world = $target->getWorld(); $pos = $sender instanceof Player ? $sender->getPosition() : $world->getSpawnLocation(); $x = $this->getRelativeDouble($pos->x, $sender, $args[1]); - $y = $this->getRelativeDouble($pos->y, $sender, $args[2], 0, World::Y_MAX); + $y = $this->getRelativeDouble($pos->y, $sender, $args[2], World::Y_MIN, World::Y_MAX); $z = $this->getRelativeDouble($pos->z, $sender, $args[3]); $target->setSpawn(new Position($x, $y, $z, $world)); diff --git a/src/world/World.php b/src/world/World.php index 51cd90ed9..2fadf68cb 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -124,9 +124,8 @@ class World implements ChunkManager{ private static $worldIdCounter = 1; public const Y_MASK = 0xFF; - public const Y_MAX = 0x100; //256 - - public const HALF_Y_MAX = self::Y_MAX / 2; + public const Y_MAX = 320; + public const Y_MIN = -64; public const TIME_DAY = 1000; public const TIME_NOON = 6000; @@ -296,6 +295,8 @@ class World implements ChunkManager{ private const MORTON3D_BIT_SIZE = 21; private const BLOCKHASH_Y_BITS = 9; + private const BLOCKHASH_Y_PADDING = 128; //size (in blocks) of padding after both boundaries of the Y axis + private const BLOCKHASH_Y_OFFSET = self::BLOCKHASH_Y_PADDING - self::Y_MIN; private const BLOCKHASH_Y_MASK = (1 << self::BLOCKHASH_Y_BITS) - 1; private const BLOCKHASH_XZ_MASK = (1 << self::MORTON3D_BIT_SIZE) - 1; private const BLOCKHASH_XZ_EXTRA_BITS = 6; @@ -305,7 +306,7 @@ class World implements ChunkManager{ private const BLOCKHASH_Z_SHIFT = self::BLOCKHASH_X_SHIFT + self::BLOCKHASH_XZ_EXTRA_BITS; public static function blockHash(int $x, int $y, int $z) : int{ - $shiftedY = $y + self::HALF_Y_MAX; + $shiftedY = $y + self::BLOCKHASH_Y_OFFSET; if(($shiftedY & (~0 << self::BLOCKHASH_Y_BITS)) !== 0){ throw new \InvalidArgumentException("Y coordinate $y is out of range!"); } @@ -335,7 +336,7 @@ class World implements ChunkManager{ $extraZ = ((($baseY >> self::BLOCKHASH_Z_SHIFT) & self::BLOCKHASH_XZ_EXTRA_MASK) << self::MORTON3D_BIT_SIZE); $x = (($baseX & self::BLOCKHASH_XZ_MASK) | $extraX) << self::BLOCKHASH_XZ_SIGN_SHIFT >> self::BLOCKHASH_XZ_SIGN_SHIFT; - $y = ($baseY & self::BLOCKHASH_Y_MASK) - self::HALF_Y_MAX; + $y = ($baseY & self::BLOCKHASH_Y_MASK) - self::BLOCKHASH_Y_OFFSET; $z = (($baseZ & self::BLOCKHASH_XZ_MASK) | $extraZ) << self::BLOCKHASH_XZ_SIGN_SHIFT >> self::BLOCKHASH_XZ_SIGN_SHIFT; }