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