mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-16 03:51:37 +00:00
Added static create() functions for many packets
There are a few motivations here: 1) Less boilerplate code (this can be written inline) 2) It's possible to provide multiple constructors for different packet variations to reduce the chance of errors. 3) It makes things catch fire on updates in ways that static analysers can understand.
This commit is contained in:
@@ -133,11 +133,7 @@ class PlayerInventory extends BaseInventory{
|
||||
public function sendHeldItem($target) : void{
|
||||
$item = $this->getItemInHand();
|
||||
|
||||
$pk = new MobEquipmentPacket();
|
||||
$pk->entityRuntimeId = $this->getHolder()->getId();
|
||||
$pk->item = $item;
|
||||
$pk->inventorySlot = $pk->hotbarSlot = $this->getHeldItemIndex();
|
||||
$pk->windowId = ContainerIds::INVENTORY;
|
||||
$pk = MobEquipmentPacket::create($this->getHolder()->getId(), $item, $this->getHeldItemIndex(), ContainerIds::INVENTORY);
|
||||
|
||||
if(!is_array($target)){
|
||||
$target->sendDataPacket($pk);
|
||||
@@ -166,16 +162,15 @@ class PlayerInventory extends BaseInventory{
|
||||
if(!($holder instanceof Player)){
|
||||
throw new \LogicException("Cannot send creative inventory contents to non-player inventory holder");
|
||||
}
|
||||
$pk = new InventoryContentPacket();
|
||||
$pk->windowId = ContainerIds::CREATIVE;
|
||||
|
||||
$items = [];
|
||||
if(!$holder->isSpectator()){ //fill it for all gamemodes except spectator
|
||||
foreach(Item::getCreativeItems() as $i => $item){
|
||||
$pk->items[$i] = clone $item;
|
||||
$items[$i] = clone $item;
|
||||
}
|
||||
}
|
||||
|
||||
$holder->sendDataPacket($pk);
|
||||
$holder->sendDataPacket(InventoryContentPacket::create(ContainerIds::CREATIVE, $items));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user