mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-22 04:29:43 +00:00
void should work correctly now
This commit is contained in:
parent
394ede50e9
commit
c29d8dab9d
2 changed files with 86 additions and 56 deletions
|
|
@ -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);
|
||||||
|
|
|
||||||
|
|
@ -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,16 +1097,19 @@ 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){
|
|
||||||
$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) >
|
if($ret != false && $this->hasKnockback && is_numeric($cause) && ($entity = $this->server->api->entity->get($cause)) != false){
|
||||||
$this->knockBack($d, $d1);
|
$d = $entity->x - $this->x;
|
||||||
$this->sendMotion();
|
|
||||||
|
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;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1243,45 +1261,7 @@ 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->spawnDrops();
|
$this->makeDead($cause);
|
||||||
$this->air = 300;
|
|
||||||
$this->fire = 0;
|
|
||||||
$this->crouched = false;
|
|
||||||
$this->fallY = false;
|
|
||||||
$this->fallStart = false;
|
|
||||||
$this->updateMetadata();
|
|
||||||
$this->dead = true;
|
|
||||||
if($this->player instanceof Player){
|
|
||||||
$pk = new MoveEntityPacket_PosRot();
|
|
||||||
$pk->eid = $this->eid;
|
|
||||||
$pk->x = - 256;
|
|
||||||
$pk->y = 128;
|
|
||||||
$pk->z = - 256;
|
|
||||||
$pk->yaw = 0;
|
|
||||||
$pk->pitch = 0;
|
|
||||||
$this->server->api->player->broadcastPacket($this->level->players, $pk);
|
|
||||||
}else{
|
|
||||||
$pk = new EntityEventPacket;
|
|
||||||
$pk->eid = $this->eid;
|
|
||||||
$pk->event = 3;
|
|
||||||
$this->server->api->player->broadcastPacket($this->level->players, $pk);
|
|
||||||
/*$this->server->api->dhandle("entity.event", [
|
|
||||||
"entity" => $this,
|
|
||||||
"event" => 3
|
|
||||||
]); // Entity dead*/
|
|
||||||
}
|
|
||||||
if($this->player instanceof Player){
|
|
||||||
$this->player->blocked = true;
|
|
||||||
$this->server->api->dhandle("player.death", [
|
|
||||||
"player" => $this->player,
|
|
||||||
"cause" => $cause
|
|
||||||
]);
|
|
||||||
if($this->server->api->getProperty("hardcore") == 1){
|
|
||||||
$this->server->api->ban->ban($this->player->username);
|
|
||||||
}
|
|
||||||
} else{
|
|
||||||
$this->close();
|
|
||||||
}
|
|
||||||
} elseif($this->health > 0){
|
} elseif($this->health > 0){
|
||||||
$this->dead = false;
|
$this->dead = false;
|
||||||
}
|
}
|
||||||
|
|
@ -1297,6 +1277,48 @@ class Entity extends Position
|
||||||
$this->radius = $w / 2;
|
$this->radius = $w / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function makeDead($cause){
|
||||||
|
$this->spawnDrops();
|
||||||
|
$this->air = 300;
|
||||||
|
$this->fire = 0;
|
||||||
|
$this->crouched = false;
|
||||||
|
$this->fallY = false;
|
||||||
|
$this->fallStart = false;
|
||||||
|
$this->updateMetadata();
|
||||||
|
$this->dead = true;
|
||||||
|
if($this->player instanceof Player){
|
||||||
|
$pk = new MoveEntityPacket_PosRot();
|
||||||
|
$pk->eid = $this->eid;
|
||||||
|
$pk->x = - 256;
|
||||||
|
$pk->y = 128;
|
||||||
|
$pk->z = - 256;
|
||||||
|
$pk->yaw = 0;
|
||||||
|
$pk->pitch = 0;
|
||||||
|
$this->server->api->player->broadcastPacket($this->level->players, $pk);
|
||||||
|
}else{
|
||||||
|
$pk = new EntityEventPacket;
|
||||||
|
$pk->eid = $this->eid;
|
||||||
|
$pk->event = 3;
|
||||||
|
$this->server->api->player->broadcastPacket($this->level->players, $pk);
|
||||||
|
/*$this->server->api->dhandle("entity.event", [
|
||||||
|
"entity" => $this,
|
||||||
|
"event" => 3
|
||||||
|
]); // Entity dead*/
|
||||||
|
}
|
||||||
|
if($this->player instanceof Player){
|
||||||
|
$this->player->blocked = true;
|
||||||
|
$this->server->api->dhandle("player.death", [
|
||||||
|
"player" => $this->player,
|
||||||
|
"cause" => $cause
|
||||||
|
]);
|
||||||
|
if($this->server->api->getProperty("hardcore") == 1){ //poor player =<
|
||||||
|
$this->server->api->ban->ban($this->player->username);
|
||||||
|
}
|
||||||
|
} else{
|
||||||
|
$this->close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function setSpeed($s)
|
public function setSpeed($s)
|
||||||
{
|
{
|
||||||
$this->speed = $s;
|
$this->speed = $s;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue