diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index 9a19cd73..e22379a1 100755 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -293,10 +293,10 @@ class BlockAPI{ } break; case "give": - $player = $this->server->api->player->get(nullsafe($args[0], "")); + $player = $this->server->api->player->get($args[0] ?? ""); if($player instanceof Player){ - $item = self::fromString(nullsafe($args[1], "")); + $item = self::fromString($args[1] ?? ""); if(($player->gamemode & 0x01) === 0x01){ return "Player is in creative mode."; } @@ -314,7 +314,7 @@ class BlockAPI{ $output .= "Giving ".$item->count." of ".$item->getName()." (".$item->getID().":".$item->getMetadata().") to ".$player->username; break; }else{ - $item = self::fromString(nullsafe($args[0], "")); + $item = self::fromString($args[0] ?? ""); if(!($issuer instanceof Player)){ return "You cant give an item to a non-player."; } diff --git a/src/API/EntityAPI.php b/src/API/EntityAPI.php index ee209a83..91800f4f 100644 --- a/src/API/EntityAPI.php +++ b/src/API/EntityAPI.php @@ -176,7 +176,7 @@ class EntityAPI{ } public function get($eid){ - return nullsafe($this->entities[$eid], false); + return $this->entities[$eid] ?? false; } public function remove($eid){ diff --git a/src/API/TimeAPI.php b/src/API/TimeAPI.php index b02da668..51924611 100644 --- a/src/API/TimeAPI.php +++ b/src/API/TimeAPI.php @@ -31,7 +31,7 @@ class TimeAPI{ $p = strtolower(array_shift($args)); switch($p){ case "check": - if(substr(nullsafe($args[0], ""), 0, 2) === "w:"){ + if(substr($args[0] ?? "", 0, 2) === "w:"){ $levelName = preg_replace("/w:/", "", $args[0]); $level = $this->server->api->level->get($levelName); if($level instanceof Level){ @@ -44,7 +44,7 @@ class TimeAPI{ $output .= "Time" . $world . ": " . $this->getDate($level) . ", " . $this->getPhase($level) . " (" . $this->get(true, $level) . " ticks)\n"; break; case "add": - if(substr(nullsafe($args[1], ""), 0, 2) === "w:"){ + if(substr($args[1] ?? "", 0, 2) === "w:"){ $levelName = preg_replace("/w:/", "", $args[1]); $level = $this->server->api->level->get($levelName); if($level instanceof Level){ diff --git a/src/Player.php b/src/Player.php index 15a6744c..4798b9f4 100755 --- a/src/Player.php +++ b/src/Player.php @@ -166,24 +166,15 @@ class Player{ foreach($this->level->entityList as $e){ if($e->eid !== $this->entity->eid){ if($e->isPlayer()){ - $pk = new MovePlayerPacket(); + $pk = new MoveEntityPacket_PosRot(); $pk->eid = $this->entity->eid; $pk->x = -256; $pk->y = 128; $pk->z = -256; $pk->yaw = 0; $pk->pitch = 0; - $pk->bodyYaw = 0; $e->player->dataPacket($pk); - - $pk = new MovePlayerPacket(); $pk->eid = $e->eid; - $pk->x = -256; - $pk->y = 128; - $pk->z = -256; - $pk->yaw = 0; - $pk->pitch = 0; - $pk->bodyYaw = 0; $this->dataPacket($pk); }else{ @@ -243,7 +234,7 @@ class Player{ $this->entity->calculateVelocity(); if($terrain === true){ $this->orderChunks(); - $this->server->schedule(1, [$this, "getNextChunk"], $this->level); + $this->getNextChunk($this->level); } $this->entity->check = true; if($force === true){ diff --git a/src/dependencies.php b/src/dependencies.php index 71e71536..d5fb697f 100644 --- a/src/dependencies.php +++ b/src/dependencies.php @@ -17,8 +17,8 @@ set_error_handler("error_handler", E_ALL); $errors = 0; -if(version_compare("5.4.0", PHP_VERSION) > 0){ - console("[ERROR] Use PHP >= 5.4.0", true, true, 0); +if(version_compare("8.0.0", PHP_VERSION) > 0){ + console("[ERROR] Use PHP >= 8.0.0", true, true, 0); ++$errors; } diff --git a/src/entity/Entity.php b/src/entity/Entity.php index fd6d80b7..4e1879c6 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -462,7 +462,7 @@ class Entity extends Position } break; case CACTUS: // Cactus damage - if ($this->inBlockNonVector($x, $y, $z)) { + if ((new AxisAlignedBB($x, $y, $z, $x + 1, $y + 1, $z + 1))->intersectsWith($this->boundingBox)) { $this->harm(1, "cactus"); $hasUpdate = true; } @@ -1048,7 +1048,7 @@ class Entity extends Position $angle = Utils::angle3D($pos2, $pos); $this->yaw = $angle["yaw"]; $this->pitch = $angle["pitch"]; - $this->server->query("UPDATE entities SET pitch = " . $this->pitch . ", yaw = " . $this->yaw . " WHERE EID = " . $this->eid . ";"); + //$this->server->query("UPDATE entities SET pitch = " . $this->pitch . ", yaw = " . $this->yaw . " WHERE EID = " . $this->eid . ";"); } public function move(Vector3 $pos, $yaw = 0, $pitch = 0) @@ -1060,7 +1060,7 @@ class Entity extends Position $this->yaw %= 360; $this->pitch += $pitch; $this->pitch %= 90; - $this->server->query("UPDATE entities SET x = " . $this->x . ", y = " . $this->y . ", z = " . $this->z . ", pitch = " . $this->pitch . ", yaw = " . $this->yaw . " WHERE EID = " . $this->eid . ";"); + //$this->server->query("UPDATE entities SET x = " . $this->x . ", y = " . $this->y . ", z = " . $this->z . ", pitch = " . $this->pitch . ", yaw = " . $this->yaw . " WHERE EID = " . $this->eid . ";"); $this->updateAABB(); } @@ -1074,7 +1074,7 @@ class Entity extends Position public function updatePosition() { - $this->server->query("UPDATE entities SET level = '" . $this->level->getName() . "', x = " . $this->x . ", y = " . $this->y . ", z = " . $this->z . ", pitch = " . $this->pitch . ", yaw = " . $this->yaw . " WHERE EID = " . $this->eid . ";"); + //$this->server->query("UPDATE entities SET level = '" . $this->level->getName() . "', x = " . $this->x . ", y = " . $this->y . ", z = " . $this->z . ", pitch = " . $this->pitch . ", yaw = " . $this->yaw . " WHERE EID = " . $this->eid . ";"); $this->sendMoveUpdate(); // $this->sendMotion(); $this->updateAABB(); @@ -1372,7 +1372,7 @@ class Entity extends Position "cause" => $cause )) !== false or $force === true){ $this->health = min(127, max(- 127, $health)); - $this->server->query("UPDATE entities SET health = " . $this->health . " WHERE EID = " . $this->eid . ";"); + //$this->server->query("UPDATE entities SET health = " . $this->health . " WHERE EID = " . $this->eid . ";"); if($harm === true){ $pk = new EntityEventPacket; $pk->eid = $this->eid; diff --git a/src/functions.php b/src/functions.php index ab350fd6..90632ecd 100644 --- a/src/functions.php +++ b/src/functions.php @@ -62,19 +62,11 @@ function kill($pid){ } } -if(version_compare(PHP_VERSION, '7.0.0') >= 0){ //php > 7.0 - eval(' - function nullsafe(&$a, $null){ - return $a ?? $null; - } - '); - -}else{ - eval(' - function nullsafe(&$value, $null){ - return isset($value) ? $value : $null; - } - '); //behavior will change if you replace ' with ". +/** + * @deprecated Use $a ?? $null + */ +function nullsafe(&$a, $null){ + return $a ?? $null; } diff --git a/src/material/StaticBlock.php b/src/material/StaticBlock.php index d60dfc28..d74ea36c 100644 --- a/src/material/StaticBlock.php +++ b/src/material/StaticBlock.php @@ -40,16 +40,16 @@ class StaticBlock } public static function getBlock($id){ - return nullsafe(Block::$class[$id], Block::$class[0]); + return Block::$class[$id] ?? Block::$class[0]; } public static function getHardness($id){ - return nullsafe(self::$hardness[$id], StaticBlock::DEFAULT_HARDNESS); + return self::$hardness[$id] ?? StaticBlock::DEFAULT_HARDNESS; } public static function getBoundingBoxForBlockCoords($id, $x, $y, $z){ /**@var AxisAlignedBB $bb*/ - $bb = nullsafe(self::$boundingBoxes[$id], false); + $bb = self::$boundingBoxes[$id] ?? false; if($bb === false){ return clone self::$NULL_BOUNDS; } @@ -59,39 +59,39 @@ class StaticBlock public static function getSlipperiness($id){ - return nullsafe(self::$slipperiness[$id], StaticBlock::DEFAULT_SLIPPERINESS); + return self::$slipperiness[$id] ?? StaticBlock::DEFAULT_SLIPPERINESS; } public static function getIsSolid($id){ - return nullsafe(self::$isSolid[$id], false); + return self::$isSolid[$id] ?? false; } public static function getIsTransparent($id){ - return nullsafe(self::$isTransparent[$id], false); + return self::$isTransparent[$id] ?? false; } public static function getIsFlowable($id){ - return nullsafe(self::$isFlowable[$id], false); + return self::$isFlowable[$id] ?? false; } public static function getIsReplaceable($id){ - return nullsafe(self::$isReplaceable[$id], false); + return self::$isReplaceable[$id] ?? false; } public static function getIsPlaceable($id){ - return nullsafe(self::$isPlaceable[$id], false); + return self::$isPlaceable[$id] ?? false; } public static function getHasPhysics($id){ - return nullsafe(self::$hasPhysics[$id], false); + return self::$hasPhysics[$id] ?? false; } public static function getIsLiquid($id){ - return nullsafe(self::$isLiquid[$id], false); + return self::$isLiquid[$id] ?? false; } public static function getIsFullBlock($id){ - return nullsafe(self::$isFullBlock[$id], false); + return self::$isFullBlock[$id] ?? false; } } diff --git a/src/material/block/DoorBlock.php b/src/material/block/DoorBlock.php index 1218b3b3..157a8b56 100644 --- a/src/material/block/DoorBlock.php +++ b/src/material/block/DoorBlock.php @@ -10,7 +10,7 @@ class DoorBlock extends TransparentBlock{ parent::__construct($id, $meta, $name); $this->isSolid = false; } - + /** * @param int $type * diff --git a/src/material/block/TransparentBlock.php b/src/material/block/TransparentBlock.php index 07181e2b..beda68ce 100644 --- a/src/material/block/TransparentBlock.php +++ b/src/material/block/TransparentBlock.php @@ -15,6 +15,6 @@ class TransparentBlock extends GenericBlock{ $this->isReplaceable = false; $this->isPlaceable = true; $this->isSolid = true; - $this->boundingBox->setBounds($this->x, $this->y, $this->z, $this->x + 1, $this->y + 1.2, $this->z + 1); + $this->boundingBox->setBounds($this->x, $this->y, $this->z, $this->x + 1, $this->y + 1, $this->z + 1); } } \ No newline at end of file diff --git a/src/math/AxisAlignedBB.php b/src/math/AxisAlignedBB.php index f32b77ea..ca353649 100644 --- a/src/math/AxisAlignedBB.php +++ b/src/math/AxisAlignedBB.php @@ -182,13 +182,7 @@ class AxisAlignedBB{ } public function intersectsWith(AxisAlignedBB $bb){ - if($bb->maxX > $this->minX and $bb->minX < $this->maxX){ - if($bb->maxY > $this->minY and $bb->minY < $this->maxY){ - return $bb->maxZ > $this->minZ and $bb->minZ < $this->maxZ; - } - } - - return false; + return $bb->maxX > $this->minX and $bb->minX < $this->maxX && $bb->maxZ > $this->minZ and $bb->minZ < $this->maxZ && $bb->maxY > $this->minY and $bb->minY < $this->maxY; } public function isXYZInside($x, $y, $z){