mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-09 23:39:43 +00:00
Vine: Clean up awful bounding-box calculation
the logic here is deceptively simple, just obscured by a lot of really nasty code.
This commit is contained in:
parent
41d754de5a
commit
90e6073202
@ -30,8 +30,8 @@ use pocketmine\math\Facing;
|
|||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
use function array_intersect_key;
|
use function array_intersect_key;
|
||||||
use function max;
|
use function array_keys;
|
||||||
use function min;
|
use function count;
|
||||||
|
|
||||||
class Vine extends Flowable{
|
class Vine extends Flowable{
|
||||||
private const FLAG_SOUTH = 0x01;
|
private const FLAG_SOUTH = 0x01;
|
||||||
@ -90,55 +90,14 @@ class Vine extends Flowable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
||||||
$minX = 1;
|
switch(count($this->faces)){
|
||||||
$minZ = 1;
|
case 0:
|
||||||
$maxX = 0;
|
return AxisAlignedBB::one()->trim(Facing::DOWN, 15 / 16);
|
||||||
$maxZ = 0;
|
case 1:
|
||||||
|
return AxisAlignedBB::one()->trim(Facing::opposite(array_keys($this->faces)[0]), 15 / 16);
|
||||||
$minY = 0;
|
default:
|
||||||
$hasSide = false;
|
return AxisAlignedBB::one();
|
||||||
|
|
||||||
if(isset($this->faces[Facing::WEST])){
|
|
||||||
$maxX = max($maxX, 0.0625);
|
|
||||||
$minX = 0;
|
|
||||||
$minZ = 0;
|
|
||||||
$maxZ = 1;
|
|
||||||
$hasSide = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($this->faces[Facing::EAST])){
|
|
||||||
$minX = min($minX, 0.9375);
|
|
||||||
$maxX = 1;
|
|
||||||
$minZ = 0;
|
|
||||||
$maxZ = 1;
|
|
||||||
$hasSide = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isset($this->faces[Facing::SOUTH])){
|
|
||||||
$minZ = min($minZ, 0.9375);
|
|
||||||
$maxZ = 1;
|
|
||||||
$minX = 0;
|
|
||||||
$maxX = 1;
|
|
||||||
$hasSide = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isset($this->faces[Facing::NORTH])){
|
|
||||||
$maxZ = max($maxZ, 0.0625);
|
|
||||||
$minZ = 0;
|
|
||||||
$minX = 0;
|
|
||||||
$maxX = 1;
|
|
||||||
$hasSide = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$hasSide){
|
|
||||||
$minY = 0.9375;
|
|
||||||
$minX = 0;
|
|
||||||
$maxX = 1;
|
|
||||||
$minZ = 0;
|
|
||||||
$maxZ = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new AxisAlignedBB($minX, $minY, $minZ, $maxX, 1, $maxZ);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function recalculateCollisionBoxes() : array{
|
protected function recalculateCollisionBoxes() : array{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user