PocketMine-MP 5.23.3 git-976fc63567edab7a6fb6aeae739f43cf9fe57de4
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
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
67 protected function recalculateCollisionBoxes() : array{
68 return $this->open ? [] : [AxisAlignedBB::one()->extend(Facing::UP, 0.5)->squash(Facing::axis($this->facing), 6 / 16)];
69 }
70
71 public function getSupportType(int $facing) : SupportType{
72 return SupportType::NONE;
73 }
74
75 private function checkInWall() : bool{
76 return (
77 $this->getSide(Facing::rotateY($this->facing, false)) instanceof Wall ||
78 $this->getSide(Facing::rotateY($this->facing, true)) instanceof Wall
79 );
80 }
81
82 public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
83 if($player !== null){
84 $this->facing = $player->getHorizontalFacing();
85 }
86
87 $this->inWall = $this->checkInWall();
88
89 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
90 }
91
92 public function onNearbyBlockChange() : void{
93 $inWall = $this->checkInWall();
94 if($inWall !== $this->inWall){
95 $this->inWall = $inWall;
96 $this->position->getWorld()->setBlock($this->position, $this);
97 }
98 }
99
100 public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
101 $this->open = !$this->open;
102 if($this->open && $player !== null){
103 $playerFacing = $player->getHorizontalFacing();
104 if($playerFacing === Facing::opposite($this->facing)){
105 $this->facing = $playerFacing;
106 }
107 }
108
109 $world = $this->position->getWorld();
110 $world->setBlock($this->position, $this);
111 $world->addSound($this->position, new DoorSound());
112 return true;
113 }
114
115 public function getFuelTime() : int{
116 return $this->woodType->isFlammable() ? 300 : 0;
117 }
118
119 public function getFlameEncouragement() : int{
120 return $this->woodType->isFlammable() ? 5 : 0;
121 }
122
123 public function getFlammability() : int{
124 return $this->woodType->isFlammable() ? 20 : 0;
125 }
126}
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
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:82
getSupportType(int $facing)
Definition FenceGate.php:71