Improved entity movement ySize offset

This commit is contained in:
Shoghi Cervantes 2015-04-08 22:09:06 +02:00
parent 71657a2a4e
commit 02ba9ffc16
No known key found for this signature in database
GPG Key ID: 78464DB0A7837F89
5 changed files with 29 additions and 67 deletions

View File

@ -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;

View File

@ -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(){

View File

@ -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;

View File

@ -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);
}

View File

@ -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(){