PocketMine-MP 5.21.2 git-a6534ecbbbcf369264567d27e5ed70f7f5be9816
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
60 $bbs = [];
61
62 if(isset($this->connections[Facing::WEST]) || isset($this->connections[Facing::EAST])){
63 $bb = AxisAlignedBB::one()->squash(Axis::Z, $inset);
64
65 if(!isset($this->connections[Facing::WEST])){
66 $bb->trim(Facing::WEST, $inset);
67 }elseif(!isset($this->connections[Facing::EAST])){
68 $bb->trim(Facing::EAST, $inset);
69 }
70 $bbs[] = $bb;
71 }
72
73 if(isset($this->connections[Facing::NORTH]) || isset($this->connections[Facing::SOUTH])){
74 $bb = AxisAlignedBB::one()->squash(Axis::X, $inset);
75
76 if(!isset($this->connections[Facing::NORTH])){
77 $bb->trim(Facing::NORTH, $inset);
78 }elseif(!isset($this->connections[Facing::SOUTH])){
79 $bb->trim(Facing::SOUTH, $inset);
80 }
81 $bbs[] = $bb;
82 }
83
84 if(count($bbs) === 0){
85 //centre post AABB (only needed if not connected on any axis - other BBs overlapping will do this if any connections are made)
86 return [
87 AxisAlignedBB::one()->contract($inset, 0, $inset)
88 ];
89 }
90
91 return $bbs;
92 }
93
94 public function getSupportType(int $facing) : SupportType{
95 return SupportType::NONE;
96 }
97}
getSide(int $side, int $step=1)
Definition Block.php:770
getSupportType(int $facing)
Definition Thin.php:94
getSupportType(int $facing)
Definition Wall.php:154