diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 6d00a8f81..f3b8e0dd1 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -153,6 +153,7 @@ use pocketmine\network\mcpe\protocol\StartGamePacket; use pocketmine\network\mcpe\protocol\TakeItemEntityPacket; use pocketmine\network\mcpe\protocol\TextPacket; use pocketmine\network\mcpe\protocol\TransferPacket; +use pocketmine\network\mcpe\protocol\types\ContainerIds; use pocketmine\network\mcpe\protocol\UpdateAttributesPacket; use pocketmine\network\mcpe\protocol\UpdateBlockPacket; use pocketmine\network\mcpe\protocol\UseItemPacket; @@ -2761,21 +2762,21 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade } switch($packet->windowid){ - case ContainerSetContentPacket::SPECIAL_INVENTORY: //Normal inventory change + case ContainerIds::INVENTORY: //Normal inventory change if($packet->slot >= $this->inventory->getSize()){ return false; } $transaction = new BaseTransaction($this->inventory, $packet->slot, $this->inventory->getItem($packet->slot), $packet->item); break; - case ContainerSetContentPacket::SPECIAL_ARMOR: //Armour change + case ContainerIds::ARMOR: //Armour change if($packet->slot >= 4){ return false; } $transaction = new BaseTransaction($this->inventory, $packet->slot + $this->inventory->getSize(), $this->inventory->getArmorItem($packet->slot), $packet->item); break; - case ContainerSetContentPacket::SPECIAL_HOTBAR: //Hotbar link update + case ContainerIds::HOTBAR: //Hotbar link update //hotbarSlot 0-8, slot 9-44 $this->inventory->setHotbarSlotIndex($packet->hotbarSlot, $packet->slot - 9); return true; diff --git a/src/pocketmine/inventory/PlayerInventory.php b/src/pocketmine/inventory/PlayerInventory.php index b7b5bf41a..994cfd5f7 100644 --- a/src/pocketmine/inventory/PlayerInventory.php +++ b/src/pocketmine/inventory/PlayerInventory.php @@ -32,6 +32,7 @@ use pocketmine\network\mcpe\protocol\ContainerSetContentPacket; use pocketmine\network\mcpe\protocol\ContainerSetSlotPacket; use pocketmine\network\mcpe\protocol\MobArmorEquipmentPacket; use pocketmine\network\mcpe\protocol\MobEquipmentPacket; +use pocketmine\network\mcpe\protocol\types\ContainerIds; use pocketmine\Player; use pocketmine\Server; @@ -238,7 +239,7 @@ class PlayerInventory extends BaseInventory{ $pk->item = $item; $pk->inventorySlot = $this->getHeldItemSlot(); $pk->hotbarSlot = $this->getHeldItemIndex(); - $pk->windowId = ContainerSetContentPacket::SPECIAL_INVENTORY; + $pk->windowId = ContainerIds::INVENTORY; if(!is_array($target)){ $target->dataPacket($pk); @@ -424,7 +425,7 @@ class PlayerInventory extends BaseInventory{ foreach($target as $player){ if($player === $this->getHolder()){ $pk2 = new ContainerSetContentPacket(); - $pk2->windowid = ContainerSetContentPacket::SPECIAL_ARMOR; + $pk2->windowid = ContainerIds::ARMOR; $pk2->slots = $armor; $pk2->targetEid = $player->getId(); $player->dataPacket($pk2); @@ -473,7 +474,7 @@ class PlayerInventory extends BaseInventory{ if($player === $this->getHolder()){ /** @var Player $player */ $pk2 = new ContainerSetSlotPacket(); - $pk2->windowid = ContainerSetContentPacket::SPECIAL_ARMOR; + $pk2->windowid = ContainerIds::ARMOR; $pk2->slot = $index - $this->getSize(); $pk2->item = $this->getItem($index); $player->dataPacket($pk2); @@ -523,7 +524,7 @@ class PlayerInventory extends BaseInventory{ public function sendCreativeContents(){ $pk = new ContainerSetContentPacket(); - $pk->windowid = ContainerSetContentPacket::SPECIAL_CREATIVE; + $pk->windowid = ContainerIds::CREATIVE; if($this->getHolder()->getGamemode() === Player::CREATIVE){ foreach(Item::getCreativeItems() as $i => $item){ $pk->slots[$i] = clone $item; diff --git a/src/pocketmine/network/mcpe/protocol/ContainerSetContentPacket.php b/src/pocketmine/network/mcpe/protocol/ContainerSetContentPacket.php index 62723d4f3..bb47539b7 100644 --- a/src/pocketmine/network/mcpe/protocol/ContainerSetContentPacket.php +++ b/src/pocketmine/network/mcpe/protocol/ContainerSetContentPacket.php @@ -27,17 +27,11 @@ namespace pocketmine\network\mcpe\protocol; use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\protocol\types\ContainerIds; class ContainerSetContentPacket extends DataPacket{ const NETWORK_ID = ProtocolInfo::CONTAINER_SET_CONTENT_PACKET; - const SPECIAL_INVENTORY = 0; - const SPECIAL_OFFHAND = 0x77; - const SPECIAL_ARMOR = 0x78; - const SPECIAL_CREATIVE = 0x79; - const SPECIAL_HOTBAR = 0x7a; - const SPECIAL_FIXED_INVENTORY = 0x7b; - public $windowid; public $targetEid; public $slots = []; @@ -70,7 +64,7 @@ class ContainerSetContentPacket extends DataPacket{ foreach($this->slots as $slot){ $this->putSlot($slot); } - if($this->windowid === self::SPECIAL_INVENTORY and count($this->hotbar) > 0){ + if($this->windowid === ContainerIds::INVENTORY and count($this->hotbar) > 0){ $this->putUnsignedVarInt(count($this->hotbar)); foreach($this->hotbar as $slot){ $this->putVarInt($slot); diff --git a/src/pocketmine/network/mcpe/protocol/types/ContainerIds.php b/src/pocketmine/network/mcpe/protocol/types/ContainerIds.php new file mode 100644 index 000000000..640dea519 --- /dev/null +++ b/src/pocketmine/network/mcpe/protocol/types/ContainerIds.php @@ -0,0 +1,38 @@ +