PocketMine-MP 5.33.2 git-1133d49c924b4358c79d44eeb97dcbf56cb4d1eb
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
27use pocketmine\block\utils\AnimatedContainerLikeTrait;
29use pocketmine\block\utils\AnyFacingTrait;
31use pocketmine\block\utils\ContainerTrait;
42use function abs;
43
45 use AnimatedContainerLikeTrait;
46 use AnyFacingTrait;
47 use ContainerTrait;
48
49 protected bool $open = false;
50
51 protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
52 $w->enum($this->facing);
53 $w->bool($this->open);
54 }
55
56 public function isOpen() : bool{
57 return $this->open;
58 }
59
61 public function setOpen(bool $open) : Barrel{
62 $this->open = $open;
63 return $this;
64 }
65
66 public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player = null) : bool{
67 if($player !== null){
68 if(abs($player->getPosition()->x - $this->position->x) < 2 && abs($player->getPosition()->z - $this->position->z) < 2){
69 $y = $player->getEyePos()->y;
70
71 if($y - $this->position->y > 2){
72 $this->facing = Facing::UP;
73 }elseif($this->position->y - $y > 0){
74 $this->facing = Facing::DOWN;
75 }else{
76 $this->facing = Facing::opposite($player->getHorizontalFacing());
77 }
78 }else{
79 $this->facing = Facing::opposite($player->getHorizontalFacing());
80 }
81 }
82
83 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
84 }
85
86 public function getFuelTime() : int{
87 return 300;
88 }
89
90 protected function getOpenSound() : Sound{
91 return new BarrelOpenSound();
92 }
93
94 protected function getCloseSound() : Sound{
95 return new BarrelCloseSound();
96 }
97
98 protected function playAnimationVisual(Position $position, bool $isOpen) : void{
99 $world = $position->getWorld();
100 $block = $world->getBlock($position);
101 if($block instanceof Barrel){
102 $world->setBlock($position, $block->setOpen($isOpen));
103 }
104 }
105}
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player=null)
Definition Barrel.php:66
setOpen(bool $open)
Definition Barrel.php:61
describeBlockOnlyState(RuntimeDataDescriber $w)
Definition Barrel.php:51