Merge branch 'minor-next' into major-next

This commit is contained in:
Dylan K. Taylor
2023-04-10 14:38:23 +01:00
17 changed files with 427 additions and 222 deletions

View File

@ -211,7 +211,7 @@ class InGamePacketHandler extends PacketHandler{
if($newPos->distanceSquared($curPos) > 1){ //Tolerate up to 1 block to avoid problems with client-sided physics when spawning in blocks
$this->session->getLogger()->debug("Got outdated pre-teleport movement, received " . $newPos . ", expected " . $curPos);
//Still getting movements from before teleport, ignore them
return false;
return true;
}
// Once we get a movement within a reasonable distance, treat it as a teleport ACK and remove position lock

View File

@ -44,6 +44,7 @@ use pocketmine\network\mcpe\protocol\types\PlayerMovementType;
use pocketmine\network\mcpe\protocol\types\SpawnSettings;
use pocketmine\player\Player;
use pocketmine\Server;
use pocketmine\timings\Timings;
use pocketmine\VersionInfo;
use Ramsey\Uuid\Uuid;
use function sprintf;
@ -60,89 +61,94 @@ class PreSpawnPacketHandler extends PacketHandler{
){}
public function setUp() : void{
$location = $this->player->getLocation();
$world = $location->getWorld();
Timings::$playerNetworkSendPreSpawnGameData->startTiming();
try{
$location = $this->player->getLocation();
$world = $location->getWorld();
$this->session->getLogger()->debug("Preparing StartGamePacket");
$levelSettings = new LevelSettings();
$levelSettings->seed = -1;
$levelSettings->spawnSettings = new SpawnSettings(SpawnSettings::BIOME_TYPE_DEFAULT, "", DimensionIds::OVERWORLD); //TODO: implement this properly
$levelSettings->worldGamemode = TypeConverter::getInstance()->coreGameModeToProtocol($this->server->getGamemode());
$levelSettings->difficulty = $world->getDifficulty();
$levelSettings->spawnPosition = BlockPosition::fromVector3($world->getSpawnLocation());
$levelSettings->hasAchievementsDisabled = true;
$levelSettings->time = $world->getTime();
$levelSettings->eduEditionOffer = 0;
$levelSettings->rainLevel = 0; //TODO: implement these properly
$levelSettings->lightningLevel = 0;
$levelSettings->commandsEnabled = true;
$levelSettings->gameRules = [
"naturalregeneration" => new BoolGameRule(false, false) //Hack for client side regeneration
];
$levelSettings->experiments = new Experiments([], false);
$this->session->getLogger()->debug("Preparing StartGamePacket");
$levelSettings = new LevelSettings();
$levelSettings->seed = -1;
$levelSettings->spawnSettings = new SpawnSettings(SpawnSettings::BIOME_TYPE_DEFAULT, "", DimensionIds::OVERWORLD); //TODO: implement this properly
$levelSettings->worldGamemode = TypeConverter::getInstance()->coreGameModeToProtocol($this->server->getGamemode());
$levelSettings->difficulty = $world->getDifficulty();
$levelSettings->spawnPosition = BlockPosition::fromVector3($world->getSpawnLocation());
$levelSettings->hasAchievementsDisabled = true;
$levelSettings->time = $world->getTime();
$levelSettings->eduEditionOffer = 0;
$levelSettings->rainLevel = 0; //TODO: implement these properly
$levelSettings->lightningLevel = 0;
$levelSettings->commandsEnabled = true;
$levelSettings->gameRules = [
"naturalregeneration" => new BoolGameRule(false, false) //Hack for client side regeneration
];
$levelSettings->experiments = new Experiments([], false);
$this->session->sendDataPacket(StartGamePacket::create(
$this->player->getId(),
$this->player->getId(),
TypeConverter::getInstance()->coreGameModeToProtocol($this->player->getGamemode()),
$this->player->getOffsetPosition($location),
$location->pitch,
$location->yaw,
new CacheableNbt(CompoundTag::create()), //TODO: we don't care about this right now
$levelSettings,
"",
$this->server->getMotd(),
"",
false,
new PlayerMovementSettings(PlayerMovementType::SERVER_AUTHORITATIVE_V1, 0, false),
0,
0,
"",
true,
sprintf("%s %s", VersionInfo::NAME, VersionInfo::VERSION()->getFullVersion(true)),
Uuid::fromString(Uuid::NIL),
false,
[],
0,
GlobalItemTypeDictionary::getInstance()->getDictionary()->getEntries(),
));
$this->session->sendDataPacket(StartGamePacket::create(
$this->player->getId(),
$this->player->getId(),
TypeConverter::getInstance()->coreGameModeToProtocol($this->player->getGamemode()),
$this->player->getOffsetPosition($location),
$location->pitch,
$location->yaw,
new CacheableNbt(CompoundTag::create()), //TODO: we don't care about this right now
$levelSettings,
"",
$this->server->getMotd(),
"",
false,
new PlayerMovementSettings(PlayerMovementType::SERVER_AUTHORITATIVE_V1, 0, false),
0,
0,
"",
true,
sprintf("%s %s", VersionInfo::NAME, VersionInfo::VERSION()->getFullVersion(true)),
Uuid::fromString(Uuid::NIL),
false,
[],
0,
GlobalItemTypeDictionary::getInstance()->getDictionary()->getEntries(),
));
$this->session->getLogger()->debug("Sending actor identifiers");
$this->session->sendDataPacket(StaticPacketCache::getInstance()->getAvailableActorIdentifiers());
$this->session->getLogger()->debug("Sending actor identifiers");
$this->session->sendDataPacket(StaticPacketCache::getInstance()->getAvailableActorIdentifiers());
$this->session->getLogger()->debug("Sending biome definitions");
$this->session->sendDataPacket(StaticPacketCache::getInstance()->getBiomeDefs());
$this->session->getLogger()->debug("Sending biome definitions");
$this->session->sendDataPacket(StaticPacketCache::getInstance()->getBiomeDefs());
$this->session->getLogger()->debug("Sending attributes");
$this->session->getEntityEventBroadcaster()->syncAttributes([$this->session], $this->player, $this->player->getAttributeMap()->getAll());
$this->session->getLogger()->debug("Sending attributes");
$this->session->getEntityEventBroadcaster()->syncAttributes([$this->session], $this->player, $this->player->getAttributeMap()->getAll());
$this->session->getLogger()->debug("Sending available commands");
$this->session->syncAvailableCommands();
$this->session->getLogger()->debug("Sending available commands");
$this->session->syncAvailableCommands();
$this->session->getLogger()->debug("Sending abilities");
$this->session->syncAbilities($this->player);
$this->session->syncAdventureSettings();
$this->session->getLogger()->debug("Sending abilities");
$this->session->syncAbilities($this->player);
$this->session->syncAdventureSettings();
$this->session->getLogger()->debug("Sending effects");
foreach($this->player->getEffects()->all() as $effect){
$this->session->getEntityEventBroadcaster()->onEntityEffectAdded([$this->session], $this->player, $effect, false);
$this->session->getLogger()->debug("Sending effects");
foreach($this->player->getEffects()->all() as $effect){
$this->session->getEntityEventBroadcaster()->onEntityEffectAdded([$this->session], $this->player, $effect, false);
}
$this->session->getLogger()->debug("Sending actor metadata");
$this->player->sendData([$this->player]);
$this->session->getLogger()->debug("Sending inventory");
$this->inventoryManager->syncAll();
$this->inventoryManager->syncSelectedHotbarSlot();
$this->session->getLogger()->debug("Sending creative inventory data");
$this->inventoryManager->syncCreative();
$this->session->getLogger()->debug("Sending crafting data");
$this->session->sendDataPacket(CraftingDataCache::getInstance()->getCache($this->server->getCraftingManager()));
$this->session->getLogger()->debug("Sending player list");
$this->session->syncPlayerList($this->server->getOnlinePlayers());
}finally{
Timings::$playerNetworkSendPreSpawnGameData->stopTiming();
}
$this->session->getLogger()->debug("Sending actor metadata");
$this->player->sendData([$this->player]);
$this->session->getLogger()->debug("Sending inventory");
$this->inventoryManager->syncAll();
$this->inventoryManager->syncSelectedHotbarSlot();
$this->session->getLogger()->debug("Sending creative inventory data");
$this->inventoryManager->syncCreative();
$this->session->getLogger()->debug("Sending crafting data");
$this->session->sendDataPacket(CraftingDataCache::getInstance()->getCache($this->server->getCraftingManager()));
$this->session->getLogger()->debug("Sending player list");
$this->session->syncPlayerList($this->server->getOnlinePlayers());
}
public function handleRequestChunkRadius(RequestChunkRadiusPacket $packet) : bool{