PocketMine-MP 5.14.2 git-50e2c469a547a16a23b2dc691e70a51d34e29395
SavedItemStackData.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
24namespace pocketmine\data\bedrock\item;
25
30use function array_map;
31use function count;
32
34
35 public const TAG_COUNT = "Count";
36 public const TAG_SLOT = "Slot";
37 public const TAG_WAS_PICKED_UP = "WasPickedUp";
38 public const TAG_CAN_PLACE_ON = "CanPlaceOn";
39 public const TAG_CAN_DESTROY = "CanDestroy";
40
45 public function __construct(
46 private SavedItemData $typeData,
47 private int $count,
48 private ?int $slot,
49 private ?bool $wasPickedUp,
50 private array $canPlaceOn,
51 private array $canDestroy
52 ){}
53
54 public function getTypeData() : SavedItemData{ return $this->typeData; }
55
56 public function getCount() : int{ return $this->count; }
57
58 public function getSlot() : ?int{ return $this->slot; }
59
60 public function getWasPickedUp() : ?bool{ return $this->wasPickedUp; }
61
63 public function getCanPlaceOn() : array{ return $this->canPlaceOn; }
64
66 public function getCanDestroy() : array{ return $this->canDestroy; }
67
68 public function toNbt() : CompoundTag{
69 $result = CompoundTag::create();
70 $result->setByte(self::TAG_COUNT, Binary::signByte($this->count));
71
72 if($this->slot !== null){
73 $result->setByte(self::TAG_SLOT, Binary::signByte($this->slot));
74 }
75 if($this->wasPickedUp !== null){
76 $result->setByte(self::TAG_WAS_PICKED_UP, $this->wasPickedUp ? 1 : 0);
77 }
78 if(count($this->canPlaceOn) !== 0){
79 $result->setTag(self::TAG_CAN_PLACE_ON, new ListTag(array_map(fn(string $s) => new StringTag($s), $this->canPlaceOn)));
80 }
81 if(count($this->canDestroy) !== 0){
82 $result->setTag(self::TAG_CAN_DESTROY, new ListTag(array_map(fn(string $s) => new StringTag($s), $this->canDestroy)));
83 }
84
85 return $result->merge($this->typeData->toNbt());
86 }
87}
__construct(private SavedItemData $typeData, private int $count, private ?int $slot, private ?bool $wasPickedUp, private array $canPlaceOn, private array $canDestroy)
setByte(string $name, int $value)