diff --git a/src/Player.php b/src/Player.php index 3a1352f9..1c790a06 100755 --- a/src/Player.php +++ b/src/Player.php @@ -1848,7 +1848,7 @@ class Player{ "z" => $this->entity->z, "yaw" => $this->entity->yaw, "pitch" => $this->entity->pitch, - "shooter" => $this->entity, + "shooter" => $this->entity->eid, "shootX" => $shootX, "shootY" => $shootY, "shootZ" => $shootZ @@ -1860,6 +1860,7 @@ class Player{ $e = $this->server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_SNOWBALL, $data); } + $this->removeItem($slotItem->getID(), $slotItem->meta, 1); $this->server->api->entity->spawnToAll($e); } @@ -1903,7 +1904,8 @@ class Player{ "y" => $this->entity->y + 1.6, "z" => $this->entity->z, "yaw" => $this->entity->yaw, - "pitch" => $this->entity->pitch + "pitch" => $this->entity->pitch, + "shooter" => $this->entity->eid, ]; $e = $this->server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_ARROW, $d); $e->speedX = -sin(($e->yaw / 180) * M_PI) * cos(($e->pitch / 180) * M_PI); diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 04df2ecf..f3527e9b 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -396,8 +396,8 @@ class Entity extends Position if($this->isPlayer() && $this->player->spawned === true && $this->player->blocked !== true && !$this->dead){ $myBB = $this->boundingBox->grow(1, 0.5, 1); - foreach($this->server->api->entity->getRadius($this, 2, ENTITY_ITEM) as $item){ - if(!$item->closed && $item->spawntime > 0 && $item->delayBeforePickup <= 0){ + foreach($this->server->api->entity->getRadius($this, 2, false) as $item){ + if($item->class === ENTITY_ITEM && !$item->closed && $item->spawntime > 0 && $item->delayBeforePickup <= 0){ if($item->boundingBox->intersectsWith($myBB)){ if((($this->player->gamemode & 0x01) === 1 || $this->player->hasSpace($item->type, $item->meta, $item->stack) === true) && $this->server->api->dhandle("player.pickup", array( "eid" => $this->player->eid, @@ -410,7 +410,11 @@ class Entity extends Position $item->close(); } } - + }else if($item->class == ENTITY_OBJECT && !$item->closed && $item->type == OBJECT_ARROW && $item->shotByPlayer && $item->inGround && $item->shake <= 0 && $item->boundingBox->intersectsWith($myBB)){ + if(($this->player->gamemode & 0x01) == 1 || $this->player->hasSpace(ARROW, 0, 1)){ + $this->player->addItem(ARROW, 0, 1); + $item->close(); + } } } unset($myBB); @@ -1262,6 +1266,9 @@ class Entity extends Position 0 => $this->yaw, 1 => $this->pitch, ], + "speedX" => $this->speedX, + "speedY" => $this->speedY, + "speedZ" => $this->speedZ ]; if($this->class === ENTITY_OBJECT){ @@ -1274,7 +1281,7 @@ class Entity extends Position } if($this->class === ENTITY_ITEM){ $data["Item"] = [ - "id" => $this->type, + "id" => $this->itemID, "Damage" => $this->meta, "Count" => $this->stack, ]; diff --git a/src/entity/Projectile.php b/src/entity/Projectile.php index a390bed2..3c37424b 100644 --- a/src/entity/Projectile.php +++ b/src/entity/Projectile.php @@ -19,6 +19,13 @@ abstract class Projectile extends Entity{ $this->z -= cos($this->yaw / 180 * M_PI) * 0.16; $this->boundingBox->setBounds($this->x - $this->radius, $this->y - $this->yOffset /*+ $this->ySize*/, $this->z - $this->radius, $this->x + $this->radius, $this->y - $this->yOffset + $this->height /*+ $this->ySize*/, $this->z + $this->radius); $shooter = $data["shooter"] ?? false; + if($shooter !== false) $shooter = $this->level->entityList[$shooter] ?? false; + $this->inTile = $data["inTile"] ?? $this->inTile; + $this->inGround = $data["inGround"] ?? $this->inGround; + $this->xTile = $data["xTile"] ?? $this->xTile; + $this->yTile = $data["yTile"] ?? $this->yTile; + $this->zTile = $data["zTile"] ?? $this->zTile; + if($shooter instanceof Entity){ $this->shooterEID = $shooter->eid; if($shooter->isPlayer()){ @@ -180,7 +187,17 @@ abstract class Projectile extends Entity{ public function onHit(MovingObjectPosition $hitResult){ } - + public function createSaveData(){ + $data = parent::createSaveData(); + + $data["inTile"] = $this->inTile; + $data["inGround"] = $this->inGround; + $data["xTile"] = $this->xTile; + $data["yTile"] = $this->yTile; + $data["zTile"] = $this->zTile; + + return $data; + } public function spawn($player) { $pk = new AddEntityPacket(); diff --git a/src/entity/object/Arrow.php b/src/entity/object/Arrow.php index 61477938..ff1e86af 100644 --- a/src/entity/object/Arrow.php +++ b/src/entity/object/Arrow.php @@ -5,8 +5,6 @@ class Arrow extends Entity{ const CLASS_TYPE = ENTITY_OBJECT; public $shooterEID = 0; - public $shotByEntity; - public $xTile, $yTile, $zTile; public $inTile, $inData; public $shake; @@ -14,18 +12,41 @@ class Arrow extends Entity{ public $airTicks = 0; public $criticial = false; public $groundTicks = 0; + public $shotByPlayer = false; - function __construct(Level $level, $eid, $class, $type = 0, $data = [], $shooter = false){ + function __construct(Level $level, $eid, $class, $type = 0, $data = []){ parent::__construct($level, $eid, $class, $type, $data); $this->gravity = 0.05; $this->setSize(0.5, 0.5); $this->setName("Arrow"); - $this->shooterEID = $shooter; - $this->shotByEntity = $shooter instanceof Entity; + $shooter = $data["shooter"] ?? false; + if($shooter !== false){ + $this->shooterEID = $shooter; + $this->shotByPlayer = $level->entityList[$shooter]->isPlayer(); + } $this->airTicks = $this->groundTicks = 0; + $this->inTile = $data["inTile"] ?? $this->inTile; + $this->inData = $data["inData"] ?? $this->inData; + $this->inGround = $data["inGround"] ?? $this->inGround; + $this->xTile = $data["xTile"] ?? $this->xTile; + $this->yTile = $data["yTile"] ?? $this->yTile; + $this->zTile = $data["zTile"] ?? $this->zTile; + $this->shotByPlayer = $data["shotByPlayer"] ?? $this->shotByPlayer; + //$this->server->schedule(1210, array($this, "update")); //Despawn } - + public function createSaveData(){ + $data = parent::createSaveData(); + + $data["inTile"] = $this->inTile; + $data["inData"] = $this->inData; + $data["inGround"] = $this->inGround; + $data["xTile"] = $this->xTile; + $data["yTile"] = $this->yTile; + $data["zTile"] = $this->zTile; + $data["shotByPlayer"] = $this->shotByPlayer; + return $data; + } public function handleUpdate(){ $pk = new MoveEntityPacket_PosRot; $pk->eid = $this->eid; @@ -203,9 +224,11 @@ class Arrow extends Entity{ $this->speedZ = $v4->hitVector->z - $this->z; $v21 = sqrt($this->speedX*$this->speedX + $this->speedY*$this->speedY + $this->speedZ*$this->speedZ); - $this->x -= $this->speedX / $v21 * 0.05; - $this->y -= $this->speedY / $v21 * 0.05; - $this->z -= $this->speedZ / $v21 * 0.05; + if($v21 != 0){ + $this->x -= $this->speedX / $v21 * 0.05; + $this->y -= $this->speedY / $v21 * 0.05; + $this->z -= $this->speedZ / $v21 * 0.05; + } $this->inGround = true; $this->shake = 7;