mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
rewrote riding
This commit is contained in:
parent
c3b09096b4
commit
5f5c2b82de
4 changed files with 62 additions and 48 deletions
|
|
@ -724,14 +724,15 @@ class Player{
|
|||
switch($event){
|
||||
case "entity.link":
|
||||
$pk = new SetEntityLinkPacket();
|
||||
if($data["rider"] === $this->eid){
|
||||
$pk->rider = 0;
|
||||
}else{
|
||||
$pk->rider = $data["rider"];
|
||||
}
|
||||
$pk->riding = $data["riding"];
|
||||
$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){
|
||||
|
|
@ -2466,25 +2467,29 @@ class Player{
|
|||
}
|
||||
break;
|
||||
case ProtocolInfo::PLAYER_INPUT_PACKET:
|
||||
if(strlen(bin2hex($packet->buffer)) === 24 && $this->entity->linkedEntity instanceof Entity){
|
||||
$this->entity->linkedEntity->linkEntity($this->entity->linkedEntity, SetEntityLinkPacket::TYPE_RIDE);
|
||||
$this->entity->linkedEntity->linkedEntity = false;
|
||||
$this->entity->linkedEntity = false;
|
||||
if(strlen(bin2hex($packet->buffer)) === 24 && $this->entity->linkedEntity != 0){
|
||||
$this->entity->stopRiding();
|
||||
}
|
||||
if($this->entity->linkedEntity instanceof Entity){
|
||||
if($this->entity->linkedEntity != 0){ //TODO better riding
|
||||
$e = $this->entity->level->entityList[$this->entity->linkedEntity] ?? false;
|
||||
if($e === false) {
|
||||
ConsoleAPI::warn("Player is riding on entity that doesnt exist in world! ({$this->iusername}, {$this->entity->linkedEntity})");
|
||||
$this->entity->stopRiding();
|
||||
break;
|
||||
}
|
||||
$pk = new SetEntityMotionPacket;
|
||||
$pk->eid = $this->entity->linkedEntity->eid;
|
||||
$pk->speedX = ($this->entity->x - $this->entity->linkedEntity->x)*1.2;
|
||||
$pk->speedY = ($this->entity->y - $this->entity->linkedEntity->y)*1.2;
|
||||
$pk->speedZ = ($this->entity->z - $this->entity->linkedEntity->z)*1.2;
|
||||
$pk->eid = $e->eid;
|
||||
$pk->speedX = ($this->entity->x - $e->x)*1.2;
|
||||
$pk->speedY = ($this->entity->y - $e->y)*1.2;
|
||||
$pk->speedZ = ($this->entity->z - $e->z)*1.2;
|
||||
foreach($this->level->players as $p){
|
||||
if($p->entity->eid != $this->entity->eid){
|
||||
$p->dataPacket(clone $pk);
|
||||
}
|
||||
}
|
||||
|
||||
$this->entity->linkedEntity->setPosition($this->entity);
|
||||
$this->entity->linkedEntity->sendMoveUpdate();
|
||||
$e->setPosition($this->entity);
|
||||
$e->sendMoveUpdate();
|
||||
//$this->entity->linkedEntity->moveFlying($packet->moveStrafe, $packet->moveForward, 1);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -481,13 +481,6 @@ class Entity extends Position
|
|||
$hasUpdate = true;
|
||||
}
|
||||
|
||||
$startX = floor($this->boundingBox->minX);
|
||||
$startY = floor($this->boundingBox->minY);
|
||||
$startZ = floor($this->boundingBox->minZ);
|
||||
$endX = ceil($this->boundingBox->maxX);
|
||||
$endY = ceil($this->boundingBox->maxY);
|
||||
$endZ = ceil($this->boundingBox->maxZ);
|
||||
|
||||
if(!($this instanceof Painting) && !($this->isPlayer() && $this->player->isSleeping !== false)){ //TODO better way to fix
|
||||
$x = floor($this->x);
|
||||
$y = floor($this->y + $this->getEyeHeight());
|
||||
|
|
@ -1394,12 +1387,38 @@ class Entity extends Position
|
|||
{
|
||||
return $this->setHealth(min(20, $this->getHealth() + ((int) $health)), $cause);
|
||||
}
|
||||
|
||||
public function linkEntity(Entity $e, $type)
|
||||
|
||||
public function stopRiding(){
|
||||
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;
|
||||
}
|
||||
}else{
|
||||
$this->linkedEntity = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function setRiding(Entity $e, $type = 0)
|
||||
{
|
||||
$this->linkedEntity = $e;
|
||||
$e->linkedEntity = $this;
|
||||
$this->server->api->dhandle("entity.link", ["rider" => $e->eid, "riding" => $this->eid, "type" => 0]);
|
||||
if(!isset($this->level->entityList[$e->eid])){
|
||||
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;
|
||||
$this->server->api->dhandle("entity.link", ["rider" => $this->eid, "riding" => $e->eid, "type" => $type]);
|
||||
}else{
|
||||
$this->linkedEntity = $e->eid;
|
||||
$e->linkedEntity = $this->eid;
|
||||
$this->server->api->dhandle("entity.link", ["rider" => $this->eid, "riding" => $e->eid, "type" => 0]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function isPlayer()
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class Pig extends Animal implements Rideable{
|
|||
}
|
||||
|
||||
public function canRide($e){
|
||||
return $this->isSaddled() && !($this->linkedEntity instanceof Entity);
|
||||
return $this->isSaddled() && $this->linkedEntity == 0 && $e->linkedEntity == 0;
|
||||
}
|
||||
|
||||
public function interactWith(Entity $e, $action)
|
||||
|
|
@ -43,17 +43,10 @@ class Pig extends Animal implements Rideable{
|
|||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$slot = $e->player->getHeldItem();
|
||||
if($this->canRide($e)){
|
||||
$this->linkedEntity = $e;
|
||||
$e->isRiding = true;
|
||||
$this->linkEntity($e, SetEntityLinkPacket::TYPE_RIDE);
|
||||
return true;
|
||||
}
|
||||
if($e->isRiding && $this->linkedEntity instanceof Entity && $this->linkedEntity->eid === $e->eid){
|
||||
$this->linkEntity($e, SetEntityLinkPacket::TYPE_REMOVE);
|
||||
$e->isRiding = false;
|
||||
$this->linkedEntity = 0;
|
||||
$e->setRiding($this);
|
||||
return true;
|
||||
}
|
||||
|
||||
if($slot->getID() === SADDLE){
|
||||
if(!$this->isSaddled()){
|
||||
$e->player->removeItem($slot->getID(), 0, 1);
|
||||
|
|
|
|||
|
|
@ -102,23 +102,20 @@ class Minecart extends Vehicle{
|
|||
}
|
||||
|
||||
public function interactWith(Entity $e, $action){
|
||||
console($action);
|
||||
if($action === InteractPacket::ACTION_HOLD && $e->isPlayer() && $this->canRide($e)){
|
||||
$this->linkedEntity = $e;
|
||||
$e->isRiding = true;
|
||||
$this->linkEntity($e, SetEntityLinkPacket::TYPE_RIDE);
|
||||
console("set ride");
|
||||
$e->setRiding($this);
|
||||
return true;
|
||||
}
|
||||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$this->linkEntity($e, SetEntityLinkPacket::TYPE_REMOVE);
|
||||
$this->linkedEntity = 0;
|
||||
$e->isRiding = false;
|
||||
return true;
|
||||
if($action === InteractPacket::ACTION_ATTACK && $e->eid == $this->linkedEntity){
|
||||
return false; //TODO more vanilla way?
|
||||
}
|
||||
parent::interactWith($e, $action);
|
||||
}
|
||||
public function canRide($e)
|
||||
{
|
||||
return !($this->linkedEntity instanceof Entity) && !$e->isRiding;
|
||||
return $this->linkedEntity == 0 && $e->linkedEntity == 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue