diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 0b693919..e42a9df2 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -4,130 +4,69 @@ class Entity extends Position { const TYPE = - 1; - const CLASS_TYPE = - 1; public static $updateOnTick; - public $isCollidable; - public $canBeAttacked; - public $moveTime, $lookTime, $idleTime; - public $needsUpdate; - public $speedModifer; - + public $hasGravity; /** - * * @var AxisAlignedBB */ public $boundingBox; - public $age; - public $air; - public $spawntime; - public $dmgcounter; - public $eid; - public $type; - public $name; - public $x; - public $y; - public $z; - public $speedX; - public $speedY; - public $speedZ; - public $speed; - - public $last = array( - 0, - 0, - 0, - 0, - 0, - 0 - ); - + public $last = array(0, 0, 0, 0, 0, 0); public $yaw; - public $pitch; - public $dead; - public $data; - public $class; - public $attach; - public $closed; - /** - * * @var Player */ public $player; - public $fallY; - public $fallStart; - private $state; - private $tickCounter; - - private $speedMeasure = array( - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ); - + private $speedMeasure = array(0, 0, 0, 0, 0, 0, 0); public $server; - private $isStatic; - public $level; - public $isRiding = false; - public $lastUpdate; - public $linkedEntity = null; - public $check = true; - public $width = 1; - public $height = 1; - public $random; - public $radius; - public $inAction = false; + public $hasKnockback; function __construct(Level $level, $eid, $class, $type = 0, $data = array()) { $this->random = new Random(); $this->canBeAttacked = false; + $this->hasKnockback = false; $this->level = $level; $this->speedModifer = 0.7; $this->fallY = false; @@ -141,11 +80,8 @@ class Entity extends Position $this->data = $data; $this->status = 0; $this->health = 20; - $this->dmgcounter = array( - 0, - 0, - 0 - ); + $this->hasGravity = false; + $this->dmgcounter = array(0, 0, 0); $this->air = 300; $this->fire = 0; $this->crouched = false; @@ -186,6 +122,8 @@ class Entity extends Position $this->speedModifer = 1; $this->width = 1.2; $this->height = 1.9; + $this->hasKnockback = true; + $this->hasGravity = true; $this->canBeAttacked = true; break; case ENTITY_ITEM: @@ -196,6 +134,7 @@ class Entity extends Position $this->meta = (int) $this->data["meta"]; $this->stack = (int) $this->data["stack"]; } + $this->hasGravity = true; $this->setHealth(5, "generic"); $this->server->schedule(6010, array( $this, @@ -208,6 +147,7 @@ class Entity extends Position $this->setHealth(PHP_INT_MAX, "generic"); $this->height = 0.98; $this->width = 0.98; + $this->hasGravity = true; break; case ENTITY_OBJECT: $this->x = isset($this->data["TileX"]) ? $this->data["TileX"] : $this->x; @@ -639,7 +579,7 @@ class Entity extends Position $update = true; } - if($support === false){ + if($this->hasGravity && $support === false){ $this->speedY -= $this->class === ENTITY_FALLING ? 0.04 : 0.08; // TODO: replace with $gravity $update = true; } else{ @@ -1138,7 +1078,21 @@ class Entity extends Position 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) @@ -1215,9 +1169,6 @@ class Entity extends Position public function setHealth($health, $cause = "generic", $force = false) { - if(! $this->canBeAttacked){ - return false; - } $health = (int) $health; $harm = false; if($health < $this->health){ @@ -1334,17 +1285,6 @@ class Entity extends Position } elseif($this->health > 0){ $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 false; diff --git a/src/entity/Living.php b/src/entity/Living.php index 68d09ce3..89d762a3 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -11,6 +11,8 @@ abstract class Living extends Entity implements Damageable{ $this->pathNavigator = new PathNavigator($this); parent::__construct($level, $eid, $class, $type, $data); $this->canBeAttacked = true; + $this->hasGravity = true; + $this->hasKnockback = true; } public function update(){ @@ -19,4 +21,4 @@ abstract class Living extends Entity implements Damageable{ parent::update(); } -} \ No newline at end of file +} diff --git a/src/entity/object/Minecart.php b/src/entity/object/Minecart.php index 96b1d14f..bb3f13c4 100644 --- a/src/entity/object/Minecart.php +++ b/src/entity/object/Minecart.php @@ -9,6 +9,7 @@ class Minecart extends Vehicle{ function __construct(Level $level, $eid, $class, $type = 0, $data = []){ parent::__construct($level, $eid, $class, $type, $data); + $this->canBeAttacked = true; $this->x = isset($this->data["TileX"]) ? $this->data["TileX"]:$this->x; $this->y = isset($this->data["TileY"]) ? $this->data["TileY"]:$this->y; $this->z = isset($this->data["TileZ"]) ? $this->data["TileZ"]:$this->z; @@ -60,6 +61,7 @@ class Minecart extends Vehicle{ $e->isRiding = false; return true; } + parent::interactWith($e, $action); } public function canRide($e) @@ -67,4 +69,4 @@ class Minecart extends Vehicle{ return !($this->linkedEntity instanceof Entity) && !$e->isRiding; } -} \ No newline at end of file +} diff --git a/src/entity/object/Painting.php b/src/entity/object/Painting.php index 78dc08ed..fb571cfd 100644 --- a/src/entity/object/Painting.php +++ b/src/entity/object/Painting.php @@ -8,6 +8,7 @@ class Painting extends Hanging{ $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"); + $this->canBeAttacked = true; $this->width = 1; $this->isStatic = true; } @@ -28,4 +29,4 @@ class Painting extends Hanging{ $pk->title = $this->data["Motive"]; $player->dataPacket($pk); } -} \ No newline at end of file +}