mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-22 12:39:43 +00:00
minecart entity tweaks
This commit is contained in:
parent
39bfa7115d
commit
b362f262f4
7 changed files with 23 additions and 19 deletions
|
|
@ -779,9 +779,6 @@ class Player{
|
||||||
$pk->speedY = $data->speedY;
|
$pk->speedY = $data->speedY;
|
||||||
$pk->speedZ = $data->speedZ;
|
$pk->speedZ = $data->speedZ;
|
||||||
$this->dataPacket($pk);
|
$this->dataPacket($pk);
|
||||||
$data->lastSpeedZ = $data->speedZ;
|
|
||||||
$data->lastSpeedY = $data->speedY;
|
|
||||||
$data->lastSpeedX = $data->speedX;
|
|
||||||
break;
|
break;
|
||||||
case "entity.animate":
|
case "entity.animate":
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ class TileNavigator implements ITileNavigator
|
||||||
|
|
||||||
public function navigate(PathTile $from, PathTile $to, $maxDist)
|
public function navigate(PathTile $from, PathTile $to, $maxDist)
|
||||||
{
|
{
|
||||||
$open = new SplPriorityQueue();
|
$open = [0 => $from];
|
||||||
$open->insert($from, 0);
|
//$open->insert(, 0);
|
||||||
$path = [];
|
$path = [];
|
||||||
$gScore = [];
|
$gScore = [];
|
||||||
$gScore[(string) $from] = 0;
|
$gScore[(string) $from] = 0;
|
||||||
|
|
@ -37,16 +37,16 @@ class TileNavigator implements ITileNavigator
|
||||||
}
|
}
|
||||||
$visited = [];
|
$visited = [];
|
||||||
$maxDist*=$maxDist; //no square root
|
$maxDist*=$maxDist; //no square root
|
||||||
while(!$open->isEmpty())
|
while(count($open) > 0)
|
||||||
{
|
{
|
||||||
$current = $open->top();
|
$current = array_pop($open);
|
||||||
$open->next();
|
|
||||||
if ($current == $to){
|
if ($current == $to){
|
||||||
return $this->reconstructPath($path, $current);
|
return $this->reconstructPath($path, $current);
|
||||||
}
|
}
|
||||||
foreach($this->neighborProvider->getNeighbors($current) as $neighbor)
|
foreach($this->neighborProvider->getNeighbors($current) as $neighbor)
|
||||||
{
|
{
|
||||||
if(!Utils::in_range(($from->x - $neighbor->x)*($from->x - $neighbor->x) + ($from->y - $neighbor->y)*($from->y - $neighbor->y) + ($from->z - $neighbor->z)*($from->z - $neighbor->z), -$maxDist, $maxDist)){ //Utils::distance_noroot($neighbor->asArray(), $from->asArray())
|
$dist = ($from->x - $neighbor->x)*($from->x - $neighbor->x) + ($from->y - $neighbor->y)*($from->y - $neighbor->y) + ($from->z - $neighbor->z)*($from->z - $neighbor->z);
|
||||||
|
if($dist < -$maxDist || $dist > $maxDist){ //Utils::distance_noroot($neighbor->asArray(), $from->asArray())
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(isset($visited[(string)$neighbor])){
|
if(isset($visited[(string)$neighbor])){
|
||||||
|
|
@ -58,7 +58,7 @@ class TileNavigator implements ITileNavigator
|
||||||
$tentativeG = $gScore[(string) $current] + $distbetweenCost;
|
$tentativeG = $gScore[(string) $current] + $distbetweenCost;
|
||||||
if (!isset($has[(string)$neighbor]))
|
if (!isset($has[(string)$neighbor]))
|
||||||
{
|
{
|
||||||
$open->insert($neighbor, -$tentativeG);
|
$open[-$tentativeG] = $neighbor;
|
||||||
$has[(string)$neighbor] = true;
|
$has[(string)$neighbor] = true;
|
||||||
}
|
}
|
||||||
elseif ($tentativeG >= $gScore[(string) $neighbor])
|
elseif ($tentativeG >= $gScore[(string) $neighbor])
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,11 @@
|
||||||
|
|
||||||
class MCDiagonalProvider implements INeighborProvider
|
class MCDiagonalProvider implements INeighborProvider
|
||||||
{
|
{
|
||||||
private static $neighbors = array([ 0, 0, -1 ], [ 1, 0, 0 ], [ 0, 0, 1 ], [ -1, 0, 0 ]);
|
private static $neighbors = array(
|
||||||
|
[ -1, 0, -1 ], [-1, 0, 0], [-1, 0, 1],
|
||||||
|
[0, 0, -1], [0, 0, 1],
|
||||||
|
[1, 0, -1], [1, 0, 0], [1, 0, -1]
|
||||||
|
);
|
||||||
private static $jumpOffset = [0, 1, 0];
|
private static $jumpOffset = [0, 1, 0];
|
||||||
private static $moveDownOffset = [0, -1, 0];
|
private static $moveDownOffset = [0, -1, 0];
|
||||||
public function getNeighbors(PathTile $tile)
|
public function getNeighbors(PathTile $tile)
|
||||||
|
|
@ -12,12 +16,12 @@ class MCDiagonalProvider implements INeighborProvider
|
||||||
foreach(MCDiagonalProvider::$neighbors as $offset){
|
foreach(MCDiagonalProvider::$neighbors as $offset){
|
||||||
$pnt = $tile->addOffset($offset);
|
$pnt = $tile->addOffset($offset);
|
||||||
if(!StaticBlock::getIsSolid($tile->level->level->getBlockID($pnt->x, $pnt->y, $pnt->z))){
|
if(!StaticBlock::getIsSolid($tile->level->level->getBlockID($pnt->x, $pnt->y, $pnt->z))){
|
||||||
if(!StaticBlock::getIsSolid($tile->level->level->getBlockID($pnt->x, $pnt->y - 1, $pnt->z, false))){
|
if(!StaticBlock::getIsSolid($tile->level->level->getBlockID($pnt->x, $pnt->y - 1, $pnt->z))){
|
||||||
--$pnt->y;
|
--$pnt->y;
|
||||||
}
|
}
|
||||||
$pnts[] = $pnt;
|
$pnts[] = $pnt;
|
||||||
}else{
|
}else{
|
||||||
if(!StaticBlock::getIsSolid($tile->level->level->getBlockID($pnt->x, $pnt->y + 1, $pnt->z, false))){
|
if(!StaticBlock::getIsSolid($tile->level->level->getBlockID($pnt->x, $pnt->y + 1, $pnt->z))){
|
||||||
++$pnt->y;
|
++$pnt->y;
|
||||||
$pnts[] = $pnt;
|
$pnts[] = $pnt;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -625,6 +625,9 @@ class Entity extends Position
|
||||||
$hasUpdate = true;
|
$hasUpdate = true;
|
||||||
if(($this->server->ticks % 4 === 0 && $this->class === ENTITY_ITEM) || $this->class != ENTITY_ITEM){ //update item speed every 4 ticks
|
if(($this->server->ticks % 4 === 0 && $this->class === ENTITY_ITEM) || $this->class != ENTITY_ITEM){ //update item speed every 4 ticks
|
||||||
$this->server->api->handle("entity.motion", $this);
|
$this->server->api->handle("entity.motion", $this);
|
||||||
|
$this->lastSpeedZ = $this->speedZ;
|
||||||
|
$this->lastSpeedY = $this->speedY;
|
||||||
|
$this->lastSpeedX = $this->speedX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->updateFallState($this->speedY);
|
$this->updateFallState($this->speedY);
|
||||||
|
|
@ -1316,7 +1319,7 @@ class Entity extends Position
|
||||||
public function moveEntityWithOffset($oX, $oY, $oZ)
|
public function moveEntityWithOffset($oX, $oY, $oZ)
|
||||||
{
|
{
|
||||||
$oX = $oX === 0 ? $this->speedX : ($this->getSpeedModifer() * $oX * $this->getSpeed());
|
$oX = $oX === 0 ? $this->speedX : ($this->getSpeedModifer() * $oX * $this->getSpeed());
|
||||||
$oY = $oY <= 0 ? $this->speedY : (0.42);
|
$oY = $oY <= 0 ? $this->speedY : (0.40);
|
||||||
$oZ = $oZ === 0 ? $this->speedZ : ($this->getSpeedModifer() * $oZ * $this->getSpeed());
|
$oZ = $oZ === 0 ? $this->speedZ : ($this->getSpeedModifer() * $oZ * $this->getSpeed());
|
||||||
$this->setVelocity($oX, $oY, $oZ);
|
$this->setVelocity($oX, $oY, $oZ);
|
||||||
}
|
}
|
||||||
|
|
@ -1436,7 +1439,7 @@ class Entity extends Position
|
||||||
$this->server->api->ban->ban($this->player->username);
|
$this->server->api->ban->ban($this->player->username);
|
||||||
}
|
}
|
||||||
} else{
|
} else{
|
||||||
if($this instanceof Painting){ //TODO better fix
|
if($this instanceof Painting || $this instanceof Minecart){ //TODO better fix
|
||||||
$this->close();
|
$this->close();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ class PathFollower{
|
||||||
$this->entity->path = null;
|
$this->entity->path = null;
|
||||||
$this->entity->currentIndex = 0;
|
$this->entity->currentIndex = 0;
|
||||||
$this->entity->currentNode = false;
|
$this->entity->currentNode = false;
|
||||||
}elseif($this->entity->path != null && ($this->entity->currentNode == false || $this->entity->ai->mobController->moveTo($this->entity->currentNode->x, $this->entity->currentNode->y, $this->entity->currentNode->z) === false)){
|
}elseif($this->entity->path != null && ($this->entity->currentNode == false || $this->entity->boundingBox->isXYZInside($this->entity->currentNode->x, $this->entity->currentNode->y, $this->entity->currentNode->z) || $this->entity->ai->mobController->moveTo($this->entity->currentNode->x, $this->entity->currentNode->y, $this->entity->currentNode->z) === false)){
|
||||||
$this->entity->currentNode = $this->entity->path[$this->entity->currentIndex++];
|
$this->entity->currentNode = $this->entity->path[$this->entity->currentIndex++];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ class Minecart extends Vehicle{
|
||||||
$this->x = isset($this->data["TileX"]) ? $this->data["TileX"]:$this->x;
|
$this->x = isset($this->data["TileX"]) ? $this->data["TileX"]:$this->x;
|
||||||
$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(3, "generic");
|
$this->setHealth(1, "generic"); //orig: 3
|
||||||
$this->width = 0.98;
|
$this->width = 0.98;
|
||||||
$this->height = 0.7;
|
$this->height = 0.7;
|
||||||
$this->update();
|
$this->update();
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,9 @@ class MinecartItem extends Item{
|
||||||
}
|
}
|
||||||
$server = ServerAPI::request();
|
$server = ServerAPI::request();
|
||||||
$data = [
|
$data = [
|
||||||
"x" => $target->getX(),
|
"x" => $target->getX() + 0.5,
|
||||||
"y" => $target->getY() + 0.8,
|
"y" => $target->getY() + 0.8,
|
||||||
"z" => $target->getZ(),
|
"z" => $target->getZ() + 0.5,
|
||||||
];
|
];
|
||||||
$e = $server->api->entity->add($level, ENTITY_OBJECT, OBJECT_MINECART, $data);
|
$e = $server->api->entity->add($level, ENTITY_OBJECT, OBJECT_MINECART, $data);
|
||||||
$server->api->entity->spawnToAll($e);
|
$server->api->entity->spawnToAll($e);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue