diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 41dca435c..01711ea4c 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -635,7 +635,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->level->requestChunk($X, $Z, $this, LevelProvider::ORDER_ZXY); } - if(count($this->usedChunks) >= 16 and $this->spawned === false){ + if(count($this->usedChunks) >= 8 and $this->spawned === false){ $spawned = 0; foreach($this->usedChunks as $d){ if($d === true){ @@ -643,7 +643,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } } - if($spawned < 8){ + if($spawned < 4){ return; } @@ -1071,8 +1071,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->motionToSend[$entityId] = [$entityId, $x, $y, $z]; } - public function addEntityMovement($entityId, $x, $y, $z, $yaw, $pitch){ - $this->moveToSend[$entityId] = [$entityId, $x, $y, $z, $yaw, $pitch]; + public function addEntityMovement($entityId, $x, $y, $z, $yaw, $pitch, $headYaw = null){ + $this->moveToSend[$entityId] = [$entityId, $x, $y, $z, $yaw, $headYaw === null ? $yaw : $headYaw, $pitch]; } protected function processMovement($currentTick){ @@ -1574,19 +1574,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->orderChunks(); $this->sendNextChunk(); break; - case ProtocolInfo::ROTATE_HEAD_PACKET: - if($this->spawned === false or $this->dead === true){ - break; - } - $packet->yaw %= 360; - $packet->pitch %= 360; - - if($packet->yaw < 0){ - $packet->yaw += 360; - } - - $this->setRotation($packet->yaw, $this->pitch); - break; case ProtocolInfo::MOVE_PLAYER_PACKET: $newPos = new Vector3($packet->x, $packet->y, $packet->z); @@ -1657,7 +1644,13 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ break; } }else{ - $this->inventory->setHeldItemSlot($packet->slot); //set Air + if($packet->selectedSlot >= 0 and $packet->selectedSlot < 9){ + $this->inventory->setHeldItemIndex($packet->selectedSlot); + $this->inventory->setHeldItemSlot($packet->slot); + }else{ + $this->inventory->sendContents($this); + break; + } } }elseif(!isset($item) or $slot === -1 or $item->getId() !== $packet->item or $item->getDamage() !== $packet->meta){ // packet error or not implemented $this->inventory->sendContents($this); @@ -1670,7 +1663,13 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ ); $this->inventory->setHeldItemIndex($packet->slot); }else{ - $this->inventory->setHeldItemSlot($slot); + if($packet->selectedSlot >= 0 and $packet->selectedSlot < 9){ + $this->inventory->setHeldItemIndex($packet->selectedSlot); + $this->inventory->setHeldItemSlot($slot); + }else{ + $this->inventory->sendContents($this); + break; + } } $this->inventory->sendHeldItem($this->hasSpawned); @@ -1716,6 +1715,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $block = $target->getSide($packet->face); $this->level->sendBlocks([$this], [$target, $block], UpdateBlockPacket::FLAG_ALL_PRIORITY); + + $this->inventory->sendHeldItem($this); break; }elseif($packet->face === 0xff){ if($this->isCreative()){ @@ -1894,6 +1895,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->level->sendBlocks([$this], [$target], UpdateBlockPacket::FLAG_ALL_PRIORITY); + $this->inventory->sendHeldItem($this); + if($tile instanceof Spawnable){ $tile->spawnTo($this); } diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index bba7d5e63..706907bbe 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -766,22 +766,9 @@ abstract class Entity extends Location implements Metadatable{ $this->lastYaw = $this->yaw; $this->lastPitch = $this->pitch; - if($this instanceof Human){ - $pk = new MovePlayerPacket(); - $pk->eid = $this->id; - $pk->x = $this->x; - $pk->y = $this->y; - $pk->z = $this->z; - $pk->yaw = $this->yaw; - $pk->pitch = $this->pitch; - $pk->bodyYaw = $this->yaw; - Server::broadcastPacket($this->hasSpawned, $pk); - }else{ - foreach($this->hasSpawned as $player){ - $player->addEntityMovement($this->id, $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch); - } + foreach($this->hasSpawned as $player){ + $player->addEntityMovement($this->id, $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch, $this->yaw); } - } if(($this->lastMotionX != $this->motionX or $this->lastMotionY != $this->motionY or $this->lastMotionZ != $this->motionZ)){ @@ -1428,7 +1415,7 @@ abstract class Entity extends Location implements Metadatable{ $this->lastPitch = $this->pitch; foreach($this->hasSpawned as $player){ - $player->addEntityMovement($this->getId(), $this->x, $this->y, $this->z, $this->yaw, $this->pitch); + $player->addEntityMovement($this->getId(), $this->x, $this->y, $this->z, $this->yaw, $this->pitch, $this->yaw); } return true; diff --git a/src/pocketmine/level/format/anvil/ChunkRequestTask.php b/src/pocketmine/level/format/anvil/ChunkRequestTask.php index 964e36f18..d609e9648 100644 --- a/src/pocketmine/level/format/anvil/ChunkRequestTask.php +++ b/src/pocketmine/level/format/anvil/ChunkRequestTask.php @@ -102,7 +102,7 @@ class ChunkRequestTask extends AsyncTask{ $biomeColors = pack("N*", ...$this->biomeColors); - $ordered = zlib_encode(Binary::writeLInt($this->chunkX) . Binary::writeLInt($this->chunkZ) . $orderedIds . $orderedData . $orderedSkyLight . $orderedLight . $this->biomeIds . $biomeColors . $this->tiles, ZLIB_ENCODING_DEFLATE, $this->compressionLevel); + $ordered = zlib_encode($orderedIds . $orderedData . $orderedSkyLight . $orderedLight . $this->biomeIds . $biomeColors . $this->tiles, ZLIB_ENCODING_DEFLATE, $this->compressionLevel); $this->setResult($ordered); } diff --git a/src/pocketmine/level/format/leveldb/LevelDB.php b/src/pocketmine/level/format/leveldb/LevelDB.php index 3bc80f78f..243d26b9f 100644 --- a/src/pocketmine/level/format/leveldb/LevelDB.php +++ b/src/pocketmine/level/format/leveldb/LevelDB.php @@ -149,7 +149,6 @@ class LevelDB extends BaseLevelProvider{ $biomeColors = pack("N*", ...$chunk->getBiomeColorArray()); $ordered = zlib_encode( - Binary::writeLInt($x) . Binary::writeLInt($z) . $chunk->getBlockIdArray() . $chunk->getBlockDataArray() . $chunk->getBlockSkyLightArray() . diff --git a/src/pocketmine/level/format/mcregion/McRegion.php b/src/pocketmine/level/format/mcregion/McRegion.php index 643432f55..d198bbee9 100644 --- a/src/pocketmine/level/format/mcregion/McRegion.php +++ b/src/pocketmine/level/format/mcregion/McRegion.php @@ -130,7 +130,6 @@ class McRegion extends BaseLevelProvider{ $biomeColors = pack("N*", ...$chunk->getBiomeColorArray()); $ordered = zlib_encode( - Binary::writeLInt($x) . Binary::writeLInt($z) . $chunk->getBlockIdArray() . $chunk->getBlockDataArray() . $chunk->getBlockSkyLightArray() . diff --git a/src/pocketmine/network/RakLibInterface.php b/src/pocketmine/network/RakLibInterface.php index 96c5c3cf8..1813ef3b3 100644 --- a/src/pocketmine/network/RakLibInterface.php +++ b/src/pocketmine/network/RakLibInterface.php @@ -59,7 +59,6 @@ use pocketmine\network\protocol\RemoveBlockPacket; use pocketmine\network\protocol\RemoveEntityPacket; use pocketmine\network\protocol\RemovePlayerPacket; use pocketmine\network\protocol\RespawnPacket; -use pocketmine\network\protocol\RotateHeadPacket; use pocketmine\network\protocol\SetDifficultyPacket; use pocketmine\network\protocol\SetEntityDataPacket; use pocketmine\network\protocol\SetEntityMotionPacket; @@ -312,7 +311,6 @@ class RakLibInterface implements ServerInstance, SourceInterface{ $this->registerPacket(ProtocolInfo::ADD_ITEM_ENTITY_PACKET, AddItemEntityPacket::class); $this->registerPacket(ProtocolInfo::TAKE_ITEM_ENTITY_PACKET, TakeItemEntityPacket::class); $this->registerPacket(ProtocolInfo::MOVE_ENTITY_PACKET, MoveEntityPacket::class); - $this->registerPacket(ProtocolInfo::ROTATE_HEAD_PACKET, RotateHeadPacket::class); $this->registerPacket(ProtocolInfo::MOVE_PLAYER_PACKET, MovePlayerPacket::class); $this->registerPacket(ProtocolInfo::REMOVE_BLOCK_PACKET, RemoveBlockPacket::class); $this->registerPacket(ProtocolInfo::UPDATE_BLOCK_PACKET, UpdateBlockPacket::class); diff --git a/src/pocketmine/network/protocol/FullChunkDataPacket.php b/src/pocketmine/network/protocol/FullChunkDataPacket.php index bb9ef5baf..685ac20f7 100644 --- a/src/pocketmine/network/protocol/FullChunkDataPacket.php +++ b/src/pocketmine/network/protocol/FullChunkDataPacket.php @@ -42,6 +42,8 @@ class FullChunkDataPacket extends DataPacket{ public function encode(){ $this->reset(); + $this->putInt($this->chunkX); + $this->putInt($this->chunkZ); $this->put($this->data); } diff --git a/src/pocketmine/network/protocol/Info.php b/src/pocketmine/network/protocol/Info.php index a6ec22b2f..b8ca5024d 100644 --- a/src/pocketmine/network/protocol/Info.php +++ b/src/pocketmine/network/protocol/Info.php @@ -52,45 +52,44 @@ interface Info{ const TAKE_ITEM_ENTITY_PACKET = 0x8e; const MOVE_ENTITY_PACKET = 0x8f; - const ROTATE_HEAD_PACKET = 0x90; - const MOVE_PLAYER_PACKET = 0x91; + const MOVE_PLAYER_PACKET = 0x90; - const REMOVE_BLOCK_PACKET = 0x92; - const UPDATE_BLOCK_PACKET = 0x93; + const REMOVE_BLOCK_PACKET = 0x91; + const UPDATE_BLOCK_PACKET = 0x92; - const ADD_PAINTING_PACKET = 0x94; + const ADD_PAINTING_PACKET = 0x93; - const EXPLODE_PACKET = 0x95; + const EXPLODE_PACKET = 0x94; - const LEVEL_EVENT_PACKET = 0x96; - const TILE_EVENT_PACKET = 0x97; - const ENTITY_EVENT_PACKET = 0x98; - const MOB_EFFECT_PACKET = 0x99; + const LEVEL_EVENT_PACKET = 0x95; + const TILE_EVENT_PACKET = 0x96; + const ENTITY_EVENT_PACKET = 0x97; + const MOB_EFFECT_PACKET = 0x98; - const PLAYER_EQUIPMENT_PACKET = 0x9a; - const PLAYER_ARMOR_EQUIPMENT_PACKET = 0x9b; - const INTERACT_PACKET = 0x9c; - const USE_ITEM_PACKET = 0x9d; - const PLAYER_ACTION_PACKET = 0x9e; - const HURT_ARMOR_PACKET = 0x9f; - const SET_ENTITY_DATA_PACKET = 0xa0; - const SET_ENTITY_MOTION_PACKET = 0xa1; - //const SET_ENTITY_LINK_PACKET = 0xa2; - const SET_HEALTH_PACKET = 0xa3; - const SET_SPAWN_POSITION_PACKET = 0xa4; - const ANIMATE_PACKET = 0xa5; - const RESPAWN_PACKET = 0xa6; - const DROP_ITEM_PACKET = 0xa7; - const CONTAINER_OPEN_PACKET = 0xa8; - const CONTAINER_CLOSE_PACKET = 0xa9; - const CONTAINER_SET_SLOT_PACKET = 0xaa; - const CONTAINER_SET_DATA_PACKET = 0xab; - const CONTAINER_SET_CONTENT_PACKET = 0xac; - //const CONTAINER_ACK_PACKET = 0xad; - const ADVENTURE_SETTINGS_PACKET = 0xae; - const TILE_ENTITY_DATA_PACKET = 0xaf; - //const PLAYER_INPUT_PACKET = 0xb0; - const FULL_CHUNK_DATA_PACKET = 0xb1; - const SET_DIFFICULTY_PACKET = 0xb2; + const PLAYER_EQUIPMENT_PACKET = 0x99; + const PLAYER_ARMOR_EQUIPMENT_PACKET = 0x9a; + const INTERACT_PACKET = 0x9b; + const USE_ITEM_PACKET = 0x9c; + const PLAYER_ACTION_PACKET = 0x9d; + const HURT_ARMOR_PACKET = 0x9e; + const SET_ENTITY_DATA_PACKET = 0x9f; + const SET_ENTITY_MOTION_PACKET = 0xa0; + //const SET_ENTITY_LINK_PACKET = 0xa1; + const SET_HEALTH_PACKET = 0xa2; + const SET_SPAWN_POSITION_PACKET = 0xa3; + const ANIMATE_PACKET = 0xa4; + const RESPAWN_PACKET = 0xa5; + const DROP_ITEM_PACKET = 0xa6; + const CONTAINER_OPEN_PACKET = 0xa7; + const CONTAINER_CLOSE_PACKET = 0xa8; + const CONTAINER_SET_SLOT_PACKET = 0xa9; + const CONTAINER_SET_DATA_PACKET = 0xaa; + const CONTAINER_SET_CONTENT_PACKET = 0xab; + //const CONTAINER_ACK_PACKET = 0xac; + const ADVENTURE_SETTINGS_PACKET = 0xad; + const TILE_ENTITY_DATA_PACKET = 0xae; + //const PLAYER_INPUT_PACKET = 0xaf; + const FULL_CHUNK_DATA_PACKET = 0xb0; + const SET_DIFFICULTY_PACKET = 0xb1; } diff --git a/src/pocketmine/network/protocol/MoveEntityPacket.php b/src/pocketmine/network/protocol/MoveEntityPacket.php index 51afde98f..90cff6cef 100644 --- a/src/pocketmine/network/protocol/MoveEntityPacket.php +++ b/src/pocketmine/network/protocol/MoveEntityPacket.php @@ -55,7 +55,8 @@ class MoveEntityPacket extends DataPacket{ $this->putFloat($d[2]); //y $this->putFloat($d[3]); //z $this->putFloat($d[4]); //yaw - $this->putFloat($d[5]); //pitch + $this->putFloat($d[5]); //headYaw + $this->putFloat($d[6]); //pitch } } diff --git a/src/pocketmine/network/protocol/RotateHeadPacket.php b/src/pocketmine/network/protocol/RotateHeadPacket.php deleted file mode 100644 index e432edf71..000000000 --- a/src/pocketmine/network/protocol/RotateHeadPacket.php +++ /dev/null @@ -1,58 +0,0 @@ - - - -class RotateHeadPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; - - - // eid, yaw - /** @var array[] */ - public $entities = []; - - public function pid(){ - return Info::ROTATE_HEAD_PACKET; - } - - public function clean(){ - $this->entities = []; - return parent::clean(); - } - - public function decode(){ - - } - - public function encode(){ - $this->reset(); - $this->putInt(count($this->entities)); - foreach($this->entities as $d){ - $this->putLong($d[0]); //eid - $this->putFloat($d[1]); - } - } - -}