first look at separating Entity and Location

This commit is contained in:
Dylan K. Taylor
2019-08-19 17:20:34 +01:00
parent 591d35889e
commit 2d4a32fc77
36 changed files with 302 additions and 257 deletions

View File

@@ -623,8 +623,9 @@ class NetworkSession{
}
public function syncMovement(Vector3 $pos, ?float $yaw = null, ?float $pitch = null, int $mode = MovePlayerPacket::MODE_NORMAL) : void{
$yaw = $yaw ?? $this->player->getYaw();
$pitch = $pitch ?? $this->player->getPitch();
$location = $this->player->getLocation();
$yaw = $yaw ?? $location->getYaw();
$pitch = $pitch ?? $location->getPitch();
$pk = new MovePlayerPacket();
$pk->entityRuntimeId = $this->player->getId();
@@ -767,7 +768,7 @@ class NetworkSession{
public function startUsingChunk(int $chunkX, int $chunkZ, \Closure $onCompletion) : void{
Utils::validateCallableSignature(function(int $chunkX, int $chunkZ){}, $onCompletion);
$world = $this->player->getWorld();
$world = $this->player->getLocation()->getWorld();
assert($world !== null);
ChunkCache::getInstance($world)->request($chunkX, $chunkZ)->onResolve(
@@ -776,16 +777,17 @@ class NetworkSession{
if(!$this->isConnected()){
return;
}
if($world !== $this->player->getWorld() or !$this->player->isUsingChunk($chunkX, $chunkZ)){
$currentWorld = $this->player->getLocation()->getWorld();
if($world !== $currentWorld or !$this->player->isUsingChunk($chunkX, $chunkZ)){
$this->logger->debug("Tried to send no-longer-active chunk $chunkX $chunkZ in world " . $world->getFolderName());
return;
}
$this->player->world->timings->syncChunkSendTimer->startTiming();
$currentWorld->timings->syncChunkSendTimer->startTiming();
try{
$this->queueCompressed($promise);
$onCompletion($chunkX, $chunkZ);
}finally{
$this->player->world->timings->syncChunkSendTimer->stopTiming();
$currentWorld->timings->syncChunkSendTimer->stopTiming();
}
}
);

View File

@@ -301,7 +301,7 @@ class InGamePacketHandler extends PacketHandler{
*/
private function onFailedBlockAction(Vector3 $blockPos, ?int $face) : void{
$this->session->getInvManager()->syncSlot($this->player->getInventory(), $this->player->getInventory()->getHeldItemIndex());
if($blockPos->distanceSquared($this->player) < 10000){
if($blockPos->distanceSquared($this->player->getLocation()) < 10000){
$blocks = $blockPos->sidesArray();
if($face !== null){
$sidePos = $blockPos->getSide($face);
@@ -311,7 +311,7 @@ class InGamePacketHandler extends PacketHandler{
}else{
$blocks[] = $blockPos;
}
$this->player->getWorld()->sendBlocks([$this->player], $blocks);
$this->player->getLocation()->getWorld()->sendBlocks([$this->player], $blocks);
}
}
@@ -510,11 +510,11 @@ class InGamePacketHandler extends PacketHandler{
public function handleBlockActorData(BlockActorDataPacket $packet) : bool{
$pos = new Vector3($packet->x, $packet->y, $packet->z);
if($pos->distanceSquared($this->player) > 10000){
if($pos->distanceSquared($this->player->getLocation()) > 10000){
return false;
}
$block = $this->player->getWorld()->getBlock($pos);
$block = $this->player->getLocation()->getWorld()->getBlock($pos);
try{
$offset = 0;
$nbt = (new NetworkNbtSerializer())->read($packet->namedtag, $offset, 512)->getTag();
@@ -703,7 +703,7 @@ class InGamePacketHandler extends PacketHandler{
}
public function handleLevelSoundEvent(LevelSoundEventPacket $packet) : bool{
$this->player->getWorld()->broadcastPacketToViewers($this->player->asVector3(), $packet);
$this->player->getWorld()->broadcastPacketToViewers($this->player->getPosition(), $packet);
return true;
}

View File

@@ -53,23 +53,24 @@ class PreSpawnPacketHandler extends PacketHandler{
public function setUp() : void{
$spawnPosition = $this->player->getSpawn();
$location = $this->player->getLocation();
$pk = new StartGamePacket();
$pk->entityUniqueId = $this->player->getId();
$pk->entityRuntimeId = $this->player->getId();
$pk->playerGamemode = NetworkSession::getClientFriendlyGamemode($this->player->getGamemode());
$pk->playerPosition = $this->player->getOffsetPosition($this->player);
$pk->pitch = $this->player->pitch;
$pk->yaw = $this->player->yaw;
$pk->playerPosition = $this->player->getOffsetPosition($location);
$pk->pitch = $location->pitch;
$pk->yaw = $location->yaw;
$pk->seed = -1;
$pk->dimension = DimensionIds::OVERWORLD; //TODO: implement this properly
$pk->worldGamemode = NetworkSession::getClientFriendlyGamemode($this->server->getGamemode());
$pk->difficulty = $this->player->getWorld()->getDifficulty();
$pk->difficulty = $location->getWorld()->getDifficulty();
$pk->spawnX = $spawnPosition->getFloorX();
$pk->spawnY = $spawnPosition->getFloorY();
$pk->spawnZ = $spawnPosition->getFloorZ();
$pk->hasAchievementsDisabled = true;
$pk->time = $this->player->getWorld()->getTime();
$pk->time = $location->getWorld()->getTime();
$pk->eduMode = false;
$pk->rainLevel = 0; //TODO: implement these properly
$pk->lightningLevel = 0;