PocketMine-MP 5.21.1 git-e598364f0695495cbe71ddf0b62f134b51091c6e
FenceGate.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\utils\HorizontalFacingTrait;
27use pocketmine\block\utils\SupportType;
28use pocketmine\block\utils\WoodTypeTrait;
37
38class FenceGate extends Transparent{
39 use WoodTypeTrait;
40 use HorizontalFacingTrait;
41
42 protected bool $open = false;
43 protected bool $inWall = false;
44
45 protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
46 $w->horizontalFacing($this->facing);
47 $w->bool($this->open);
48 $w->bool($this->inWall);
49 }
50
51 public function isOpen() : bool{ return $this->open; }
52
54 public function setOpen(bool $open) : self{
55 $this->open = $open;
56 return $this;
57 }
58
59 public function isInWall() : bool{ return $this->inWall; }
60
62 public function setInWall(bool $inWall) : self{
63 $this->inWall = $inWall;
64 return $this;
65 }
66
70 protected function recalculateCollisionBoxes() : array{
71 return $this->open ? [] : [AxisAlignedBB::one()->extend(Facing::UP, 0.5)->squash(Facing::axis($this->facing), 6 / 16)];
72 }
73
74 public function getSupportType(int $facing) : SupportType{
75 return SupportType::NONE;
76 }
77
78 private function checkInWall() : bool{
79 return (
80 $this->getSide(Facing::rotateY($this->facing, false)) instanceof Wall ||
81 $this->getSide(Facing::rotateY($this->facing, true)) instanceof Wall
82 );
83 }
84
85 public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
86 if($player !== null){
87 $this->facing = $player->getHorizontalFacing();
88 }
89
90 $this->inWall = $this->checkInWall();
91
92 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
93 }
94
95 public function onNearbyBlockChange() : void{
96 $inWall = $this->checkInWall();
97 if($inWall !== $this->inWall){
98 $this->inWall = $inWall;
99 $this->position->getWorld()->setBlock($this->position, $this);
100 }
101 }
102
103 public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
104 $this->open = !$this->open;
105 if($this->open && $player !== null){
106 $playerFacing = $player->getHorizontalFacing();
107 if($playerFacing === Facing::opposite($this->facing)){
108 $this->facing = $playerFacing;
109 }
110 }
111
112 $world = $this->position->getWorld();
113 $world->setBlock($this->position, $this);
114 $world->addSound($this->position, new DoorSound());
115 return true;
116 }
117
118 public function getFuelTime() : int{
119 return $this->woodType->isFlammable() ? 300 : 0;
120 }
121
122 public function getFlameEncouragement() : int{
123 return $this->woodType->isFlammable() ? 5 : 0;
124 }
125
126 public function getFlammability() : int{
127 return $this->woodType->isFlammable() ? 20 : 0;
128 }
129}
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
Definition: FenceGate.php:103
setInWall(bool $inWall)
Definition: FenceGate.php:62
describeBlockOnlyState(RuntimeDataDescriber $w)
Definition: FenceGate.php:45
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)
Definition: FenceGate.php:85
getSupportType(int $facing)
Definition: FenceGate.php:74