minecart pushing test

This commit is contained in:
GameHerobrine 2024-06-09 05:24:57 +03:00
parent fb13a6123b
commit 39dbd6db34
5 changed files with 110 additions and 22 deletions

View file

@ -1263,8 +1263,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 +1274,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 +1316,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();

View file

@ -221,7 +221,7 @@ class Entity extends Position
} }
public function isPushable(){ public function isPushable(){
return false; return $this->isPlayer();
} }
public function applyCollision(Entity $collided){ public function applyCollision(Entity $collided){

View file

@ -99,7 +99,7 @@ abstract class Living extends Entity implements Pathfindable{
foreach($this->level->entityListPositioned[$ind] ?? [] as $entid){ foreach($this->level->entityListPositioned[$ind] ?? [] as $entid){
if(($this->level->entityList[$entid] ?? null) instanceof Entity){ if(($this->level->entityList[$entid] ?? null) instanceof Entity){
if($this->level->entityList[$entid]->isPushable() && $bb->intersectsWith($this->level->entityList[$entid]->boundingBox)){ if($this->level->entityList[$entid]->isPushable() && $bb->intersectsWith($this->level->entityList[$entid]->boundingBox)){
$this->level->entityList[$entid]->applyCollision($this); $this->level->entityList[$entid]->applyCollision($this, true);
} }
} }
} }
@ -188,9 +188,9 @@ abstract class Living extends Entity implements Pathfindable{
} }
//$this->ai->mobController->movementTick(); $this->ai->mobController->movementTick();
//$this->ai->mobController->rotateTick(); $this->ai->mobController->rotateTick();
//$this->ai->mobController->jumpTick(); $this->ai->mobController->jumpTick();
if(abs($this->speedX) < self::MIN_POSSIBLE_SPEED) $this->speedX = 0; if(abs($this->speedX) < self::MIN_POSSIBLE_SPEED) $this->speedX = 0;
if(abs($this->speedZ) < self::MIN_POSSIBLE_SPEED) $this->speedZ = 0; if(abs($this->speedZ) < self::MIN_POSSIBLE_SPEED) $this->speedZ = 0;

View file

@ -10,14 +10,14 @@ class Pig extends Animal implements Rideable{
$this->setName("Pig"); $this->setName("Pig");
$this->setSpeed(0.25); $this->setSpeed(0.25);
//$this->ai->addTask(new TaskRandomWalk(1.0)); $this->ai->addTask(new TaskRandomWalk(1.0));
//$this->ai->addTask(new TaskLookAtPlayer(6)); $this->ai->addTask(new TaskLookAtPlayer(6));
//$this->ai->addTask(new TaskPanic(1.5)); $this->ai->addTask(new TaskPanic(1.5));
//$this->ai->addTask(new TaskLookAround()); $this->ai->addTask(new TaskLookAround());
$this->ai->addTask(new TaskSwimming()); $this->ai->addTask(new TaskSwimming());
//$this->ai->addTask(new TaskTempt(1.0)); $this->ai->addTask(new TaskTempt(1.0));
//$this->ai->addTask(new TaskMate(1.0)); $this->ai->addTask(new TaskMate(1.0));
//$this->ai->addTask(new TaskFollowParent(1.1)); $this->ai->addTask(new TaskFollowParent(1.1));
} }
/** /**
* @return boolean * @return boolean
@ -38,7 +38,7 @@ class Pig extends Animal implements Rideable{
} }
public function updateEntityMovement(){ public function updateEntityMovement(){
if($this->linkedEntity != 0){ /*if($this->linkedEntity != 0){
$e = $this->level->entityList[$this->linkedEntity] ?? false; $e = $this->level->entityList[$this->linkedEntity] ?? false;
if($e instanceof Entity){ if($e instanceof Entity){
$this->setAIMoveSpeed($this->getSpeed()); $this->setAIMoveSpeed($this->getSpeed());
@ -46,7 +46,7 @@ class Pig extends Animal implements Rideable{
$this->moveForward = $e->player->moveForward; $this->moveForward = $e->player->moveForward;
$this->yaw = $e->headYaw; $this->yaw = $e->headYaw;
} }
} }*/
parent::updateEntityMovement(); parent::updateEntityMovement();
} }

View file

@ -63,9 +63,8 @@ class Minecart extends Vehicle{
$this->y = isset($this->data["TileY"]) ? $this->data["TileY"]:$this->y; $this->y = isset($this->data["TileY"]) ? $this->data["TileY"]:$this->y;
$this->z = isset($this->data["TileZ"]) ? $this->data["TileZ"]:$this->z; $this->z = isset($this->data["TileZ"]) ? $this->data["TileZ"]:$this->z;
$this->setHealth(1, "generic"); //orig: 3 $this->setHealth(1, "generic"); //orig: 3
$this->width = 0.98; $this->setSize(0.98, 0.7);
$this->height = 0.7; //$this->yOffset = $this->height / 2;
$this->yOffset = $this->height / 2;
} }
public function isPickable(){ public function isPickable(){
@ -78,12 +77,101 @@ class Minecart extends Vehicle{
]; ];
} }
public function comeOffTrack($topSpeed){
if($this->speedX < -$topSpeed) $this->speedX = -$topSpeed;
else if($this->speedX > $topSpeed) $this->speedX = $topSpeed;
if($this->speedZ < -$topSpeed) $this->speedZ = -$topSpeed;
else if($this->speedZ > $topSpeed) $this->speedZ = $topSpeed;
if($this->onGround){
console("speedX");
$this->speedX *= 0.5;
$this->speedY *= 0.5;
$this->speedZ *= 0.5;
}
$this->move($this->speedX, $this->speedY, $this->speedZ);
if(!$this->onGround){
$this->speedX *= 0.95;
$this->speedY *= 0.95;
$this->speedZ *= 0.95;
}
}
public function applyCollision(Entity $collided){
console("nya");
$diffX = $collided->x - $this->x;
$diffZ = $collided->z - $this->z;
$dist = $diffX*$diffX + $diffZ*$diffZ;
if($dist >= 0.0001){
$sqrtMax = sqrt($dist);
$diffX /= $sqrtMax;
$diffZ /= $sqrtMax;
$col = (($v = 1 / $sqrtMax) > 1 ? 1 : $v);
$diffX *= $col;
$diffZ *= $col;
$diffX *= 0.1;
$diffZ *= 0.1;
$diffX *= 0.5;
$diffZ *= 0.5;
$this->addVelocity(-$diffX, 0, -$diffZ);
$collided->addVelocity($diffX / 4, 0, $diffZ / 4);
}
//parent::applyCollision($collided);
}
public function update($now){ public function update($now){
if($this->closed === true){ if($this->closed === true){
return false; return false;
} }
console($this->boundingBox);
$this->updateLast();
$this->updatePosition();
$this->speedY -= 0.04;
//TODO port stuff
$this->comeOffTrack(0.4);
$bb = $this->boundingBox->expand(0.2, 0, 0.2);
$minChunkX = ((int)($bb->minX)) >> 4;
$minChunkZ = ((int)($bb->minZ)) >> 4;
$maxChunkX = ((int)($bb->minX)) >> 4;
$maxChunkZ = ((int)($bb->minZ)) >> 4;
//TODO also index by chunkY?
for($chunkX = $minChunkX; $chunkX <= $maxChunkX; ++$chunkX){
for($chunkZ = $minChunkZ; $chunkZ <= $maxChunkZ; ++$chunkZ){
$ind = "$chunkX $chunkZ";
foreach($this->level->entityListPositioned[$ind] ?? [] as $entid){
$e = ($this->level->entityList[$entid] ?? null);
if($e instanceof Entity && $e->eid != $this->eid && $e->eid != $this->linkedEntity){
if($e->isPushable() && $this->boundingBox->intersectsWith($e->boundingBox)){
if($e->isPlayer()){
$this->applyCollision($e, true);
}else{
$e->applyCollision($this);
console("colliding with $e");
}
}
}
}
}
}
$motion = new SetEntityMotionPacket();
$motion->eid = $e->eid;
$motion->speedX = $e->speedX;
$motion->speedY = $e->speedY;
$motion->speedZ = $e->speedZ;
foreach($this->level->players as $p){
$p->directDataPacket(clone $motion);
}
} }
public function close() public function close()