Separate ID handling from GameMode

the aliases of 0,1,2,3 remain for user-interface level compatibility.
This commit is contained in:
Dylan K. Taylor
2021-06-27 20:32:35 +01:00
parent 5cdf0b169f
commit 902ea515f7
7 changed files with 83 additions and 31 deletions

View File

@ -29,6 +29,7 @@ use pocketmine\block\UnknownBlock;
use pocketmine\block\VanillaBlocks;
use pocketmine\command\CommandSender;
use pocketmine\crafting\CraftingGrid;
use pocketmine\data\java\GameModeIdMap;
use pocketmine\entity\animation\Animation;
use pocketmine\entity\animation\ArmSwingAnimation;
use pocketmine\entity\animation\CriticalHitAnimation;
@ -332,7 +333,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
$this->lastPlayed = $nbt->getLong("lastPlayed", $now);
if(!$this->server->getForceGamemode() and ($gameModeTag = $nbt->getTag("playerGameType")) instanceof IntTag){
$this->internalSetGameMode(GameMode::fromMagicNumber($gameModeTag->getValue() & 0x03)); //TODO: bad hack here to avoid crashes on corrupted data
$this->internalSetGameMode(GameModeIdMap::getInstance()->fromId($gameModeTag->getValue()) ?? GameMode::SURVIVAL()); //TODO: bad hack here to avoid crashes on corrupted data
}else{
$this->internalSetGameMode($this->server->getGamemode());
}
@ -2069,7 +2070,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
$nbt->setInt("SpawnZ", $spawn->getFloorZ());
}
$nbt->setInt("playerGameType", $this->gamemode->getMagicNumber());
$nbt->setInt("playerGameType", GameModeIdMap::getInstance()->toId($this->gamemode));
$nbt->setLong("firstPlayed", $this->firstPlayed);
$nbt->setLong("lastPlayed", (int) floor(microtime(true) * 1000));