mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-17 11:18:52 +00:00
do not rely on GameMode::getMagicNumber() to match protocol IDs
This commit is contained in:
parent
5c16261374
commit
465285b3c2
@ -684,7 +684,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(TypeConverter::getInstance()->getClientFriendlyGamemode($mode)));
|
$this->sendDataPacket(SetPlayerGameTypePacket::create(TypeConverter::getInstance()->coreGameModeToProtocol($mode)));
|
||||||
$this->syncAdventureSettings($this->player);
|
$this->syncAdventureSettings($this->player);
|
||||||
if(!$isRollback){
|
if(!$isRollback){
|
||||||
$this->invManager->syncCreative();
|
$this->invManager->syncCreative();
|
||||||
|
@ -56,7 +56,7 @@ class TypeConverter{
|
|||||||
*
|
*
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
public function getClientFriendlyGamemode(GameMode $gamemode) : int{
|
public function coreGameModeToProtocol(GameMode $gamemode) : int{
|
||||||
switch($gamemode->id()){
|
switch($gamemode->id()){
|
||||||
case GameMode::SURVIVAL()->id():
|
case GameMode::SURVIVAL()->id():
|
||||||
return ProtocolGameMode::SURVIVAL;
|
return ProtocolGameMode::SURVIVAL;
|
||||||
@ -70,6 +70,22 @@ class TypeConverter{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function protocolGameModeToCore(int $gameMode) : GameMode{
|
||||||
|
switch($gameMode){
|
||||||
|
case ProtocolGameMode::SURVIVAL:
|
||||||
|
return GameMode::SURVIVAL();
|
||||||
|
case ProtocolGameMode::CREATIVE:
|
||||||
|
return GameMode::CREATIVE();
|
||||||
|
case ProtocolGameMode::ADVENTURE:
|
||||||
|
return GameMode::ADVENTURE();
|
||||||
|
case ProtocolGameMode::CREATIVE_VIEWER:
|
||||||
|
case ProtocolGameMode::SURVIVAL_VIEWER:
|
||||||
|
return GameMode::SPECTATOR();
|
||||||
|
default:
|
||||||
|
throw new \UnexpectedValueException("Unmapped protocol game mode $gameMode");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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());
|
||||||
|
@ -582,7 +582,8 @@ class InGamePacketHandler extends PacketHandler{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function handleSetPlayerGameType(SetPlayerGameTypePacket $packet) : bool{
|
public function handleSetPlayerGameType(SetPlayerGameTypePacket $packet) : bool{
|
||||||
if($packet->gamemode !== $this->player->getGamemode()->getMagicNumber()){
|
$converter = TypeConverter::getInstance();
|
||||||
|
if(!$converter->protocolGameModeToCore($packet->gamemode)->equals($this->player->getGamemode())){
|
||||||
//Set this back to default. TODO: handle this properly
|
//Set this back to default. TODO: handle this properly
|
||||||
$this->session->syncGameMode($this->player->getGamemode(), true);
|
$this->session->syncGameMode($this->player->getGamemode(), true);
|
||||||
}
|
}
|
||||||
|
@ -59,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 = TypeConverter::getInstance()->getClientFriendlyGamemode($this->player->getGamemode());
|
$pk->playerGamemode = TypeConverter::getInstance()->coreGameModeToProtocol($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 = TypeConverter::getInstance()->getClientFriendlyGamemode($this->server->getGamemode());
|
$pk->worldGamemode = TypeConverter::getInstance()->coreGameModeToProtocol($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();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user