Inventory: Fix creative/spectator inventory sending

This commit is contained in:
Dylan K. Taylor
2016-09-06 13:05:53 +01:00
parent 5851e7fe55
commit f14a8e46be
3 changed files with 37 additions and 45 deletions

View File

@ -384,16 +384,14 @@ class PlayerInventory extends BaseInventory{
$pk = new ContainerSetContentPacket();
$pk->slots = [];
$holder = $this->getHolder();
if($holder instanceof Player and $holder->isCreative()){
//TODO: Remove this workaround because of broken client
foreach(Item::getCreativeItems() as $i => $item){
$pk->slots[$i] = Item::getCreativeItem($i);
}
}else{
for($i = 0; $i < $this->getSize(); ++$i){ //Do not send armor by error here
$pk->slots[$i] = $this->getItem($i);
}
for($i = 0; $i < $this->getSize(); ++$i){ //Do not send armor by error here
$pk->slots[$i] = $this->getItem($i);
}
//Because PE is stupid and shows 9 less slots than you send it, give it 9 dummy slots so it shows all the REAL slots.
for($i = $this->getSize(); $i < $this->getSize() + $this->getHotbarSize(); ++$i){
$pk->slots[$i] = Item::get(Item::AIR, 0, 0);
}
foreach($target as $player){
@ -401,7 +399,16 @@ class PlayerInventory extends BaseInventory{
if($player === $this->getHolder()){
for($i = 0; $i < $this->getHotbarSize(); ++$i){
$index = $this->getHotbarSlotIndex($i);
$pk->hotbar[] = $index <= -1 ? -1 : $index + 9;
$pk->hotbar[] = $index <= -1 ? -1 : $index + $this->getHotbarSize();
}
if($player->getGamemode() & 0x01 === 0x01){ //Send special inventory for creative or spectator
$pk2 = new ContainerSetContentPacket();
$pk2->windowid = ContainerSetContentPacket::SPECIAL_CREATIVE;
if($player->getGamemode() === Player::CREATIVE){
$pk2->slots = Item::getCreativeItems();
}
$player->dataPacket($pk2);
}
}
if(($id = $player->getWindowId($this)) === -1 or $player->spawned !== true){