mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
arrow physics kinda changed(still doesnt normally work)
This commit is contained in:
parent
577e00378e
commit
f9a11b5eba
4 changed files with 61 additions and 47 deletions
|
|
@ -1692,58 +1692,22 @@ class Player{
|
|||
case 5: //Shot arrow
|
||||
if($this->entity->inAction === true){
|
||||
if($this->getSlot($this->slot)->getID() === BOW){
|
||||
console($this->getSlot($this->slot)->getMetadata());
|
||||
if($this->startAction !== false){
|
||||
$time = microtime(true) - $this->startAction;
|
||||
$d = array(
|
||||
"x" => $this->entity->x,
|
||||
"y" => $this->entity->y + 1.6,
|
||||
"z" => $this->entity->z,
|
||||
"yaw" => $this->entity->yaw,
|
||||
"pitch" => $this->entity->pitch
|
||||
);
|
||||
$e = $this->server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_ARROW, $d);
|
||||
$e->yaw = $this->entity->yaw;
|
||||
$e->pitch = $this->entity->pitch;
|
||||
$rotation = ($this->entity->yaw - 90) % 360;
|
||||
if($rotation < 0){
|
||||
$rotation = (360 + $rotation);
|
||||
}
|
||||
$rotation = ($rotation + 180);
|
||||
if($rotation >= 360){
|
||||
$rotation = ($rotation - 360);
|
||||
}
|
||||
$X = 1;
|
||||
$Z = 1;
|
||||
$overturn = false;
|
||||
if(0 <= $rotation and $rotation < 90){
|
||||
|
||||
}elseif(90 <= $rotation and $rotation < 180){
|
||||
$rotation -= 90;
|
||||
$X = (-1);
|
||||
$overturn = true;
|
||||
}elseif(180 <= $rotation and $rotation < 270){
|
||||
$rotation -= 180;
|
||||
$X = (-1);
|
||||
$Z = (-1);
|
||||
}elseif(270 <= $rotation and $rotation < 360){
|
||||
$rotation -= 270;
|
||||
$Z = (-1);
|
||||
$overturn = true;
|
||||
}
|
||||
$rad = deg2rad($rotation);
|
||||
$pitch = (-($this->entity->pitch));
|
||||
$speed = 80;
|
||||
$speedY = (sin(deg2rad($pitch)) * $speed);
|
||||
$speedXZ = (cos(deg2rad($pitch)) * $speed);
|
||||
if($overturn){
|
||||
$speedX = (sin($rad) * $speedXZ * $X);
|
||||
$speedZ = (cos($rad) * $speedXZ * $Z);
|
||||
}
|
||||
else{
|
||||
$speedX = (cos($rad) * $speedXZ * $X);
|
||||
$speedZ = (sin($rad) * $speedXZ * $Z);
|
||||
}
|
||||
$e->speedX = $speedX;
|
||||
$e->speedZ = $speedZ;
|
||||
$e->speedY = $speedY;
|
||||
$e->speedX = -sin(($e->yaw / 180) * M_PI) * cos(($e->pitch / 180) * M_PI);
|
||||
$e->speedZ = cos(($e->yaw / 180) * M_PI) * cos(($e->pitch / 180) * M_PI);
|
||||
$e->speedY = -sin(($e->pitch / 180) * M_PI);
|
||||
$e->shoot($e->speedX, $e->speedY, $e->speedZ, 1.5*2, 1.0);
|
||||
console($e->yaw);
|
||||
$this->server->api->entity->spawnToAll($e);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,9 +14,40 @@ class Arrow extends Projectile{
|
|||
if(($time - $this->spawntime) >= 60){
|
||||
$this->close();
|
||||
return false;
|
||||
}else{
|
||||
/*$f3 = 0.99;
|
||||
$f5 = 0.03;
|
||||
$this->speedX *= $f3;
|
||||
$this->speedY *= $f3;
|
||||
$this->speedZ *= $f3;
|
||||
$this->speedY -= $f5;
|
||||
$this->move(new Vector3($this->speedX, $this->speedY, $this->speedZ), $this->yaw, $this->pitch);
|
||||
$this->updateMovement();
|
||||
return true;*/
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function shoot($d, $d1, $d2, $f, $f1){ //original name from 0.8.1 IDA decompilation, var names are taken from b1.7.3
|
||||
$random = new Random();
|
||||
console($d." ".$d1." ".$d2." ".$f." ".$f1);
|
||||
$f2 = sqrt($d * $d + $d1 * $d1 + $d2 * $d2);
|
||||
$d /= $f2;
|
||||
$d1 /= $f2;
|
||||
$d2 /= $f2;
|
||||
$d += $random->nextGaussian() * 0.0075 * $f1; //0.0074999998323619366 replaced with 0.0075
|
||||
$d1 += $random->nextGaussian() * 0.0075 * $f1;
|
||||
$d2 += $random->nextGaussian() * 0.0075 * $f1;
|
||||
$d *= $f;
|
||||
$d1 *= $f;
|
||||
$d2 *= $f;
|
||||
$this->speedX = $d;
|
||||
$this->speedY = $d1;
|
||||
$this->speedZ = $d2;
|
||||
$f3 = sqrt($d * $d + $d2 * $d2);
|
||||
$this->yaw = (atan2($d, $d2) * 180) / M_PI;
|
||||
$this->pitch = (atan2($d1, $f3) * 180) / M_PI;
|
||||
//TODO i guess? $ticksInGround = 0;
|
||||
}
|
||||
public function spawn($player){
|
||||
if($this->type === OBJECT_ARROW){
|
||||
$pk = new AddEntityPacket;
|
||||
|
|
|
|||
|
|
@ -37,7 +37,8 @@ class PlayerActionPacket extends RakNetDataPacket{
|
|||
$this->y = $this->getInt();
|
||||
$this->z = $this->getInt();
|
||||
$this->face = $this->getInt();
|
||||
$this->eid = $this->getInt();
|
||||
$this->eid = $this->getInt();
|
||||
console($this->getInt());
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@
|
|||
//Unsecure, not used for "Real Randomness"
|
||||
class Random{
|
||||
private $x, $y, $z, $w;
|
||||
private $haveNextNextGaussian = false;
|
||||
private $nextNextGaussian = 0;
|
||||
public function __construct($seed = false){
|
||||
$this->setSeed($seed);
|
||||
}
|
||||
|
|
@ -42,7 +44,23 @@ class Random{
|
|||
$this->state = $state;
|
||||
$this->i = $this->j = 0;
|
||||
}
|
||||
|
||||
public function nextGaussian(){
|
||||
if ($this->haveNextNextGaussian) {
|
||||
$this->haveNextNextGaussian = false;
|
||||
return $this->nextNextGaussian;
|
||||
} else {
|
||||
$v1 = $v2 = $s = null;
|
||||
do {
|
||||
$v1 = 2 * $this->nextFloat() - 1; // between -1.0 and 1.0
|
||||
$v2 = 2 * $this->nextFloat() - 1; // between -1.0 and 1.0
|
||||
$s = $v1 * $v1 + $v2 * $v2;
|
||||
} while ($s >= 1 || $s == 0);
|
||||
$multiplier = sqrt(-2 * log($s)/$s);
|
||||
$nextNextGaussian = $v2 * $multiplier;
|
||||
$haveNextNextGaussian = true;
|
||||
return $v1 * $multiplier;
|
||||
}
|
||||
}
|
||||
public function nextInt(){
|
||||
return Utils::readInt($this->nextBytes(4)) & 0x7FFFFFFF;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue