From 02ba9ffc1605460375b9c24d3aac045201a6d424 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Wed, 8 Apr 2015 22:09:06 +0200 Subject: [PATCH] Improved entity movement ySize offset --- src/pocketmine/Player.php | 35 +++++++----- src/pocketmine/block/Slab.php | 2 +- src/pocketmine/entity/Entity.php | 55 ++----------------- src/pocketmine/network/Network.php | 2 + .../network/protocol/MovePlayerPacket.php | 2 +- 5 files changed, 29 insertions(+), 67 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index de1e1f26a..81cb9fe21 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -626,10 +626,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->sendData($this); $this->inventory->sendContents($this); $this->inventory->sendArmorContents($this); - - $pk = new PlayStatusPacket(); - $pk->status = PlayStatusPacket::PLAYER_SPAWN; - $this->dataPacket($pk); $pk = new SetTimePacket(); $pk->time = $this->level->getTime(); @@ -642,6 +638,10 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->teleport($ev->getRespawnPosition()); + $pk = new PlayStatusPacket(); + $pk->status = PlayStatusPacket::PLAYER_SPAWN; + $this->dataPacket($pk); + $this->server->getPluginManager()->callEvent($ev = new PlayerJoinEvent($this, TextFormat::YELLOW . $this->getName() . " joined the game")); if(strlen(trim($ev->getJoinMessage())) > 0){ $this->server->broadcastMessage($ev->getJoinMessage()); @@ -1074,13 +1074,15 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $dy = $this->newPosition->y - $this->y; $dz = $this->newPosition->z - $this->z; - $this->fastMove($dx, $dy, $dz); + $this->move($dx, $dy, $dz); $diffX = $this->x - $this->newPosition->x; - $diffZ = $this->z - $this->newPosition->z; $diffY = $this->y - $this->newPosition->y; - if($diffY >= -0.5 or $diffY <= 0.5){ - $diffY = 0; + $diffZ = $this->z - $this->newPosition->z; + + $yS = 0.5 + $this->ySize; + if($diffY >= -$yS or $diffY <= $yS){ + $diffY = 0; } $diff = $diffX ** 2 + $diffY ** 2 + $diffZ ** 2; @@ -1097,7 +1099,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->y = $this->newPosition->y; $this->z = $this->newPosition->z; $radius = $this->width / 2; - $this->boundingBox->setBounds($this->x - $radius, $this->y + $this->ySize, $this->z - $radius, $this->x + $radius, $this->y + $this->height + $this->ySize, $this->z + $radius); + $this->boundingBox->setBounds($this->x - $radius, $this->y, $this->z - $radius, $this->x + $radius, $this->y + $this->height, $this->z + $radius); } } @@ -1128,7 +1130,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->teleport($ev->getTo()); }else{ foreach($this->hasSpawned as $player){ - $player->addEntityMovement($this->id, $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch, $this->yaw); + $player->addEntityMovement($this->id, $this->x, $this->y + $this->height, $this->z, $this->yaw, $this->pitch, $this->yaw); } } } @@ -1151,11 +1153,12 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $pk = new MovePlayerPacket(); $pk->eid = $this->getId(); $pk->x = $from->x; - $pk->y = $from->y + $this->getEyeHeight(); + $pk->y = $from->y + $this->height; $pk->z = $from->z; $pk->bodyYaw = $from->yaw; $pk->pitch = $from->pitch; $pk->yaw = $from->yaw; + $pk->mode = 1; $this->directDataPacket($pk); $this->forceMovement = new Vector3($from->x, $from->y, $from->z); }else{ @@ -1187,8 +1190,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->timings->startTiming(); - $this->lastUpdate = $currentTick; - if($this->spawned){ $this->processMovement($currentTick); @@ -1295,6 +1296,9 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->motionToSend = []; } + + $this->lastUpdate = $currentTick; + $this->timings->stopTiming(); return true; @@ -1523,11 +1527,12 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $pk = new MovePlayerPacket(); $pk->eid = $this->getId(); $pk->x = $this->forceMovement->x; - $pk->y = $this->forceMovement->y + $this->getEyeHeight(); + $pk->y = $this->forceMovement->y + $this->height; $pk->z = $this->forceMovement->z; $pk->bodyYaw = $packet->bodyYaw; $pk->pitch = $packet->pitch; $pk->yaw = $packet->yaw; + $pk->mode = 1; $this->directDataPacket($pk); }else{ $packet->yaw %= 360; @@ -2660,7 +2665,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $pk = new MovePlayerPacket(); $pk->eid = $this->getId(); $pk->x = $this->x; - $pk->y = $this->y + $this->getEyeHeight(); + $pk->y = $this->y + $this->height; $pk->z = $this->z; $pk->bodyYaw = $this->yaw; $pk->pitch = $this->pitch; diff --git a/src/pocketmine/block/Slab.php b/src/pocketmine/block/Slab.php index dc5dc435f..fa8c0eb8e 100644 --- a/src/pocketmine/block/Slab.php +++ b/src/pocketmine/block/Slab.php @@ -48,7 +48,7 @@ class Slab extends Transparent{ 6 => "Quartz", 7 => "", ]; - return (($this->meta & 0x08) === 0x08 ? "Upper " : "") . $names[$this->meta & 0x07] . " Slab"; + return (($this->meta & 0x08) > 0 ? "Upper " : "") . $names[$this->meta & 0x07] . " Slab"; } protected function recalculateBoundingBox(){ diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 741f88760..00a3c7967 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -53,7 +53,6 @@ use pocketmine\nbt\tag\Short; use pocketmine\nbt\tag\String; use pocketmine\Network; use pocketmine\network\protocol\MobEffectPacket; -use pocketmine\network\protocol\MovePlayerPacket; use pocketmine\network\protocol\RemoveEntityPacket; use pocketmine\network\protocol\SetEntityDataPacket; use pocketmine\network\protocol\SetTimePacket; @@ -796,7 +795,7 @@ abstract class Entity extends Location implements Metadatable{ if(!($this instanceof Player)){ foreach($this->hasSpawned as $player){ - $player->addEntityMovement($this->id, $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch, $this->yaw); + $player->addEntityMovement($this->id, $this->x, $this->y + $this->height, $this->z, $this->yaw, $this->pitch, $this->yaw); } } } @@ -1013,7 +1012,7 @@ abstract class Entity extends Location implements Metadatable{ $newBB = $this->boundingBox->getOffsetBoundingBox($dx, $dy, $dz); - $list = $this->level->getCollisionCubes($this, $newBB->expand(-0.01, -0.01, -0.01), false); + $list = $this->level->getCollisionCubes($this, $newBB->grow(-0.01, -0.01, -0.01), false); if(count($list) === 0){ $this->boundingBox = $newBB; @@ -1021,7 +1020,7 @@ abstract class Entity extends Location implements Metadatable{ $pos = new Vector3( ($this->boundingBox->minX + $this->boundingBox->maxX) / 2, - $this->boundingBox->minY + $this->ySize, + $this->boundingBox->minY, ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2 ); @@ -1118,12 +1117,6 @@ abstract class Entity extends Location implements Metadatable{ $this->boundingBox->offset(0, $dy, 0); - if($movY != $dy){ - $dx = 0; - $dy = 0; - $dz = 0; - } - $fallingFlag = ($this->onGround or ($dy != $movY and $movY < 0)); foreach($list as $bb){ @@ -1132,24 +1125,12 @@ abstract class Entity extends Location implements Metadatable{ $this->boundingBox->offset($dx, 0, 0); - if($movX != $dx){ - $dx = 0; - $dy = 0; - $dz = 0; - } - foreach($list as $bb){ $dz = $bb->calculateZOffset($this->boundingBox, $dz); } $this->boundingBox->offset(0, 0, $dz); - if($movZ != $dz){ - $dx = 0; - $dy = 0; - $dz = 0; - } - if($this->stepHeight > 0 and $fallingFlag and $this->ySize < 0.05 and ($movX != $dx or $movZ != $dz)){ $cx = $dx; @@ -1176,34 +1157,12 @@ abstract class Entity extends Location implements Metadatable{ } $this->boundingBox->offset($dx, 0, 0); - if($movX != $dx){ - $dx = 0; - $dy = 0; - $dz = 0; - } foreach($list as $bb){ $dz = $bb->calculateZOffset($this->boundingBox, $dz); } $this->boundingBox->offset(0, 0, $dz); - if($movZ != $dz){ - $dx = 0; - $dy = 0; - $dz = 0; - } - - if($dy == 0){ - $dx = 0; - $dy = 0; - $dz = 0; - }else{ - $dy = -$this->stepHeight; - foreach($list as $bb){ - $dy = $bb->calculateYOffset($this->boundingBox, $dy); - } - $this->boundingBox->offset(0, $dy, 0); - } if(($cx ** 2 + $cz ** 2) >= ($dx ** 2 + $dz ** 2)){ $dx = $cx; @@ -1211,11 +1170,7 @@ abstract class Entity extends Location implements Metadatable{ $dz = $cz; $this->boundingBox->setBB($axisalignedbb1); }else{ - $diff = $this->boundingBox->minY - (int) $this->boundingBox->minY; - - if($diff > 0){ - $this->ySize += $diff + 0.01; - } + $this->ySize += 0.5; } } @@ -1444,7 +1399,7 @@ abstract class Entity extends Location implements Metadatable{ $this->lastPitch = $this->pitch; foreach($this->hasSpawned as $player){ - $player->addEntityMovement($this->getId(), $this->x, $this->y, $this->z, $this->yaw, $this->pitch, $this->yaw); + $player->addEntityMovement($this->getId(), $this->x, $this->y + $this->height, $this->z, $this->yaw, $this->pitch, $this->yaw); } return true; diff --git a/src/pocketmine/network/Network.php b/src/pocketmine/network/Network.php index 0ea8758b6..86890343e 100644 --- a/src/pocketmine/network/Network.php +++ b/src/pocketmine/network/Network.php @@ -38,6 +38,7 @@ use pocketmine\network\protocol\ContainerSetDataPacket; use pocketmine\network\protocol\ContainerSetSlotPacket; use pocketmine\network\protocol\DataPacket; use pocketmine\network\protocol\DropItemPacket; +use pocketmine\network\protocol\FullChunkDataPacket; use pocketmine\network\protocol\Info; use pocketmine\network\protocol\SetEntityLinkPacket; use pocketmine\network\protocol\TileEntityDataPacket; @@ -299,6 +300,7 @@ class Network{ $this->registerPacket(ProtocolInfo::CONTAINER_SET_CONTENT_PACKET, ContainerSetContentPacket::class); $this->registerPacket(ProtocolInfo::ADVENTURE_SETTINGS_PACKET, AdventureSettingsPacket::class); $this->registerPacket(ProtocolInfo::TILE_ENTITY_DATA_PACKET, TileEntityDataPacket::class); + $this->registerPacket(ProtocolInfo::FULL_CHUNK_DATA_PACKET, FullChunkDataPacket::class); $this->registerPacket(ProtocolInfo::SET_DIFFICULTY_PACKET, SetDifficultyPacket::class); $this->registerPacket(ProtocolInfo::BATCH_PACKET, BatchPacket::class); } diff --git a/src/pocketmine/network/protocol/MovePlayerPacket.php b/src/pocketmine/network/protocol/MovePlayerPacket.php index 67619de86..75d93e7e2 100644 --- a/src/pocketmine/network/protocol/MovePlayerPacket.php +++ b/src/pocketmine/network/protocol/MovePlayerPacket.php @@ -33,8 +33,8 @@ class MovePlayerPacket extends DataPacket{ public $y; public $z; public $yaw; - public $pitch; public $bodyYaw; + public $pitch; public $mode = 0; public function pid(){