Creative inventory fixes

This commit is contained in:
Dylan K. Taylor 2016-10-01 12:21:39 +01:00
parent 98ea674d20
commit 92784054cd
2 changed files with 18 additions and 9 deletions

View File

@ -1098,6 +1098,9 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->inventory->sendContents($this);
$this->inventory->sendContents($this->getViewers());
$this->inventory->sendHeldItem($this->hasSpawned);
if($this->isCreative()){
$this->inventory->sendCreativeContents();
}
return true;
}
@ -1733,6 +1736,10 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
$this->setRemoveFormat(false);
}
if($this->isCreative()){
$this->inventory->sendCreativeContents();
}
$this->forceMovement = $this->teleportPosition = $this->getPosition();
$this->server->onPlayerLogin($this);

View File

@ -399,15 +399,6 @@ class PlayerInventory extends BaseInventory{
$index = $this->getHotbarSlotIndex($i);
$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){
$this->close($player);
@ -418,6 +409,17 @@ class PlayerInventory extends BaseInventory{
}
}
public function sendCreativeContents(){
$pk = new ContainerSetContentPacket();
$pk->windowid = ContainerSetContentPacket::SPECIAL_CREATIVE;
if($this->getHolder()->getGamemode() === Player::CREATIVE){
foreach(Item::getCreativeItems() as $i => $item){
$pk->slots[$i] = clone $item;
}
}
$this->getHolder()->dataPacket($pk);
}
/**
* @param int $index
* @param Player|Player[] $target