From b54c0835b789e399ccb5160f231cd552d1749f3c Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 12 Mar 2015 18:37:22 +0100 Subject: [PATCH 01/17] Update RakLib --- src/raklib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/raklib b/src/raklib index 660bdff07..1f175c185 160000 --- a/src/raklib +++ b/src/raklib @@ -1 +1 @@ -Subproject commit 660bdff07d85c0270e57da2a5ce69eff2a87649a +Subproject commit 1f175c18558020477f429bb830325502ff97f10c From 4f47dac8ec4e36f652b583d91d50331ec1dfa860 Mon Sep 17 00:00:00 2001 From: Alejandro Liu Date: Fri, 13 Mar 2015 06:23:32 +0100 Subject: [PATCH 02/17] Fix some Chunk corrumption due to Chunk overlap --- src/pocketmine/level/format/mcregion/RegionLoader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/level/format/mcregion/RegionLoader.php b/src/pocketmine/level/format/mcregion/RegionLoader.php index 6a1142d28..2735683fa 100644 --- a/src/pocketmine/level/format/mcregion/RegionLoader.php +++ b/src/pocketmine/level/format/mcregion/RegionLoader.php @@ -189,8 +189,8 @@ class RegionLoader{ $sectors = (int) ceil(($length + 4) / 4096); $index = self::getChunkOffset($x, $z); if($this->locationTable[$index][1] < $sectors){ + $this->locationTable[$index][0] = $this->lastSector+1; $this->lastSector += $sectors; //The GC will clean this shift "later" - $this->locationTable[$index][0] = $this->lastSector; } $this->locationTable[$index][1] = $sectors; $this->locationTable[$index][2] = time(); From 59e9446fe5711215a09537dfc420ba4fa349afe2 Mon Sep 17 00:00:00 2001 From: Alejandro Liu Date: Fri, 13 Mar 2015 08:19:47 +0100 Subject: [PATCH 03/17] Added another place where the same happens --- src/pocketmine/level/format/mcregion/RegionLoader.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/level/format/mcregion/RegionLoader.php b/src/pocketmine/level/format/mcregion/RegionLoader.php index 2735683fa..ec833c242 100644 --- a/src/pocketmine/level/format/mcregion/RegionLoader.php +++ b/src/pocketmine/level/format/mcregion/RegionLoader.php @@ -247,7 +247,8 @@ class RegionLoader{ $chunk = Binary::writeInt(strlen($chunk)) . $chunk; $sectors = (int) ceil(strlen($chunk) / 4096); if($sectors > $this->locationTable[$i][1]){ - $this->locationTable[$i][0] = $this->lastSector += $sectors; + $this->locationTable[$i][0] = $this->lastSector + 1; + $this->lastSector += $sectors; } fseek($this->filePointer, $this->locationTable[$i][0] << 12); fwrite($this->filePointer, str_pad($chunk, $sectors << 12, "\x00", STR_PAD_RIGHT)); From 2cd757d80ac733d1ccd24f9db256e7b0f429e08c Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 13 Mar 2015 09:26:37 +0100 Subject: [PATCH 04/17] Fixed formatting of #2771 --- src/pocketmine/level/format/mcregion/RegionLoader.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/level/format/mcregion/RegionLoader.php b/src/pocketmine/level/format/mcregion/RegionLoader.php index ec833c242..7d5955290 100644 --- a/src/pocketmine/level/format/mcregion/RegionLoader.php +++ b/src/pocketmine/level/format/mcregion/RegionLoader.php @@ -189,7 +189,7 @@ class RegionLoader{ $sectors = (int) ceil(($length + 4) / 4096); $index = self::getChunkOffset($x, $z); if($this->locationTable[$index][1] < $sectors){ - $this->locationTable[$index][0] = $this->lastSector+1; + $this->locationTable[$index][0] = $this->lastSector + 1; $this->lastSector += $sectors; //The GC will clean this shift "later" } $this->locationTable[$index][1] = $sectors; @@ -359,4 +359,4 @@ class RegionLoader{ return $this->z; } -} \ No newline at end of file +} From 8679ad5b86d3a0e67ebddc01f94b47a17790c20c Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 1 Feb 2015 13:56:39 +0100 Subject: [PATCH 05/17] Added colors, Disconnect Packet, protocol 21 --- src/pocketmine/Player.php | 12 +- src/pocketmine/network/RakLibInterface.php | 6 +- ...adChunkPacket.php => DisconnectPacket.php} | 14 +-- src/pocketmine/network/protocol/Info.php | 110 +++++++++--------- 4 files changed, 76 insertions(+), 66 deletions(-) rename src/pocketmine/network/protocol/{UnloadChunkPacket.php => DisconnectPacket.php} (84%) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 572db9d14..4083bc38d 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -88,6 +88,7 @@ use pocketmine\nbt\tag\String; use pocketmine\network\protocol\AdventureSettingsPacket; use pocketmine\network\protocol\AnimatePacket; use pocketmine\network\protocol\DataPacket; +use pocketmine\network\protocol\DisconnectPacket; use pocketmine\network\protocol\EntityEventPacket; use pocketmine\network\protocol\FullChunkDataPacket; use pocketmine\network\protocol\Info as ProtocolInfo; @@ -164,7 +165,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ protected $forceMovement = null; protected $connected = true; protected $ip; - protected $removeFormat = true; + protected $removeFormat = false; protected $port; protected $username; protected $iusername; @@ -2399,7 +2400,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->server->getPluginManager()->callEvent($ev = new PlayerKickEvent($this, $reason, TextFormat::YELLOW . $this->username . " has left the game")); if(!$ev->isCancelled()){ $message = "Kicked by admin." . ($reason !== "" ? " Reason: " . $reason : ""); - $this->sendMessage($message); $this->close($ev->getQuitMessage(), $message); return true; @@ -2440,6 +2440,12 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->tasks = []; if($this->connected and !$this->closed){ + if($message != ""){ + $pk = new DisconnectPacket; + $pk->message = $reason; + $this->directDataPacket($pk); + } + $this->connected = false; if($this->username != ""){ $this->server->getPluginManager()->callEvent($ev = new PlayerQuitEvent($this, $message)); @@ -2458,7 +2464,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ foreach($this->windowIndex as $window){ $this->removeWindow($window); } - + $this->interface->close($this, $reason); $chunkX = $chunkZ = null; diff --git a/src/pocketmine/network/RakLibInterface.php b/src/pocketmine/network/RakLibInterface.php index 824b45fd7..3d6449cda 100644 --- a/src/pocketmine/network/RakLibInterface.php +++ b/src/pocketmine/network/RakLibInterface.php @@ -47,6 +47,7 @@ use pocketmine\network\protocol\HurtArmorPacket; use pocketmine\network\protocol\Info as ProtocolInfo; use pocketmine\network\protocol\InteractPacket; use pocketmine\network\protocol\LevelEventPacket; +use pocketmine\network\protocol\DisconnectPacket; use pocketmine\network\protocol\LoginPacket; use pocketmine\network\protocol\LoginStatusPacket; use pocketmine\network\protocol\MessagePacket; @@ -71,7 +72,6 @@ use pocketmine\network\protocol\StartGamePacket; use pocketmine\network\protocol\TakeItemEntityPacket; use pocketmine\network\protocol\TileEventPacket; use pocketmine\network\protocol\UnknownPacket; -use pocketmine\network\protocol\UnloadChunkPacket; use pocketmine\network\protocol\UpdateBlockPacket; use pocketmine\network\protocol\UseItemPacket; use pocketmine\Player; @@ -306,6 +306,7 @@ class RakLibInterface implements ServerInstance, SourceInterface{ private function registerPackets(){ $this->packetPool = new \SplFixedArray(256); + $this->registerPacket(ProtocolInfo::DISCONNECT_PACKET, DisconnectPacket::class); $this->registerPacket(ProtocolInfo::LOGIN_PACKET, LoginPacket::class); $this->registerPacket(ProtocolInfo::LOGIN_STATUS_PACKET, LoginStatusPacket::class); $this->registerPacket(ProtocolInfo::MESSAGE_PACKET, MessagePacket::class); @@ -350,7 +351,6 @@ class RakLibInterface implements ServerInstance, SourceInterface{ $this->registerPacket(ProtocolInfo::CHAT_PACKET, ChatPacket::class); $this->registerPacket(ProtocolInfo::ADVENTURE_SETTINGS_PACKET, AdventureSettingsPacket::class); $this->registerPacket(ProtocolInfo::ENTITY_DATA_PACKET, EntityDataPacket::class); - $this->registerPacket(ProtocolInfo::UNLOAD_CHUNK_PACKET, UnloadChunkPacket::class); $this->registerPacket(ProtocolInfo::SET_DIFFICULTY_PACKET, SetDifficultyPacket::class); } @@ -365,4 +365,4 @@ class RakLibInterface implements ServerInstance, SourceInterface{ return $data; } -} \ No newline at end of file +} diff --git a/src/pocketmine/network/protocol/UnloadChunkPacket.php b/src/pocketmine/network/protocol/DisconnectPacket.php similarity index 84% rename from src/pocketmine/network/protocol/UnloadChunkPacket.php rename to src/pocketmine/network/protocol/DisconnectPacket.php index 9d78f6d0c..5a83bd7d5 100644 --- a/src/pocketmine/network/protocol/UnloadChunkPacket.php +++ b/src/pocketmine/network/protocol/DisconnectPacket.php @@ -24,25 +24,23 @@ namespace pocketmine\network\protocol; #include -class UnloadChunkPacket extends DataPacket{ +class DisconnectPacket extends DataPacket{ public static $pool = []; public static $next = 0; - public $chunkX; - public $chunkZ; + public $message; public function pid(){ - return Info::UNLOAD_CHUNK_PACKET; + return Info::DISCONNECT_PACKET; } public function decode(){ - + $this->message = $this->getString(); } public function encode(){ $this->reset(); - $this->putInt($this->chunkX); - $this->putInt($this->chunkZ); + $this->putString($this->message); } -} \ No newline at end of file +} diff --git a/src/pocketmine/network/protocol/Info.php b/src/pocketmine/network/protocol/Info.php index 944a57a5d..25d4094f9 100644 --- a/src/pocketmine/network/protocol/Info.php +++ b/src/pocketmine/network/protocol/Info.php @@ -30,64 +30,70 @@ interface Info{ /** * Actual Minecraft: PE protocol version */ - const CURRENT_PROTOCOL = 20; + const CURRENT_PROTOCOL = 21; - const LOGIN_PACKET = 0x82; - const LOGIN_STATUS_PACKET = 0x83; - + const DISCONNECT_PACKET = 0x82; + + const LOGIN_PACKET = 0x83; + const LOGIN_STATUS_PACKET = 0x84; + const MESSAGE_PACKET = 0x85; const SET_TIME_PACKET = 0x86; + const START_GAME_PACKET = 0x87; + const ADD_MOB_PACKET = 0x88; const ADD_PLAYER_PACKET = 0x89; const REMOVE_PLAYER_PACKET = 0x8a; + + const ADD_ENTITY_PACKET = 0x8b; + const REMOVE_ENTITY_PACKET = 0x8c; + const ADD_ITEM_ENTITY_PACKET = 0x8d; + const TAKE_ITEM_ENTITY_PACKET = 0x8e; + + const MOVE_ENTITY_PACKET = 0x8f; + const ROTATE_HEAD_PACKET = 0x90; + const MOVE_PLAYER_PACKET = 0x91; + + const REMOVE_BLOCK_PACKET = 0x92; + const UPDATE_BLOCK_PACKET = 0x93; + + const ADD_PAINTING_PACKET = 0x94; + + const EXPLODE_PACKET = 0x95; + + const LEVEL_EVENT_PACKET = 0x96; + const TILE_EVENT_PACKET = 0x97; + const ENTITY_EVENT_PACKET = 0x98; + //const MOB_EFFECT_paCKET = 0x99; + + 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 SEND_INVENTORY_PACKET = 0xa7; + const DROP_ITEM_PACKET = 0xa8; + const CONTAINER_OPEN_PACKET = 0xa9; + const CONTAINER_CLOSE_PACKET = 0xaa; + const CONTAINER_SET_SLOT_PACKET = 0xab; + const CONTAINER_SET_DATA_PACKET = 0xac; + const CONTAINER_SET_CONTENT_PACKET = 0xad; + //const CONTAINER_ACK_PACKET = 0xae; + const CHAT_PACKET = 0xaf; + const ADVENTURE_SETTINGS_PACKET = 0xb0; + const ENTITY_DATA_PACKET = 0xb1; + //const PLAYER_INPUT_PACKET = 0xb2; + const FULL_CHUNK_DATA_PACKET = 0xb3; + const SET_DIFFICULTY_PACKET = 0xb4; - const ADD_ENTITY_PACKET = 0x8c; - const REMOVE_ENTITY_PACKET = 0x8d; - const ADD_ITEM_ENTITY_PACKET = 0x8e; - const TAKE_ITEM_ENTITY_PACKET = 0x8f; - const MOVE_ENTITY_PACKET = 0x90; - - const ROTATE_HEAD_PACKET = 0x94; - const MOVE_PLAYER_PACKET = 0x95; - //const PLACE_BLOCK_PACKET = 0x96; - const REMOVE_BLOCK_PACKET = 0x97; - const UPDATE_BLOCK_PACKET = 0x98; - const ADD_PAINTING_PACKET = 0x99; - const EXPLODE_PACKET = 0x9a; - const LEVEL_EVENT_PACKET = 0x9b; - const TILE_EVENT_PACKET = 0x9c; - const ENTITY_EVENT_PACKET = 0x9d; - - const PLAYER_EQUIPMENT_PACKET = 0xa0; - const PLAYER_ARMOR_EQUIPMENT_PACKET = 0xa1; - const INTERACT_PACKET = 0xa2; - const USE_ITEM_PACKET = 0xa3; - const PLAYER_ACTION_PACKET = 0xa4; - - const HURT_ARMOR_PACKET = 0xa6; - const SET_ENTITY_DATA_PACKET = 0xa7; - const SET_ENTITY_MOTION_PACKET = 0xa8; - //const SET_ENTITY_LINK_PACKET = 0xa9; - const SET_HEALTH_PACKET = 0xaa; - const SET_SPAWN_POSITION_PACKET = 0xab; - const ANIMATE_PACKET = 0xac; - const RESPAWN_PACKET = 0xad; - const SEND_INVENTORY_PACKET = 0xae; - const DROP_ITEM_PACKET = 0xaf; - const CONTAINER_OPEN_PACKET = 0xb0; - const CONTAINER_CLOSE_PACKET = 0xb1; - const CONTAINER_SET_SLOT_PACKET = 0xb2; - const CONTAINER_SET_DATA_PACKET = 0xb3; - const CONTAINER_SET_CONTENT_PACKET = 0xb4; - //const CONTAINER_ACK_PACKET = 0xb5; - const CHAT_PACKET = 0xb6; - const ADVENTURE_SETTINGS_PACKET = 0xb7; - const ENTITY_DATA_PACKET = 0xb8; - //const PLAYER_INPUT_PACKET = 0xb9; - const FULL_CHUNK_DATA_PACKET = 0xba; - const UNLOAD_CHUNK_PACKET = 0xbb; - const SET_DIFFICULTY_PACKET = 0xbc; - -} \ No newline at end of file +} From eeeaac04e9a899e0e1e602479e674e813c7a25d3 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 10 Feb 2015 12:02:59 +0100 Subject: [PATCH 06/17] Updated packet order, removed player entity id as 0 --- src/pocketmine/Player.php | 18 +++++++++--------- src/pocketmine/entity/Entity.php | 10 +--------- src/pocketmine/network/protocol/Info.php | 9 ++++----- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 4083bc38d..c8c3bc01a 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -969,7 +969,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $pk->spawnZ = (int) $spawnPosition->z; $pk->generator = 1; //0 old, 1 infinite, 2 flat $pk->gamemode = $this->gamemode & 0x01; - $pk->eid = 0; //Always use EntityID as zero for the actual player + $pk->eid = $this->getId(); $this->dataPacket($pk); $this->sendSettings(); @@ -1202,7 +1202,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->lastPitch = $from->pitch; $pk = new MovePlayerPacket(); - $pk->eid = 0; + $pk->eid = $this->getId(); $pk->x = $from->x; $pk->y = $from->y + $this->getEyeHeight(); $pk->z = $from->z; @@ -1306,7 +1306,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } $pk = new TakeItemEntityPacket(); - $pk->eid = 0; + $pk->eid = $this->getId(); $pk->target = $entity->getId(); $this->dataPacket($pk); $pk = new TakeItemEntityPacket(); @@ -1340,7 +1340,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } $pk = new TakeItemEntityPacket(); - $pk->eid = 0; + $pk->eid = $this->getId(); $pk->target = $entity->getId(); $this->dataPacket($pk); $pk = new TakeItemEntityPacket(); @@ -1549,7 +1549,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $pk->spawnZ = (int) $spawnPosition->z; $pk->generator = 1; //0 old, 1 infinite, 2 flat $pk->gamemode = $this->gamemode & 0x01; - $pk->eid = 0; //Always use EntityID as zero for the actual player + $pk->eid = $this->getId(); //Always use EntityID as zero for the actual player $this->dataPacket($pk); $pk = new SetTimePacket(); @@ -1605,7 +1605,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ if($this->forceMovement instanceof Vector3 and (($dist = $newPos->distanceSquared($this->forceMovement)) > 0.04 or $revert)){ $pk = new MovePlayerPacket(); - $pk->eid = 0; + $pk->eid = $this->getId(); $pk->x = $this->forceMovement->x; $pk->y = $this->forceMovement->y + $this->getEyeHeight(); $pk->z = $this->forceMovement->z; @@ -2139,7 +2139,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } $pk = new EntityEventPacket(); - $pk->eid = 0; + $pk->eid = $this->getId(); $pk->event = 9; $this->dataPacket($pk); $pk->eid = $this->getId(); @@ -2696,7 +2696,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ if($this->getLastDamageCause() === $source){ $pk = new EntityEventPacket(); - $pk->eid = 0; + $pk->eid = $this->getId(); $pk->event = 2; $this->dataPacket($pk); } @@ -2742,7 +2742,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->newPosition = null; $pk = new MovePlayerPacket(); - $pk->eid = 0; + $pk->eid = $this->getId(); $pk->x = $this->x; $pk->y = $this->y + $this->getEyeHeight(); $pk->z = $this->z; diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 0e72eb431..cdda34cd7 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -332,15 +332,7 @@ abstract class Entity extends Location implements Metadatable{ $pk->encode(); $pk->isEncoded = true; foreach($player as $p){ - if($p === $this){ - /** @var Player $p */ - $pk2 = new SetEntityDataPacket(); - $pk2->eid = 0; - $pk2->metadata = $this->getData(); - $p->dataPacket($pk2); - }else{ - $p->dataPacket($pk); - } + $p->dataPacket($pk); } } diff --git a/src/pocketmine/network/protocol/Info.php b/src/pocketmine/network/protocol/Info.php index 25d4094f9..51ec4197e 100644 --- a/src/pocketmine/network/protocol/Info.php +++ b/src/pocketmine/network/protocol/Info.php @@ -31,12 +31,11 @@ interface Info{ * Actual Minecraft: PE protocol version */ const CURRENT_PROTOCOL = 21; - - - const DISCONNECT_PACKET = 0x82; - const LOGIN_PACKET = 0x83; - const LOGIN_STATUS_PACKET = 0x84; + const LOGIN_PACKET = 0x82; + const LOGIN_STATUS_PACKET = 0x83; + + const DISCONNECT_PACKET = 0x84; const MESSAGE_PACKET = 0x85; const SET_TIME_PACKET = 0x86; From 218fd999b0ebab5de631cefd38b912ebd2ba4ac7 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 11 Feb 2015 12:36:01 +0100 Subject: [PATCH 07/17] More packets changed, unique IDs D: --- src/pocketmine/network/RakLibInterface.php | 4 +- .../network/protocol/AddEntityPacket.php | 6 +- .../network/protocol/AddItemEntityPacket.php | 4 +- .../network/protocol/AddMobPacket.php | 2 +- .../network/protocol/AddPaintingPacket.php | 4 +- .../network/protocol/AddPlayerPacket.php | 4 +- .../network/protocol/AnimatePacket.php | 6 +- .../network/protocol/EntityEventPacket.php | 6 +- src/pocketmine/network/protocol/Info.php | 27 ++++---- .../network/protocol/InteractPacket.php | 6 +- .../network/protocol/MoveEntityPacket.php | 4 +- .../network/protocol/MovePlayerPacket.php | 6 +- .../network/protocol/PlayerActionPacket.php | 4 +- .../protocol/PlayerArmorEquipmentPacket.php | 6 +- .../protocol/PlayerEquipmentPacket.php | 6 +- .../network/protocol/RemoveEntityPacket.php | 4 +- .../network/protocol/RemovePlayerPacket.php | 4 +- .../network/protocol/RespawnPacket.php | 6 +- .../network/protocol/RotateHeadPacket.php | 4 +- .../network/protocol/SendInventoryPacket.php | 69 ------------------- .../network/protocol/SetEntityDataPacket.php | 4 +- .../protocol/SetEntityMotionPacket.php | 4 +- .../network/protocol/StartGamePacket.php | 4 +- .../network/protocol/TakeItemEntityPacket.php | 4 +- .../network/protocol/UseItemPacket.php | 4 +- 25 files changed, 65 insertions(+), 137 deletions(-) delete mode 100644 src/pocketmine/network/protocol/SendInventoryPacket.php diff --git a/src/pocketmine/network/RakLibInterface.php b/src/pocketmine/network/RakLibInterface.php index 3d6449cda..84b0e03ae 100644 --- a/src/pocketmine/network/RakLibInterface.php +++ b/src/pocketmine/network/RakLibInterface.php @@ -61,7 +61,6 @@ use pocketmine\network\protocol\RemoveEntityPacket; use pocketmine\network\protocol\RemovePlayerPacket; use pocketmine\network\protocol\RespawnPacket; use pocketmine\network\protocol\RotateHeadPacket; -use pocketmine\network\protocol\SendInventoryPacket; use pocketmine\network\protocol\SetDifficultyPacket; use pocketmine\network\protocol\SetEntityDataPacket; use pocketmine\network\protocol\SetEntityMotionPacket; @@ -306,9 +305,9 @@ class RakLibInterface implements ServerInstance, SourceInterface{ private function registerPackets(){ $this->packetPool = new \SplFixedArray(256); - $this->registerPacket(ProtocolInfo::DISCONNECT_PACKET, DisconnectPacket::class); $this->registerPacket(ProtocolInfo::LOGIN_PACKET, LoginPacket::class); $this->registerPacket(ProtocolInfo::LOGIN_STATUS_PACKET, LoginStatusPacket::class); + $this->registerPacket(ProtocolInfo::DISCONNECT_PACKET, DisconnectPacket::class); $this->registerPacket(ProtocolInfo::MESSAGE_PACKET, MessagePacket::class); $this->registerPacket(ProtocolInfo::SET_TIME_PACKET, SetTimePacket::class); $this->registerPacket(ProtocolInfo::START_GAME_PACKET, StartGamePacket::class); @@ -341,7 +340,6 @@ class RakLibInterface implements ServerInstance, SourceInterface{ $this->registerPacket(ProtocolInfo::SET_SPAWN_POSITION_PACKET, SetSpawnPositionPacket::class); $this->registerPacket(ProtocolInfo::ANIMATE_PACKET, AnimatePacket::class); $this->registerPacket(ProtocolInfo::RESPAWN_PACKET, RespawnPacket::class); - $this->registerPacket(ProtocolInfo::SEND_INVENTORY_PACKET, SendInventoryPacket::class); $this->registerPacket(ProtocolInfo::DROP_ITEM_PACKET, DropItemPacket::class); $this->registerPacket(ProtocolInfo::CONTAINER_OPEN_PACKET, ContainerOpenPacket::class); $this->registerPacket(ProtocolInfo::CONTAINER_CLOSE_PACKET, ContainerClosePacket::class); diff --git a/src/pocketmine/network/protocol/AddEntityPacket.php b/src/pocketmine/network/protocol/AddEntityPacket.php index a020fc1d0..aac99adc5 100644 --- a/src/pocketmine/network/protocol/AddEntityPacket.php +++ b/src/pocketmine/network/protocol/AddEntityPacket.php @@ -48,12 +48,12 @@ class AddEntityPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putInt($this->eid); + $this->putLong($this->eid); $this->putInt($this->type); $this->putFloat($this->x); $this->putFloat($this->y); $this->putFloat($this->z); - $this->putInt($this->did); + $this->putLong($this->did); if($this->did > 0){ $this->putShort($this->speedX * 8000); $this->putShort($this->speedY * 8000); @@ -61,4 +61,4 @@ class AddEntityPacket extends DataPacket{ } } -} \ No newline at end of file +} diff --git a/src/pocketmine/network/protocol/AddItemEntityPacket.php b/src/pocketmine/network/protocol/AddItemEntityPacket.php index c2786ad94..c8fe7a1aa 100644 --- a/src/pocketmine/network/protocol/AddItemEntityPacket.php +++ b/src/pocketmine/network/protocol/AddItemEntityPacket.php @@ -47,7 +47,7 @@ class AddItemEntityPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putInt($this->eid); + $this->putLong($this->eid); $this->putSlot($this->item); $this->putFloat($this->x); $this->putFloat($this->y); @@ -57,4 +57,4 @@ class AddItemEntityPacket extends DataPacket{ $this->putByte($this->roll); } -} \ No newline at end of file +} diff --git a/src/pocketmine/network/protocol/AddMobPacket.php b/src/pocketmine/network/protocol/AddMobPacket.php index a5ff3b81f..5a2123e4a 100644 --- a/src/pocketmine/network/protocol/AddMobPacket.php +++ b/src/pocketmine/network/protocol/AddMobPacket.php @@ -51,7 +51,7 @@ class AddMobPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putInt($this->eid); + $this->putLong($this->eid); $this->putInt($this->type); $this->putInt($this->x); $this->putInt($this->y); diff --git a/src/pocketmine/network/protocol/AddPaintingPacket.php b/src/pocketmine/network/protocol/AddPaintingPacket.php index d0272d002..81f25986c 100644 --- a/src/pocketmine/network/protocol/AddPaintingPacket.php +++ b/src/pocketmine/network/protocol/AddPaintingPacket.php @@ -45,7 +45,7 @@ class AddPaintingPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putInt($this->eid); + $this->putLevel($this->eid); $this->putInt($this->x); $this->putInt($this->y); $this->putInt($this->z); @@ -53,4 +53,4 @@ class AddPaintingPacket extends DataPacket{ $this->putString($this->title); } -} \ No newline at end of file +} diff --git a/src/pocketmine/network/protocol/AddPlayerPacket.php b/src/pocketmine/network/protocol/AddPlayerPacket.php index 5df4fa714..b54dd6b0f 100644 --- a/src/pocketmine/network/protocol/AddPlayerPacket.php +++ b/src/pocketmine/network/protocol/AddPlayerPacket.php @@ -56,7 +56,7 @@ class AddPlayerPacket extends DataPacket{ $this->reset(); $this->putLong($this->clientID); $this->putString($this->username); - $this->putInt($this->eid); + $this->putLong($this->eid); $this->putFloat($this->x); $this->putFloat($this->y); $this->putFloat($this->z); @@ -67,4 +67,4 @@ class AddPlayerPacket extends DataPacket{ $this->put(Binary::writeMetadata($this->metadata)); } -} \ No newline at end of file +} diff --git a/src/pocketmine/network/protocol/AnimatePacket.php b/src/pocketmine/network/protocol/AnimatePacket.php index 6e4eca5db..721132e20 100644 --- a/src/pocketmine/network/protocol/AnimatePacket.php +++ b/src/pocketmine/network/protocol/AnimatePacket.php @@ -37,13 +37,13 @@ class AnimatePacket extends DataPacket{ public function decode(){ $this->action = $this->getByte(); - $this->eid = $this->getInt(); + $this->eid = $this->getLong(); } public function encode(){ $this->reset(); $this->putByte($this->action); - $this->putInt($this->eid); + $this->putLong($this->eid); } -} \ No newline at end of file +} diff --git a/src/pocketmine/network/protocol/EntityEventPacket.php b/src/pocketmine/network/protocol/EntityEventPacket.php index 335612adf..bbd915bb5 100644 --- a/src/pocketmine/network/protocol/EntityEventPacket.php +++ b/src/pocketmine/network/protocol/EntityEventPacket.php @@ -36,14 +36,14 @@ class EntityEventPacket extends DataPacket{ } public function decode(){ - $this->eid = $this->getInt(); + $this->eid = $this->getLong(); $this->event = $this->getByte(); } public function encode(){ $this->reset(); - $this->putInt($this->eid); + $this->putLong($this->eid); $this->putByte($this->event); } -} \ No newline at end of file +} diff --git a/src/pocketmine/network/protocol/Info.php b/src/pocketmine/network/protocol/Info.php index 51ec4197e..8fea7506c 100644 --- a/src/pocketmine/network/protocol/Info.php +++ b/src/pocketmine/network/protocol/Info.php @@ -80,19 +80,18 @@ interface Info{ const SET_SPAWN_POSITION_PACKET = 0xa4; const ANIMATE_PACKET = 0xa5; const RESPAWN_PACKET = 0xa6; - const SEND_INVENTORY_PACKET = 0xa7; - const DROP_ITEM_PACKET = 0xa8; - const CONTAINER_OPEN_PACKET = 0xa9; - const CONTAINER_CLOSE_PACKET = 0xaa; - const CONTAINER_SET_SLOT_PACKET = 0xab; - const CONTAINER_SET_DATA_PACKET = 0xac; - const CONTAINER_SET_CONTENT_PACKET = 0xad; - //const CONTAINER_ACK_PACKET = 0xae; - const CHAT_PACKET = 0xaf; - const ADVENTURE_SETTINGS_PACKET = 0xb0; - const ENTITY_DATA_PACKET = 0xb1; - //const PLAYER_INPUT_PACKET = 0xb2; - const FULL_CHUNK_DATA_PACKET = 0xb3; - const SET_DIFFICULTY_PACKET = 0xb4; + 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 CHAT_PACKET = 0xae; + const ADVENTURE_SETTINGS_PACKET = 0xaf; + const ENTITY_DATA_PACKET = 0xb0; + //const PLAYER_INPUT_PACKET = 0xb1; + const FULL_CHUNK_DATA_PACKET = 0xb2; + const SET_DIFFICULTY_PACKET = 0xb3; } diff --git a/src/pocketmine/network/protocol/InteractPacket.php b/src/pocketmine/network/protocol/InteractPacket.php index d0b209780..06d52d6a9 100644 --- a/src/pocketmine/network/protocol/InteractPacket.php +++ b/src/pocketmine/network/protocol/InteractPacket.php @@ -45,8 +45,8 @@ class InteractPacket extends DataPacket{ public function encode(){ $this->reset(); $this->putByte($this->action); - $this->putInt($this->eid); - $this->putInt($this->target); + $this->putLong($this->eid); + $this->putLong($this->target); } -} \ No newline at end of file +} diff --git a/src/pocketmine/network/protocol/MoveEntityPacket.php b/src/pocketmine/network/protocol/MoveEntityPacket.php index cf7adf99e..51afde98f 100644 --- a/src/pocketmine/network/protocol/MoveEntityPacket.php +++ b/src/pocketmine/network/protocol/MoveEntityPacket.php @@ -50,7 +50,7 @@ class MoveEntityPacket extends DataPacket{ $this->reset(); $this->putInt(count($this->entities)); foreach($this->entities as $d){ - $this->putInt($d[0]); //eid + $this->putLong($d[0]); //eid $this->putFloat($d[1]); //x $this->putFloat($d[2]); //y $this->putFloat($d[3]); //z @@ -59,4 +59,4 @@ class MoveEntityPacket extends DataPacket{ } } -} \ No newline at end of file +} diff --git a/src/pocketmine/network/protocol/MovePlayerPacket.php b/src/pocketmine/network/protocol/MovePlayerPacket.php index 16aa83be0..c5c096371 100644 --- a/src/pocketmine/network/protocol/MovePlayerPacket.php +++ b/src/pocketmine/network/protocol/MovePlayerPacket.php @@ -47,7 +47,7 @@ class MovePlayerPacket extends DataPacket{ } public function decode(){ - $this->eid = $this->getInt(); + $this->eid = $this->getLong(); $this->x = $this->getFloat(); $this->y = $this->getFloat(); $this->z = $this->getFloat(); @@ -60,7 +60,7 @@ class MovePlayerPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putInt($this->eid); + $this->putLong($this->eid); $this->putFloat($this->x); $this->putFloat($this->y); $this->putFloat($this->z); @@ -70,4 +70,4 @@ class MovePlayerPacket extends DataPacket{ $this->putByte($this->teleport == true ? 0x80 : 0x00); } -} \ No newline at end of file +} diff --git a/src/pocketmine/network/protocol/PlayerActionPacket.php b/src/pocketmine/network/protocol/PlayerActionPacket.php index 22d76159a..285659ea6 100644 --- a/src/pocketmine/network/protocol/PlayerActionPacket.php +++ b/src/pocketmine/network/protocol/PlayerActionPacket.php @@ -45,11 +45,11 @@ class PlayerActionPacket extends DataPacket{ $this->y = $this->getInt(); $this->z = $this->getInt(); $this->face = $this->getInt(); - $this->eid = $this->getInt(); + $this->eid = $this->getLong(); } public function encode(){ } -} \ No newline at end of file +} diff --git a/src/pocketmine/network/protocol/PlayerArmorEquipmentPacket.php b/src/pocketmine/network/protocol/PlayerArmorEquipmentPacket.php index 493e74c69..5cdad7cd1 100644 --- a/src/pocketmine/network/protocol/PlayerArmorEquipmentPacket.php +++ b/src/pocketmine/network/protocol/PlayerArmorEquipmentPacket.php @@ -36,7 +36,7 @@ class PlayerArmorEquipmentPacket extends DataPacket{ } public function decode(){ - $this->eid = $this->getInt(); + $this->eid = $this->getLong(); $this->slots[0] = $this->getByte(); $this->slots[1] = $this->getByte(); $this->slots[2] = $this->getByte(); @@ -45,11 +45,11 @@ class PlayerArmorEquipmentPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putInt($this->eid); + $this->putLong($this->eid); $this->putByte($this->slots[0]); $this->putByte($this->slots[1]); $this->putByte($this->slots[2]); $this->putByte($this->slots[3]); } -} \ No newline at end of file +} diff --git a/src/pocketmine/network/protocol/PlayerEquipmentPacket.php b/src/pocketmine/network/protocol/PlayerEquipmentPacket.php index a2c88f846..b5d79ef6a 100644 --- a/src/pocketmine/network/protocol/PlayerEquipmentPacket.php +++ b/src/pocketmine/network/protocol/PlayerEquipmentPacket.php @@ -38,7 +38,7 @@ class PlayerEquipmentPacket extends DataPacket{ } public function decode(){ - $this->eid = $this->getInt(); + $this->eid = $this->getLong(); $this->item = $this->getShort(); $this->meta = $this->getShort(); $this->slot = $this->getByte(); @@ -46,10 +46,10 @@ class PlayerEquipmentPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putInt($this->eid); + $this->putLong($this->eid); $this->putShort($this->item); $this->putShort($this->meta); $this->putByte($this->slot); } -} \ No newline at end of file +} diff --git a/src/pocketmine/network/protocol/RemoveEntityPacket.php b/src/pocketmine/network/protocol/RemoveEntityPacket.php index fc414eb4a..8757dcf78 100644 --- a/src/pocketmine/network/protocol/RemoveEntityPacket.php +++ b/src/pocketmine/network/protocol/RemoveEntityPacket.php @@ -40,7 +40,7 @@ class RemoveEntityPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putInt($this->eid); + $this->putLong($this->eid); } -} \ No newline at end of file +} diff --git a/src/pocketmine/network/protocol/RemovePlayerPacket.php b/src/pocketmine/network/protocol/RemovePlayerPacket.php index bcf539fac..5f8f4600b 100644 --- a/src/pocketmine/network/protocol/RemovePlayerPacket.php +++ b/src/pocketmine/network/protocol/RemovePlayerPacket.php @@ -41,8 +41,8 @@ class RemovePlayerPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putInt($this->eid); + $this->putLong($this->eid); $this->putLong($this->clientID); } -} \ No newline at end of file +} diff --git a/src/pocketmine/network/protocol/RespawnPacket.php b/src/pocketmine/network/protocol/RespawnPacket.php index 9943a86f7..6991b2fa0 100644 --- a/src/pocketmine/network/protocol/RespawnPacket.php +++ b/src/pocketmine/network/protocol/RespawnPacket.php @@ -38,7 +38,7 @@ class RespawnPacket extends DataPacket{ } public function decode(){ - $this->eid = $this->getInt(); + $this->eid = $this->getLong(); $this->x = $this->getFloat(); $this->y = $this->getFloat(); $this->z = $this->getFloat(); @@ -46,10 +46,10 @@ class RespawnPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putInt($this->eid); + $this->putLong($this->eid); $this->putFloat($this->x); $this->putFloat($this->y); $this->putFloat($this->z); } -} \ No newline at end of file +} diff --git a/src/pocketmine/network/protocol/RotateHeadPacket.php b/src/pocketmine/network/protocol/RotateHeadPacket.php index 0b93a3613..129df23e6 100644 --- a/src/pocketmine/network/protocol/RotateHeadPacket.php +++ b/src/pocketmine/network/protocol/RotateHeadPacket.php @@ -50,9 +50,9 @@ class RotateHeadPacket extends DataPacket{ $this->reset(); $this->putInt(count($this->entities)); foreach($this->entities as $d){ - $this->putInt($d[0]); //eid + $this->putLong($d[0]); //eid $this->putByte((int) ($d[1] / 360)); } } -} \ No newline at end of file +} diff --git a/src/pocketmine/network/protocol/SendInventoryPacket.php b/src/pocketmine/network/protocol/SendInventoryPacket.php deleted file mode 100644 index 3133af325..000000000 --- a/src/pocketmine/network/protocol/SendInventoryPacket.php +++ /dev/null @@ -1,69 +0,0 @@ - - - -class SendInventoryPacket extends DataPacket{ - public static $pool = []; - public static $next = 0; - - public $eid; - public $windowid; - public $slots = []; - public $armor = []; - - public function pid(){ - return Info::SEND_INVENTORY_PACKET; - } - - public function decode(){ - $this->eid = $this->getInt(); - $this->windowid = $this->getByte(); - $count = $this->getShort(); - for($s = 0; $s < $count and !$this->feof(); ++$s){ - $this->slots[$s] = $this->getSlot(); - } - if($this->windowid === 1){ //Armor is sent - for($s = 0; $s < 4; ++$s){ - $this->armor[$s] = $this->getSlot(); - } - } - } - - public function encode(){ - $this->reset(); - $this->putInt($this->eid); - $this->putByte($this->windowid); - $this->putShort(count($this->slots)); - foreach($this->slots as $slot){ - $this->putSlot($slot); - } - if($this->windowid === 1 and count($this->armor) === 4){ - for($s = 0; $s < 4; ++$s){ - $this->putSlot($this->armor[$s]); - } - } - } - -} \ No newline at end of file diff --git a/src/pocketmine/network/protocol/SetEntityDataPacket.php b/src/pocketmine/network/protocol/SetEntityDataPacket.php index 23842fe23..55178357e 100644 --- a/src/pocketmine/network/protocol/SetEntityDataPacket.php +++ b/src/pocketmine/network/protocol/SetEntityDataPacket.php @@ -45,8 +45,8 @@ class SetEntityDataPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putInt($this->eid); + $this->putLong($this->eid); $this->put(Binary::writeMetadata($this->metadata)); } -} \ No newline at end of file +} diff --git a/src/pocketmine/network/protocol/SetEntityMotionPacket.php b/src/pocketmine/network/protocol/SetEntityMotionPacket.php index d73433b98..1c6babc8c 100644 --- a/src/pocketmine/network/protocol/SetEntityMotionPacket.php +++ b/src/pocketmine/network/protocol/SetEntityMotionPacket.php @@ -50,11 +50,11 @@ class SetEntityMotionPacket extends DataPacket{ $this->reset(); $this->putInt(count($this->entities)); foreach($this->entities as $d){ - $this->putInt($d[0]); //eid + $this->putLong($d[0]); //eid $this->putShort((int) ($d[1] * 8000)); //motX $this->putShort((int) ($d[2] * 8000)); //motY $this->putShort((int) ($d[3] * 8000)); //motZ } } -} \ No newline at end of file +} diff --git a/src/pocketmine/network/protocol/StartGamePacket.php b/src/pocketmine/network/protocol/StartGamePacket.php index 459dce4f7..5f3fcce91 100644 --- a/src/pocketmine/network/protocol/StartGamePacket.php +++ b/src/pocketmine/network/protocol/StartGamePacket.php @@ -52,7 +52,7 @@ class StartGamePacket extends DataPacket{ $this->putInt($this->seed); $this->putInt($this->generator); $this->putInt($this->gamemode); - $this->putInt($this->eid); + $this->putLong($this->eid); $this->putInt($this->spawnX); $this->putInt($this->spawnY); $this->putInt($this->spawnZ); @@ -61,4 +61,4 @@ class StartGamePacket extends DataPacket{ $this->putFloat($this->z); } -} \ No newline at end of file +} diff --git a/src/pocketmine/network/protocol/TakeItemEntityPacket.php b/src/pocketmine/network/protocol/TakeItemEntityPacket.php index 1e4dddba0..5fef8888c 100644 --- a/src/pocketmine/network/protocol/TakeItemEntityPacket.php +++ b/src/pocketmine/network/protocol/TakeItemEntityPacket.php @@ -42,7 +42,7 @@ class TakeItemEntityPacket extends DataPacket{ public function encode(){ $this->reset(); $this->putInt($this->target); - $this->putInt($this->eid); + $this->putLong($this->eid); } -} \ No newline at end of file +} diff --git a/src/pocketmine/network/protocol/UseItemPacket.php b/src/pocketmine/network/protocol/UseItemPacket.php index 73afa9619..ead8d5237 100644 --- a/src/pocketmine/network/protocol/UseItemPacket.php +++ b/src/pocketmine/network/protocol/UseItemPacket.php @@ -53,7 +53,7 @@ class UseItemPacket extends DataPacket{ $this->face = $this->getByte(); $this->item = $this->getShort(); $this->meta = $this->getShort(); - $this->eid = $this->getInt(); + $this->eid = $this->getLong(); $this->fx = $this->getFloat(); $this->fy = $this->getFloat(); $this->fz = $this->getFloat(); @@ -66,4 +66,4 @@ class UseItemPacket extends DataPacket{ } -} \ No newline at end of file +} From fc128affc5f45e07f7b0483a60e97a4c0d9ed08c Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 16 Feb 2015 23:44:22 +0100 Subject: [PATCH 08/17] Removed chat wrapping, deprecated TextWrapper --- src/pocketmine/Player.php | 3 +-- src/pocketmine/Server.php | 1 + src/pocketmine/utils/TextWrapper.php | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index c8c3bc01a..4e0add586 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -113,7 +113,6 @@ use pocketmine\tile\Sign; use pocketmine\tile\Spawnable; use pocketmine\tile\Tile; use pocketmine\utils\TextFormat; -use pocketmine\utils\TextWrapper; /** * Main class that handles networking, recovery, and packet sending to the server part @@ -2415,7 +2414,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ */ public function sendMessage($message){ if($this->removeFormat !== false){ - $message = TextWrapper::wrap(TextFormat::clean($message)); + $message = TextFormat::clean($message); } $mes = explode("\n", $message); foreach($mes as $m){ diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 43633f662..d1212b0f8 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -1610,6 +1610,7 @@ class Server{ InventoryType::init(); Block::init(); Item::init(); + /** TODO: @deprecated */ TextWrapper::init(); $this->craftingManager = new CraftingManager(); diff --git a/src/pocketmine/utils/TextWrapper.php b/src/pocketmine/utils/TextWrapper.php index 1754bc853..efe313ab5 100644 --- a/src/pocketmine/utils/TextWrapper.php +++ b/src/pocketmine/utils/TextWrapper.php @@ -21,6 +21,10 @@ namespace pocketmine\utils; + +/** + * @deprecated + */ abstract class TextWrapper{ private static $characterWidths = [ @@ -47,6 +51,13 @@ abstract class TextWrapper{ } } + /** + * @deprecated + * + * @param $text + * + * @return string + */ public static function wrap($text){ $result = ""; $len = strlen($text); From 15ee0c37c6258d168dd3a1dd211c5d52e474c3c5 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 18 Feb 2015 00:39:31 +0100 Subject: [PATCH 09/17] Fixed Entity->setMotion() for Players --- src/pocketmine/entity/Entity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index cdda34cd7..8a60e6a43 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -1199,7 +1199,7 @@ abstract class Entity extends Location implements Metadatable{ if(!$this->justCreated){ if($this instanceof Player){ - $this->addEntityMotion(0, $this->motionX, $this->motionY, $this->motionZ); + $this->addEntityMotion($this->getId(), $this->motionX, $this->motionY, $this->motionZ); } $this->updateMovement(); } From 8ddd701d762c383ff92c9e167d019a1929b45dc1 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 12 Mar 2015 10:35:39 +0100 Subject: [PATCH 10/17] Renamed LoginStatusPacket to PlayStatusPacket, added spawn status, new colors --- src/pocketmine/Player.php | 22 +++++++----- src/pocketmine/network/RakLibInterface.php | 4 +-- src/pocketmine/network/protocol/Info.php | 2 +- ...nStatusPacket.php => PlayStatusPacket.php} | 12 +++++-- src/pocketmine/utils/TextFormat.php | 35 ++++++++++--------- 5 files changed, 43 insertions(+), 32 deletions(-) rename src/pocketmine/network/protocol/{LoginStatusPacket.php => PlayStatusPacket.php} (83%) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 4e0add586..052103ee2 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -92,7 +92,7 @@ use pocketmine\network\protocol\DisconnectPacket; use pocketmine\network\protocol\EntityEventPacket; use pocketmine\network\protocol\FullChunkDataPacket; use pocketmine\network\protocol\Info as ProtocolInfo; -use pocketmine\network\protocol\LoginStatusPacket; +use pocketmine\network\protocol\PlayStatusPacket; use pocketmine\network\protocol\MessagePacket; use pocketmine\network\protocol\MoveEntityPacket; use pocketmine\network\protocol\MovePlayerPacket; @@ -637,7 +637,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->level->requestChunk($X, $Z, $this, LevelProvider::ORDER_ZXY); } - if(count($this->usedChunks) >= 56 and $this->spawned === false){ + if(count($this->usedChunks) >= 16 and $this->spawned === false){ $spawned = 0; foreach($this->usedChunks as $d){ if($d === true){ @@ -645,11 +645,15 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } } - if($spawned < 56){ + if($spawned < 16){ return; } $this->spawned = true; + + $pk = new PlayStatusPacket(); + $pk->status = PlayStatusPacket::PLAYER_SPAWN; + $this->dataPacket($pk); $pk = new SetTimePacket(); $pk->time = $this->level->getTime(); @@ -1420,12 +1424,12 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } if($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL){ if($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL){ - $pk = new LoginStatusPacket(); - $pk->status = 1; + $pk = new PlayStatusPacket(); + $pk->status = PlayStatusPacket::LOGIN_FAILED_CLIENT; $this->dataPacket($pk); }else{ - $pk = new LoginStatusPacket(); - $pk->status = 2; + $pk = new PlayStatusPacket(); + $pk->status = PlayStatusPacket::LOGIN_FAILED_SERVER; $this->dataPacket($pk); } $this->close("", "Incorrect protocol #" . $packet->protocol1, false); @@ -1526,8 +1530,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->inventory->setHeldItemSlot(0); } - $pk = new LoginStatusPacket(); - $pk->status = 0; + $pk = new PlayStatusPacket(); + $pk->status = PlayStatusPacket::LOGIN_SUCCESS; $this->dataPacket($pk); if($this->spawnPosition === null and isset($this->namedtag->SpawnLevel) and ($level = $this->server->getLevelByName($this->namedtag["SpawnLevel"])) instanceof Level){ diff --git a/src/pocketmine/network/RakLibInterface.php b/src/pocketmine/network/RakLibInterface.php index 84b0e03ae..a9384f470 100644 --- a/src/pocketmine/network/RakLibInterface.php +++ b/src/pocketmine/network/RakLibInterface.php @@ -49,7 +49,7 @@ use pocketmine\network\protocol\InteractPacket; use pocketmine\network\protocol\LevelEventPacket; use pocketmine\network\protocol\DisconnectPacket; use pocketmine\network\protocol\LoginPacket; -use pocketmine\network\protocol\LoginStatusPacket; +use pocketmine\network\protocol\PlayStatusPacket; use pocketmine\network\protocol\MessagePacket; use pocketmine\network\protocol\MoveEntityPacket; use pocketmine\network\protocol\MovePlayerPacket; @@ -306,7 +306,7 @@ class RakLibInterface implements ServerInstance, SourceInterface{ $this->packetPool = new \SplFixedArray(256); $this->registerPacket(ProtocolInfo::LOGIN_PACKET, LoginPacket::class); - $this->registerPacket(ProtocolInfo::LOGIN_STATUS_PACKET, LoginStatusPacket::class); + $this->registerPacket(ProtocolInfo::PLAY_STATUS_PACKET, PlayStatusPacket::class); $this->registerPacket(ProtocolInfo::DISCONNECT_PACKET, DisconnectPacket::class); $this->registerPacket(ProtocolInfo::MESSAGE_PACKET, MessagePacket::class); $this->registerPacket(ProtocolInfo::SET_TIME_PACKET, SetTimePacket::class); diff --git a/src/pocketmine/network/protocol/Info.php b/src/pocketmine/network/protocol/Info.php index 8fea7506c..5b6973835 100644 --- a/src/pocketmine/network/protocol/Info.php +++ b/src/pocketmine/network/protocol/Info.php @@ -33,7 +33,7 @@ interface Info{ const CURRENT_PROTOCOL = 21; const LOGIN_PACKET = 0x82; - const LOGIN_STATUS_PACKET = 0x83; + const PLAY_STATUS_PACKET = 0x83; const DISCONNECT_PACKET = 0x84; diff --git a/src/pocketmine/network/protocol/LoginStatusPacket.php b/src/pocketmine/network/protocol/PlayStatusPacket.php similarity index 83% rename from src/pocketmine/network/protocol/LoginStatusPacket.php rename to src/pocketmine/network/protocol/PlayStatusPacket.php index e3e92d3e9..ca9ec3c0d 100644 --- a/src/pocketmine/network/protocol/LoginStatusPacket.php +++ b/src/pocketmine/network/protocol/PlayStatusPacket.php @@ -24,14 +24,20 @@ namespace pocketmine\network\protocol; #include -class LoginStatusPacket extends DataPacket{ +class PlayStatusPacket extends DataPacket{ + + const LOGIN_SUCCESS = 0; + const LOGIN_FAILED_CLIENT = 1; + const LOGIN_FAILED_SERVER = 2; + const PLAYER_SPAWN = 3; + public static $pool = []; public static $next = 0; public $status; public function pid(){ - return Info::LOGIN_STATUS_PACKET; + return Info::PLAY_STATUS_PACKET; } public function decode(){ @@ -43,4 +49,4 @@ class LoginStatusPacket extends DataPacket{ $this->putInt($this->status); } -} \ No newline at end of file +} diff --git a/src/pocketmine/utils/TextFormat.php b/src/pocketmine/utils/TextFormat.php index 185569d74..25c83624a 100644 --- a/src/pocketmine/utils/TextFormat.php +++ b/src/pocketmine/utils/TextFormat.php @@ -390,6 +390,7 @@ abstract class TextFormat{ foreach($string as $token){ switch($token){ case TextFormat::BOLD: + $newString .= "\x1b[1m"; break; case TextFormat::OBFUSCATED: $newString .= "\x1b[8m"; @@ -409,52 +410,52 @@ abstract class TextFormat{ //Colors case TextFormat::BLACK: - $newString .= "\x1b[0;30m"; + $newString .= "\x1b[38;2;0;0;0m"; break; case TextFormat::DARK_BLUE: - $newString .= "\x1b[0;34m"; + $newString .= "\x1b[38;2;0;0;170m"; break; case TextFormat::DARK_GREEN: - $newString .= "\x1b[0;32m"; + $newString .= "\x1b[38;2;0;170;0m"; break; case TextFormat::DARK_AQUA: - $newString .= "\x1b[0;36m"; + $newString .= "\x1b[38;2;0;170;170m"; break; case TextFormat::DARK_RED: - $newString .= "\x1b[0;31m"; + $newString .= "\x1b[38;2;170;0;0m"; break; case TextFormat::DARK_PURPLE: - $newString .= "\x1b[0;35m"; + $newString .= "\x1b[38;2;170;0;170m"; break; case TextFormat::GOLD: - $newString .= "\x1b[0;33m"; + $newString .= "\x1b[38;2;255;170;0m"; break; case TextFormat::GRAY: - $newString .= "\x1b[0;37m"; + $newString .= "\x1b[38;2;170;170;170m"; break; case TextFormat::DARK_GRAY: - $newString .= "\x1b[30;1m"; + $newString .= "\x1b[38;2;85;85;85m"; break; case TextFormat::BLUE: - $newString .= "\x1b[34;1m"; + $newString .= "\x1b[38;2;85;85;255m"; break; case TextFormat::GREEN: - $newString .= "\x1b[32;1m"; + $newString .= "\x1b[38;2;85;255;85m"; break; case TextFormat::AQUA: - $newString .= "\x1b[36;1m"; + $newString .= "\x1b[38;2;85;255;255m"; break; case TextFormat::RED: - $newString .= "\x1b[31;1m"; + $newString .= "\x1b[38;2;255;85;85m"; break; case TextFormat::LIGHT_PURPLE: - $newString .= "\x1b[35;1m"; + $newString .= "\x1b[38;2;255;85;255m"; break; case TextFormat::YELLOW: - $newString .= "\x1b[33;1m"; + $newString .= "\x1b[38;2;255;255;85m"; break; case TextFormat::WHITE: - $newString .= "\x1b[37;1m"; + $newString .= "\x1b[38;2;255;255;255m"; break; default: $newString .= $token; @@ -465,4 +466,4 @@ abstract class TextFormat{ return $newString; } -} \ No newline at end of file +} From a6c19734ceb4ea05c7854373849bf472569fcd2e Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 12 Mar 2015 11:43:24 +0100 Subject: [PATCH 11/17] Fixed picking up items, entity IDs on packets --- src/pocketmine/Player.php | 10 +--------- src/pocketmine/network/protocol/DropItemPacket.php | 4 ++-- src/pocketmine/network/protocol/InteractPacket.php | 4 ++-- .../network/protocol/PlayerEquipmentPacket.php | 3 +++ src/pocketmine/network/protocol/RemoveBlockPacket.php | 4 ++-- .../network/protocol/TakeItemEntityPacket.php | 2 +- 6 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 052103ee2..889f17cc2 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -645,7 +645,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } } - if($spawned < 16){ + if($spawned < 8){ return; } @@ -1308,10 +1308,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ continue; } - $pk = new TakeItemEntityPacket(); - $pk->eid = $this->getId(); - $pk->target = $entity->getId(); - $this->dataPacket($pk); $pk = new TakeItemEntityPacket(); $pk->eid = $this->getId(); $pk->target = $entity->getId(); @@ -1342,10 +1338,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ break; } - $pk = new TakeItemEntityPacket(); - $pk->eid = $this->getId(); - $pk->target = $entity->getId(); - $this->dataPacket($pk); $pk = new TakeItemEntityPacket(); $pk->eid = $this->getId(); $pk->target = $entity->getId(); diff --git a/src/pocketmine/network/protocol/DropItemPacket.php b/src/pocketmine/network/protocol/DropItemPacket.php index 908b0094b..2e7d12b0a 100644 --- a/src/pocketmine/network/protocol/DropItemPacket.php +++ b/src/pocketmine/network/protocol/DropItemPacket.php @@ -37,7 +37,7 @@ class DropItemPacket extends DataPacket{ } public function decode(){ - $this->eid = $this->getInt(); + $this->eid = $this->getLong(); $this->unknown = $this->getByte(); $this->item = $this->getSlot(); } @@ -46,4 +46,4 @@ class DropItemPacket extends DataPacket{ } -} \ No newline at end of file +} diff --git a/src/pocketmine/network/protocol/InteractPacket.php b/src/pocketmine/network/protocol/InteractPacket.php index 06d52d6a9..9ee88cf7c 100644 --- a/src/pocketmine/network/protocol/InteractPacket.php +++ b/src/pocketmine/network/protocol/InteractPacket.php @@ -38,8 +38,8 @@ class InteractPacket extends DataPacket{ public function decode(){ $this->action = $this->getByte(); - $this->eid = $this->getInt(); - $this->target = $this->getInt(); + $this->eid = $this->getLong(); + $this->target = $this->getLong(); } public function encode(){ diff --git a/src/pocketmine/network/protocol/PlayerEquipmentPacket.php b/src/pocketmine/network/protocol/PlayerEquipmentPacket.php index b5d79ef6a..98619f059 100644 --- a/src/pocketmine/network/protocol/PlayerEquipmentPacket.php +++ b/src/pocketmine/network/protocol/PlayerEquipmentPacket.php @@ -32,6 +32,7 @@ class PlayerEquipmentPacket extends DataPacket{ public $item; public $meta; public $slot; + public $selectedSlot; public function pid(){ return Info::PLAYER_EQUIPMENT_PACKET; @@ -42,6 +43,7 @@ class PlayerEquipmentPacket extends DataPacket{ $this->item = $this->getShort(); $this->meta = $this->getShort(); $this->slot = $this->getByte(); + $this->selectedSlot = $this->getByte(); } public function encode(){ @@ -50,6 +52,7 @@ class PlayerEquipmentPacket extends DataPacket{ $this->putShort($this->item); $this->putShort($this->meta); $this->putByte($this->slot); + $this->putByte($this->selectedSlot); } } diff --git a/src/pocketmine/network/protocol/RemoveBlockPacket.php b/src/pocketmine/network/protocol/RemoveBlockPacket.php index 4b9348958..c0c9b4992 100644 --- a/src/pocketmine/network/protocol/RemoveBlockPacket.php +++ b/src/pocketmine/network/protocol/RemoveBlockPacket.php @@ -38,7 +38,7 @@ class RemoveBlockPacket extends DataPacket{ } public function decode(){ - $this->eid = $this->getInt(); + $this->eid = $this->getLong(); $this->x = $this->getInt(); $this->z = $this->getInt(); $this->y = $this->getByte(); @@ -48,4 +48,4 @@ class RemoveBlockPacket extends DataPacket{ } -} \ No newline at end of file +} diff --git a/src/pocketmine/network/protocol/TakeItemEntityPacket.php b/src/pocketmine/network/protocol/TakeItemEntityPacket.php index 5fef8888c..cdc8fe648 100644 --- a/src/pocketmine/network/protocol/TakeItemEntityPacket.php +++ b/src/pocketmine/network/protocol/TakeItemEntityPacket.php @@ -41,7 +41,7 @@ class TakeItemEntityPacket extends DataPacket{ public function encode(){ $this->reset(); - $this->putInt($this->target); + $this->putLong($this->target); $this->putLong($this->eid); } From 3af784012c1a5dcc84435dc341047141ee93380e Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 12 Mar 2015 15:38:17 +0100 Subject: [PATCH 12/17] Fixed packets --- src/pocketmine/Player.php | 7 +------ src/pocketmine/network/RakLibInterface.php | 4 ++-- src/pocketmine/network/protocol/Info.php | 2 +- .../{EntityDataPacket.php => TileEntityDataPacket.php} | 6 +++--- src/pocketmine/tile/Spawnable.php | 6 +++--- 5 files changed, 10 insertions(+), 15 deletions(-) rename src/pocketmine/network/protocol/{EntityDataPacket.php => TileEntityDataPacket.php} (93%) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 889f17cc2..85b668ddc 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2342,12 +2342,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ break; - case ProtocolInfo::SEND_INVENTORY_PACKET: //TODO, Mojang, enable this ยด^_^` - if($this->spawned === false){ - break; - } - break; - case ProtocolInfo::ENTITY_DATA_PACKET: + case ProtocolInfo::TILE_ENTITY_DATA_PACKET: if($this->spawned === false or $this->blocked === true or $this->dead === true){ break; } diff --git a/src/pocketmine/network/RakLibInterface.php b/src/pocketmine/network/RakLibInterface.php index a9384f470..55b406249 100644 --- a/src/pocketmine/network/RakLibInterface.php +++ b/src/pocketmine/network/RakLibInterface.php @@ -40,7 +40,7 @@ use pocketmine\network\protocol\ContainerSetDataPacket; use pocketmine\network\protocol\ContainerSetSlotPacket; use pocketmine\network\protocol\DataPacket; use pocketmine\network\protocol\DropItemPacket; -use pocketmine\network\protocol\EntityDataPacket; +use pocketmine\network\protocol\TileEntityDataPacket; use pocketmine\network\protocol\EntityEventPacket; use pocketmine\network\protocol\ExplodePacket; use pocketmine\network\protocol\HurtArmorPacket; @@ -348,7 +348,7 @@ class RakLibInterface implements ServerInstance, SourceInterface{ $this->registerPacket(ProtocolInfo::CONTAINER_SET_CONTENT_PACKET, ContainerSetContentPacket::class); $this->registerPacket(ProtocolInfo::CHAT_PACKET, ChatPacket::class); $this->registerPacket(ProtocolInfo::ADVENTURE_SETTINGS_PACKET, AdventureSettingsPacket::class); - $this->registerPacket(ProtocolInfo::ENTITY_DATA_PACKET, EntityDataPacket::class); + $this->registerPacket(ProtocolInfo::TILE_ENTITY_DATA_PACKET, TileEntityDataPacket::class); $this->registerPacket(ProtocolInfo::SET_DIFFICULTY_PACKET, SetDifficultyPacket::class); } diff --git a/src/pocketmine/network/protocol/Info.php b/src/pocketmine/network/protocol/Info.php index 5b6973835..9b4a938fb 100644 --- a/src/pocketmine/network/protocol/Info.php +++ b/src/pocketmine/network/protocol/Info.php @@ -89,7 +89,7 @@ interface Info{ //const CONTAINER_ACK_PACKET = 0xad; const CHAT_PACKET = 0xae; const ADVENTURE_SETTINGS_PACKET = 0xaf; - const ENTITY_DATA_PACKET = 0xb0; + const TILE_ENTITY_DATA_PACKET = 0xb0; //const PLAYER_INPUT_PACKET = 0xb1; const FULL_CHUNK_DATA_PACKET = 0xb2; const SET_DIFFICULTY_PACKET = 0xb3; diff --git a/src/pocketmine/network/protocol/EntityDataPacket.php b/src/pocketmine/network/protocol/TileEntityDataPacket.php similarity index 93% rename from src/pocketmine/network/protocol/EntityDataPacket.php rename to src/pocketmine/network/protocol/TileEntityDataPacket.php index 3b0063821..e8f4bd888 100644 --- a/src/pocketmine/network/protocol/EntityDataPacket.php +++ b/src/pocketmine/network/protocol/TileEntityDataPacket.php @@ -24,7 +24,7 @@ namespace pocketmine\network\protocol; #include -class EntityDataPacket extends DataPacket{ +class TileEntityDataPacket extends DataPacket{ public static $pool = []; public static $next = 0; @@ -34,7 +34,7 @@ class EntityDataPacket extends DataPacket{ public $namedtag; public function pid(){ - return Info::ENTITY_DATA_PACKET; + return Info::TILE_ENTITY_DATA_PACKET; } public function decode(){ @@ -52,4 +52,4 @@ class EntityDataPacket extends DataPacket{ $this->put($this->namedtag); } -} \ No newline at end of file +} diff --git a/src/pocketmine/tile/Spawnable.php b/src/pocketmine/tile/Spawnable.php index 794e1d153..c7fb287cf 100644 --- a/src/pocketmine/tile/Spawnable.php +++ b/src/pocketmine/tile/Spawnable.php @@ -24,7 +24,7 @@ namespace pocketmine\tile; use pocketmine\level\format\FullChunk; use pocketmine\nbt\NBT; use pocketmine\nbt\tag\Compound; -use pocketmine\network\protocol\EntityDataPacket; +use pocketmine\network\protocol\TileEntityDataPacket; use pocketmine\Player; abstract class Spawnable extends Tile{ @@ -36,7 +36,7 @@ abstract class Spawnable extends Tile{ $nbt = new NBT(NBT::LITTLE_ENDIAN); $nbt->setData($this->getSpawnCompound()); - $pk = new EntityDataPacket(); + $pk = new TileEntityDataPacket(); $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; @@ -64,4 +64,4 @@ abstract class Spawnable extends Tile{ } } } -} \ No newline at end of file +} From 7f9aad68404bdb801a871593757e3812c8fe3649 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Thu, 12 Mar 2015 15:58:10 +0100 Subject: [PATCH 13/17] Removed player foreach on Entity --- src/pocketmine/entity/Entity.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 8a60e6a43..402c64975 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -329,11 +329,7 @@ abstract class Entity extends Location implements Metadatable{ $pk = new SetEntityDataPacket(); $pk->eid = $this->id; $pk->metadata = $this->getData(); - $pk->encode(); - $pk->isEncoded = true; - foreach($player as $p){ - $p->dataPacket($pk); - } + Server::broadcastPacket($player, $pk); } /** From 1ce7cc64a6a3e9c404dd87e350f653990d106b41 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 13 Mar 2015 10:25:48 +0100 Subject: [PATCH 14/17] Use ContainerSetSlotPacket instead of ContainerSetContentsPacket --- src/pocketmine/inventory/PlayerInventory.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/pocketmine/inventory/PlayerInventory.php b/src/pocketmine/inventory/PlayerInventory.php index 83cc156ec..913ff2fd6 100644 --- a/src/pocketmine/inventory/PlayerInventory.php +++ b/src/pocketmine/inventory/PlayerInventory.php @@ -146,9 +146,7 @@ class PlayerInventory extends BaseInventory{ foreach($target as $player){ if($player === $this->getHolder()){ - //TODO: Check if Mojang enabled sending a single slot this - //$this->sendSlot($this->getHeldItemSlot()); - $this->sendContents($player); + $this->sendSlot($this->getHeldItemSlot()); }else{ $player->dataPacket($pk); } @@ -393,9 +391,6 @@ class PlayerInventory extends BaseInventory{ foreach($target as $player){ if($player === $this->getHolder()){ /** @var Player $player */ - //$pk2 = clone $pk; - //$pk2->eid = 0; - $pk2 = new ContainerSetSlotPacket(); $pk2->windowid = 0x78; //Armor window id constant $pk2->slot = $index; @@ -454,7 +449,8 @@ class PlayerInventory extends BaseInventory{ foreach($target as $player){ if($player === $this->getHolder()){ /** @var Player $player */ - $this->sendContents($player); //#blamemojang + $pk->windowid = 0; + $player->dataPacket(clone $pk); }else{ if(($id = $player->getWindowId($this)) === -1){ $this->close($player); @@ -473,4 +469,4 @@ class PlayerInventory extends BaseInventory{ return parent::getHolder(); } -} \ No newline at end of file +} From e48a3e5713b8b008975f0e20ec851ebe89509cfd Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 13 Mar 2015 14:24:19 +0100 Subject: [PATCH 15/17] Added some types of Particles, Block break particles --- src/pocketmine/Player.php | 2 +- src/pocketmine/level/Level.php | 13 +++++ .../level/particle/DestroyBlockParticle.php | 47 ++++++++++++++++++ .../level/particle/ExplodeParticle.php | 42 ++++++++++++++++ .../level/particle/MobSpawnParticle.php | 48 +++++++++++++++++++ src/pocketmine/level/particle/Particle.php | 34 +++++++++++++ src/pocketmine/network/protocol/Info.php | 2 +- .../network/protocol/LevelEventPacket.php | 4 +- 8 files changed, 188 insertions(+), 4 deletions(-) create mode 100644 src/pocketmine/level/particle/DestroyBlockParticle.php create mode 100644 src/pocketmine/level/particle/ExplodeParticle.php create mode 100644 src/pocketmine/level/particle/MobSpawnParticle.php create mode 100644 src/pocketmine/level/particle/Particle.php diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 85b668ddc..0aa092d17 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1246,7 +1246,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->lastUpdate = $currentTick; - if($this->spawned){ + if($this->spawned){ $this->processMovement($currentTick); $this->entityBaseTick(1); diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index e19538be8..d2598a42e 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -95,6 +95,8 @@ use pocketmine\utils\LevelException; use pocketmine\utils\MainLogger; use pocketmine\utils\ReversePriorityQueue; use pocketmine\utils\TextFormat; +use pocketmine\level\particle\Particle; +use pocketmine\level\particle\DestroyBlockParticle; #include @@ -355,6 +357,13 @@ class Level implements ChunkManager, Metadatable{ $this->blockCache = []; $this->temporalPosition = null; } + + public function addParticle(Particle $particle){ + $pk = $particle->encode(); + if($pk !== null){ + Server::broadcastPacket($this->getUsingChunk($particle->x >> 4, $particle->z >> 4), $pk); + } + } /** * @return bool @@ -1259,7 +1268,11 @@ class Level implements ChunkManager, Metadatable{ } } $drops = $target->getDrops($item); //Fixes tile entities being deleted before getting drops + + $this->addParticle(new DestroyBlockParticle($target, $target)); + $target->onBreak($item); + $tile = $this->getTile($target); if($tile instanceof Tile){ if($tile instanceof InventoryHolder){ diff --git a/src/pocketmine/level/particle/DestroyBlockParticle.php b/src/pocketmine/level/particle/DestroyBlockParticle.php new file mode 100644 index 000000000..eae28f775 --- /dev/null +++ b/src/pocketmine/level/particle/DestroyBlockParticle.php @@ -0,0 +1,47 @@ +x, $pos->y, $pos->z); + $this->data = $b->getId() + ($b->getDamage() << 12); + } + + public function encode(){ + $pk = new LevelEventPacket; + $pk->evid = 2001; + $pk->x = $this->x; + $pk->y = $this->y; + $pk->z = $this->z; + $pk->data = $this->data; + + return $pk; + } +} diff --git a/src/pocketmine/level/particle/ExplodeParticle.php b/src/pocketmine/level/particle/ExplodeParticle.php new file mode 100644 index 000000000..7317c5e95 --- /dev/null +++ b/src/pocketmine/level/particle/ExplodeParticle.php @@ -0,0 +1,42 @@ +x, $pos->y, $pos->z); + } + + public function encode(){ + $pk = new ExplodePacket; + $pk->x = $this->x; + $pk->y = $this->y; + $pk->z = $this->z; + $pk->radius = 0; + + return $pk; + } +} diff --git a/src/pocketmine/level/particle/MobSpawnParticle.php b/src/pocketmine/level/particle/MobSpawnParticle.php new file mode 100644 index 000000000..b65fa7ae6 --- /dev/null +++ b/src/pocketmine/level/particle/MobSpawnParticle.php @@ -0,0 +1,48 @@ +x, $pos->y, $pos->z); + $this->width = $width; + $this->height = $height; + } + + public function encode(){ + $pk = new LevelEventPacket; + $pk->evid = 2004; + $pk->x = $this->x; + $pk->y = $this->y; + $pk->z = $this->z; + $pk->data = 0; + + return $pk; + } +} diff --git a/src/pocketmine/level/particle/Particle.php b/src/pocketmine/level/particle/Particle.php new file mode 100644 index 000000000..66ce268ee --- /dev/null +++ b/src/pocketmine/level/particle/Particle.php @@ -0,0 +1,34 @@ +reset(); $this->putShort($this->evid); $this->putInt($this->x); - $this->putShort($this->y); + $this->putByte($this->y); $this->putInt($this->z); $this->putInt($this->data); } -} \ No newline at end of file +} From 9e0b9a6e5b3427d62575285702ccf8eb2d8a4495 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 13 Mar 2015 14:39:37 +0100 Subject: [PATCH 16/17] Added right and left click interaction events --- src/pocketmine/Player.php | 7 ++++++- .../event/player/PlayerInteractEvent.php | 17 +++++++++++++++-- src/pocketmine/level/Level.php | 4 ++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 0aa092d17..7888249ae 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1749,7 +1749,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } $target = $this->level->getBlock($blockVector); - $ev = new PlayerInteractEvent($this, $item, $target, $packet->face); + $ev = new PlayerInteractEvent($this, $item, $target, $packet->face, PlayerInteractEvent::RIGHT_CLICK_AIR); $this->server->getPluginManager()->callEvent($ev); @@ -1807,6 +1807,11 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $packet->eid = $this->id; switch($packet->action){ + case 0: //Start break + $target = $this->level->getBlock(new Vector3($packet->x, $packet->y, $packet->z)); + $ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $target, $packet->face, $target->getId() === 0 ? PlayerInteractEvent::LEFT_CLICK_AIR : PlayerInteractEvent::LEFT_CLICK_BLOCK); + $this->lastBreak = microtime(true); + break; case 5: //Shot arrow if($this->inventory->getItemInHand()->getId() === Item::BOW){ $bow = $this->inventory->getItemInHand(); diff --git a/src/pocketmine/event/player/PlayerInteractEvent.php b/src/pocketmine/event/player/PlayerInteractEvent.php index 20a7c2f6a..c35b843bb 100644 --- a/src/pocketmine/event/player/PlayerInteractEvent.php +++ b/src/pocketmine/event/player/PlayerInteractEvent.php @@ -32,6 +32,12 @@ use pocketmine\Player; class PlayerInteractEvent extends PlayerEvent implements Cancellable{ public static $handlerList = null; + const LEFT_CLICK_BLOCK = 0; + const RIGHT_CLICK_BLOCK = 1; + const LEFT_CLICK_AIR = 2; + const RIGHT_CLICK_AIR = 3; + const PHYSICAL = 4; + /** * @var \pocketmine\block\Block; */ @@ -42,12 +48,19 @@ class PlayerInteractEvent extends PlayerEvent implements Cancellable{ /** @var \pocketmine\item\Item */ protected $item; + + protected $action; - public function __construct(Player $player, Item $item, Block $block, $face){ + public function __construct(Player $player, Item $item, Block $block, $face, $action = PlayerInteractEvent::RIGHT_CLICK){ $this->blockTouched = $block; $this->player = $player; $this->item = $item; $this->blockFace = (int) $face; + $this->action = (int) $action; + } + + public function getAction(){ + return $this->action; } public function getItem(){ @@ -61,4 +74,4 @@ class PlayerInteractEvent extends PlayerEvent implements Cancellable{ public function getFace(){ return $this->blockFace; } -} \ No newline at end of file +} diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index d2598a42e..c0e9ea29a 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1252,7 +1252,7 @@ class Level implements ChunkManager, Metadatable{ return false; } - $player->lastBreak = microtime(true); + $player->lastBreak = PHP_INT_MAX; }elseif($item instanceof Item and !$target->isBreakable($item)){ return false; } @@ -1332,7 +1332,7 @@ class Level implements ChunkManager, Metadatable{ } if($player instanceof Player){ - $ev = new PlayerInteractEvent($player, $item, $target, $face); + $ev = new PlayerInteractEvent($player, $item, $target, $face, $target->getId() === 0 ? PlayerInteractEvent::RIGHT_CLICK_AIR : PlayerInteractEvent::RIGHT_CLICK_BLOCK); if(!$player->isOp() and ($distance = $this->server->getSpawnRadius()) > -1){ $t = new Vector2($target->x, $target->z); $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z); From 91e8bdbd371dcccf7cc90deee0fdca91ef353dc8 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Fri, 13 Mar 2015 16:21:33 +0100 Subject: [PATCH 17/17] Fixed size on MobSpawnParticle --- src/pocketmine/Player.php | 2 +- src/pocketmine/level/particle/MobSpawnParticle.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 7888249ae..f4151a8af 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1246,7 +1246,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->lastUpdate = $currentTick; - if($this->spawned){ + if($this->spawned){ $this->processMovement($currentTick); $this->entityBaseTick(1); diff --git a/src/pocketmine/level/particle/MobSpawnParticle.php b/src/pocketmine/level/particle/MobSpawnParticle.php index b65fa7ae6..379b8b854 100644 --- a/src/pocketmine/level/particle/MobSpawnParticle.php +++ b/src/pocketmine/level/particle/MobSpawnParticle.php @@ -41,7 +41,7 @@ class MobSpawnParticle extends Particle{ $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; - $pk->data = 0; + $pk->data = ($this->width & 0xff) + (($this->height & 0xff) << 8); return $pk; }