PocketMine-MP 5.33.2 git-1133d49c924b4358c79d44eeb97dcbf56cb4d1eb
Loading...
Searching...
No Matches
tile/Hopper.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\block\tile;
25
31
32class Hopper extends Spawnable implements ContainerTile, Nameable{
33
35 use NameableTrait;
36
37 private const TAG_TRANSFER_COOLDOWN = "TransferCooldown";
38
39 private Inventory $inventory;
40 private int $transferCooldown = 0;
41
42 public function __construct(World $world, Vector3 $pos){
43 parent::__construct($world, $pos);
44 $this->inventory = new SimpleInventory(5);
45 }
46
47 public function readSaveData(CompoundTag $nbt) : void{
48 $this->loadItems($nbt);
49 $this->loadName($nbt);
50
51 $this->transferCooldown = $nbt->getInt(self::TAG_TRANSFER_COOLDOWN, 0);
52 }
53
54 protected function writeSaveData(CompoundTag $nbt) : void{
55 $this->saveItems($nbt);
56 $this->saveName($nbt);
57
58 $nbt->setInt(self::TAG_TRANSFER_COOLDOWN, $this->transferCooldown);
59 }
60
61 public function close() : void{
62 if(!$this->closed){
63 $this->inventory->removeAllWindows();
64
65 parent::close();
66 }
67 }
68
69 public function getDefaultName() : string{
70 return "Hopper";
71 }
72
73 public function getInventory() : Inventory{
74 return $this->inventory;
75 }
76
77 public function getRealInventory() : Inventory{
78 return $this->inventory;
79 }
80}
writeSaveData(CompoundTag $nbt)
setInt(string $name, int $value)