Fence: cleanup some BB handling

This commit is contained in:
Dylan K. Taylor 2019-05-12 16:22:41 +01:00
parent 166d821bcf
commit 85c6eb5003

View File

@ -50,14 +50,14 @@ abstract class Fence extends Transparent{
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
$width = 0.5 - $this->getThickness() / 2; $width = 0.5 - $this->getThickness() / 2;
return new AxisAlignedBB( $bb = AxisAlignedBB::one()
(isset($this->connections[Facing::WEST]) ? 0 : $width), ->extend(Facing::UP, 0.5);
0, foreach(Facing::HORIZONTAL as $facing){
(isset($this->connections[Facing::NORTH]) ? 0 : $width), if(!isset($this->connections[$facing])){
1 - (isset($this->connections[Facing::EAST]) ? 0 : $width), $bb->trim($facing, $width);
1.5, }
1 - (isset($this->connections[Facing::WEST]) ? 0 : $width) }
); return $bb;
} }
protected function recalculateCollisionBoxes() : array{ protected function recalculateCollisionBoxes() : array{
@ -71,14 +71,11 @@ abstract class Fence extends Transparent{
if($connectWest or $connectEast){ if($connectWest or $connectEast){
//X axis (west/east) //X axis (west/east)
$bbs[] = new AxisAlignedBB( $bbs[] = AxisAlignedBB::one()
($connectWest ? 0 : $inset), ->squash(Facing::AXIS_Z, $inset)
0, ->extend(Facing::UP, 0.5)
$inset, ->trim(Facing::WEST, $connectWest ? 0 : $inset)
1 - ($connectEast ? 0 : $inset), ->trim(Facing::EAST, $connectEast ? 0 : $inset);
1.5,
1 - $inset
);
} }
$connectNorth = isset($this->connections[Facing::NORTH]); $connectNorth = isset($this->connections[Facing::NORTH]);
@ -86,27 +83,19 @@ abstract class Fence extends Transparent{
if($connectNorth or $connectSouth){ if($connectNorth or $connectSouth){
//Z axis (north/south) //Z axis (north/south)
$bbs[] = new AxisAlignedBB( $bbs[] = AxisAlignedBB::one()
$inset, ->squash(Facing::AXIS_X, $inset)
0, ->extend(Facing::UP, 0.5)
($connectNorth ? 0 : $inset), ->trim(Facing::NORTH, $connectNorth ? 0 : $inset)
1 - $inset, ->trim(Facing::SOUTH, $connectSouth ? 0 : $inset);
1.5,
1 - ($connectSouth ? 0 : $inset)
);
} }
if(empty($bbs)){ 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) //centre post AABB (only needed if not connected on any axis - other BBs overlapping will do this if any connections are made)
return [ return [
new AxisAlignedBB( AxisAlignedBB::one()
$inset, ->extend(Facing::UP, 0.5)
0, ->contract($inset, 0, $inset)
$inset,
1 - $inset,
1.5,
1 - $inset
)
]; ];
} }