From cb6e649081599dcc1b4d41f602223abae8a8bc5c Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Fri, 24 Feb 2023 06:10:41 +0300 Subject: [PATCH] made pushing disableable in config, php8.1+particial 8.2 comp(not recommended) --- PocketMine-MP.php | 1 - src/API/ConsoleAPI.php | 2 +- src/API/EntityAPI.php | 2 +- src/API/ServerAPI.php | 4 ++++ src/Player.php | 4 ++-- src/PocketMinecraftServer.php | 6 ++++- src/entity/Entity.php | 2 ++ src/entity/Living.php | 6 +++-- src/math/Matrix.php | 8 +++---- src/network/MinecraftInterface.php | 2 +- src/network/UDPSocket.php | 4 ++-- src/network/raknet/RakNetCodec.php | 6 ++--- src/network/raknet/RakNetDataPacket.php | 2 +- src/pmf/PMFLevel.php | 2 +- src/utils/AsyncMultipleQueue.php | 4 ++-- src/utils/Random.php | 4 +++- src/utils/Utils.php | 2 +- src/world/Level.php | 30 ++++++++++++------------- src/world/Tile.php | 4 +++- 19 files changed, 55 insertions(+), 40 deletions(-) diff --git a/PocketMine-MP.php b/PocketMine-MP.php index c2572794..f883bae3 100644 --- a/PocketMine-MP.php +++ b/PocketMine-MP.php @@ -1,5 +1,4 @@ help = []; $this->cmds = []; diff --git a/src/API/EntityAPI.php b/src/API/EntityAPI.php index e6f6e516..2361f857 100644 --- a/src/API/EntityAPI.php +++ b/src/API/EntityAPI.php @@ -4,7 +4,7 @@ class EntityAPI{ public $entities; private $server; private $eCnt = 1; - + private $serverSpawnAnimals, $serverSpawnMobs; function __construct(){ $this->entities = []; $this->server = ServerAPI::request(); diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index e71ed9cb..5095937c 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -56,6 +56,10 @@ class ServerAPI{ * @var PluginAPI */ public $plugin; + /** + * @var QueryHandler + */ + public $query; private $asyncCalls = []; private $server; diff --git a/src/Player.php b/src/Player.php index 5f1d0806..ef0d3888 100755 --- a/src/Player.php +++ b/src/Player.php @@ -411,8 +411,8 @@ class Player{ if(!($this->entity instanceof Entity) or $this->connected === false){ return false; } - $X = $this->entity->x >> 4; - $Z = $this->entity->z >> 4; + $X = ((int)$this->entity->x) >> 4; + $Z = ((int)$this->entity->z) >> 4; $v = new Vector2($X, $Z); $this->chunksOrder = []; for($x = 0; $x < 16; ++$x){ diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index 9ced5b39..68d83f02 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -9,7 +9,9 @@ class PocketMinecraftServer{ */ public $api; private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $memoryStats, $async = [], $asyncID = 0; - + + public $doTick, $levelData, $tiles, $entities, $schedule, $scheduleCnt, $whitelist, $spawn, $difficulty, $stop, $asyncThread; + function __construct($name, $gamemode = SURVIVAL, $seed = false, $port = 19132, $serverip = "0.0.0.0"){ $this->port = (int) $port; $this->doTick = true; @@ -84,8 +86,10 @@ class PocketMinecraftServer{ "discord-bot-name" => "NostalgiaCore Logger", "despawn-mobs" => true, "mob-despawn-ticks" => 18000, + "entity-pushing" => false ]); + Living::$entityPushing = $this->extraprops->get("entity-pushing"); Living::$despawnMobs = $this->extraprops->get("despawn-mobs"); Living::$despawnTimer = $this->extraprops->get("mob-despawn-ticks"); Entity::$allowedAI = $this->extraprops->get("enable-mob-ai"); diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 67211d43..7923db4f 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -72,6 +72,8 @@ class Entity extends Position public $inAction = false; public $hasKnockback; public $hasJumped; + public $invincible, $crouched, $fire, $health, $status; + public $position; public $onGround, $inWater; public $carryoverDamage; function __construct(Level $level, $eid, $class, $type = 0, $data = array()) diff --git a/src/entity/Living.php b/src/entity/Living.php index 7d2aae36..b22c9c6a 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -2,7 +2,7 @@ abstract class Living extends Entity implements Damageable, Pathfindable{ - public static $despawnMobs, $despawnTimer; + public static $despawnMobs, $despawnTimer, $entityPushing; public $target, $ai; public $pathFinder, $path = null, $currentIndex = 0, $currentNode, $pathFollower; @@ -65,7 +65,9 @@ abstract class Living extends Entity implements Damageable, Pathfindable{ } $this->ai->mobController->rotateTick(); $this->ai->mobController->movementTick(); - $this->collideHandler(); + if(self::$entityPushing){ + $this->collideHandler(); + } if($this->onGround){ //if(!$this->hasPath() && $this->pathFinder instanceof ITileNavigator){ // $this->path = $this->pathFinder->navigate(new PathTileXYZ($this->x, $this->y, $this->z, $this->level), new PathTileXYZ($this->x + mt_rand(-10, 10), $this->y + mt_rand(-1, 1), $this->z + mt_rand(-10, 10), $this->level), 10); diff --git a/src/math/Matrix.php b/src/math/Matrix.php index 44fe49f7..a341f935 100644 --- a/src/math/Matrix.php +++ b/src/math/Matrix.php @@ -20,19 +20,19 @@ class Matrix implements ArrayAccess{ } } } - + #[\ReturnTypeWillChange] public function offsetExists($offset){ return isset($this->matrix[(int) $offset]); } - + #[\ReturnTypeWillChange] public function offsetGet($offset){ return $this->matrix[(int) $offset]; } - + #[\ReturnTypeWillChange] public function offsetSet($offset, $value){ $this->matrix[(int) $offset] = $value; } - + #[\ReturnTypeWillChange] public function offsetUnset($offset){ unset($this->matrix[(int) $offset]); } diff --git a/src/network/MinecraftInterface.php b/src/network/MinecraftInterface.php index 38450b18..ad91322e 100644 --- a/src/network/MinecraftInterface.php +++ b/src/network/MinecraftInterface.php @@ -5,7 +5,7 @@ class MinecraftInterface{ public $bandwidth; private $socket; private $packets; - + public $start; function __construct($server, $port = 25565, $serverip = "0.0.0.0"){ $this->socket = new UDPSocket($server, $port, true, $serverip); if($this->socket->connected === false){ diff --git a/src/network/UDPSocket.php b/src/network/UDPSocket.php index 6a3263d0..01d4a318 100644 --- a/src/network/UDPSocket.php +++ b/src/network/UDPSocket.php @@ -2,8 +2,8 @@ class UDPSocket{ - public $connected, $sock, $server; - + public $connected, $sock, $server, $port; + function __construct($server, $port, $listen = false, $serverip = "0.0.0.0"){ $this->server = $server; $this->port = $port; diff --git a/src/network/raknet/RakNetCodec.php b/src/network/raknet/RakNetCodec.php index b7754061..34393bc6 100644 --- a/src/network/raknet/RakNetCodec.php +++ b/src/network/raknet/RakNetCodec.php @@ -3,15 +3,15 @@ class RakNetCodec{ public $packet; - + public $buffer; public function __construct(RakNetPacket $packet){ $this->packet = $packet; - $this->buffer =& $this->packet->buffer; + $this->buffer = &$this->packet->buffer; $this->encode(); } private function encode(){ - if(strlen($this->packet->buffer) > 0){ + if($this->packet->buffer != null && strlen($this->packet->buffer) > 0){ return; } $this->buffer .= chr($this->packet->pid()); diff --git a/src/network/raknet/RakNetDataPacket.php b/src/network/raknet/RakNetDataPacket.php index b9d842b3..012fd7c7 100755 --- a/src/network/raknet/RakNetDataPacket.php +++ b/src/network/raknet/RakNetDataPacket.php @@ -139,7 +139,7 @@ abstract class RakNetDataPacket extends stdClass{ } protected function putByte($v){ - $this->buffer .= chr($v); + $this->buffer .= chr((int)$v); } protected function getString(){ diff --git a/src/pmf/PMFLevel.php b/src/pmf/PMFLevel.php index 41fa8281..19e5ddf1 100644 --- a/src/pmf/PMFLevel.php +++ b/src/pmf/PMFLevel.php @@ -11,7 +11,7 @@ class PMFLevel extends PMF{ private $payloadOffset = 0; private $chunks = []; private $chunkChange = []; - + public $level; public function __construct($file, $blank = false){ if(is_array($blank)){ $this->create($file, 0); diff --git a/src/utils/AsyncMultipleQueue.php b/src/utils/AsyncMultipleQueue.php index 688c531d..e8de55a7 100644 --- a/src/utils/AsyncMultipleQueue.php +++ b/src/utils/AsyncMultipleQueue.php @@ -84,9 +84,9 @@ class Async extends Thread{ public function run(){ if(($this->result = call_user_func_array($this->method, $this->params))){ - return true; + //return true; }else{ - return false; + //return false; } } diff --git a/src/utils/Random.php b/src/utils/Random.php index a208f883..21a7f766 100644 --- a/src/utils/Random.php +++ b/src/utils/Random.php @@ -6,7 +6,9 @@ class Random{ private $x, $y, $z, $w; private $haveNextNextGaussian = false; private $nextNextGaussian = 0; - + + public $state; + public $i, $j; public function __construct($seed = false){ $this->setSeed($seed); } diff --git a/src/utils/Utils.php b/src/utils/Utils.php index d933d319..c72f305d 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -41,7 +41,7 @@ class Utils{ public static function wrapAngleTo360($angle) { - $angle %= 360; + $angle = fmod($angle, 360); return $angle < 0 ? $angle + 360 : $angle; } public static function wrapAngleTo180($angle) diff --git a/src/world/Level.php b/src/world/Level.php index e9d6424a..bbba18df 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -16,9 +16,9 @@ class Level{ */ public $entityChunked; - public $tiles, $blockUpdates, $nextSave, $players = [], $level; + public $tiles, $blockUpdates, $nextSave, $players = [], $level, $mobSpawner; private $time, $startCheck, $startTime, $server, $name, $usedChunks, $changedBlocks, $changedCount, $stopTime; - + public function __construct(PMFLevel $level, Config $entities, Config $tiles, Config $blockUpdates, $name){ $this->server = ServerAPI::request(); $this->level = $level; @@ -298,12 +298,12 @@ class Level{ } } public function applyCallbackToNearbyEntities(Entity $e, callable $c, $radius = 5){ - $minChunkX = ((int)($e->x - $radius)) >> 4; - $minChunkY = ((int)($e->y - $radius)) >> 4; - $minChunkZ = ((int)($e->z - $radius)) >> 4; - $maxChunkX = ((int)($e->x + $radius)) >> 4; - $maxChunkY = ((int)($e->y + $radius)) >> 4; - $maxChunkZ = ((int)($e->z + $radius)) >> 4; + $minChunkX = ((int)($e->x - $radius)) >> 2; + $minChunkY = ((int)($e->y - $radius)) >> 2; + $minChunkZ = ((int)($e->z - $radius)) >> 2; + $maxChunkX = ((int)($e->x + $radius)) >> 2; + $maxChunkY = ((int)($e->y + $radius)) >> 2; + $maxChunkZ = ((int)($e->z + $radius)) >> 2; $ents = []; for($chunkX = $minChunkX; $chunkX <= $maxChunkX; ++$chunkX){ for($chunkY = $minChunkY; $chunkY <= $maxChunkY; ++$chunkY){ @@ -318,12 +318,12 @@ class Level{ //unset($ents[$e->eid]); } public function getEntitiesNearby(Entity $e, $radius = 5){ - $minChunkX = ((int)($e->x - $radius)) >> 4; - $minChunkY = ((int)($e->y - $radius)) >> 4; - $minChunkZ = ((int)($e->z - $radius)) >> 4; - $maxChunkX = ((int)($e->x + $radius)) >> 4; - $maxChunkY = ((int)($e->y + $radius)) >> 4; - $maxChunkZ = ((int)($e->z + $radius)) >> 4; + $minChunkX = ((int)($e->x - $radius)) >> 2; + $minChunkY = ((int)($e->y - $radius)) >> 2; + $minChunkZ = ((int)($e->z - $radius)) >> 2; + $maxChunkX = ((int)($e->x + $radius)) >> 2; + $maxChunkY = ((int)($e->y + $radius)) >> 2; + $maxChunkZ = ((int)($e->z + $radius)) >> 2; $ents = []; for($chunkX = $minChunkX; $chunkX <= $maxChunkX; ++$chunkX){ for($chunkY = $minChunkY; $chunkY <= $maxChunkY; ++$chunkY){ @@ -516,7 +516,7 @@ class Level{ */ public function getBlockWithoutVector($x, $y, $z, $positionfy = true){ - $b = $this->level->getBlock($x, $y, $z); + $b = $this->level->getBlock((int)$x, (int)$y, (int)$z); return BlockAPI::get($b[0], $b[1], $positionfy ? new Position($x, $y, $z, $this) : false); } diff --git a/src/world/Tile.php b/src/world/Tile.php index 64c8fbfe..e270a68b 100644 --- a/src/world/Tile.php +++ b/src/world/Tile.php @@ -14,7 +14,9 @@ class Tile extends Position{ public $metadata; public $closed; private $server; - + + public $scheduledUpdate, $lastUpdate; + function __construct(Level $level, $id, $class, $x, $y, $z, $data = []){ $this->server = ServerAPI::request(); $this->level = $level;