mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-16 10:49:10 +00:00
Fence: cleanup some BB handling
This commit is contained in:
parent
166d821bcf
commit
85c6eb5003
@ -50,14 +50,14 @@ abstract class Fence extends Transparent{
|
||||
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
||||
$width = 0.5 - $this->getThickness() / 2;
|
||||
|
||||
return new AxisAlignedBB(
|
||||
(isset($this->connections[Facing::WEST]) ? 0 : $width),
|
||||
0,
|
||||
(isset($this->connections[Facing::NORTH]) ? 0 : $width),
|
||||
1 - (isset($this->connections[Facing::EAST]) ? 0 : $width),
|
||||
1.5,
|
||||
1 - (isset($this->connections[Facing::WEST]) ? 0 : $width)
|
||||
);
|
||||
$bb = AxisAlignedBB::one()
|
||||
->extend(Facing::UP, 0.5);
|
||||
foreach(Facing::HORIZONTAL as $facing){
|
||||
if(!isset($this->connections[$facing])){
|
||||
$bb->trim($facing, $width);
|
||||
}
|
||||
}
|
||||
return $bb;
|
||||
}
|
||||
|
||||
protected function recalculateCollisionBoxes() : array{
|
||||
@ -71,14 +71,11 @@ abstract class Fence extends Transparent{
|
||||
|
||||
if($connectWest or $connectEast){
|
||||
//X axis (west/east)
|
||||
$bbs[] = new AxisAlignedBB(
|
||||
($connectWest ? 0 : $inset),
|
||||
0,
|
||||
$inset,
|
||||
1 - ($connectEast ? 0 : $inset),
|
||||
1.5,
|
||||
1 - $inset
|
||||
);
|
||||
$bbs[] = AxisAlignedBB::one()
|
||||
->squash(Facing::AXIS_Z, $inset)
|
||||
->extend(Facing::UP, 0.5)
|
||||
->trim(Facing::WEST, $connectWest ? 0 : $inset)
|
||||
->trim(Facing::EAST, $connectEast ? 0 : $inset);
|
||||
}
|
||||
|
||||
$connectNorth = isset($this->connections[Facing::NORTH]);
|
||||
@ -86,27 +83,19 @@ abstract class Fence extends Transparent{
|
||||
|
||||
if($connectNorth or $connectSouth){
|
||||
//Z axis (north/south)
|
||||
$bbs[] = new AxisAlignedBB(
|
||||
$inset,
|
||||
0,
|
||||
($connectNorth ? 0 : $inset),
|
||||
1 - $inset,
|
||||
1.5,
|
||||
1 - ($connectSouth ? 0 : $inset)
|
||||
);
|
||||
$bbs[] = AxisAlignedBB::one()
|
||||
->squash(Facing::AXIS_X, $inset)
|
||||
->extend(Facing::UP, 0.5)
|
||||
->trim(Facing::NORTH, $connectNorth ? 0 : $inset)
|
||||
->trim(Facing::SOUTH, $connectSouth ? 0 : $inset);
|
||||
}
|
||||
|
||||
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 [
|
||||
new AxisAlignedBB(
|
||||
$inset,
|
||||
0,
|
||||
$inset,
|
||||
1 - $inset,
|
||||
1.5,
|
||||
1 - $inset
|
||||
)
|
||||
AxisAlignedBB::one()
|
||||
->extend(Facing::UP, 0.5)
|
||||
->contract($inset, 0, $inset)
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user