mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 02:08:21 +00:00
Removed pocketmine subdirectory, map PSR-4 style
This commit is contained in:
94
src/block/Thin.php
Normal file
94
src/block/Thin.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
use pocketmine\math\Facing;
|
||||
|
||||
class Thin extends Transparent{
|
||||
/** @var bool[] facing => dummy */
|
||||
protected $connections = [];
|
||||
|
||||
public function readStateFromWorld() : void{
|
||||
parent::readStateFromWorld();
|
||||
|
||||
foreach(Facing::HORIZONTAL as $facing){
|
||||
$side = $this->getSide($facing);
|
||||
//FIXME: currently there's no proper way to tell if a block is a full-block, so we check the bounding box size
|
||||
if($side instanceof Thin or ($bb = $side->getBoundingBox()) !== null and $bb->getAverageEdgeLength() >= 1){
|
||||
$this->connections[$facing] = true;
|
||||
}else{
|
||||
unset($this->connections[$facing]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
||||
$bb = AxisAlignedBB::one();
|
||||
foreach(Facing::HORIZONTAL as $facing){
|
||||
if(!isset($this->connections[$facing])){
|
||||
$bb->trim($facing, 7 / 16);
|
||||
}
|
||||
}
|
||||
return $bb;
|
||||
}
|
||||
|
||||
protected function recalculateCollisionBoxes() : array{
|
||||
$inset = 7 / 16;
|
||||
|
||||
/** @var AxisAlignedBB[] $bbs */
|
||||
$bbs = [];
|
||||
|
||||
if(isset($this->connections[Facing::WEST]) or isset($this->connections[Facing::EAST])){
|
||||
$bb = AxisAlignedBB::one()->squash(Facing::AXIS_Z, $inset);
|
||||
|
||||
if(!isset($this->connections[Facing::WEST])){
|
||||
$bb->trim(Facing::WEST, $inset);
|
||||
}elseif(!isset($this->connections[Facing::EAST])){
|
||||
$bb->trim(Facing::EAST, $inset);
|
||||
}
|
||||
$bbs[] = $bb;
|
||||
}
|
||||
|
||||
if(isset($this->connections[Facing::NORTH]) or isset($this->connections[Facing::SOUTH])){
|
||||
$bb = AxisAlignedBB::one()->squash(Facing::AXIS_X, $inset);
|
||||
|
||||
if(!isset($this->connections[Facing::NORTH])){
|
||||
$bb->trim(Facing::NORTH, $inset);
|
||||
}elseif(!isset($this->connections[Facing::SOUTH])){
|
||||
$bb->trim(Facing::SOUTH, $inset);
|
||||
}
|
||||
$bbs[] = $bb;
|
||||
}
|
||||
|
||||
if(empty($bbs)){
|
||||
//centre post AABB (only needed if not connected on any axis - other BBs overlapping will do this if any connections are made)
|
||||
return [
|
||||
AxisAlignedBB::one()->contract($inset, 0, $inset)
|
||||
];
|
||||
}
|
||||
|
||||
return $bbs;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user