php5 is dead, reverted some teleport tweaks, nullsafe is deprecated, cactus hitbox is fixed

This commit is contained in:
GameHerobrine 2023-08-21 01:34:44 +03:00
parent 2e374fb09c
commit 0c8b56e22b
11 changed files with 35 additions and 58 deletions

View file

@ -293,10 +293,10 @@ class BlockAPI{
} }
break; break;
case "give": case "give":
$player = $this->server->api->player->get(nullsafe($args[0], "")); $player = $this->server->api->player->get($args[0] ?? "");
if($player instanceof Player){ if($player instanceof Player){
$item = self::fromString(nullsafe($args[1], "")); $item = self::fromString($args[1] ?? "");
if(($player->gamemode & 0x01) === 0x01){ if(($player->gamemode & 0x01) === 0x01){
return "Player is in creative mode."; 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; $output .= "Giving ".$item->count." of ".$item->getName()." (".$item->getID().":".$item->getMetadata().") to ".$player->username;
break; break;
}else{ }else{
$item = self::fromString(nullsafe($args[0], "")); $item = self::fromString($args[0] ?? "");
if(!($issuer instanceof Player)){ if(!($issuer instanceof Player)){
return "You cant give an item to a non-player."; return "You cant give an item to a non-player.";
} }

View file

@ -176,7 +176,7 @@ class EntityAPI{
} }
public function get($eid){ public function get($eid){
return nullsafe($this->entities[$eid], false); return $this->entities[$eid] ?? false;
} }
public function remove($eid){ public function remove($eid){

View file

@ -31,7 +31,7 @@ class TimeAPI{
$p = strtolower(array_shift($args)); $p = strtolower(array_shift($args));
switch($p){ switch($p){
case "check": case "check":
if(substr(nullsafe($args[0], ""), 0, 2) === "w:"){ if(substr($args[0] ?? "", 0, 2) === "w:"){
$levelName = preg_replace("/w:/", "", $args[0]); $levelName = preg_replace("/w:/", "", $args[0]);
$level = $this->server->api->level->get($levelName); $level = $this->server->api->level->get($levelName);
if($level instanceof Level){ 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"; $output .= "Time" . $world . ": " . $this->getDate($level) . ", " . $this->getPhase($level) . " (" . $this->get(true, $level) . " ticks)\n";
break; break;
case "add": case "add":
if(substr(nullsafe($args[1], ""), 0, 2) === "w:"){ if(substr($args[1] ?? "", 0, 2) === "w:"){
$levelName = preg_replace("/w:/", "", $args[1]); $levelName = preg_replace("/w:/", "", $args[1]);
$level = $this->server->api->level->get($levelName); $level = $this->server->api->level->get($levelName);
if($level instanceof Level){ if($level instanceof Level){

View file

@ -166,24 +166,15 @@ class Player{
foreach($this->level->entityList as $e){ foreach($this->level->entityList as $e){
if($e->eid !== $this->entity->eid){ if($e->eid !== $this->entity->eid){
if($e->isPlayer()){ if($e->isPlayer()){
$pk = new MovePlayerPacket(); $pk = new MoveEntityPacket_PosRot();
$pk->eid = $this->entity->eid; $pk->eid = $this->entity->eid;
$pk->x = -256; $pk->x = -256;
$pk->y = 128; $pk->y = 128;
$pk->z = -256; $pk->z = -256;
$pk->yaw = 0; $pk->yaw = 0;
$pk->pitch = 0; $pk->pitch = 0;
$pk->bodyYaw = 0;
$e->player->dataPacket($pk); $e->player->dataPacket($pk);
$pk = new MovePlayerPacket();
$pk->eid = $e->eid; $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); $this->dataPacket($pk);
}else{ }else{
@ -243,7 +234,7 @@ class Player{
$this->entity->calculateVelocity(); $this->entity->calculateVelocity();
if($terrain === true){ if($terrain === true){
$this->orderChunks(); $this->orderChunks();
$this->server->schedule(1, [$this, "getNextChunk"], $this->level); $this->getNextChunk($this->level);
} }
$this->entity->check = true; $this->entity->check = true;
if($force === true){ if($force === true){

View file

@ -17,8 +17,8 @@ set_error_handler("error_handler", E_ALL);
$errors = 0; $errors = 0;
if(version_compare("5.4.0", PHP_VERSION) > 0){ if(version_compare("8.0.0", PHP_VERSION) > 0){
console("[ERROR] Use PHP >= 5.4.0", true, true, 0); console("[ERROR] Use PHP >= 8.0.0", true, true, 0);
++$errors; ++$errors;
} }

View file

@ -462,7 +462,7 @@ class Entity extends Position
} }
break; break;
case CACTUS: // Cactus damage 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"); $this->harm(1, "cactus");
$hasUpdate = true; $hasUpdate = true;
} }
@ -1048,7 +1048,7 @@ class Entity extends Position
$angle = Utils::angle3D($pos2, $pos); $angle = Utils::angle3D($pos2, $pos);
$this->yaw = $angle["yaw"]; $this->yaw = $angle["yaw"];
$this->pitch = $angle["pitch"]; $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) public function move(Vector3 $pos, $yaw = 0, $pitch = 0)
@ -1060,7 +1060,7 @@ class Entity extends Position
$this->yaw %= 360; $this->yaw %= 360;
$this->pitch += $pitch; $this->pitch += $pitch;
$this->pitch %= 90; $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(); $this->updateAABB();
} }
@ -1074,7 +1074,7 @@ class Entity extends Position
public function updatePosition() 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->sendMoveUpdate();
// $this->sendMotion(); // $this->sendMotion();
$this->updateAABB(); $this->updateAABB();
@ -1372,7 +1372,7 @@ class Entity extends Position
"cause" => $cause "cause" => $cause
)) !== false or $force === true){ )) !== false or $force === true){
$this->health = min(127, max(- 127, $health)); $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){ if($harm === true){
$pk = new EntityEventPacket; $pk = new EntityEventPacket;
$pk->eid = $this->eid; $pk->eid = $this->eid;

View file

@ -62,20 +62,12 @@ function kill($pid){
} }
} }
if(version_compare(PHP_VERSION, '7.0.0') >= 0){ //php > 7.0 /**
eval(' * @deprecated Use $a ?? $null
*/
function nullsafe(&$a, $null){ function nullsafe(&$a, $null){
return $a ?? $null; return $a ?? $null;
} }
');
}else{
eval('
function nullsafe(&$value, $null){
return isset($value) ? $value : $null;
}
'); //behavior will change if you replace ' with ".
}

View file

@ -40,16 +40,16 @@ class StaticBlock
} }
public static function getBlock($id){ 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){ 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){ public static function getBoundingBoxForBlockCoords($id, $x, $y, $z){
/**@var AxisAlignedBB $bb*/ /**@var AxisAlignedBB $bb*/
$bb = nullsafe(self::$boundingBoxes[$id], false); $bb = self::$boundingBoxes[$id] ?? false;
if($bb === false){ if($bb === false){
return clone self::$NULL_BOUNDS; return clone self::$NULL_BOUNDS;
} }
@ -59,39 +59,39 @@ class StaticBlock
public static function getSlipperiness($id){ 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){ public static function getIsSolid($id){
return nullsafe(self::$isSolid[$id], false); return self::$isSolid[$id] ?? false;
} }
public static function getIsTransparent($id){ public static function getIsTransparent($id){
return nullsafe(self::$isTransparent[$id], false); return self::$isTransparent[$id] ?? false;
} }
public static function getIsFlowable($id){ public static function getIsFlowable($id){
return nullsafe(self::$isFlowable[$id], false); return self::$isFlowable[$id] ?? false;
} }
public static function getIsReplaceable($id){ public static function getIsReplaceable($id){
return nullsafe(self::$isReplaceable[$id], false); return self::$isReplaceable[$id] ?? false;
} }
public static function getIsPlaceable($id){ public static function getIsPlaceable($id){
return nullsafe(self::$isPlaceable[$id], false); return self::$isPlaceable[$id] ?? false;
} }
public static function getHasPhysics($id){ public static function getHasPhysics($id){
return nullsafe(self::$hasPhysics[$id], false); return self::$hasPhysics[$id] ?? false;
} }
public static function getIsLiquid($id){ public static function getIsLiquid($id){
return nullsafe(self::$isLiquid[$id], false); return self::$isLiquid[$id] ?? false;
} }
public static function getIsFullBlock($id){ public static function getIsFullBlock($id){
return nullsafe(self::$isFullBlock[$id], false); return self::$isFullBlock[$id] ?? false;
} }
} }

View file

@ -15,6 +15,6 @@ class TransparentBlock extends GenericBlock{
$this->isReplaceable = false; $this->isReplaceable = false;
$this->isPlaceable = true; $this->isPlaceable = true;
$this->isSolid = 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);
} }
} }

View file

@ -182,13 +182,7 @@ class AxisAlignedBB{
} }
public function intersectsWith(AxisAlignedBB $bb){ public function intersectsWith(AxisAlignedBB $bb){
if($bb->maxX > $this->minX and $bb->minX < $this->maxX){ 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;
if($bb->maxY > $this->minY and $bb->minY < $this->maxY){
return $bb->maxZ > $this->minZ and $bb->minZ < $this->maxZ;
}
}
return false;
} }
public function isXYZInside($x, $y, $z){ public function isXYZInside($x, $y, $z){