mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
fixed unmount (hopefully one last time)
This commit is contained in:
parent
5f5c2b82de
commit
fb13a6123b
10 changed files with 100 additions and 36 deletions
|
|
@ -76,6 +76,15 @@ class Player{
|
|||
public $blockUpdateQueue;
|
||||
public $blockUpdateQueueLength = 0;
|
||||
|
||||
/**
|
||||
* Sent by a client while it is linked to some entity.
|
||||
* @var float $moveStrafe
|
||||
* @var float $moveForward
|
||||
* @var boolean $isJumping
|
||||
* @var boolean $isSneaking
|
||||
*/
|
||||
public $moveStrafe, $moveForward, $isJumping, $isSneaking;
|
||||
|
||||
/**
|
||||
* @param integer $clientID
|
||||
* @param string $ip
|
||||
|
|
@ -727,12 +736,7 @@ class Player{
|
|||
$pk->rider = $data["rider"] == $this->entity->eid ? 0 : $data["rider"];
|
||||
$pk->riding = $data["riding"] == $this->entity->eid ? 0 : $data["riding"];
|
||||
$pk->type = 0;
|
||||
if($data["type"] == $this->entity->eid){
|
||||
console("dont send to {$this}");
|
||||
break;
|
||||
}
|
||||
$this->dataPacket($pk);
|
||||
console("nya");
|
||||
break;
|
||||
case "tile.update":
|
||||
if($data->level === $this->level){
|
||||
|
|
@ -2467,8 +2471,15 @@ class Player{
|
|||
}
|
||||
break;
|
||||
case ProtocolInfo::PLAYER_INPUT_PACKET:
|
||||
|
||||
$this->moveStrafe = $packet->moveStrafe;
|
||||
$this->moveForward = $packet->moveForward;
|
||||
$this->isJumping = $packet->isJumping;
|
||||
$this->isSneaking = $packet->isSneaking;
|
||||
|
||||
if(strlen(bin2hex($packet->buffer)) === 24 && $this->entity->linkedEntity != 0){
|
||||
$this->entity->stopRiding();
|
||||
break;
|
||||
}
|
||||
if($this->entity->linkedEntity != 0){ //TODO better riding
|
||||
$e = $this->entity->level->entityList[$this->entity->linkedEntity] ?? false;
|
||||
|
|
@ -2477,7 +2488,7 @@ class Player{
|
|||
$this->entity->stopRiding();
|
||||
break;
|
||||
}
|
||||
$pk = new SetEntityMotionPacket;
|
||||
/*$pk = new SetEntityMotionPacket;
|
||||
$pk->eid = $e->eid;
|
||||
$pk->speedX = ($this->entity->x - $e->x)*1.2;
|
||||
$pk->speedY = ($this->entity->y - $e->y)*1.2;
|
||||
|
|
@ -2487,10 +2498,8 @@ class Player{
|
|||
$p->dataPacket(clone $pk);
|
||||
}
|
||||
}
|
||||
|
||||
$e->setPosition($this->entity);
|
||||
$e->sendMoveUpdate();
|
||||
//$this->entity->linkedEntity->moveFlying($packet->moveStrafe, $packet->moveForward, 1);
|
||||
console("{$e} {$this->entity}");
|
||||
//$this->entity->linkedEntity->moveFlying($packet->moveStrafe, $packet->moveForward, 1);*/
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ class TileNavigator
|
|||
}
|
||||
|
||||
public function reconstructPath($path, $current){
|
||||
console("path built");
|
||||
$totalPath = [$current];
|
||||
while (isset($path[(string)$current]))
|
||||
{
|
||||
|
|
@ -172,7 +173,7 @@ class TileNavigator
|
|||
$path[$neighbor] = $current;
|
||||
|
||||
if($targetDist < $closestToTargetDist){
|
||||
console("found new best to target: $neighbor($closestToTargetDist -> $targetDist)");
|
||||
//console("found new best to target: $neighbor($closestToTargetDist -> $targetDist)");
|
||||
|
||||
$closestToTarget = $neighbor;
|
||||
$closestToTargetDist = $targetDist;
|
||||
|
|
|
|||
|
|
@ -73,6 +73,10 @@ abstract class Creature extends Living{
|
|||
$pk->speedY = $this->speedY;
|
||||
$pk->speedZ = $this->speedZ;
|
||||
$player->dataPacket($pk);
|
||||
|
||||
if($this->linkedEntity != 0 && $this->isRider){
|
||||
$player->eventHandler(["rider" => $this->eid, "riding" => $this->linkedEntity, "type" => 0], "entity.link");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,8 @@ class Entity extends Position
|
|||
public $level;
|
||||
public $isRiding = false;
|
||||
public $lastUpdate;
|
||||
public $linkedEntity = null;
|
||||
public $linkedEntity = 0;
|
||||
public $isRider = false;
|
||||
public $check = true;
|
||||
public $width = 1;
|
||||
public $height = 1;
|
||||
|
|
@ -1104,6 +1105,12 @@ class Entity extends Position
|
|||
$pk->did = -$this->data["Tile"];
|
||||
$player->dataPacket($pk);
|
||||
}
|
||||
|
||||
if($this->linkedEntity != 0 && $this->isRider){
|
||||
console("send $player");
|
||||
$player->eventHandler(["rider" => $this->eid, "riding" => $this->linkedEntity, "type" => 0], "entity.link"); //TODO fix it
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function counterUpdate(){
|
||||
|
|
@ -1276,7 +1283,7 @@ class Entity extends Position
|
|||
],
|
||||
"speedX" => $this->speedX,
|
||||
"speedY" => $this->speedY,
|
||||
"speedZ" => $this->speedZ
|
||||
"speedZ" => $this->speedZ,
|
||||
|
||||
];
|
||||
if($this->class === ENTITY_OBJECT){
|
||||
|
|
@ -1392,9 +1399,11 @@ class Entity extends Position
|
|||
if(isset($this->level->entityList[$this->linkedEntity])){
|
||||
$e = $this->level->entityList[$this->linkedEntity];
|
||||
if(!$e->dead && !$e->closed){
|
||||
$e->setRiding($e, $this->eid); //why mojang
|
||||
$this->linkedEntity = 0;
|
||||
$e->linkedEntity = 0;
|
||||
$this->server->api->dhandle("entity.link", ["rider" => $this->eid, "riding" => -1, "type" => 1]);
|
||||
$this->server->api->dhandle("entity.link", ["rider" => $this->linkedEntity, "riding" => -1, "type" => 1]);
|
||||
$this->isRider = false;
|
||||
}
|
||||
}else{
|
||||
$this->linkedEntity = 0;
|
||||
|
|
@ -1407,7 +1416,7 @@ class Entity extends Position
|
|||
ConsoleAPI::warn("Tried linking $this with $e that doesnt exist in the world!");
|
||||
return;
|
||||
}
|
||||
console("unlink $this $e");
|
||||
|
||||
if($this->linkedEntity == $e->eid || $e->eid == $this->eid){
|
||||
$this->linkedEntity = 0;
|
||||
$e->linkedEntity = 0;
|
||||
|
|
@ -1415,6 +1424,7 @@ class Entity extends Position
|
|||
}else{
|
||||
$this->linkedEntity = $e->eid;
|
||||
$e->linkedEntity = $this->eid;
|
||||
$this->isRider = true;
|
||||
$this->server->api->dhandle("entity.link", ["rider" => $this->eid, "riding" => $e->eid, "type" => 0]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -134,15 +134,21 @@ abstract class Living extends Entity implements Pathfindable{
|
|||
//$target = new PathTileXYZ($this->x + mt_rand(-10, 10), $this->y + mt_rand(-1, 1), $this->z + mt_rand(-10, 10), $this->level);
|
||||
$pl = null;
|
||||
if(count($this->level->players) > 0){
|
||||
$pl = array_values($this->level->players)[0];
|
||||
//$pl = array_values($this->level->players)[0];
|
||||
//$target = new PathTileXYZ($pl->entity->x, $pl->entity->y, $pl->entity->z, $this->level);
|
||||
}
|
||||
if(self::$pathfind){
|
||||
$this->path = $this->pathFinder->navigate($this->level, (int)$this->x, (int)$this->y, (int)$this->z, (int)$pl->entity->x, (int)$pl->entity->y, (int)$pl->entity->z, 10);
|
||||
$this->path = $this->pathFinder->navigate(
|
||||
$this->level,
|
||||
(int)$this->x, (int)$this->y, (int)$this->z,
|
||||
//(int)$pl->entity->x, (int)$pl->entity->y, (int)$pl->entity->z,
|
||||
(int)$this->x + mt_rand(-16, 16), (int)$this->y, (int)$this->z + mt_rand(-16, 16),
|
||||
16
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if($this->path){
|
||||
/*if($this->path){
|
||||
console("Found path of length ".count($this->path));
|
||||
|
||||
foreach($this->path as $node){
|
||||
|
|
@ -161,7 +167,7 @@ abstract class Living extends Entity implements Pathfindable{
|
|||
$player->dataPacket($pk);
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
$this->pathFollower->followPath();
|
||||
}
|
||||
|
|
@ -182,14 +188,13 @@ 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;
|
||||
if(abs($this->speedY) < self::MIN_POSSIBLE_SPEED) $this->speedY = 0;
|
||||
|
||||
$this->moveStrafing *= 0.98;
|
||||
$this->moveForward *= 0.98;
|
||||
$savedLandFactor = $this->landMovementFactor;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ class PathFollower{
|
|||
$this->entity->ai->mobController->setMovingTarget($moveX, $moveY, $moveZ, 1.0);
|
||||
if($this->entity->boundingBox->isXYZInsideNS($moveX, $moveY, $moveZ)){
|
||||
++$this->entity->currentIndex;
|
||||
console("next");
|
||||
//console("next");
|
||||
$this->entity->currentNode = null;
|
||||
}
|
||||
|
||||
|
|
@ -35,13 +35,13 @@ class PathFollower{
|
|||
$this->entity->path = null;
|
||||
$this->entity->currentIndex = 0;
|
||||
|
||||
foreach($this->entity->pathEIDS as $eid){
|
||||
/*foreach($this->entity->pathEIDS as $eid){
|
||||
$pk = new RemoveEntityPacket();
|
||||
$pk->eid = $eid;
|
||||
foreach($this->entity->level->players as $player){
|
||||
$player->dataPacket($pk);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,15 +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
|
||||
|
|
@ -37,7 +36,21 @@ class Pig extends Animal implements Rideable{
|
|||
public function canRide($e){
|
||||
return $this->isSaddled() && $this->linkedEntity == 0 && $e->linkedEntity == 0;
|
||||
}
|
||||
|
||||
|
||||
public function updateEntityMovement(){
|
||||
if($this->linkedEntity != 0){
|
||||
$e = $this->level->entityList[$this->linkedEntity] ?? false;
|
||||
if($e instanceof Entity){
|
||||
$this->setAIMoveSpeed($this->getSpeed());
|
||||
$this->moveStrafing = $e->player->moveStrafe;
|
||||
$this->moveForward = $e->player->moveForward;
|
||||
$this->yaw = $e->headYaw;
|
||||
}
|
||||
}
|
||||
|
||||
parent::updateEntityMovement();
|
||||
}
|
||||
|
||||
public function interactWith(Entity $e, $action)
|
||||
{
|
||||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
|
|
|
|||
|
|
@ -78,6 +78,27 @@ class Minecart extends Vehicle{
|
|||
];
|
||||
}
|
||||
|
||||
public function update($now){
|
||||
if($this->closed === true){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function close()
|
||||
{
|
||||
parent::close();
|
||||
if($this->linkedEntity != 0){
|
||||
$ent = $this->level->entityList[$this->linkedEntity] ?? false;
|
||||
if($ent instanceof Entity){
|
||||
$ent->stopRiding();
|
||||
}else{
|
||||
ConsoleAPI::warn("$this is being ridden by invalid entity {$this->linkedEntity}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function isPushable(){
|
||||
return false; //TODO replace with true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class MinecartItem extends Item{
|
|||
$server = ServerAPI::request();
|
||||
$data = [
|
||||
"x" => $target->getX() + 0.5,
|
||||
"y" => $target->getY() + 0.8,
|
||||
"y" => $target->getY() + 1,
|
||||
"z" => $target->getZ() + 0.5,
|
||||
];
|
||||
$e = $server->api->entity->add($level, ENTITY_OBJECT, OBJECT_MINECART, $data);
|
||||
|
|
|
|||
|
|
@ -295,6 +295,7 @@ class Level{
|
|||
|
||||
if($extra !== false){
|
||||
$entities = [];
|
||||
|
||||
foreach($this->entityList as $entity){
|
||||
if($entity instanceof Entity){
|
||||
$entities[] = $entity->createSaveData();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue