|
| | __construct (Human $player, $contents=null) |
| |
| | getSize () |
| |
| | setSize ($size) |
| |
| | getHotbarSlotIndex ($index) |
| |
| | setHotbarSlotIndex ($index, $slot) |
| |
| | getHeldItemIndex () |
| |
| | setHeldItemIndex ($hotbarSlotIndex, $sendToHolder=true, $slotMapping=null) |
| |
| | getItemInHand () |
| |
| | setItemInHand (Item $item) |
| |
| | getHotbar () |
| |
| | getHeldItemSlot () |
| |
| | setHeldItemSlot ($slot) |
| |
| | sendHeldItem ($target) |
| |
| | onSlotChange ($index, $before, $send) |
| |
| | getHotbarSize () |
| |
| | getArmorItem ($index) |
| |
| | setArmorItem ($index, Item $item) |
| |
| | damageArmor ($index, $cost) |
| |
| | getHelmet () |
| |
| | getChestplate () |
| |
| | getLeggings () |
| |
| | getBoots () |
| |
| | setHelmet (Item $helmet) |
| |
| | setChestplate (Item $chestplate) |
| |
| | setLeggings (Item $leggings) |
| |
| | setBoots (Item $boots) |
| |
| | setItem ($index, Item $item, $send=true) |
| |
| | clear ($index, $send=true) |
| |
| | getArmorContents () |
| |
| | clearAll ($send=true) |
| |
| | sendArmorContents ($target) |
| |
| | setArmorContents (array $items) |
| |
| | sendContents ($target) |
| |
| | getHolder () |
| |
| | __construct (InventoryHolder $holder, InventoryType $type, array $items=[], $overrideSize=null, $overrideTitle=null) |
| |
| | __destruct () |
| |
| | getSize () |
| |
| | getHotbarSize () |
| |
| | setSize ($size) |
| |
| | getMaxStackSize () |
| |
| | getName () |
| |
| | getTitle () |
| |
| | getItem ($index) |
| |
| | getContents () |
| |
| | setContents (array $items, $send=true) |
| |
| | setItem ($index, Item $item, $send=true) |
| |
| | contains (Item $item) |
| |
| | slotContains ($slot, Item $item, $matchCount=false) |
| |
| | all (Item $item) |
| |
| | remove (Item $item, $send=true) |
| |
| | first (Item $item) |
| |
| | firstEmpty () |
| |
| | firstOccupied () |
| |
| | canAddItem (Item $item) |
| |
| | clear ($index, $send=true) |
| |
| | clearAll ($send=true) |
| |
| | getViewers () |
| |
| | getHolder () |
| |
| | setMaxStackSize ($size) |
| |
| | open (Player $who) |
| |
| | close (Player $who) |
| |
| | onOpen (Player $who) |
| |
| | onClose (Player $who) |
| |
| | onSlotChange ($index, $before, $send) |
| |
| | processSlotChange (Transaction $transaction) |
| |
| | sendContents ($target) |
| |
| | sendSlot ($index, $target) |
| |
| | getType () |
| |
| | setItem ($index, Item $item) |
| |
| | addItem (... $slots) |
| |
| | removeItem (... $slots) |
| |
| | setContents (array $items) |
| |
| | remove (Item $item) |
| |
| | clear ($index) |
| |
| | clearAll () |
| |
◆ __construct()
| __construct |
( |
Human |
$player, |
|
|
|
$contents = null |
|
) |
| |
PlayerInventory constructor.
- Parameters
-
| Human | $player | |
| null | $contents | |
53 if($contents !== null){
54 if($contents instanceof
ListTag){
55 foreach($contents as $item){
56 if($item[
"Slot"] >= 0 and $item[
"Slot"] < $this->
getHotbarSize()){
57 if(isset($item[
"TrueSlot"])){
60 if(0 <= $item[
"TrueSlot"] and $item[
"TrueSlot"] < $this->
getSize()){
61 $this->hotbar[$item[
"Slot"]] = $item[
"TrueSlot"];
63 }elseif($item[
"TrueSlot"] < 0){
64 $this->hotbar[$item[
"Slot"]] = -1;
69 }elseif($item[
"Slot"] >= 100 and $item[
"Slot"] < 104){
76 throw new \InvalidArgumentException(
"Expecting ListTag, received " . gettype($contents));
◆ clear()
| clear |
( |
|
$index, |
|
|
|
$send = true |
|
) |
| |
- Parameters
-
- Returns
- bool
433 if(isset($this->slots[$index])){
435 $old = $this->slots[$index];
436 if($index >= $this->
getSize() and $index < $this->size){
438 if($ev->isCancelled()){
439 if($index >= $this->size){
440 $this->sendArmorSlot($index, $this->
getViewers());
446 $item = $ev->getNewItem();
449 if($ev->isCancelled()){
450 if($index >= $this->size){
451 $this->sendArmorSlot($index, $this->
getViewers());
457 $item = $ev->getNewItem();
460 $this->slots[$index] = clone $item;
462 unset($this->slots[$index]);
◆ clearAll()
486 for($index = 0; $index < $limit; ++$index){
487 $this->
clear($index,
false);
◆ damageArmor()
| damageArmor |
( |
|
$index, |
|
|
|
$cost |
|
) |
| |
- Parameters
-
317 $this->slots[$this->
getSize() + $index]->useOn($this->slots[$this->
getSize() + $index], $cost);
318 if($this->slots[$this->
getSize() + $index]->getDamage() >= $this->slots[$this->
getSize() + $index]->getMaxDurability()){
◆ getArmorContents()
- Returns
- Item[]
477 for($i = 0; $i < 4; ++$i){
◆ getArmorItem()
◆ getBoots()
◆ getChestplate()
◆ getHeldItemIndex()
- Returns
- int
Returns the index of the inventory slot the player is currently holding
◆ getHeldItemSlot()
- Returns
- int
Returns the inventory slot index of the currently equipped slot
◆ getHelmet()
◆ getHolder()
- Returns
- Human|Player
Implements Inventory.
641 return parent::getHolder();
◆ getHotbar()
- Returns
- int[]
Returns an array of hotbar indices
◆ getHotbarSize()
◆ getHotbarSlotIndex()
| getHotbarSlotIndex |
( |
|
$index | ) |
|
- Parameters
-
- Returns
- int
Returns the index of the inventory slot linked to the specified hotbar slot
104 return ($index >= 0 and $index < $this->
getHotbarSize()) ? $this->hotbar[$index] : -1;
◆ getItemInHand()
- Returns
- Item
Returns the item the player is currently holding
190 if($item instanceof Item){
◆ getLeggings()
◆ getSize()
- Returns
- int
Implements Inventory.
85 return parent::getSize() - 4;
◆ onSlotChange()
| onSlotChange |
( |
|
$index, |
|
|
|
$before, |
|
|
|
$send |
|
) |
| |
- Parameters
-
| int | $index | |
| Item | $before | |
| bool | $send | |
Implements Inventory.
272 parent::onSlotChange($index, $before, $send);
274 if($index === $this->itemInHandIndex){
280 }elseif($index >= $this->
getSize()){
281 $this->sendArmorSlot($index, $this->
getViewers());
◆ sendArmorContents()
| sendArmorContents |
( |
|
$target | ) |
|
- Parameters
-
497 if($target instanceof Player){
503 $pk =
new MobArmorEquipmentPacket();
507 $pk->isEncoded =
true;
509 foreach($target as $player){
511 $pk2 =
new ContainerSetContentPacket();
513 $pk2->slots = $armor;
514 $pk2->targetEid = $player->getId();
515 $player->dataPacket($pk2);
517 $player->dataPacket($pk);
◆ sendContents()
- Parameters
-
Implements Inventory.
575 if($target instanceof Player){
579 $pk =
new ContainerSetContentPacket();
581 for($i = 0; $i < $this->
getSize(); ++$i){
582 $pk->slots[$i] = $this->
getItem($i);
590 foreach($target as $player){
595 $pk->hotbar[$i] = $index <= -1 ? -1 : $index + $this->
getHotbarSize();
598 if(($id = $player->getWindowId($this)) === -1 or $player->spawned !==
true){
599 $this->
close($player);
603 $pk->targetEid = $player->getId();
604 $player->dataPacket(clone $pk);
◆ sendHeldItem()
- Parameters
-
240 $pk =
new MobEquipmentPacket();
247 if(!is_array($target)){
248 $target->dataPacket($pk);
253 $this->
getHolder()->getLevel()->getServer()->broadcastPacket($target, $pk);
◆ setArmorContents()
| setArmorContents |
( |
array |
$items | ) |
|
- Parameters
-
526 for($i = 0; $i < 4; ++$i){
527 if(!isset($items[$i]) or !($items[$i] instanceof Item)){
◆ setArmorItem()
| setArmorItem |
( |
|
$index, |
|
|
Item |
$item |
|
) |
| |
◆ setBoots()
◆ setChestplate()
| setChestplate |
( |
Item |
$chestplate | ) |
|
◆ setHeldItemIndex()
| setHeldItemIndex |
( |
|
$hotbarSlotIndex, |
|
|
|
$sendToHolder = true, |
|
|
|
$slotMapping = null |
|
) |
| |
- Parameters
-
| int | $hotbarSlotIndex | |
| bool | $sendToHolder | |
| int | $slotMapping | Sets which hotbar slot the player is currently holding. Allows slot remapping as specified by a MobEquipmentPacket. DO NOT CHANGE SLOT MAPPING IN PLUGINS! This new implementation is fully compatible with older APIs. NOTE: Slot mapping is the raw slot index sent by MCPE, which will be between 9 and 44. |
141 if($slotMapping !== null){
145 if(0 <= $hotbarSlotIndex and $hotbarSlotIndex < $this->
getHotbarSize()){
146 $this->itemInHandIndex = $hotbarSlotIndex;
147 if($slotMapping !== null){
151 if($slotMapping < 0 or $slotMapping >= $this->
getSize()){
157 $item = $this->
getItem($slotMapping);
158 if($this->
getHolder() instanceof Player){
159 Server::getInstance()->getPluginManager()->callEvent($ev =
new PlayerItemHeldEvent($this->
getHolder(), $item, $slotMapping, $hotbarSlotIndex));
160 if($ev->isCancelled()){
167 if(($key = array_search($slotMapping, $this->hotbar)) !==
false and $slotMapping !== -1){
◆ setHeldItemSlot()
◆ setHelmet()
| setHelmet |
( |
Item |
$helmet | ) |
|
◆ setHotbarSlotIndex()
| setHotbarSlotIndex |
( |
|
$index, |
|
|
|
$slot |
|
) |
| |
- Deprecated:
Changes the linkage of the specified hotbar slot. This should never be done unless it is requested by the client.
- Parameters
-
116 if($this->
getHolder()->getServer()->getProperty(
"settings.deprecated-verbose") !==
false){
117 trigger_error(
"Do not attempt to change hotbar links in plugins!", E_USER_DEPRECATED);
◆ setItem()
| setItem |
( |
|
$index, |
|
|
Item |
$item, |
|
|
|
$send = true |
|
) |
| |
- Parameters
-
| int | $index | |
| Item | $item | |
| bool | $send | |
- Returns
- bool
396 if($index < 0 or $index >= $this->size){
398 }elseif($item->getId() === 0 or $item->getCount() <= 0){
399 return $this->
clear($index, $send);
402 if($index >= $this->
getSize()){
404 if($ev->isCancelled() and $this->
getHolder() instanceof Human){
405 $this->sendArmorSlot($index, $this->
getViewers());
408 $item = $ev->getNewItem();
411 if($ev->isCancelled()){
415 $item = $ev->getNewItem();
420 $this->slots[$index] = clone $item;
◆ setItemInHand()
| setItemInHand |
( |
Item |
$item | ) |
|
- Parameters
-
- Returns
- bool
Sets the item in the inventory slot the player is currently holding.
◆ setLeggings()
| setLeggings |
( |
Item |
$leggings | ) |
|
◆ setSize()
- Parameters
-
92 parent::setSize(
$size + 4);
◆ $hotbar
◆ $itemInHandIndex
The documentation for this class was generated from the following file:
- src/pocketmine/inventory/PlayerInventory.php