mobs will spawn after restart

This commit is contained in:
GameHerobrine 2022-08-05 17:45:25 +03:00
parent 4ffa7f46a4
commit 78da6226f0
4 changed files with 49 additions and 30 deletions

View file

@ -12,4 +12,31 @@ abstract class Creature extends Living{
//$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type));
$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);
}
}

View file

@ -64,12 +64,12 @@ class Entity extends Position{
$this->name = "";
$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->x = isset($this->data["x"]) ? (float) $this->data["x"]:0;
$this->y = isset($this->data["y"]) ? (float) $this->data["y"]:0;
$this->z = isset($this->data["z"]) ? (float) $this->data["z"]:0;
$this->speedX = isset($this->data["speedX"]) ? (float) $this->data["speedX"]:0;
$this->speedY = isset($this->data["speedY"]) ? (float) $this->data["speedY"]:0;
$this->speedZ = isset($this->data["speedZ"]) ? (float) $this->data["speedZ"]:0;
$this->x = isset($this->data["x"]) ? (float) $this->data["x"] : 0;
$this->y = isset($this->data["y"]) ? (float) $this->data["y"] : 0;
$this->z = isset($this->data["z"]) ? (float) $this->data["z"] : 0;
$this->speedX = isset($this->data["speedX"]) ? (float) $this->data["speedX"] : 0;
$this->speedY = isset($this->data["speedY"]) ? (float) $this->data["speedY"] : 0;
$this->speedZ = isset($this->data["speedZ"]) ? (float) $this->data["speedZ"] : 0;
$this->speed = 0;
$this->yaw = isset($this->data["yaw"]) ? (float) $this->data["yaw"]:0;
$this->pitch = isset($this->data["pitch"]) ? (float) $this->data["pitch"]:0;
@ -627,25 +627,6 @@ class Entity extends Position{
$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);
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->eid = $this->eid;
$pk->speedX = $this->speedX;

View file

@ -2,6 +2,8 @@
class Sheep extends Animal{
const TYPE = MOB_SHEEP;
const NOT_SHEARED = 0;
const SHEARED = 1;
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 8, "generic");
@ -24,10 +26,12 @@ class Sheep extends Animal{
public function getMetadata(){
$d = parent::getMetadata();
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();
}
$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;
}
public function sheepColor(){