mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-01 23:59:53 +00:00
Save and send last slot used by player
This commit is contained in:
parent
01015d0db3
commit
624eb93058
@ -454,6 +454,7 @@ class PlayerAPI{
|
|||||||
"z" => $this->server->spawn->z,
|
"z" => $this->server->spawn->z,
|
||||||
),
|
),
|
||||||
"inventory" => array_fill(0, PLAYER_SURVIVAL_SLOTS, array(AIR, 0, 0)),
|
"inventory" => array_fill(0, PLAYER_SURVIVAL_SLOTS, array(AIR, 0, 0)),
|
||||||
|
"slot" => 0,
|
||||||
"armor" => array_fill(0, 4, array(AIR, 0)),
|
"armor" => array_fill(0, 4, array(AIR, 0)),
|
||||||
"gamemode" => $this->server->gamemode,
|
"gamemode" => $this->server->gamemode,
|
||||||
"health" => 20,
|
"health" => 20,
|
||||||
|
@ -251,6 +251,7 @@ class Player{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->data->set("inventory", $inv);
|
$this->data->set("inventory", $inv);
|
||||||
|
$this->data->set("slot", $this->slot);
|
||||||
|
|
||||||
$armor = array();
|
$armor = array();
|
||||||
foreach($this->armor as $slot => $item){
|
foreach($this->armor as $slot => $item){
|
||||||
@ -1366,6 +1367,8 @@ class Player{
|
|||||||
));
|
));
|
||||||
if(($this->gamemode & 0x01) === 0x01){
|
if(($this->gamemode & 0x01) === 0x01){
|
||||||
$this->slot = 0;
|
$this->slot = 0;
|
||||||
|
}elseif($this->data->exists("slot")){
|
||||||
|
$this->slot = (int) $this->data->get("slot");
|
||||||
}else{
|
}else{
|
||||||
$this->slot = -1;//0
|
$this->slot = -1;//0
|
||||||
}
|
}
|
||||||
@ -1487,7 +1490,6 @@ class Player{
|
|||||||
if($this->spawned === false){
|
if($this->spawned === false){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$data["eid"] = $this->eid;
|
$data["eid"] = $this->eid;
|
||||||
$data["player"] = $this;
|
$data["player"] = $this;
|
||||||
|
|
||||||
@ -2198,10 +2200,16 @@ class Player{
|
|||||||
if(($this->gamemode & 0x01) === CREATIVE){
|
if(($this->gamemode & 0x01) === CREATIVE){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
$hotbar = array();
|
||||||
|
$hotbar[] = $this->slot == -1 ? -1:($this->slot + 9);
|
||||||
|
for($i = 1; $i < 9; ++$i){
|
||||||
|
$hotbar[] = -1;
|
||||||
|
}
|
||||||
$this->dataPacket(MC_CONTAINER_SET_CONTENT, array(
|
$this->dataPacket(MC_CONTAINER_SET_CONTENT, array(
|
||||||
"windowid" => 0,
|
"windowid" => 0,
|
||||||
"count" => count($this->inventory),
|
"count" => count($this->inventory),
|
||||||
"slots" => $this->inventory,
|
"slots" => $this->inventory,
|
||||||
|
"hotbar" => $hotbar,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -800,12 +800,29 @@ class CustomPacketHandler{
|
|||||||
for($s = 0; $s < $this->data["count"] and !$this->feof(); ++$s){
|
for($s = 0; $s < $this->data["count"] and !$this->feof(); ++$s){
|
||||||
$this->data["slots"][$s] = Utils::readSlot($this);
|
$this->data["slots"][$s] = Utils::readSlot($this);
|
||||||
}
|
}
|
||||||
|
if($this->data["windowid"] == 0){
|
||||||
|
$slots = min(9, Utils::readShort($this->get(2), false));
|
||||||
|
$this->data["hotbar"] = array();
|
||||||
|
if($slots > 0){
|
||||||
|
for($s = 0; $s < $slots; ++$s){
|
||||||
|
$this->data["hotbar"][$s] = Utils::readInt($this->get(4));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
$this->raw .= chr($this->data["windowid"]);
|
$this->raw .= chr($this->data["windowid"]);
|
||||||
$this->raw .= Utils::writeShort(count($this->data["slots"]));
|
$this->raw .= Utils::writeShort(count($this->data["slots"]));
|
||||||
foreach($this->data["slots"] as $slot){
|
foreach($this->data["slots"] as $slot){
|
||||||
$this->raw .= Utils::writeSlot($slot);
|
$this->raw .= Utils::writeSlot($slot);
|
||||||
}
|
}
|
||||||
|
if($this->data["windowid"] == 0 and isset($this->data["hotbar"])){
|
||||||
|
if(count($this->data["hotbar"]) > 0){
|
||||||
|
$this->raw .= Utils::writeShort(count($this->data["hotbar"]));
|
||||||
|
foreach($this->data["hotbar"] as $slot){
|
||||||
|
$this->raw .= Utils::writeInt($slot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MC_CONTAINER_SET_DATA:
|
case MC_CONTAINER_SET_DATA:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user