Fixed Arrows not hitting entities, added new movement system

This commit is contained in:
Shoghi Cervantes
2015-06-07 21:08:46 +02:00
parent d0f743a99e
commit 7b17bf416e
4 changed files with 65 additions and 44 deletions

View File

@ -90,6 +90,8 @@ use pocketmine\nbt\tag\String;
use pocketmine\network\Network;
use pocketmine\network\protocol\DataPacket;
use pocketmine\network\protocol\LevelEventPacket;
use pocketmine\network\protocol\MoveEntityPacket;
use pocketmine\network\protocol\SetEntityMotionPacket;
use pocketmine\network\protocol\SetTimePacket;
use pocketmine\network\protocol\UpdateBlockPacket;
use pocketmine\Player;
@ -132,6 +134,9 @@ class Level implements ChunkManager, Metadatable{
/** @var Tile[] */
private $tiles = [];
private $motionToSend = [];
private $moveToSend = [];
/** @var Player[] */
private $players = [];
@ -709,6 +714,22 @@ class Level implements ChunkManager, Metadatable{
$this->checkSleep();
}
foreach($this->moveToSend as $index => $entry){
Level::getXZ($index, $chunkX, $chunkZ);
$pk = new MoveEntityPacket();
$pk->entities = $entry;
Server::broadcastPacket($this->getChunkPlayers($chunkX, $chunkZ), $pk->setChannel(Network::CHANNEL_MOVEMENT));
}
$this->moveToSend = [];
foreach($this->motionToSend as $index => $entry){
Level::getXZ($index, $chunkX, $chunkZ);
$pk = new SetEntityMotionPacket();
$pk->entities = $entry;
Server::broadcastPacket($this->getChunkPlayers($chunkX, $chunkZ), $pk->setChannel(Network::CHANNEL_MOVEMENT));
}
$this->motionToSend = [];
$this->timings->doTick->stopTiming();
}
@ -1699,7 +1720,7 @@ class Level implements ChunkManager, Metadatable{
for($x = $minX; $x <= $maxX; ++$x){
for($z = $minZ; $z <= $maxZ; ++$z){
foreach($this->getChunkEntities($x, $z) as $ent){
if(($entity === null or ($ent !== $entity and $ent->canCollideWith($entity))) and $ent->boundingBox->intersectsWith($bb)){
if(($entity === null or ($ent !== $entity and $entity->canCollideWith($ent))) and $ent->boundingBox->intersectsWith($bb)){
$nearby[] = $ent;
}
}
@ -2729,4 +2750,18 @@ class Level implements ChunkManager, Metadatable{
public function removeMetadata($metadataKey, Plugin $plugin){
$this->server->getLevelMetadata()->removeMetadata($this, $metadataKey, $plugin);
}
public function addEntityMotion($chunkX, $chunkZ, $entityId, $x, $y, $z){
if(!isset($this->motionToSend[$index = Level::chunkHash($chunkX, $chunkZ)])){
$this->motionToSend[$index] = [];
}
$this->motionToSend[$index][$entityId] = [$entityId, $x, $y, $z];
}
public function addEntityMovement($chunkX, $chunkZ, $entityId, $x, $y, $z, $yaw, $pitch, $headYaw = null){
if(!isset($this->moveToSend[$index = Level::chunkHash($chunkX, $chunkZ)])){
$this->moveToSend[$index] = [];
}
$this->moveToSend[$index][$entityId] = [$entityId, $x, $y, $z, $yaw, $headYaw === null ? $yaw : $headYaw, $pitch];
}
}