PocketMine-MP
5.33.2 git-1133d49c924b4358c79d44eeb97dcbf56cb4d1eb
Loading...
Searching...
No Matches
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
22
declare(strict_types=1);
23
24
namespace
pocketmine\block
;
25
26
use
pocketmine\block\inventory\window\HopperInventoryWindow
;
27
use
pocketmine\block\utils\Container
;
28
use pocketmine\block\utils\ContainerTrait;
29
use
pocketmine\block\utils\PoweredByRedstone
;
30
use pocketmine\block\utils\PoweredByRedstoneTrait;
31
use pocketmine\block\utils\SupportType;
32
use
pocketmine\data\runtime\RuntimeDataDescriber
;
33
use
pocketmine\inventory\Inventory
;
34
use
pocketmine\item\Item
;
35
use
pocketmine\math\AxisAlignedBB
;
36
use
pocketmine\math\Facing
;
37
use
pocketmine\math\Vector3
;
38
use
pocketmine\player\InventoryWindow
;
39
use
pocketmine\player\Player
;
40
use
pocketmine\world\BlockTransaction
;
41
use
pocketmine\world\Position
;
42
43
class
Hopper
extends
Transparent
implements
Container
,
PoweredByRedstone
{
44
use ContainerTrait;
45
use PoweredByRedstoneTrait;
46
47
private
Facing
$facing = Facing::DOWN;
48
49
protected
function
describeBlockOnlyState
(
RuntimeDataDescriber
$w) : void{
50
$w->facingExcept($this->facing,
Facing
::UP);
51
$w->bool($this->powered);
52
}
53
54
public
function
getFacing() :
Facing
{ return $this->facing; }
55
57
public
function
setFacing
(
Facing
$facing) : self{
58
if($facing ===
Facing
::UP){
59
throw
new \InvalidArgumentException(
"Hopper may not face upward"
);
60
}
61
$this->facing = $facing;
62
return
$this;
63
}
64
65
protected
function
recalculateCollisionBoxes
() : array{
66
$result = [
67
AxisAlignedBB
::one()->trimmedCopy(
Facing
::UP, 6 / 16)
//the empty area around the bottom is currently considered solid
68
];
69
70
foreach
(Facing::HORIZONTAL as $f){
//add the frame parts around the bowl
71
$result[] = AxisAlignedBB::one()->trimmedCopy($f, 14 / 16);
72
}
73
return
$result;
74
}
75
76
public
function
getSupportType
(
Facing
$facing) : SupportType{
77
return match($facing){
78
Facing::UP => SupportType::FULL,
79
Facing::DOWN => $this->facing === Facing::DOWN ? SupportType::CENTER : SupportType::NONE,
80
default
=> SupportType::NONE
81
};
82
}
83
84
public
function
place
(
BlockTransaction
$tx,
Item
$item,
Block
$blockReplace,
Block
$blockClicked,
Facing
$face,
Vector3
$clickVector, ?
Player
$player =
null
) : bool{
85
$this->facing = $face ===
Facing
::DOWN ?
Facing
::DOWN :
Facing
::opposite($face);
86
87
return
parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
88
}
89
90
protected
function
newMenu(
Player
$player,
Inventory
$inventory,
Position
$position) :
InventoryWindow
{
91
return new
HopperInventoryWindow
($player, $inventory, $position);
92
}
93
94
public
function
onScheduledUpdate
() : void{
95
//TODO
96
}
97
98
//TODO: redstone logic, sucking logic
99
}
pocketmine\block\Block
Definition
Block.php:62
pocketmine\block\Hopper
Definition
Hopper.php:43
pocketmine\block\Hopper\setFacing
setFacing(Facing $facing)
Definition
Hopper.php:57
pocketmine\block\Hopper\describeBlockOnlyState
describeBlockOnlyState(RuntimeDataDescriber $w)
Definition
Hopper.php:49
pocketmine\block\Hopper\getSupportType
getSupportType(Facing $facing)
Definition
Hopper.php:76
pocketmine\block\Hopper\onScheduledUpdate
onScheduledUpdate()
Definition
Hopper.php:94
pocketmine\block\Hopper\place
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player=null)
Definition
Hopper.php:84
pocketmine\block\Hopper\recalculateCollisionBoxes
recalculateCollisionBoxes()
Definition
Hopper.php:65
pocketmine\block\Transparent
Definition
Transparent.php:32
pocketmine\block\inventory\window\HopperInventoryWindow
Definition
HopperInventoryWindow.php:26
pocketmine\item\Item
Definition
Item.php:62
pocketmine\math\AxisAlignedBB
Definition
AxisAlignedBB.php:29
pocketmine\math\Vector3
Definition
Vector3.php:37
pocketmine\player\InventoryWindow
Definition
InventoryWindow.php:28
pocketmine\player\Player
Definition
Player.php:173
pocketmine\world\BlockTransaction
Definition
BlockTransaction.php:30
pocketmine\world\Position
Definition
Position.php:31
pocketmine\block\utils\Container
Definition
Container.php:32
pocketmine\block\utils\PoweredByRedstone
Definition
PoweredByRedstone.php:26
pocketmine\data\runtime\RuntimeDataDescriber
Definition
RuntimeDataDescriber.php:38
pocketmine\inventory\Inventory
Definition
Inventory.php:34
pocketmine\block
Definition
ActivatorRail.php:24
pocketmine\math\Facing
Facing
Definition
Facing.php:28
src
block
Hopper.php
Generated by
1.12.0