diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 218ba9f0b..4791dd01a 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -146,6 +146,7 @@ use pocketmine\network\mcpe\protocol\types\CommandEnum; use pocketmine\network\mcpe\protocol\types\CommandParameter; use pocketmine\network\mcpe\protocol\types\ContainerIds; use pocketmine\network\mcpe\protocol\types\DimensionIds; +use pocketmine\network\mcpe\protocol\types\GameMode; use pocketmine\network\mcpe\protocol\types\PersonaPieceTintColor; use pocketmine\network\mcpe\protocol\types\PersonaSkinPiece; use pocketmine\network\mcpe\protocol\types\PlayerPermissions; @@ -1333,12 +1334,13 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ * TODO: remove this when Spectator Mode gets added properly to MCPE */ public static function getClientFriendlyGamemode(int $gamemode) : int{ - $gamemode &= 0x03; - if($gamemode === Player::SPECTATOR){ - return Player::CREATIVE; - } - - return $gamemode; + static $map = [ + self::SURVIVAL => GameMode::SURVIVAL, + self::CREATIVE => GameMode::CREATIVE, + self::ADVENTURE => GameMode::ADVENTURE, + self::SPECTATOR => GameMode::CREATIVE + ]; + return $map[$gamemode & 0x3]; } /** diff --git a/src/pocketmine/event/player/PlayerQuitEvent.php b/src/pocketmine/event/player/PlayerQuitEvent.php index 5af86865b..4b1585384 100644 --- a/src/pocketmine/event/player/PlayerQuitEvent.php +++ b/src/pocketmine/event/player/PlayerQuitEvent.php @@ -24,7 +24,6 @@ declare(strict_types=1); namespace pocketmine\event\player; use pocketmine\lang\TextContainer; -use pocketmine\lang\TranslationContainer; use pocketmine\Player; /** diff --git a/src/pocketmine/network/mcpe/NetworkBinaryStream.php b/src/pocketmine/network/mcpe/NetworkBinaryStream.php index 9d9b121ef..fdef68675 100644 --- a/src/pocketmine/network/mcpe/NetworkBinaryStream.php +++ b/src/pocketmine/network/mcpe/NetworkBinaryStream.php @@ -37,6 +37,7 @@ use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\IntTag; use pocketmine\network\mcpe\protocol\types\CommandOriginData; use pocketmine\network\mcpe\protocol\types\EntityLink; +use pocketmine\network\mcpe\protocol\types\GameRuleType; use pocketmine\network\mcpe\protocol\types\PersonaPieceTintColor; use pocketmine\network\mcpe\protocol\types\PersonaSkinPiece; use pocketmine\network\mcpe\protocol\types\SkinAnimation; @@ -602,13 +603,13 @@ class NetworkBinaryStream extends BinaryStream{ $type = $this->getUnsignedVarInt(); $value = null; switch($type){ - case 1: + case GameRuleType::BOOL: $value = $this->getBool(); break; - case 2: + case GameRuleType::INT: $value = $this->getUnsignedVarInt(); break; - case 3: + case GameRuleType::FLOAT: $value = $this->getLFloat(); break; } @@ -632,13 +633,13 @@ class NetworkBinaryStream extends BinaryStream{ $this->putString($name); $this->putUnsignedVarInt($rule[0]); switch($rule[0]){ - case 1: + case GameRuleType::BOOL: $this->putBool($rule[1]); break; - case 2: + case GameRuleType::INT: $this->putUnsignedVarInt($rule[1]); break; - case 3: + case GameRuleType::FLOAT: $this->putLFloat($rule[1]); break; } @@ -671,7 +672,7 @@ class NetworkBinaryStream extends BinaryStream{ $result->requestId = $this->getString(); if($result->type === CommandOriginData::ORIGIN_DEV_CONSOLE or $result->type === CommandOriginData::ORIGIN_TEST){ - $result->varlong1 = $this->getVarLong(); + $result->playerEntityUniqueId = $this->getVarLong(); } return $result; @@ -683,7 +684,7 @@ class NetworkBinaryStream extends BinaryStream{ $this->putString($data->requestId); if($data->type === CommandOriginData::ORIGIN_DEV_CONSOLE or $data->type === CommandOriginData::ORIGIN_TEST){ - $this->putVarLong($data->varlong1); + $this->putVarLong($data->playerEntityUniqueId); } } diff --git a/src/pocketmine/network/mcpe/protocol/LoginPacket.php b/src/pocketmine/network/mcpe/protocol/LoginPacket.php index 5e8a5a8ed..836ed7e97 100644 --- a/src/pocketmine/network/mcpe/protocol/LoginPacket.php +++ b/src/pocketmine/network/mcpe/protocol/LoginPacket.php @@ -35,8 +35,6 @@ use function json_decode; class LoginPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::LOGIN_PACKET; - public const EDITION_POCKET = 0; - /** @var string */ public $username; /** @var int */ diff --git a/src/pocketmine/network/mcpe/protocol/MoveActorAbsolutePacket.php b/src/pocketmine/network/mcpe/protocol/MoveActorAbsolutePacket.php index 7e0e7b548..71766cc48 100644 --- a/src/pocketmine/network/mcpe/protocol/MoveActorAbsolutePacket.php +++ b/src/pocketmine/network/mcpe/protocol/MoveActorAbsolutePacket.php @@ -33,6 +33,7 @@ class MoveActorAbsolutePacket extends DataPacket{ public const FLAG_GROUND = 0x01; public const FLAG_TELEPORT = 0x02; + public const FLAG_FORCE_MOVE_LOCAL_ENTITY = 0x04; /** @var int */ public $entityRuntimeId; diff --git a/src/pocketmine/network/mcpe/protocol/MoveActorDeltaPacket.php b/src/pocketmine/network/mcpe/protocol/MoveActorDeltaPacket.php index 1728b936d..ffae8449f 100644 --- a/src/pocketmine/network/mcpe/protocol/MoveActorDeltaPacket.php +++ b/src/pocketmine/network/mcpe/protocol/MoveActorDeltaPacket.php @@ -36,6 +36,9 @@ class MoveActorDeltaPacket extends DataPacket{ public const FLAG_HAS_ROT_X = 0x08; public const FLAG_HAS_ROT_Y = 0x10; public const FLAG_HAS_ROT_Z = 0x20; + public const FLAG_GROUND = 0x40; + public const FLAG_TELEPORT = 0x80; + public const FLAG_FORCE_MOVE_LOCAL_ENTITY = 0x100; /** @var int */ public $entityRuntimeId; diff --git a/src/pocketmine/network/mcpe/protocol/NpcRequestPacket.php b/src/pocketmine/network/mcpe/protocol/NpcRequestPacket.php index 479221c01..5f9f492a6 100644 --- a/src/pocketmine/network/mcpe/protocol/NpcRequestPacket.php +++ b/src/pocketmine/network/mcpe/protocol/NpcRequestPacket.php @@ -30,6 +30,13 @@ use pocketmine\network\mcpe\NetworkSession; class NpcRequestPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::NPC_REQUEST_PACKET; + public const REQUEST_SET_ACTIONS = 0; + public const REQUEST_EXECUTE_ACTION = 1; + public const REQUEST_EXECUTE_CLOSING_COMMANDS = 2; + public const REQUEST_SET_NAME = 3; + public const REQUEST_SET_SKIN = 4; + public const REQUEST_SET_INTERACTION_TEXT = 5; + /** @var int */ public $entityRuntimeId; /** @var int */ diff --git a/src/pocketmine/network/mcpe/protocol/PlayerActionPacket.php b/src/pocketmine/network/mcpe/protocol/PlayerActionPacket.php index 647c5c573..48eae374a 100644 --- a/src/pocketmine/network/mcpe/protocol/PlayerActionPacket.php +++ b/src/pocketmine/network/mcpe/protocol/PlayerActionPacket.php @@ -49,7 +49,7 @@ class PlayerActionPacket extends DataPacket{ public const ACTION_STOP_GLIDE = 16; public const ACTION_BUILD_DENIED = 17; public const ACTION_CONTINUE_BREAK = 18; - + public const ACTION_CHANGE_SKIN = 19; public const ACTION_SET_ENCHANTMENT_SEED = 20; public const ACTION_START_SWIMMING = 21; public const ACTION_STOP_SWIMMING = 22; diff --git a/src/pocketmine/network/mcpe/protocol/SimpleEventPacket.php b/src/pocketmine/network/mcpe/protocol/SimpleEventPacket.php index 0792f199b..dbca01336 100644 --- a/src/pocketmine/network/mcpe/protocol/SimpleEventPacket.php +++ b/src/pocketmine/network/mcpe/protocol/SimpleEventPacket.php @@ -32,6 +32,7 @@ class SimpleEventPacket extends DataPacket{ public const TYPE_ENABLE_COMMANDS = 1; public const TYPE_DISABLE_COMMANDS = 2; + public const TYPE_UNLOCK_WORLD_TEMPLATE_SETTINGS = 3; /** @var int */ public $eventType; diff --git a/src/pocketmine/network/mcpe/protocol/StartGamePacket.php b/src/pocketmine/network/mcpe/protocol/StartGamePacket.php index bcddf5bab..1b38c0fdf 100644 --- a/src/pocketmine/network/mcpe/protocol/StartGamePacket.php +++ b/src/pocketmine/network/mcpe/protocol/StartGamePacket.php @@ -30,6 +30,10 @@ use pocketmine\nbt\NetworkLittleEndianNBTStream; use pocketmine\nbt\tag\ListTag; use pocketmine\network\mcpe\NetworkBinaryStream; use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\protocol\types\EducationEditionOffer; +use pocketmine\network\mcpe\protocol\types\GameRuleType; +use pocketmine\network\mcpe\protocol\types\GeneratorType; +use pocketmine\network\mcpe\protocol\types\MultiplayerGameVisibility; use pocketmine\network\mcpe\protocol\types\PlayerPermissions; use pocketmine\network\mcpe\protocol\types\RuntimeBlockMapping; use function count; @@ -65,7 +69,7 @@ class StartGamePacket extends DataPacket{ /** @var int */ public $dimension; /** @var int */ - public $generator = 1; //default infinite - 0 old, 1 infinite, 2 flat + public $generator = GeneratorType::OVERWORLD; /** @var int */ public $worldGamemode; /** @var int */ @@ -81,7 +85,7 @@ class StartGamePacket extends DataPacket{ /** @var int */ public $time = -1; /** @var int */ - public $eduEditionOffer = 0; + public $eduEditionOffer = EducationEditionOffer::NONE; /** @var bool */ public $hasEduFeaturesEnabled = false; /** @var float */ @@ -95,9 +99,9 @@ class StartGamePacket extends DataPacket{ /** @var bool */ public $hasLANBroadcast = true; /** @var int */ - public $xboxLiveBroadcastMode = 0; //TODO: find values + public $xboxLiveBroadcastMode = MultiplayerGameVisibility::FRIENDS_OF_FRIENDS; /** @var int */ - public $platformBroadcastMode = 0; + public $platformBroadcastMode = MultiplayerGameVisibility::FRIENDS_OF_FRIENDS; /** @var bool */ public $commandsEnabled; /** @var bool */ @@ -107,7 +111,7 @@ class StartGamePacket extends DataPacket{ * @phpstan-var array */ public $gameRules = [ //TODO: implement this - "naturalregeneration" => [1, false] //Hack for client side regeneration + "naturalregeneration" => [GameRuleType::BOOL, false] //Hack for client side regeneration ]; /** @var bool */ public $hasBonusChestEnabled = false; diff --git a/src/pocketmine/network/mcpe/protocol/UpdateBlockSyncedPacket.php b/src/pocketmine/network/mcpe/protocol/UpdateBlockSyncedPacket.php index 5fce02e5c..a98f2f59e 100644 --- a/src/pocketmine/network/mcpe/protocol/UpdateBlockSyncedPacket.php +++ b/src/pocketmine/network/mcpe/protocol/UpdateBlockSyncedPacket.php @@ -30,21 +30,25 @@ use pocketmine\network\mcpe\NetworkSession; class UpdateBlockSyncedPacket extends UpdateBlockPacket{ public const NETWORK_ID = ProtocolInfo::UPDATE_BLOCK_SYNCED_PACKET; + public const TYPE_NONE = 0; + public const TYPE_CREATE = 1; + public const TYPE_DESTROY = 2; + /** @var int */ - public $entityUniqueId = 0; + public $entityUniqueId; /** @var int */ - public $uvarint64_2 = 0; + public $updateType; protected function decodePayload(){ parent::decodePayload(); $this->entityUniqueId = $this->getUnsignedVarLong(); - $this->uvarint64_2 = $this->getUnsignedVarLong(); + $this->updateType = $this->getUnsignedVarLong(); } protected function encodePayload(){ parent::encodePayload(); $this->putUnsignedVarLong($this->entityUniqueId); - $this->putUnsignedVarLong($this->uvarint64_2); + $this->putUnsignedVarLong($this->updateType); } public function handle(NetworkSession $session) : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/types/CommandOriginData.php b/src/pocketmine/network/mcpe/protocol/types/CommandOriginData.php index ca35b39f7..738cff75a 100644 --- a/src/pocketmine/network/mcpe/protocol/types/CommandOriginData.php +++ b/src/pocketmine/network/mcpe/protocol/types/CommandOriginData.php @@ -48,5 +48,5 @@ class CommandOriginData{ public $requestId; /** @var int */ - public $varlong1; + public $playerEntityUniqueId; } diff --git a/src/pocketmine/network/mcpe/protocol/types/EducationEditionOffer.php b/src/pocketmine/network/mcpe/protocol/types/EducationEditionOffer.php new file mode 100644 index 000000000..eedf874aa --- /dev/null +++ b/src/pocketmine/network/mcpe/protocol/types/EducationEditionOffer.php @@ -0,0 +1,35 @@ +x = $this->y; $this->y = $this->z; $this->z = $this->w; - $this->w = ($this->w ^ (($this->w >> 19) & 0x7fffffff) - ^ ($t ^ (($t >> 8) & 0x7fffffff))) & 0xffffffff; + $this->w = ($this->w ^ (($this->w >> 19) & 0x7fffffff) ^ ($t ^ (($t >> 8) & 0x7fffffff))) & 0xffffffff; return $this->w; } diff --git a/src/pocketmine/utils/Terminal.php b/src/pocketmine/utils/Terminal.php index e129cfae5..22071cf23 100644 --- a/src/pocketmine/utils/Terminal.php +++ b/src/pocketmine/utils/Terminal.php @@ -28,6 +28,7 @@ use function fopen; use function function_exists; use function getenv; use function is_array; +use function sapi_windows_vt100_support; use function stream_isatty; abstract class Terminal{