mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-14 17:59:41 +00:00
Merge commit '3ec2994d7f05f30e2519430379ae0f3106be5074'
# Conflicts: # resources/vanilla # src/pocketmine/Player.php
This commit is contained in:
commit
570a709059
@ -682,7 +682,7 @@ class NetworkSession{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function syncGameMode(GameMode $mode, bool $isRollback = false) : void{
|
public function syncGameMode(GameMode $mode, bool $isRollback = false) : void{
|
||||||
$this->sendDataPacket(SetPlayerGameTypePacket::create(self::getClientFriendlyGamemode($mode)));
|
$this->sendDataPacket(SetPlayerGameTypePacket::create(TypeConverter::getInstance()->getClientFriendlyGamemode($mode)));
|
||||||
$this->syncAdventureSettings($this->player);
|
$this->syncAdventureSettings($this->player);
|
||||||
if(!$isRollback){
|
if(!$isRollback){
|
||||||
$this->invManager->syncCreative();
|
$this->invManager->syncCreative();
|
||||||
@ -943,18 +943,4 @@ class NetworkSession{
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a client-friendly gamemode of the specified real gamemode
|
|
||||||
* This function takes care of handling gamemodes known to MCPE (as of 1.1.0.3, that includes Survival, Creative and Adventure)
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
public static function getClientFriendlyGamemode(GameMode $gamemode) : int{
|
|
||||||
if($gamemode->equals(GameMode::SPECTATOR())){
|
|
||||||
return GameMode::CREATIVE()->getMagicNumber();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $gamemode->getMagicNumber();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -34,11 +34,14 @@ use pocketmine\item\ItemFactory;
|
|||||||
use pocketmine\item\ItemIds;
|
use pocketmine\item\ItemIds;
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\nbt\tag\IntTag;
|
use pocketmine\nbt\tag\IntTag;
|
||||||
|
use pocketmine\network\mcpe\protocol\types\GameMode as ProtocolGameMode;
|
||||||
use pocketmine\network\mcpe\protocol\types\inventory\ContainerIds;
|
use pocketmine\network\mcpe\protocol\types\inventory\ContainerIds;
|
||||||
use pocketmine\network\mcpe\protocol\types\inventory\ItemStack;
|
use pocketmine\network\mcpe\protocol\types\inventory\ItemStack;
|
||||||
use pocketmine\network\mcpe\protocol\types\inventory\NetworkInventoryAction;
|
use pocketmine\network\mcpe\protocol\types\inventory\NetworkInventoryAction;
|
||||||
use pocketmine\network\mcpe\protocol\types\recipe\RecipeIngredient;
|
use pocketmine\network\mcpe\protocol\types\recipe\RecipeIngredient;
|
||||||
|
use pocketmine\player\GameMode;
|
||||||
use pocketmine\player\Player;
|
use pocketmine\player\Player;
|
||||||
|
use pocketmine\utils\AssumptionFailedError;
|
||||||
use pocketmine\utils\SingletonTrait;
|
use pocketmine\utils\SingletonTrait;
|
||||||
|
|
||||||
class TypeConverter{
|
class TypeConverter{
|
||||||
@ -47,6 +50,26 @@ class TypeConverter{
|
|||||||
private const DAMAGE_TAG = "Damage"; //TAG_Int
|
private const DAMAGE_TAG = "Damage"; //TAG_Int
|
||||||
private const DAMAGE_TAG_CONFLICT_RESOLUTION = "___Damage_ProtocolCollisionResolution___";
|
private const DAMAGE_TAG_CONFLICT_RESOLUTION = "___Damage_ProtocolCollisionResolution___";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a client-friendly gamemode of the specified real gamemode
|
||||||
|
* This function takes care of handling gamemodes known to MCPE (as of 1.1.0.3, that includes Survival, Creative and Adventure)
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
public function getClientFriendlyGamemode(GameMode $gamemode) : int{
|
||||||
|
switch($gamemode->id()){
|
||||||
|
case GameMode::SURVIVAL()->id():
|
||||||
|
return ProtocolGameMode::SURVIVAL;
|
||||||
|
case GameMode::CREATIVE()->id():
|
||||||
|
case GameMode::SPECTATOR()->id():
|
||||||
|
return ProtocolGameMode::CREATIVE;
|
||||||
|
case GameMode::ADVENTURE()->id():
|
||||||
|
return ProtocolGameMode::ADVENTURE;
|
||||||
|
default:
|
||||||
|
throw new AssumptionFailedError("Unknown game mode");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function coreItemStackToRecipeIngredient(Item $itemStack) : RecipeIngredient{
|
public function coreItemStackToRecipeIngredient(Item $itemStack) : RecipeIngredient{
|
||||||
$meta = $itemStack->getMeta();
|
$meta = $itemStack->getMeta();
|
||||||
return new RecipeIngredient($itemStack->getId(), $meta === -1 ? 0x7fff : $meta, $itemStack->getCount());
|
return new RecipeIngredient($itemStack->getId(), $meta === -1 ? 0x7fff : $meta, $itemStack->getCount());
|
||||||
|
@ -25,6 +25,7 @@ namespace pocketmine\network\mcpe\handler;
|
|||||||
|
|
||||||
use pocketmine\data\bedrock\LegacyItemIdToStringIdMap;
|
use pocketmine\data\bedrock\LegacyItemIdToStringIdMap;
|
||||||
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
|
use pocketmine\network\mcpe\convert\RuntimeBlockMapping;
|
||||||
|
use pocketmine\network\mcpe\convert\TypeConverter;
|
||||||
use pocketmine\network\mcpe\NetworkSession;
|
use pocketmine\network\mcpe\NetworkSession;
|
||||||
use pocketmine\network\mcpe\protocol\RequestChunkRadiusPacket;
|
use pocketmine\network\mcpe\protocol\RequestChunkRadiusPacket;
|
||||||
use pocketmine\network\mcpe\protocol\StartGamePacket;
|
use pocketmine\network\mcpe\protocol\StartGamePacket;
|
||||||
@ -58,13 +59,13 @@ class PreSpawnPacketHandler extends PacketHandler{
|
|||||||
$pk = new StartGamePacket();
|
$pk = new StartGamePacket();
|
||||||
$pk->entityUniqueId = $this->player->getId();
|
$pk->entityUniqueId = $this->player->getId();
|
||||||
$pk->entityRuntimeId = $this->player->getId();
|
$pk->entityRuntimeId = $this->player->getId();
|
||||||
$pk->playerGamemode = NetworkSession::getClientFriendlyGamemode($this->player->getGamemode());
|
$pk->playerGamemode = TypeConverter::getInstance()->getClientFriendlyGamemode($this->player->getGamemode());
|
||||||
$pk->playerPosition = $this->player->getOffsetPosition($location);
|
$pk->playerPosition = $this->player->getOffsetPosition($location);
|
||||||
$pk->pitch = $location->pitch;
|
$pk->pitch = $location->pitch;
|
||||||
$pk->yaw = $location->yaw;
|
$pk->yaw = $location->yaw;
|
||||||
$pk->seed = -1;
|
$pk->seed = -1;
|
||||||
$pk->dimension = DimensionIds::OVERWORLD; //TODO: implement this properly
|
$pk->dimension = DimensionIds::OVERWORLD; //TODO: implement this properly
|
||||||
$pk->worldGamemode = NetworkSession::getClientFriendlyGamemode($this->server->getGamemode());
|
$pk->worldGamemode = TypeConverter::getInstance()->getClientFriendlyGamemode($this->server->getGamemode());
|
||||||
$pk->difficulty = $location->getWorldNonNull()->getDifficulty();
|
$pk->difficulty = $location->getWorldNonNull()->getDifficulty();
|
||||||
$pk->spawnX = $spawnPosition->getFloorX();
|
$pk->spawnX = $spawnPosition->getFloorX();
|
||||||
$pk->spawnY = $spawnPosition->getFloorY();
|
$pk->spawnY = $spawnPosition->getFloorY();
|
||||||
|
38
src/network/mcpe/protocol/types/GameMode.php
Normal file
38
src/network/mcpe/protocol/types/GameMode.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace pocketmine\network\mcpe\protocol\types;
|
||||||
|
|
||||||
|
final class GameMode{
|
||||||
|
|
||||||
|
private function __construct(){
|
||||||
|
//NOOP
|
||||||
|
}
|
||||||
|
|
||||||
|
public const SURVIVAL = 0;
|
||||||
|
public const CREATIVE = 1;
|
||||||
|
public const ADVENTURE = 2;
|
||||||
|
public const SURVIVAL_VIEWER = 3;
|
||||||
|
public const CREATIVE_VIEWER = 4;
|
||||||
|
public const DEFAULT = 5;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user