PocketMine-MP 5.21.2 git-b2aa6396c3cc2cafdd815eacc360e1ad89599899
Loading...
Searching...
No Matches
ArmorInventory.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
25
33
35 public const SLOT_HEAD = 0;
36 public const SLOT_CHEST = 1;
37 public const SLOT_LEGS = 2;
38 public const SLOT_FEET = 3;
39
40 public function __construct(
41 protected Living $holder
42 ){
43 parent::__construct(4);
44
45 $this->validators->add(new CallbackSlotValidator(self::validate(...)));
46 }
47
48 public function getHolder() : Living{
49 return $this->holder;
50 }
51
52 public function getHelmet() : Item{
53 return $this->getItem(self::SLOT_HEAD);
54 }
55
56 public function getChestplate() : Item{
57 return $this->getItem(self::SLOT_CHEST);
58 }
59
60 public function getLeggings() : Item{
61 return $this->getItem(self::SLOT_LEGS);
62 }
63
64 public function getBoots() : Item{
65 return $this->getItem(self::SLOT_FEET);
66 }
67
68 public function setHelmet(Item $helmet) : void{
69 $this->setItem(self::SLOT_HEAD, $helmet);
70 }
71
72 public function setChestplate(Item $chestplate) : void{
73 $this->setItem(self::SLOT_CHEST, $chestplate);
74 }
75
76 public function setLeggings(Item $leggings) : void{
77 $this->setItem(self::SLOT_LEGS, $leggings);
78 }
79
80 public function setBoots(Item $boots) : void{
81 $this->setItem(self::SLOT_FEET, $boots);
82 }
83
84 private static function validate(Inventory $inventory, Item $item, int $slot) : ?TransactionValidationException{
85 if($item instanceof Armor){
86 if($item->getArmorSlot() !== $slot){
87 return new TransactionValidationException("Armor item is in wrong slot");
88 }
89 }else{
90 if(!($slot === ArmorInventory::SLOT_HEAD && $item instanceof ItemBlock && (
91 $item->getBlock()->getTypeId() === BlockTypeIds::CARVED_PUMPKIN ||
92 $item->getBlock()->getTypeId() === BlockTypeIds::MOB_HEAD
93 ))){
94 return new TransactionValidationException("Item is not accepted in an armor slot");
95 }
96 }
97 return null;
98 }
99}
setItem(int $index, Item $item)
getBlock(?int $clickedFace=null)
Definition Item.php:491