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:
Dylan K. Taylor
2019-06-05 15:00:08 +01:00
parent 09afb8e772
commit 287c8c2dd4
51 changed files with 481 additions and 247 deletions

View File

@@ -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));
}
/**