Move inventory ID constants to their own interface

ContainerSetContentPacket will be removed in 1.2, and these aren't specific to ContainerSetContentPacket anyway.
This commit is contained in:
Dylan K. Taylor 2017-07-12 20:01:46 +01:00
parent a5c6c8b973
commit 5283975f20
4 changed files with 49 additions and 15 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -0,0 +1,38 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol\types;
interface ContainerIds{
const NONE = -1;
const INVENTORY = 0;
const FIRST = 1;
const LAST = 100;
const OFFHAND = 119;
const ARMOR = 120;
const CREATIVE = 121;
const HOTBAR = 122;
const FIXED_INVENTORY = 123;
}