mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
do not rely on GameMode::getMagicNumber() to match protocol IDs
This commit is contained in:
@ -56,7 +56,7 @@ class TypeConverter{
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function getClientFriendlyGamemode(GameMode $gamemode) : int{
|
||||
public function coreGameModeToProtocol(GameMode $gamemode) : int{
|
||||
switch($gamemode->id()){
|
||||
case GameMode::SURVIVAL()->id():
|
||||
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{
|
||||
$meta = $itemStack->getMeta();
|
||||
return new RecipeIngredient($itemStack->getId(), $meta === -1 ? 0x7fff : $meta, $itemStack->getCount());
|
||||
|
Reference in New Issue
Block a user