mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-23 21:19:44 +00:00
entity fixes
This commit is contained in:
parent
834bb3d486
commit
394ede50e9
4 changed files with 35 additions and 90 deletions
|
|
@ -4,130 +4,69 @@ class Entity extends Position
|
||||||
{
|
{
|
||||||
|
|
||||||
const TYPE = - 1;
|
const TYPE = - 1;
|
||||||
|
|
||||||
const CLASS_TYPE = - 1;
|
const CLASS_TYPE = - 1;
|
||||||
|
|
||||||
public static $updateOnTick;
|
public static $updateOnTick;
|
||||||
|
|
||||||
public $isCollidable;
|
public $isCollidable;
|
||||||
|
|
||||||
public $canBeAttacked;
|
public $canBeAttacked;
|
||||||
|
|
||||||
public $moveTime, $lookTime, $idleTime;
|
public $moveTime, $lookTime, $idleTime;
|
||||||
|
|
||||||
public $needsUpdate;
|
public $needsUpdate;
|
||||||
|
|
||||||
public $speedModifer;
|
public $speedModifer;
|
||||||
|
public $hasGravity;
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @var AxisAlignedBB
|
* @var AxisAlignedBB
|
||||||
*/
|
*/
|
||||||
public $boundingBox;
|
public $boundingBox;
|
||||||
|
|
||||||
public $age;
|
public $age;
|
||||||
|
|
||||||
public $air;
|
public $air;
|
||||||
|
|
||||||
public $spawntime;
|
public $spawntime;
|
||||||
|
|
||||||
public $dmgcounter;
|
public $dmgcounter;
|
||||||
|
|
||||||
public $eid;
|
public $eid;
|
||||||
|
|
||||||
public $type;
|
public $type;
|
||||||
|
|
||||||
public $name;
|
public $name;
|
||||||
|
|
||||||
public $x;
|
public $x;
|
||||||
|
|
||||||
public $y;
|
public $y;
|
||||||
|
|
||||||
public $z;
|
public $z;
|
||||||
|
|
||||||
public $speedX;
|
public $speedX;
|
||||||
|
|
||||||
public $speedY;
|
public $speedY;
|
||||||
|
|
||||||
public $speedZ;
|
public $speedZ;
|
||||||
|
|
||||||
public $speed;
|
public $speed;
|
||||||
|
public $last = array(0, 0, 0, 0, 0, 0);
|
||||||
public $last = array(
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0
|
|
||||||
);
|
|
||||||
|
|
||||||
public $yaw;
|
public $yaw;
|
||||||
|
|
||||||
public $pitch;
|
public $pitch;
|
||||||
|
|
||||||
public $dead;
|
public $dead;
|
||||||
|
|
||||||
public $data;
|
public $data;
|
||||||
|
|
||||||
public $class;
|
public $class;
|
||||||
|
|
||||||
public $attach;
|
public $attach;
|
||||||
|
|
||||||
public $closed;
|
public $closed;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @var Player
|
* @var Player
|
||||||
*/
|
*/
|
||||||
public $player;
|
public $player;
|
||||||
|
|
||||||
public $fallY;
|
public $fallY;
|
||||||
|
|
||||||
public $fallStart;
|
public $fallStart;
|
||||||
|
|
||||||
private $state;
|
private $state;
|
||||||
|
|
||||||
private $tickCounter;
|
private $tickCounter;
|
||||||
|
private $speedMeasure = array(0, 0, 0, 0, 0, 0, 0);
|
||||||
private $speedMeasure = array(
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0
|
|
||||||
);
|
|
||||||
|
|
||||||
public $server;
|
public $server;
|
||||||
|
|
||||||
private $isStatic;
|
private $isStatic;
|
||||||
|
|
||||||
public $level;
|
public $level;
|
||||||
|
|
||||||
public $isRiding = false;
|
public $isRiding = false;
|
||||||
|
|
||||||
public $lastUpdate;
|
public $lastUpdate;
|
||||||
|
|
||||||
public $linkedEntity = null;
|
public $linkedEntity = null;
|
||||||
|
|
||||||
public $check = true;
|
public $check = true;
|
||||||
|
|
||||||
public $width = 1;
|
public $width = 1;
|
||||||
|
|
||||||
public $height = 1;
|
public $height = 1;
|
||||||
|
|
||||||
public $random;
|
public $random;
|
||||||
|
|
||||||
public $radius;
|
public $radius;
|
||||||
|
|
||||||
public $inAction = false;
|
public $inAction = false;
|
||||||
|
public $hasKnockback;
|
||||||
|
|
||||||
function __construct(Level $level, $eid, $class, $type = 0, $data = array())
|
function __construct(Level $level, $eid, $class, $type = 0, $data = array())
|
||||||
{
|
{
|
||||||
$this->random = new Random();
|
$this->random = new Random();
|
||||||
$this->canBeAttacked = false;
|
$this->canBeAttacked = false;
|
||||||
|
$this->hasKnockback = false;
|
||||||
$this->level = $level;
|
$this->level = $level;
|
||||||
$this->speedModifer = 0.7;
|
$this->speedModifer = 0.7;
|
||||||
$this->fallY = false;
|
$this->fallY = false;
|
||||||
|
|
@ -141,11 +80,8 @@ class Entity extends Position
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
$this->status = 0;
|
$this->status = 0;
|
||||||
$this->health = 20;
|
$this->health = 20;
|
||||||
$this->dmgcounter = array(
|
$this->hasGravity = false;
|
||||||
0,
|
$this->dmgcounter = array(0, 0, 0);
|
||||||
0,
|
|
||||||
0
|
|
||||||
);
|
|
||||||
$this->air = 300;
|
$this->air = 300;
|
||||||
$this->fire = 0;
|
$this->fire = 0;
|
||||||
$this->crouched = false;
|
$this->crouched = false;
|
||||||
|
|
@ -186,6 +122,8 @@ class Entity extends Position
|
||||||
$this->speedModifer = 1;
|
$this->speedModifer = 1;
|
||||||
$this->width = 1.2;
|
$this->width = 1.2;
|
||||||
$this->height = 1.9;
|
$this->height = 1.9;
|
||||||
|
$this->hasKnockback = true;
|
||||||
|
$this->hasGravity = true;
|
||||||
$this->canBeAttacked = true;
|
$this->canBeAttacked = true;
|
||||||
break;
|
break;
|
||||||
case ENTITY_ITEM:
|
case ENTITY_ITEM:
|
||||||
|
|
@ -196,6 +134,7 @@ class Entity extends Position
|
||||||
$this->meta = (int) $this->data["meta"];
|
$this->meta = (int) $this->data["meta"];
|
||||||
$this->stack = (int) $this->data["stack"];
|
$this->stack = (int) $this->data["stack"];
|
||||||
}
|
}
|
||||||
|
$this->hasGravity = true;
|
||||||
$this->setHealth(5, "generic");
|
$this->setHealth(5, "generic");
|
||||||
$this->server->schedule(6010, array(
|
$this->server->schedule(6010, array(
|
||||||
$this,
|
$this,
|
||||||
|
|
@ -208,6 +147,7 @@ class Entity extends Position
|
||||||
$this->setHealth(PHP_INT_MAX, "generic");
|
$this->setHealth(PHP_INT_MAX, "generic");
|
||||||
$this->height = 0.98;
|
$this->height = 0.98;
|
||||||
$this->width = 0.98;
|
$this->width = 0.98;
|
||||||
|
$this->hasGravity = true;
|
||||||
break;
|
break;
|
||||||
case ENTITY_OBJECT:
|
case ENTITY_OBJECT:
|
||||||
$this->x = isset($this->data["TileX"]) ? $this->data["TileX"] : $this->x;
|
$this->x = isset($this->data["TileX"]) ? $this->data["TileX"] : $this->x;
|
||||||
|
|
@ -639,7 +579,7 @@ class Entity extends Position
|
||||||
$update = true;
|
$update = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($support === false){
|
if($this->hasGravity && $support === false){
|
||||||
$this->speedY -= $this->class === ENTITY_FALLING ? 0.04 : 0.08; // TODO: replace with $gravity
|
$this->speedY -= $this->class === ENTITY_FALLING ? 0.04 : 0.08; // TODO: replace with $gravity
|
||||||
$update = true;
|
$update = true;
|
||||||
} else{
|
} else{
|
||||||
|
|
@ -1138,7 +1078,21 @@ class Entity extends Position
|
||||||
|
|
||||||
public function harm($dmg, $cause = "generic", $force = false)
|
public function harm($dmg, $cause = "generic", $force = false)
|
||||||
{
|
{
|
||||||
return $this->setHealth(max(- 128, $this->getHealth() - ((int) $dmg)), $cause, $force);
|
if(!$this->canBeAttacked){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$ret = $this->setHealth(max(- 128, $this->getHealth() - ((int) $dmg)), $cause, $force);
|
||||||
|
if($ret != false && $this->hasKnockback && is_numeric($cause) && ($entity = $this->server->api->entity->get($cause)) != false){
|
||||||
|
$d = $entity->x - $this->x;
|
||||||
|
for($d1 = $entity->z - $this->z; $d * $d + $d1 * $d1 < 0.0001; $d1 = (Utils::randomFloat() - Utils::randomFloat()) * 0.01){
|
||||||
|
$d = (Utils::randomFloat() - Utils::randomFloat()) * 0.01;
|
||||||
|
}
|
||||||
|
|
||||||
|
// attackedAtYaw = (float)((Math.atan2($d1, $d) * 180D) / 3.1415927410125732D) >
|
||||||
|
$this->knockBack($d, $d1);
|
||||||
|
$this->sendMotion();
|
||||||
|
}
|
||||||
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setState($v)
|
public function setState($v)
|
||||||
|
|
@ -1215,9 +1169,6 @@ class Entity extends Position
|
||||||
|
|
||||||
public function setHealth($health, $cause = "generic", $force = false)
|
public function setHealth($health, $cause = "generic", $force = false)
|
||||||
{
|
{
|
||||||
if(! $this->canBeAttacked){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$health = (int) $health;
|
$health = (int) $health;
|
||||||
$harm = false;
|
$harm = false;
|
||||||
if($health < $this->health){
|
if($health < $this->health){
|
||||||
|
|
@ -1334,17 +1285,6 @@ class Entity extends Position
|
||||||
} elseif($this->health > 0){
|
} elseif($this->health > 0){
|
||||||
$this->dead = false;
|
$this->dead = false;
|
||||||
}
|
}
|
||||||
if(is_numeric($cause) && ($entity = $this->server->api->entity->get($cause)) != false){
|
|
||||||
$d = $entity->x - $this->x;
|
|
||||||
for($d1 = $entity->z - $this->z; $d * $d + $d1 * $d1 < 0.0001; $d1 = (Utils::randomFloat() - Utils::randomFloat()) * 0.01){
|
|
||||||
$d = (Utils::randomFloat() - Utils::randomFloat()) * 0.01;
|
|
||||||
}
|
|
||||||
|
|
||||||
// attackedAtYaw = (float)((Math.atan2($d1, $d) * 180D) / 3.1415927410125732D) - rotationYaw;
|
|
||||||
|
|
||||||
$this->knockBack($d, $d1);
|
|
||||||
$this->sendMotion();
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ abstract class Living extends Entity implements Damageable{
|
||||||
$this->pathNavigator = new PathNavigator($this);
|
$this->pathNavigator = new PathNavigator($this);
|
||||||
parent::__construct($level, $eid, $class, $type, $data);
|
parent::__construct($level, $eid, $class, $type, $data);
|
||||||
$this->canBeAttacked = true;
|
$this->canBeAttacked = true;
|
||||||
|
$this->hasGravity = true;
|
||||||
|
$this->hasKnockback = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(){
|
public function update(){
|
||||||
|
|
@ -19,4 +21,4 @@ abstract class Living extends Entity implements Damageable{
|
||||||
parent::update();
|
parent::update();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ class Minecart extends Vehicle{
|
||||||
|
|
||||||
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
|
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
|
||||||
parent::__construct($level, $eid, $class, $type, $data);
|
parent::__construct($level, $eid, $class, $type, $data);
|
||||||
|
$this->canBeAttacked = true;
|
||||||
$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;
|
||||||
|
|
@ -60,6 +61,7 @@ class Minecart extends Vehicle{
|
||||||
$e->isRiding = false;
|
$e->isRiding = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
parent::interactWith($e, $action);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canRide($e)
|
public function canRide($e)
|
||||||
|
|
@ -67,4 +69,4 @@ class Minecart extends Vehicle{
|
||||||
return !($this->linkedEntity instanceof Entity) && !$e->isRiding;
|
return !($this->linkedEntity instanceof Entity) && !$e->isRiding;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ class Painting extends Hanging{
|
||||||
$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");
|
$this->setHealth(1, "generic");
|
||||||
|
$this->canBeAttacked = true;
|
||||||
$this->width = 1;
|
$this->width = 1;
|
||||||
$this->isStatic = true;
|
$this->isStatic = true;
|
||||||
}
|
}
|
||||||
|
|
@ -28,4 +29,4 @@ class Painting extends Hanging{
|
||||||
$pk->title = $this->data["Motive"];
|
$pk->title = $this->data["Motive"];
|
||||||
$player->dataPacket($pk);
|
$player->dataPacket($pk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue