Added World::Y_MIN

preparation for Y axis expansion in 1.17
This commit is contained in:
Dylan K. Taylor 2021-03-17 23:19:49 +00:00
parent 5a59afbe2c
commit b844c4266d
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
4 changed files with 9 additions and 8 deletions

View File

@ -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){

View File

@ -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{

View File

@ -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));

View File

@ -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;
}