2023-01-12 22:16:41 +00:00

86 lines
2.6 KiB
PHP

<?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\block\utils\SupportType;
use pocketmine\math\Axis;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
class Wall extends Transparent{
/** @var int[] facing => facing */
protected array $connections = [];
protected bool $up = false;
public function readStateFromWorld() : void{
parent::readStateFromWorld();
foreach(Facing::HORIZONTAL as $facing){
$block = $this->getSide($facing);
if($block instanceof static || $block instanceof FenceGate || $block instanceof Thin || ($block->isSolid() && !$block->isTransparent())){
$this->connections[$facing] = $facing;
}else{
unset($this->connections[$facing]);
}
}
$this->up = $this->getSide(Facing::UP)->getId() !== BlockLegacyIds::AIR;
}
protected function recalculateCollisionBoxes() : array{
//walls don't have any special collision boxes like fences do
$north = isset($this->connections[Facing::NORTH]);
$south = isset($this->connections[Facing::SOUTH]);
$west = isset($this->connections[Facing::WEST]);
$east = isset($this->connections[Facing::EAST]);
$inset = 0.25;
if(
!$this->up && //if there is a block on top, it stays as a post
(
($north && $south && !$west && !$east) ||
(!$north && !$south && $west && $east)
)
){
//If connected to two sides on the same axis but not any others, AND there is not a block on top, there is no post and the wall is thinner
$inset = 0.3125;
}
return [
AxisAlignedBB::one()
->extend(Facing::UP, 0.5)
->trim(Facing::NORTH, $north ? 0 : $inset)
->trim(Facing::SOUTH, $south ? 0 : $inset)
->trim(Facing::WEST, $west ? 0 : $inset)
->trim(Facing::EAST, $east ? 0 : $inset)
];
}
public function getSupportType(int $facing) : SupportType{
return Facing::axis($facing) === Axis::Y ? SupportType::CENTER() : SupportType::NONE();
}
}