mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
php5 is dead, reverted some teleport tweaks, nullsafe is deprecated, cactus hitbox is fixed
This commit is contained in:
parent
2e374fb09c
commit
0c8b56e22b
11 changed files with 35 additions and 58 deletions
|
|
@ -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.";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class DoorBlock extends TransparentBlock{
|
|||
parent::__construct($id, $meta, $name);
|
||||
$this->isSolid = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $type
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue