void should work correctly now

This commit is contained in:
GameHerobrine 2022-11-10 18:38:59 +03:00
parent 394ede50e9
commit c29d8dab9d
2 changed files with 86 additions and 56 deletions

View file

@ -5,7 +5,11 @@ move methods
*/ */
abstract class Creature extends Living{ abstract class Creature extends Living{
const CLASS_TYPE = ENTITY_MOB; const CLASS_TYPE = ENTITY_MOB;
public $inPanic;
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
$this->inPanic = true;
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 1, "generic"); $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 1, "generic");
//$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type)); //$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type));
@ -15,6 +19,10 @@ abstract class Creature extends Living{
} }
} }
public function getSpeedModifer(){
return $this->speedModifer * ($this->inPanic ? 1.4 : 0.7);
}
public function spawn($player){ public function spawn($player){
if(!($player instanceof Player)){ if(!($player instanceof Player)){
$player = $this->server->api->player->get($player); $player = $this->server->api->player->get($player);

View file

@ -170,8 +170,8 @@ class Entity extends Position
$this->update(); $this->update();
$this->updateLast(); $this->updateLast();
$this->updatePosition(); $this->updatePosition();
if($this->y < 0 and $this->class !== ENTITY_PLAYER){ if($this->isInVoid()){
$this->close(); $this->outOfWorld();
} }
} }
@ -367,9 +367,8 @@ class Entity extends Position
$this->air = 300; $this->air = 300;
return false; return false;
} }
if($this->isInVoid()){
if($this->y < - 16){ $this->outOfWorld();
$this->harm(8, "void", true);
$hasUpdate = true; $hasUpdate = true;
} }
@ -456,6 +455,10 @@ class Entity extends Position
return $hasUpdate; return $hasUpdate;
} }
public function isInVoid(){
return $this->y < -1.6;
}
public function update() public function update()
{ {
if($this->closed === true){ if($this->closed === true){
@ -697,6 +700,18 @@ class Entity extends Position
$this->lastUpdate = $now; $this->lastUpdate = $now;
} }
/**
* Handle fall out of world
*/
public function outOfWorld(){
if($this->isPlayer()){
$this->health = 0;
$this->makeDead("void");
}else{
$this->close();
}
}
public function interactWith(Entity $e, $action) public function interactWith(Entity $e, $action)
{ {
if($this->class === ENTITY_PLAYER and ($this->server->api->getProperty("pvp") == false or $this->server->difficulty <= 0 or ($e->player->gamemode & 0x01) === 0x01)){ if($this->class === ENTITY_PLAYER and ($this->server->api->getProperty("pvp") == false or $this->server->difficulty <= 0 or ($e->player->gamemode & 0x01) === 0x01)){
@ -1082,8 +1097,10 @@ class Entity extends Position
return false; return false;
} }
$ret = $this->setHealth(max(- 128, $this->getHealth() - ((int) $dmg)), $cause, $force); $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){ if($ret != false && $this->hasKnockback && is_numeric($cause) && ($entity = $this->server->api->entity->get($cause)) != false){
$d = $entity->x - $this->x; $d = $entity->x - $this->x;
for($d1 = $entity->z - $this->z; $d * $d + $d1 * $d1 < 0.0001; $d1 = (Utils::randomFloat() - Utils::randomFloat()) * 0.01){ 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; $d = (Utils::randomFloat() - Utils::randomFloat()) * 0.01;
} }
@ -1092,6 +1109,7 @@ class Entity extends Position
$this->knockBack($d, $d1); $this->knockBack($d, $d1);
$this->sendMotion(); $this->sendMotion();
} }
return $ret; return $ret;
} }
@ -1243,6 +1261,23 @@ class Entity extends Position
$this->player->dataPacket($pk); $this->player->dataPacket($pk);
} }
if($this->health <= 0 and $this->dead === false){ if($this->health <= 0 and $this->dead === false){
$this->makeDead($cause);
} elseif($this->health > 0){
$this->dead = false;
}
return true;
}
return false;
}
public function setSize($w, $h)
{
$this->width = $w;
$this->height = $h;
$this->radius = $w / 2;
}
public function makeDead($cause){
$this->spawnDrops(); $this->spawnDrops();
$this->air = 300; $this->air = 300;
$this->fire = 0; $this->fire = 0;
@ -1276,25 +1311,12 @@ class Entity extends Position
"player" => $this->player, "player" => $this->player,
"cause" => $cause "cause" => $cause
]); ]);
if($this->server->api->getProperty("hardcore") == 1){ if($this->server->api->getProperty("hardcore") == 1){ //poor player =<
$this->server->api->ban->ban($this->player->username); $this->server->api->ban->ban($this->player->username);
} }
} else{ } else{
$this->close(); $this->close();
} }
} elseif($this->health > 0){
$this->dead = false;
}
return true;
}
return false;
}
public function setSize($w, $h)
{
$this->width = $w;
$this->height = $h;
$this->radius = $w / 2;
} }
public function setSpeed($s) public function setSpeed($s)