PocketMine-MP 5.32.2 git-237b304ef9858756b018e44e8f298093f66f823b
Loading...
Searching...
No Matches
Barrel.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\Barrel as TileBarrel;
28use pocketmine\block\utils\AnyFacingTrait;
35use function abs;
36
37class Barrel extends Opaque implements AnyFacing{
38 use AnyFacingTrait;
39
40 protected bool $open = false;
41
42 protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
43 $w->facing($this->facing);
44 $w->bool($this->open);
45 }
46
47 public function isOpen() : bool{
48 return $this->open;
49 }
50
52 public function setOpen(bool $open) : Barrel{
53 $this->open = $open;
54 return $this;
55 }
56
57 public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
58 if($player !== null){
59 if(abs($player->getPosition()->x - $this->position->x) < 2 && abs($player->getPosition()->z - $this->position->z) < 2){
60 $y = $player->getEyePos()->y;
61
62 if($y - $this->position->y > 2){
63 $this->facing = Facing::UP;
64 }elseif($this->position->y - $y > 0){
65 $this->facing = Facing::DOWN;
66 }else{
67 $this->facing = Facing::opposite($player->getHorizontalFacing());
68 }
69 }else{
70 $this->facing = Facing::opposite($player->getHorizontalFacing());
71 }
72 }
73
74 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
75 }
76
77 public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
78 if($player instanceof Player){
79 $barrel = $this->position->getWorld()->getTile($this->position);
80 if($barrel instanceof TileBarrel){
81 if(!$barrel->canOpenWith($item->getCustomName())){
82 return true;
83 }
84
85 $player->setCurrentWindow($barrel->getInventory());
86 }
87 }
88
89 return true;
90 }
91
92 public function getFuelTime() : int{
93 return 300;
94 }
95}
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)
Definition Barrel.php:57
setOpen(bool $open)
Definition Barrel.php:52
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
Definition Barrel.php:77
describeBlockOnlyState(RuntimeDataDescriber $w)
Definition Barrel.php:42