PocketMine-MP 5.23.3 git-976fc63567edab7a6fb6aeae739f43cf9fe57de4
Loading...
Searching...
No Matches
Thin.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\SupportType;
30use function count;
31
35class Thin extends Transparent{
37 protected array $connections = [];
38
39 public function readStateFromWorld() : Block{
40 parent::readStateFromWorld();
41
42 $this->collisionBoxes = null;
43
44 foreach(Facing::HORIZONTAL as $facing){
45 $side = $this->getSide($facing);
46 if($side instanceof Thin || $side instanceof Wall || $side->getSupportType(Facing::opposite($facing)) === SupportType::FULL){
47 $this->connections[$facing] = true;
48 }else{
49 unset($this->connections[$facing]);
50 }
51 }
52
53 return $this;
54 }
55
56 protected function recalculateCollisionBoxes() : array{
57 $inset = 7 / 16;
58
59 $bbs = [];
60
61 if(isset($this->connections[Facing::WEST]) || isset($this->connections[Facing::EAST])){
62 $bb = AxisAlignedBB::one()->squash(Axis::Z, $inset);
63
64 if(!isset($this->connections[Facing::WEST])){
65 $bb->trim(Facing::WEST, $inset);
66 }elseif(!isset($this->connections[Facing::EAST])){
67 $bb->trim(Facing::EAST, $inset);
68 }
69 $bbs[] = $bb;
70 }
71
72 if(isset($this->connections[Facing::NORTH]) || isset($this->connections[Facing::SOUTH])){
73 $bb = AxisAlignedBB::one()->squash(Axis::X, $inset);
74
75 if(!isset($this->connections[Facing::NORTH])){
76 $bb->trim(Facing::NORTH, $inset);
77 }elseif(!isset($this->connections[Facing::SOUTH])){
78 $bb->trim(Facing::SOUTH, $inset);
79 }
80 $bbs[] = $bb;
81 }
82
83 if(count($bbs) === 0){
84 //centre post AABB (only needed if not connected on any axis - other BBs overlapping will do this if any connections are made)
85 return [
86 AxisAlignedBB::one()->contract($inset, 0, $inset)
87 ];
88 }
89
90 return $bbs;
91 }
92
93 public function getSupportType(int $facing) : SupportType{
94 return SupportType::NONE;
95 }
96}
getSide(int $side, int $step=1)
Definition Block.php:773
getSupportType(int $facing)
Definition Thin.php:93
getSupportType(int $facing)
Definition Wall.php:154