mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
minecart pushing test
This commit is contained in:
parent
fb13a6123b
commit
39dbd6db34
5 changed files with 110 additions and 22 deletions
|
|
@ -1263,8 +1263,8 @@ class Player{
|
|||
if($e->modifySpeedY){
|
||||
$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->speedY < 0 && $e->onGround) || $e->speedX != 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){
|
||||
$motion = new SetEntityMotionPacket();
|
||||
$motion->eid = $e->eid;
|
||||
$motion->speedX = $e->speedX;
|
||||
|
|
@ -1274,8 +1274,8 @@ class Player{
|
|||
$len += 1 + strlen($motion->buffer);
|
||||
++$packets;
|
||||
$motionSent = true;
|
||||
}
|
||||
}
|
||||
// }
|
||||
//}
|
||||
if($e->modifySpeedY){
|
||||
$e->speedY = $svdYSpeed;
|
||||
$e->modifySpeedY = false;
|
||||
|
|
@ -1316,7 +1316,7 @@ class Player{
|
|||
$headSent = true;
|
||||
}
|
||||
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;
|
||||
if(($this->entityMovementQueueLength + $len) >= $MTU){
|
||||
$this->sendEntityMovementUpdateQueue();
|
||||
|
|
|
|||
|
|
@ -221,7 +221,7 @@ class Entity extends Position
|
|||
}
|
||||
|
||||
public function isPushable(){
|
||||
return false;
|
||||
return $this->isPlayer();
|
||||
}
|
||||
|
||||
public function applyCollision(Entity $collided){
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ abstract class Living extends Entity implements Pathfindable{
|
|||
foreach($this->level->entityListPositioned[$ind] ?? [] as $entid){
|
||||
if(($this->level->entityList[$entid] ?? null) instanceof Entity){
|
||||
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->rotateTick();
|
||||
//$this->ai->mobController->jumpTick();
|
||||
$this->ai->mobController->movementTick();
|
||||
$this->ai->mobController->rotateTick();
|
||||
$this->ai->mobController->jumpTick();
|
||||
|
||||
if(abs($this->speedX) < self::MIN_POSSIBLE_SPEED) $this->speedX = 0;
|
||||
if(abs($this->speedZ) < self::MIN_POSSIBLE_SPEED) $this->speedZ = 0;
|
||||
|
|
|
|||
|
|
@ -10,14 +10,14 @@ class Pig extends Animal implements Rideable{
|
|||
$this->setName("Pig");
|
||||
$this->setSpeed(0.25);
|
||||
|
||||
//$this->ai->addTask(new TaskRandomWalk(1.0));
|
||||
//$this->ai->addTask(new TaskLookAtPlayer(6));
|
||||
//$this->ai->addTask(new TaskPanic(1.5));
|
||||
//$this->ai->addTask(new TaskLookAround());
|
||||
$this->ai->addTask(new TaskRandomWalk(1.0));
|
||||
$this->ai->addTask(new TaskLookAtPlayer(6));
|
||||
$this->ai->addTask(new TaskPanic(1.5));
|
||||
$this->ai->addTask(new TaskLookAround());
|
||||
$this->ai->addTask(new TaskSwimming());
|
||||
//$this->ai->addTask(new TaskTempt(1.0));
|
||||
//$this->ai->addTask(new TaskMate(1.0));
|
||||
//$this->ai->addTask(new TaskFollowParent(1.1));
|
||||
$this->ai->addTask(new TaskTempt(1.0));
|
||||
$this->ai->addTask(new TaskMate(1.0));
|
||||
$this->ai->addTask(new TaskFollowParent(1.1));
|
||||
}
|
||||
/**
|
||||
* @return boolean
|
||||
|
|
@ -38,7 +38,7 @@ class Pig extends Animal implements Rideable{
|
|||
}
|
||||
|
||||
public function updateEntityMovement(){
|
||||
if($this->linkedEntity != 0){
|
||||
/*if($this->linkedEntity != 0){
|
||||
$e = $this->level->entityList[$this->linkedEntity] ?? false;
|
||||
if($e instanceof Entity){
|
||||
$this->setAIMoveSpeed($this->getSpeed());
|
||||
|
|
@ -46,7 +46,7 @@ class Pig extends Animal implements Rideable{
|
|||
$this->moveForward = $e->player->moveForward;
|
||||
$this->yaw = $e->headYaw;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
parent::updateEntityMovement();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,9 +63,8 @@ class Minecart extends Vehicle{
|
|||
$this->y = isset($this->data["TileY"]) ? $this->data["TileY"]:$this->y;
|
||||
$this->z = isset($this->data["TileZ"]) ? $this->data["TileZ"]:$this->z;
|
||||
$this->setHealth(1, "generic"); //orig: 3
|
||||
$this->width = 0.98;
|
||||
$this->height = 0.7;
|
||||
$this->yOffset = $this->height / 2;
|
||||
$this->setSize(0.98, 0.7);
|
||||
//$this->yOffset = $this->height / 2;
|
||||
}
|
||||
|
||||
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){
|
||||
if($this->closed === true){
|
||||
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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue