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