arrow speed depends on how long were u using an item

This commit is contained in:
GameHerobrine 2023-07-05 10:30:55 +03:00
parent 78a19a7da6
commit d8e242d0b5
3 changed files with 29 additions and 12 deletions

View file

@ -1607,6 +1607,7 @@ class Player{
} }
if($this->entity->inAction === true){ if($this->entity->inAction === true){
$this->entity->inAction = false; $this->entity->inAction = false;
$this->entity->inActionCounter = 0;
$this->entity->updateMetadata(); $this->entity->updateMetadata();
} }
break; break;
@ -1665,6 +1666,7 @@ class Player{
if($packet->face >= 0 and $packet->face <= 5){ //Use Block, place if($packet->face >= 0 and $packet->face <= 5){ //Use Block, place
if($this->entity->inAction === true){ if($this->entity->inAction === true){
$this->entity->inAction = false; $this->entity->inAction = false;
$this->entity->inActionCounter = 0;
$this->entity->updateMetadata(); $this->entity->updateMetadata();
} }
@ -1697,6 +1699,7 @@ class Player{
break; break;
}elseif($packet->face === 0xff and $this->server->handle("player.action", $data) !== false){ }elseif($packet->face === 0xff and $this->server->handle("player.action", $data) !== false){
$this->entity->inAction = true; $this->entity->inAction = true;
$this->entity->inActionCounter = 0;
$this->startAction = microtime(true); $this->startAction = microtime(true);
$this->entity->updateMetadata(); $this->entity->updateMetadata();
} }
@ -1736,7 +1739,7 @@ class Player{
* args: xvel, yvel, zvel, (power+power)*1.5, 1.0 * args: xvel, yvel, zvel, (power+power)*1.5, 1.0
*/ */
$initalPower = 72000 - (72000 - 20); //assume we used a bow for 1 second $initalPower = $this->entity->inActionCounter;
$power = $initalPower / 20; $power = $initalPower / 20;
$power = ($power * $power + $power * 2) / 3; $power = ($power * $power + $power * 2) / 3;
if($power > 1.0) $power = 1; if($power > 1.0) $power = 1;
@ -1744,7 +1747,7 @@ class Player{
//CANCEL but i am too lazy //CANCEL but i am too lazy
$power = 0.1; $power = 0.1;
} }
//console("Arrow sent! power: $power");
$e->shoot($e->speedX, $e->speedY, $e->speedZ, ($power+$power) * 1.5, 1.0); //TODO bow power $e->shoot($e->speedX, $e->speedY, $e->speedZ, ($power+$power) * 1.5, 1.0); //TODO bow power
$this->server->api->entity->spawnToAll($e); $this->server->api->entity->spawnToAll($e);
} }
@ -1752,6 +1755,7 @@ class Player{
} }
$this->startAction = false; $this->startAction = false;
$this->entity->inAction = false; $this->entity->inAction = false;
$this->entity->inActionCounter = 0;
$this->entity->updateMetadata(); $this->entity->updateMetadata();
break; break;
case 6: //get out of the bed case 6: //get out of the bed
@ -1811,6 +1815,7 @@ class Player{
$this->sendArmor(); $this->sendArmor();
if($this->entity->inAction === true){ if($this->entity->inAction === true){
$this->entity->inAction = false; $this->entity->inAction = false;
$this->entity->inActionCounter = 0;
$this->entity->updateMetadata(); $this->entity->updateMetadata();
} }
break; break;
@ -1876,6 +1881,7 @@ class Player{
$packet->eid = $this->eid; $packet->eid = $this->eid;
if($this->entity->inAction === true){ if($this->entity->inAction === true){
$this->entity->inAction = false; $this->entity->inAction = false;
$this->entity->inActionCounter = 0;
$this->entity->updateMetadata(); $this->entity->updateMetadata();
} }
switch($packet->event){ switch($packet->event){
@ -1947,6 +1953,7 @@ class Player{
} }
if($this->entity->inAction === true){ if($this->entity->inAction === true){
$this->entity->inAction = false; $this->entity->inAction = false;
$this->entity->inActionCounter = 0;
$this->entity->updateMetadata(); $this->entity->updateMetadata();
} }
break; break;

View file

@ -70,6 +70,7 @@ class Entity extends Position
public $random; public $random;
public $radius; public $radius;
public $inAction = false; public $inAction = false;
public $inActionCounter = 0;
public $hasKnockback; public $hasKnockback;
public $hasJumped; public $hasJumped;
public $invincible, $crouched, $fire, $health, $status; public $invincible, $crouched, $fire, $health, $status;
@ -499,6 +500,7 @@ class Entity extends Position
if($this->closed === true){ if($this->closed === true){
return false; return false;
} }
$now = microtime(true); $now = microtime(true);
if($this->check === false){ if($this->check === false){
$this->lastUpdate = $now; $this->lastUpdate = $now;
@ -727,19 +729,27 @@ class Entity extends Position
$hasUpdate = true; $hasUpdate = true;
} }
} }
if($this->knockbackTime > 0){ if($this->knockbackTime > 0){
--$this->knockbackTime; --$this->knockbackTime;
} }
if($this->moveTime > 0){ if($this->moveTime > 0){
-- $this->moveTime; --$this->moveTime;
} }
if($this->lookTime > 0){ if($this->lookTime > 0){
-- $this->lookTime; --$this->lookTime;
} }
if($this->idleTime > 0){ if($this->idleTime > 0){
-- $this->idleTime; --$this->idleTime;
} }
if($this->inAction){
++$this->inActionCounter;
}
if($this->lastHeadYaw != $this->headYaw){ if($this->lastHeadYaw != $this->headYaw){
$this->sendHeadYaw(); $this->sendHeadYaw();
} }

View file

@ -59,12 +59,6 @@ class Arrow extends Projectile{
//parent::update(); //parent::update();
$this->needsUpdate = true; $this->needsUpdate = true;
$this->speedY -= $this->gravity;
$this->speedX *= 0.99;
$this->speedY *= 0.99;
$this->speedZ *= 0.99;
if($this->speedX != 0 or $this->speedY != 0 or $this->speedZ != 0){ if($this->speedX != 0 or $this->speedY != 0 or $this->speedZ != 0){
$f = sqrt(($this->speedX * $this->speedX) + ($this->speedZ * $this->speedZ)); $f = sqrt(($this->speedX * $this->speedX) + ($this->speedZ * $this->speedZ));
$this->yaw = (atan2($this->speedX, $this->speedZ) * 180 / M_PI); $this->yaw = (atan2($this->speedX, $this->speedZ) * 180 / M_PI);
@ -73,6 +67,12 @@ class Arrow extends Projectile{
$this->x += $this->speedX; $this->x += $this->speedX;
$this->y += $this->speedY; $this->y += $this->speedY;
$this->z += $this->speedZ; $this->z += $this->speedZ;
$this->speedX *= 0.99;
$this->speedY *= 0.99;
$this->speedZ *= 0.99;
$this->speedY -= $this->gravity;
$this->sendMotion(); $this->sendMotion();
$this->updatePosition(); $this->updatePosition();
} }