mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-14 09:49:50 +00:00
Implement corner stair BB handling
This commit is contained in:
parent
0b989925d7
commit
a77e05f875
@ -50,8 +50,6 @@ abstract class Stair extends Transparent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function recalculateCollisionBoxes() : array{
|
protected function recalculateCollisionBoxes() : array{
|
||||||
//TODO: handle corners
|
|
||||||
|
|
||||||
$minYSlab = $this->upsideDown ? 0.5 : 0;
|
$minYSlab = $this->upsideDown ? 0.5 : 0;
|
||||||
|
|
||||||
$bbs = [
|
$bbs = [
|
||||||
@ -60,29 +58,55 @@ abstract class Stair extends Transparent{
|
|||||||
|
|
||||||
$minY = $this->upsideDown ? 0 : 0.5;
|
$minY = $this->upsideDown ? 0 : 0.5;
|
||||||
|
|
||||||
$minX = $minZ = 0;
|
$topStep = new AxisAlignedBB(0, $minY, 0, 1, $minY + 0.5, 1);
|
||||||
$maxX = $maxZ = 1;
|
self::setBoundsForFacing($topStep, $this->facing);
|
||||||
|
|
||||||
switch($this->facing){
|
/** @var Stair $corner */
|
||||||
case Facing::EAST:
|
if(($backFacing = $this->getPossibleCornerFacing(false)) !== null){
|
||||||
$minX = 0.5;
|
self::setBoundsForFacing($topStep, $backFacing);
|
||||||
break;
|
}elseif(($frontFacing = $this->getPossibleCornerFacing(true)) !== null){
|
||||||
case Facing::WEST:
|
//add an extra cube
|
||||||
$maxX = 0.5;
|
$extraCube = new AxisAlignedBB(0, $minY, 0, 1, $minY + 0.5, 1);
|
||||||
break;
|
self::setBoundsForFacing($extraCube, Facing::opposite($this->facing));
|
||||||
case Facing::SOUTH:
|
self::setBoundsForFacing($extraCube, $frontFacing);
|
||||||
$minZ = 0.5;
|
$bbs[] = $extraCube;
|
||||||
break;
|
|
||||||
case Facing::NORTH:
|
|
||||||
$maxZ = 0.5;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$bbs[] = new AxisAlignedBB($minX, $minY, $minZ, $maxX, $minY + 0.5, $maxZ);
|
$bbs[] = $topStep;
|
||||||
|
|
||||||
return $bbs;
|
return $bbs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getPossibleCornerFacing(bool $oppositeFacing) : ?int{
|
||||||
|
$side = $this->getSide($oppositeFacing ? Facing::opposite($this->facing) : $this->facing);
|
||||||
|
if($side instanceof Stair and $side->upsideDown === $this->upsideDown and (
|
||||||
|
$side->facing === Facing::rotate($this->facing, Facing::AXIS_Y, true) or
|
||||||
|
$side->facing === Facing::rotate($this->facing, Facing::AXIS_Y, false))
|
||||||
|
){
|
||||||
|
return $side->facing;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function setBoundsForFacing(AxisAlignedBB $bb, int $facing) : void{
|
||||||
|
switch($facing){
|
||||||
|
case Facing::EAST:
|
||||||
|
$bb->minX = 0.5;
|
||||||
|
break;
|
||||||
|
case Facing::WEST:
|
||||||
|
$bb->maxX = 0.5;
|
||||||
|
break;
|
||||||
|
case Facing::SOUTH:
|
||||||
|
$bb->minZ = 0.5;
|
||||||
|
break;
|
||||||
|
case Facing::NORTH:
|
||||||
|
$bb->maxZ = 0.5;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new \InvalidArgumentException("Facing must be horizontal");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
|
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
|
||||||
if($player !== null){
|
if($player !== null){
|
||||||
$this->facing = Bearing::toFacing($player->getDirection());
|
$this->facing = Bearing::toFacing($player->getDirection());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user