added StairShape enum

this has no practical value to plugins yet, but it will in the future.
This commit is contained in:
Dylan K. Taylor 2019-07-08 18:08:52 +01:00
parent c42817f02f
commit fe3a4baddb
2 changed files with 67 additions and 14 deletions

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\block\utils\BlockDataValidator; use pocketmine\block\utils\BlockDataValidator;
use pocketmine\block\utils\StairShape;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing; use pocketmine\math\Facing;
@ -32,18 +33,19 @@ use pocketmine\player\Player;
use pocketmine\world\BlockTransaction; use pocketmine\world\BlockTransaction;
class Stair extends Transparent{ class Stair extends Transparent{
private const SHAPE_STRAIGHT = "straight";
private const SHAPE_INNER_LEFT = "inner_left";
private const SHAPE_INNER_RIGHT = "inner_right";
private const SHAPE_OUTER_LEFT = "outer_left";
private const SHAPE_OUTER_RIGHT = "outer_right";
/** @var int */ /** @var int */
protected $facing = Facing::NORTH; protected $facing = Facing::NORTH;
/** @var bool */ /** @var bool */
protected $upsideDown = false; protected $upsideDown = false;
/** @var string */
protected $shape = self::SHAPE_STRAIGHT; /** @var StairShape */
protected $shape;
public function __construct(BlockIdentifier $idInfo, string $name, BlockBreakInfo $breakInfo){
$this->shape = StairShape::STRAIGHT();
parent::__construct($idInfo, $name, $breakInfo);
}
protected function writeStateToMeta() : int{ protected function writeStateToMeta() : int{
return (5 - $this->facing) | ($this->upsideDown ? BlockLegacyMetadata::STAIR_FLAG_UPSIDE_DOWN : 0); return (5 - $this->facing) | ($this->upsideDown ? BlockLegacyMetadata::STAIR_FLAG_UPSIDE_DOWN : 0);
@ -63,11 +65,11 @@ class Stair extends Transparent{
$clockwise = Facing::rotateY($this->facing, true); $clockwise = Facing::rotateY($this->facing, true);
if(($backFacing = $this->getPossibleCornerFacing(false)) !== null){ if(($backFacing = $this->getPossibleCornerFacing(false)) !== null){
$this->shape = $backFacing === $clockwise ? self::SHAPE_OUTER_RIGHT : self::SHAPE_OUTER_LEFT; $this->shape = $backFacing === $clockwise ? StairShape::OUTER_RIGHT() : StairShape::OUTER_LEFT();
}elseif(($frontFacing = $this->getPossibleCornerFacing(true)) !== null){ }elseif(($frontFacing = $this->getPossibleCornerFacing(true)) !== null){
$this->shape = $frontFacing === $clockwise ? self::SHAPE_INNER_RIGHT : self::SHAPE_INNER_LEFT; $this->shape = $frontFacing === $clockwise ? StairShape::INNER_RIGHT() : StairShape::INNER_LEFT();
}else{ }else{
$this->shape = self::SHAPE_STRAIGHT; $this->shape = StairShape::STRAIGHT();
} }
} }
@ -81,14 +83,14 @@ class Stair extends Transparent{
->trim(Facing::opposite($topStepFace), 0.5) ->trim(Facing::opposite($topStepFace), 0.5)
->trim(Facing::opposite($this->facing), 0.5); ->trim(Facing::opposite($this->facing), 0.5);
if($this->shape === self::SHAPE_OUTER_LEFT or $this->shape === self::SHAPE_OUTER_RIGHT){ if($this->shape->equals(StairShape::OUTER_LEFT()) or $this->shape->equals(StairShape::OUTER_RIGHT())){
$topStep->trim(Facing::rotateY($this->facing, $this->shape === self::SHAPE_OUTER_LEFT), 0.5); $topStep->trim(Facing::rotateY($this->facing, $this->shape->equals(StairShape::OUTER_LEFT())), 0.5);
}elseif($this->shape === self::SHAPE_INNER_LEFT or $this->shape === self::SHAPE_INNER_RIGHT){ }elseif($this->shape->equals(StairShape::INNER_LEFT()) or $this->shape->equals(StairShape::INNER_RIGHT())){
//add an extra cube //add an extra cube
$bbs[] = AxisAlignedBB::one() $bbs[] = AxisAlignedBB::one()
->trim(Facing::opposite($topStepFace), 0.5) ->trim(Facing::opposite($topStepFace), 0.5)
->trim($this->facing, 0.5) //avoid overlapping with main step ->trim($this->facing, 0.5) //avoid overlapping with main step
->trim(Facing::rotateY($this->facing, $this->shape === self::SHAPE_INNER_LEFT), 0.5); ->trim(Facing::rotateY($this->facing, $this->shape->equals(StairShape::INNER_LEFT())), 0.5);
} }
$bbs[] = $topStep; $bbs[] = $topStep;

View File

@ -0,0 +1,51 @@
<?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\utils;
use pocketmine\utils\EnumTrait;
/**
* This doc-block is generated automatically, do not modify it manually.
* This must be regenerated whenever enum members are added, removed or changed.
* @see EnumTrait::_generateMethodAnnotations()
*
* @method static self STRAIGHT()
* @method static self INNER_LEFT()
* @method static self INNER_RIGHT()
* @method static self OUTER_LEFT()
* @method static self OUTER_RIGHT()
*/
final class StairShape{
use EnumTrait;
protected static function setup() : iterable{
return [
new self("straight"),
new self("inner_left"),
new self("inner_right"),
new self("outer_left"),
new self("outer_right")
];
}
}