mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-23 13:09:44 +00:00
mobs will spawn after restart
This commit is contained in:
parent
4ffa7f46a4
commit
78da6226f0
4 changed files with 49 additions and 30 deletions
|
|
@ -48,6 +48,13 @@ class LevelAPI{
|
||||||
if(!isset($entity["id"])){
|
if(!isset($entity["id"])){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$entity["x"] = $entity["Pos"][0];
|
||||||
|
$entity["y"] = $entity["Pos"][1];
|
||||||
|
$entity["z"] = $entity["Pos"][2];
|
||||||
|
$entity["yaw"] = $entity["Rotation"][0];
|
||||||
|
$entity["pitch"] = $entity["Rotation"][1];
|
||||||
|
|
||||||
if($entity["id"] === 64){ //Item Drop
|
if($entity["id"] === 64){ //Item Drop
|
||||||
$e = $this->server->api->entity->add($this->levels[$name], ENTITY_ITEM, $entity["Item"]["id"], [
|
$e = $this->server->api->entity->add($this->levels[$name], ENTITY_ITEM, $entity["Item"]["id"], [
|
||||||
"meta" => $entity["Item"]["Damage"],
|
"meta" => $entity["Item"]["Damage"],
|
||||||
|
|
@ -60,15 +67,15 @@ class LevelAPI{
|
||||||
]);
|
]);
|
||||||
}elseif($entity["id"] === FALLING_SAND){
|
}elseif($entity["id"] === FALLING_SAND){
|
||||||
$e = $this->server->api->entity->add($this->levels[$name], ENTITY_FALLING, $entity["id"], $entity);
|
$e = $this->server->api->entity->add($this->levels[$name], ENTITY_FALLING, $entity["id"], $entity);
|
||||||
$e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]);
|
//$e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]);
|
||||||
$e->setHealth($entity["Health"]);
|
$e->setHealth($entity["Health"]);
|
||||||
}elseif(Utils::getEntityTypeByID($entity["id"]) === ENTITY_OBJECT){ //Object
|
}elseif(Utils::getEntityTypeByID($entity["id"]) === ENTITY_OBJECT){ //Object
|
||||||
$e = $this->server->api->entity->add($this->levels[$name], ENTITY_OBJECT, $entity["id"], $entity);
|
$e = $this->server->api->entity->add($this->levels[$name], ENTITY_OBJECT, $entity["id"], $entity);
|
||||||
$e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]);
|
//$e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]);
|
||||||
$e->setHealth(1);
|
$e->setHealth(1);
|
||||||
}else{
|
}else{
|
||||||
$e = $this->server->api->entity->add($this->levels[$name], ENTITY_MOB, $entity["id"], $entity);
|
$e = $this->server->api->entity->add($this->levels[$name], ENTITY_MOB, $entity["id"], $entity);
|
||||||
$e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]);
|
//$e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]);
|
||||||
$e->setHealth($entity["Health"]);
|
$e->setHealth($entity["Health"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,4 +12,31 @@ abstract class Creature extends Living{
|
||||||
//$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type));
|
//$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type));
|
||||||
$this->size = 1;
|
$this->size = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function spawn($player){
|
||||||
|
if(!($player instanceof Player)){
|
||||||
|
$player = $this->server->api->player->get($player);
|
||||||
|
}
|
||||||
|
if($player->eid === $this->eid or $this->closed !== false or ($player->level !== $this->level and $this->class !== ENTITY_PLAYER)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$pk = new AddMobPacket;
|
||||||
|
$pk->eid = $this->eid;
|
||||||
|
$pk->type = $this->type;
|
||||||
|
$pk->x = $this->x;
|
||||||
|
$pk->y = $this->y;
|
||||||
|
$pk->z = $this->z;
|
||||||
|
$pk->yaw = $this->yaw;
|
||||||
|
$pk->pitch = $this->pitch;
|
||||||
|
$pk->metadata = $this->getMetadata();
|
||||||
|
$player->dataPacket($pk);
|
||||||
|
|
||||||
|
$pk = new SetEntityMotionPacket;
|
||||||
|
$pk->eid = $this->eid;
|
||||||
|
$pk->speedX = $this->speedX;
|
||||||
|
$pk->speedY = $this->speedY;
|
||||||
|
$pk->speedZ = $this->speedZ;
|
||||||
|
$player->dataPacket($pk);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -64,12 +64,12 @@ class Entity extends Position{
|
||||||
$this->name = "";
|
$this->name = "";
|
||||||
$this->tickCounter = 0;
|
$this->tickCounter = 0;
|
||||||
$this->server->query("INSERT OR REPLACE INTO entities (EID, level, type, class, health, hasUpdate) VALUES (".$this->eid.", '".$this->level->getName()."', ".$this->type.", ".$this->class.", ".$this->health.", 0);");
|
$this->server->query("INSERT OR REPLACE INTO entities (EID, level, type, class, health, hasUpdate) VALUES (".$this->eid.", '".$this->level->getName()."', ".$this->type.", ".$this->class.", ".$this->health.", 0);");
|
||||||
$this->x = isset($this->data["x"]) ? (float) $this->data["x"]:0;
|
$this->x = isset($this->data["x"]) ? (float) $this->data["x"] : 0;
|
||||||
$this->y = isset($this->data["y"]) ? (float) $this->data["y"]:0;
|
$this->y = isset($this->data["y"]) ? (float) $this->data["y"] : 0;
|
||||||
$this->z = isset($this->data["z"]) ? (float) $this->data["z"]:0;
|
$this->z = isset($this->data["z"]) ? (float) $this->data["z"] : 0;
|
||||||
$this->speedX = isset($this->data["speedX"]) ? (float) $this->data["speedX"]:0;
|
$this->speedX = isset($this->data["speedX"]) ? (float) $this->data["speedX"] : 0;
|
||||||
$this->speedY = isset($this->data["speedY"]) ? (float) $this->data["speedY"]:0;
|
$this->speedY = isset($this->data["speedY"]) ? (float) $this->data["speedY"] : 0;
|
||||||
$this->speedZ = isset($this->data["speedZ"]) ? (float) $this->data["speedZ"]:0;
|
$this->speedZ = isset($this->data["speedZ"]) ? (float) $this->data["speedZ"] : 0;
|
||||||
$this->speed = 0;
|
$this->speed = 0;
|
||||||
$this->yaw = isset($this->data["yaw"]) ? (float) $this->data["yaw"]:0;
|
$this->yaw = isset($this->data["yaw"]) ? (float) $this->data["yaw"]:0;
|
||||||
$this->pitch = isset($this->data["pitch"]) ? (float) $this->data["pitch"]:0;
|
$this->pitch = isset($this->data["pitch"]) ? (float) $this->data["pitch"]:0;
|
||||||
|
|
@ -627,25 +627,6 @@ class Entity extends Position{
|
||||||
$pk->metadata = $this->getMetadata();
|
$pk->metadata = $this->getMetadata();
|
||||||
$player->dataPacket($pk);
|
$player->dataPacket($pk);
|
||||||
|
|
||||||
$pk = new SetEntityMotionPacket;
|
|
||||||
$pk->eid = $this->eid;
|
|
||||||
$pk->speedX = $this->speedX;
|
|
||||||
$pk->speedY = $this->speedY;
|
|
||||||
$pk->speedZ = $this->speedZ;
|
|
||||||
$player->dataPacket($pk);
|
|
||||||
break;
|
|
||||||
case ENTITY_MOB:
|
|
||||||
$pk = new AddMobPacket;
|
|
||||||
$pk->eid = $this->eid;
|
|
||||||
$pk->type = $this->type;
|
|
||||||
$pk->x = $this->x;
|
|
||||||
$pk->y = $this->y;
|
|
||||||
$pk->z = $this->z;
|
|
||||||
$pk->yaw = $this->yaw;
|
|
||||||
$pk->pitch = $this->pitch;
|
|
||||||
$pk->metadata = $this->getMetadata();
|
|
||||||
$player->dataPacket($pk);
|
|
||||||
|
|
||||||
$pk = new SetEntityMotionPacket;
|
$pk = new SetEntityMotionPacket;
|
||||||
$pk->eid = $this->eid;
|
$pk->eid = $this->eid;
|
||||||
$pk->speedX = $this->speedX;
|
$pk->speedX = $this->speedX;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
class Sheep extends Animal{
|
class Sheep extends Animal{
|
||||||
const TYPE = MOB_SHEEP;
|
const TYPE = MOB_SHEEP;
|
||||||
|
const NOT_SHEARED = 0;
|
||||||
|
const SHEARED = 1;
|
||||||
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||||
parent::__construct($level, $eid, $class, $type, $data);
|
parent::__construct($level, $eid, $class, $type, $data);
|
||||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 8, "generic");
|
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 8, "generic");
|
||||||
|
|
@ -24,10 +26,12 @@ class Sheep extends Animal{
|
||||||
public function getMetadata(){
|
public function getMetadata(){
|
||||||
$d = parent::getMetadata();
|
$d = parent::getMetadata();
|
||||||
if(!isset($this->data["Sheared"])){
|
if(!isset($this->data["Sheared"])){
|
||||||
$this->data["Sheared"] = 0;
|
$this->data["Sheared"] = NOT_SHEARED;
|
||||||
|
}
|
||||||
|
if(!isset($this->data["Color"])){ //Make a new random color if it is not in data
|
||||||
$this->data["Color"] = $this->sheepColor();
|
$this->data["Color"] = $this->sheepColor();
|
||||||
}
|
}
|
||||||
$d[16]["value"] = (($this->data["Sheared"] == 1 ? 1:0) << 4) | ($this->data["Color"] & 0x0F); //dark manipulations are happening here...
|
$d[16]["value"] = (($this->data["Sheared"] == 1 ? Sheep::SHEARED : Sheep::NOT_SHEARED) << 4) | ($this->data["Color"] & 0x0F); //dark manipulations are happening here...
|
||||||
return $d;
|
return $d;
|
||||||
}
|
}
|
||||||
public function sheepColor(){
|
public function sheepColor(){
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue