PocketMine-MP
5.32.2 git-237b304ef9858756b018e44e8f298093f66f823b
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\tile\Hopper
as TileHopper;
27
use
pocketmine\block\utils\PoweredByRedstone
;
28
use pocketmine\block\utils\PoweredByRedstoneTrait;
29
use pocketmine\block\utils\SupportType;
30
use
pocketmine\data\runtime\RuntimeDataDescriber
;
31
use
pocketmine\item\Item
;
32
use
pocketmine\math\AxisAlignedBB
;
33
use
pocketmine\math\Facing
;
34
use
pocketmine\math\Vector3
;
35
use
pocketmine\player\Player
;
36
use
pocketmine\world\BlockTransaction
;
37
38
class
Hopper
extends
Transparent
implements
PoweredByRedstone
{
39
use PoweredByRedstoneTrait;
40
41
private
int
$facing = Facing::DOWN;
42
43
protected
function
describeBlockOnlyState
(
RuntimeDataDescriber
$w) : void{
44
$w->facingExcept($this->facing,
Facing
::UP);
45
$w->bool($this->powered);
46
}
47
48
public
function
getFacing() : int{ return $this->facing; }
49
51
public
function
setFacing
(
int
$facing) : self{
52
if($facing ===
Facing
::UP){
53
throw
new \InvalidArgumentException(
"Hopper may not face upward"
);
54
}
55
$this->facing = $facing;
56
return
$this;
57
}
58
59
protected
function
recalculateCollisionBoxes
() : array{
60
$result = [
61
AxisAlignedBB
::one()->trim(
Facing
::UP, 6 / 16)
//the empty area around the bottom is currently considered solid
62
];
63
64
foreach
(Facing::HORIZONTAL as $f){
//add the frame parts around the bowl
65
$result[] = AxisAlignedBB::one()->trim($f, 14 / 16);
66
}
67
return
$result;
68
}
69
70
public
function
getSupportType
(
int
$facing) : SupportType{
71
return match($facing){
72
Facing::UP => SupportType::FULL,
73
Facing::DOWN => $this->facing === Facing::DOWN ? SupportType::CENTER : SupportType::NONE,
74
default
=> SupportType::NONE
75
};
76
}
77
78
public
function
place
(
BlockTransaction
$tx,
Item
$item,
Block
$blockReplace,
Block
$blockClicked,
int
$face,
Vector3
$clickVector, ?
Player
$player =
null
) : bool{
79
$this->facing = $face ===
Facing
::DOWN ?
Facing
::DOWN :
Facing
::opposite($face);
80
81
return
parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
82
}
83
84
public
function
onInteract
(
Item
$item,
int
$face,
Vector3
$clickVector, ?
Player
$player =
null
, array &$returnedItems = []) : bool{
85
if($player !== null){
86
$tile = $this->position->getWorld()->getTile($this->position);
87
if
($tile instanceof TileHopper){
//TODO: find a way to have inventories open on click without this boilerplate in every block
88
$player->setCurrentWindow($tile->getInventory());
89
}
90
return
true
;
91
}
92
return
false
;
93
}
94
95
public
function
onScheduledUpdate
() : void{
96
//TODO
97
}
98
99
//TODO: redstone logic, sucking logic
100
}
pocketmine\block\Block
Definition
Block.php:62
pocketmine\block\Hopper
Definition
Hopper.php:38
pocketmine\block\Hopper\place
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)
Definition
Hopper.php:78
pocketmine\block\Hopper\describeBlockOnlyState
describeBlockOnlyState(RuntimeDataDescriber $w)
Definition
Hopper.php:43
pocketmine\block\Hopper\onScheduledUpdate
onScheduledUpdate()
Definition
Hopper.php:95
pocketmine\block\Hopper\getSupportType
getSupportType(int $facing)
Definition
Hopper.php:70
pocketmine\block\Hopper\recalculateCollisionBoxes
recalculateCollisionBoxes()
Definition
Hopper.php:59
pocketmine\block\Hopper\setFacing
setFacing(int $facing)
Definition
Hopper.php:51
pocketmine\block\Hopper\onInteract
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
Definition
Hopper.php:84
pocketmine\block\Transparent
Definition
Transparent.php:32
pocketmine\block\tile\Hopper
Definition
tile/Hopper.php:31
pocketmine\item\Item
Definition
Item.php:60
pocketmine\math\AxisAlignedBB
Definition
AxisAlignedBB.php:29
pocketmine\math\Facing
Definition
Facing.php:28
pocketmine\math\Vector3
Definition
Vector3.php:36
pocketmine\player\Player
Definition
Player.php:173
pocketmine\world\BlockTransaction
Definition
BlockTransaction.php:30
pocketmine\block\utils\PoweredByRedstone
Definition
PoweredByRedstone.php:26
pocketmine\data\runtime\RuntimeDataDescriber
Definition
RuntimeDataDescriber.php:37
pocketmine\block
Definition
ActivatorRail.php:24
src
block
Hopper.php
Generated by
1.12.0