player can affect motion of minecart now

This commit is contained in:
GameHerobrine 2024-06-10 13:00:54 +03:00
parent 7b2b914865
commit 376240b9bc
4 changed files with 42 additions and 64 deletions

View file

@ -78,12 +78,10 @@ class Player{
/** /**
* Sent by a client while it is linked to some entity. * Sent by a client while it is linked to some entity.
* @var float $moveStrafe
* @var float $moveForward
* @var boolean $isJumping * @var boolean $isJumping
* @var boolean $isSneaking * @var boolean $isSneaking
*/ */
public $moveStrafe, $moveForward, $isJumping, $isSneaking; public $isJumping, $isSneaking;
/** /**
* @param integer $clientID * @param integer $clientID
@ -1263,8 +1261,8 @@ class Player{
if($e->modifySpeedY){ if($e->modifySpeedY){
$e->speedY = $e->modifedSpeedY; $e->speedY = $e->modifedSpeedY;
} }
//if($e->speedX != 0 || $e->speedY != 0 || $e->speedZ != 0 || $e->speedY != $e->lastSpeedY || $e->speedX != $e->lastSpeedX || $e->speedZ != $e->lastSpeedZ){ if($e->speedX != 0 || $e->speedY != 0 || $e->speedZ != 0 || $e->speedY != $e->lastSpeedY || $e->speedX != $e->lastSpeedX || $e->speedZ != $e->lastSpeedZ){
// if(!($e->speedY < 0 && $e->onGround) || $e->speedX != 0 || $e->speedZ != 0 || $e->speedY != $e->lastSpeedY || $e->speedX != $e->lastSpeedX || $e->speedZ != $e->lastSpeedZ){ if(!($e->speedY < 0 && $e->onGround) || $e->speedX != 0 || $e->speedZ != 0 || $e->speedY != $e->lastSpeedY || $e->speedX != $e->lastSpeedX || $e->speedZ != $e->lastSpeedZ){
$motion = new SetEntityMotionPacket(); $motion = new SetEntityMotionPacket();
$motion->eid = $e->eid; $motion->eid = $e->eid;
$motion->speedX = $e->speedX; $motion->speedX = $e->speedX;
@ -1274,8 +1272,8 @@ class Player{
$len += 1 + strlen($motion->buffer); $len += 1 + strlen($motion->buffer);
++$packets; ++$packets;
$motionSent = true; $motionSent = true;
// } }
//} }
if($e->modifySpeedY){ if($e->modifySpeedY){
$e->speedY = $svdYSpeed; $e->speedY = $svdYSpeed;
$e->modifySpeedY = false; $e->modifySpeedY = false;
@ -1316,7 +1314,7 @@ class Player{
$headSent = true; $headSent = true;
} }
if($packets <= 0) return; if($packets <= 0) return;
console("Update {$e}: $packets, mot: $motionSent, mov: $moveSent, hed: $headSent"); //console("Update {$e}: $packets, mot: $motionSent, mov: $moveSent, hed: $headSent");
$MTU = $this->MTU - 24; $MTU = $this->MTU - 24;
if(($this->entityMovementQueueLength + $len) >= $MTU){ if(($this->entityMovementQueueLength + $len) >= $MTU){
$this->sendEntityMovementUpdateQueue(); $this->sendEntityMovementUpdateQueue();
@ -2471,11 +2469,10 @@ class Player{
} }
break; break;
case ProtocolInfo::PLAYER_INPUT_PACKET: case ProtocolInfo::PLAYER_INPUT_PACKET:
$this->moveStrafe = $packet->moveStrafe;
$this->moveForward = $packet->moveForward;
$this->isJumping = $packet->isJumping; $this->isJumping = $packet->isJumping;
$this->isSneaking = $packet->isSneaking; $this->isSneaking = $packet->isSneaking;
$this->entity->moveForward = $packet->moveForward;
$this->entity->moveStrafing = $packet->moveStrafe;
if(strlen(bin2hex($packet->buffer)) === 24 && $this->entity->linkedEntity != 0){ if(strlen(bin2hex($packet->buffer)) === 24 && $this->entity->linkedEntity != 0){
$this->entity->stopRiding(); $this->entity->stopRiding();

View file

@ -106,6 +106,8 @@ class Entity extends Position
public $inWeb; public $inWeb;
public $inLava; public $inLava;
public $moveStrafing, $moveForward;
function __construct(Level $level, $eid, $class, $type = 0, $data = []) function __construct(Level $level, $eid, $class, $type = 0, $data = [])
{ {
$this->random = new Random(); $this->random = new Random();

View file

@ -6,7 +6,7 @@ abstract class Living extends Entity implements Pathfindable{
public static $pathfinderTest = false; public static $pathfinderTest = false;
public $moveStrafing, $moveForward;
/** /**
* @var Entity $target * @var Entity $target
* @var EntityAI $ai * @var EntityAI $ai

View file

@ -122,7 +122,7 @@ class Minecart extends Vehicle{
if($v29 < 0) ++$y; if($v29 < 0) ++$y;
if($v29 > 0) $y += 0.5; if($v29 > 0) $y += 0.5;
console("$x $y $z");
return [$x, $y, $z]; return [$x, $y, $z];
} }
@ -168,27 +168,18 @@ class Minecart extends Vehicle{
$this->speedZ = ($speedTotal * $matZDiff) / $matDiffTotal; $this->speedZ = ($speedTotal * $matZDiff) / $matDiffTotal;
if($this->linkedEntity != 0 && !$this->isRider){ if($this->linkedEntity != 0 && !$this->isRider){
//TODO additional riding physics $rider = $this->level->entityList[$this->linkedEntity] ?? false;
/* if($rider instanceof Entity && ($rider->isPlayer() || $rider->class == ENTITY_MOB)){
* if ( rider->vtable->_ZNK6Entity5isMobEv(rider) ) if($rider->moveForward > 0){
{ $v32 = sin($this->yaw * M_PI / 180);
v65 = this->base.super.rider; $v33 = cos($this->yaw * M_PI / 180);
if ( v65[10].base.prevZ > 0.0 )
{ if($this->speedZ*$this->speedZ + $this->speedX*$this->speedX < 0.01){
v32 = (float)((float)(v65->base.yaw * 3.1416) / 180.0) * 10430.0; $this->speedX -= $v32*0.1;
v33 = this->base.super.motionX; $this->speedZ += $v33*0.1;
v34 = Mth::_sin[(unsigned __int16)(int)v32]; }
v35 = (int)(float)(v32 + 16384.0); }
v36 = this->base.super.motionZ; }
if ( (float)((float)(v36 * v36) + (float)(v33 * v33)) < 0.01 )
{
v37 = v36 + (float)(Mth::_sin[v35] * 0.1);
this->base.super.motionX = v33 - (float)(v34 * 0.1);
this->base.super.motionZ = v37;
}
}
}
*/
} }
$v38 = ($x + 0.5) + ($mat[0][0] * 0.5); $v38 = ($x + 0.5) + ($mat[0][0] * 0.5);
@ -238,36 +229,24 @@ class Minecart extends Vehicle{
} }
$this->applyNaturalSlowdown(); $this->applyNaturalSlowdown();
$vec2 = $this->getPos($this->x, $this->y, $this->z);
if($vec2 !== false && $vec !== false){
$yDiff = ($vec[1] - $vec2[1]) * 0.05;
$totalSpeed = sqrt($this->speedZ*$this->speedZ + $this->speedX*$this->speedX);
//TODO more if($totalSpeed > 0){
/* $this->speedX = ($this->speedX / $totalSpeed) * ($totalSpeed + $yDiff);
* v57 = this->base.super.posZ; $this->speedZ = ($this->speedZ / $totalSpeed) * ($totalSpeed + $yDiff);
memset(&result, 0, sizeof(result)); }
if ( Minecart::getPos(this, &result, this->base.super.posX, this->base.super.posY, v57) && v71 ) $this->setPos($this->x, $vec2[1], $this->z);
{ }
v66 = (float)(posVec1.yCoord - result.yCoord) * 0.05;
v67 = Mth::sqrt( /*if($this->x != $x || $this->z != $z){ this breaks everything
(float)(this->base.super.motionZ * this->base.super.motionZ) $totalSpeed = sqrt($this->speedZ*$this->speedZ + $this->speedX*$this->speedX);
+ (float)(this->base.super.motionX * this->base.super.motionX)); $this->speedX = ($this->x - $x) * $totalSpeed;
if ( v67 > 0.0 ) $this->speedZ = ($this->z - $z) * $totalSpeed;
{ console(($this->x - $x).":".($this->z - $z).":".$totalSpeed);
this->base.super.motionX = (float)(this->base.super.motionX / v67) * (float)(v67 + v66); }*/
this->base.super.motionZ = (float)(this->base.super.motionZ / v67) * (float)(v67 + v66);
}
this->vtable->_ZN6Entity6setPosEfff((Entity *)this, this->base.super.posX, result.yCoord, this->base.super.posZ);
}
v58 = Mth::floor(this->base.super.posX);
v59 = Mth::floor(this->base.super.posZ);
if ( v58 != x || v59 != z )
{
v60 = v59 - z;
v61 = Mth::sqrt(
(float)(this->base.super.motionZ * this->base.super.motionZ)
+ (float)(this->base.super.motionX * this->base.super.motionX));
this->base.super.motionX = v61 * (float)(v58 - x);
this->base.super.motionZ = v61 * (float)v60;
}
*/
if($id == POWERED_RAIL){ if($id == POWERED_RAIL){
$totalSpeed = sqrt($this->speedZ*$this->speedZ + $this->speedX*$this->speedX); $totalSpeed = sqrt($this->speedZ*$this->speedZ + $this->speedX*$this->speedX);
@ -296,7 +275,7 @@ class Minecart extends Vehicle{
if(!StaticBlock::getIsSolid($this->level->level->getBlockID($x, $y, $z + 1))){ if(!StaticBlock::getIsSolid($this->level->level->getBlockID($x, $y, $z + 1))){
return; return;
} }
$v64 -= 0.02; $v64 = -0.02;
} }
$this->speedZ = $v64; $this->speedZ = $v64;
} }