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