Some changes.

This commit is contained in:
kotyaralih 2021-12-04 12:45:34 -08:00
parent 20c16068ec
commit d6cc8415dc
30 changed files with 359 additions and 106 deletions

View file

@ -52,6 +52,7 @@ class Player{
public $spawned = false;
public $inventory;
public $slot;
public $hotbar;
public $armor = array();
public $loggedIn = false;
public $gamemode;
@ -111,6 +112,7 @@ class Player{
$this->gamemode = $this->server->gamemode;
$this->level = $this->server->api->level->getDefault();
$this->slot = 0;
$this->hotbar = array(0, -1, -1, -1, -1, -1, -1, -1, -1);
$this->packetStats = array(0,0);
$this->server->schedule(2, array($this, "handlePacketQueues"), array(), true);
$this->server->schedule(20 * 60, array($this, "clearQueue"), array(), true);
@ -217,6 +219,9 @@ class Player{
"z" => $Z,
"data" => $this->level->getOrderedChunk($X, $Z, $Yndex),
));
if($cnt === false){
return false;
}
$this->chunkCount = array();
foreach($cnt as $i => $count){
$this->chunkCount[$count] = true;
@ -251,6 +256,7 @@ class Player{
}
}
$this->data->set("inventory", $inv);
$this->data->set("hotbar", $this->hotbar);
$armor = array();
foreach($this->armor as $slot => $item){
@ -887,7 +893,7 @@ class Player{
return false;
}
if($pos instanceof Position and $pos->level !== $this->level){
if($pos instanceof Position and $pos->level instanceof Level and $pos->level !== $this->level){
if($this->server->api->dhandle("player.teleport.level", array("player" => $this, "origin" => $this->level, "target" => $pos->level)) === false){
$this->entity->check = true;
return false;
@ -1279,6 +1285,8 @@ class Player{
$this->username = $data["username"];
$this->iusername = strtolower($this->username);
}else{
$this->username = $data["username"];
$this->iusername = strtolower($this->username);
$this->close("Bad username", false);
break;
}
@ -1362,8 +1370,13 @@ class Player{
));
if(($this->gamemode & 0x01) === 0x01){
$this->slot = 0;
$this->hotbar = array();
}elseif($this->data->exists("hotbar")){
$this->hotbar = $this->data->get("hotbar");
$this->slot = $this->hotbar[0];
}else{
$this->slot = -1;//0
$this->hotbar = array(-1, -1, -1, -1, -1, -1, -1, -1, -1);
}
$this->entity = $this->server->api->entity->add($this->level, ENTITY_PLAYER, 0, array("player" => $this));
$this->eid = $this->entity->eid;
@ -1405,7 +1418,7 @@ class Player{
if($this->spawned !== false){
break;
}
$this->entity->setHealth($this->data->get("health"));
$this->entity->setHealth($this->data->get("health"), "spawn", true);
$this->spawned = true;
$this->server->api->player->spawnAllPlayers($this);
$this->server->api->player->spawnToAllPlayers($this);
@ -1523,8 +1536,15 @@ class Player{
$data["meta"] = $data["item"]->getMetadata();
if($this->server->handle("player.equipment.change", $data) !== false){
$this->slot = $data["slot"];
if(($this->gamemode & 0x01) === SURVIVAL){
if(!in_array($this->slot, $this->hotbar)){
array_pop($this->hotbar);
array_unshift($this->hotbar, $this->slot);
}
}
}else{
$this->sendInventorySlot($data["slot"]);
//$this->sendInventorySlot($data["slot"]);
$this->sendInventory();
}
if($this->entity->inAction === true){
$this->entity->inAction = false;
@ -1822,7 +1842,7 @@ class Player{
if($this->spawned === false){
break;
}
if($this->entity->dead === false){
if(@$this->entity->dead === false){
break;
}
$this->craftingItems = array();
@ -1831,7 +1851,7 @@ class Player{
if($this->entity instanceof Entity){
$this->entity->fire = 0;
$this->entity->air = 300;
$this->entity->setHealth(20, "respawn");
$this->entity->setHealth(20, "respawn", true);
$this->entity->updateMetadata();
} else {
break;
@ -1856,7 +1876,7 @@ class Player{
switch($data["event"]){
case 9: //Eating
$items = array(
APPLE => 2,
APPLE => 4,
MUSHROOM_STEW => 10,
BEETROOT_SOUP => 10,
BREAD => 5,
@ -2194,10 +2214,15 @@ class Player{
if(($this->gamemode & 0x01) === CREATIVE){
return;
}
$hotbar = array();
foreach($this->hotbar as $slot){
$hotbar[] = $slot <= -1 ? -1 : $slot + 9;
}
$this->dataPacket(MC_CONTAINER_SET_CONTENT, array(
"windowid" => 0,
"count" => count($this->inventory),
"slots" => $this->inventory,
"hotbar" => $hotbar,
));
}