mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-15 02:09:42 +00:00
block: added HorizontalFacingTrait and AnyFacingTrait
these are primarily intended for deduplication of code and ability to cross-reference. Don't expect this API to remain the same.
This commit is contained in:
parent
060c300d50
commit
56ae3d01da
@ -27,6 +27,7 @@ use pocketmine\block\inventory\AnvilInventory;
|
|||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\BlockDataSerializer;
|
||||||
use pocketmine\block\utils\Fallable;
|
use pocketmine\block\utils\Fallable;
|
||||||
use pocketmine\block\utils\FallableTrait;
|
use pocketmine\block\utils\FallableTrait;
|
||||||
|
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ToolTier;
|
use pocketmine\item\ToolTier;
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
@ -37,9 +38,7 @@ use pocketmine\world\BlockTransaction;
|
|||||||
|
|
||||||
class Anvil extends Transparent implements Fallable{
|
class Anvil extends Transparent implements Fallable{
|
||||||
use FallableTrait;
|
use FallableTrait;
|
||||||
|
use HorizontalFacingTrait;
|
||||||
/** @var int */
|
|
||||||
protected $facing = Facing::NORTH;
|
|
||||||
|
|
||||||
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
||||||
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(5.0, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel(), 6000.0));
|
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(5.0, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel(), 6000.0));
|
||||||
|
@ -26,6 +26,7 @@ namespace pocketmine\block;
|
|||||||
use pocketmine\block\tile\Bed as TileBed;
|
use pocketmine\block\tile\Bed as TileBed;
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\BlockDataSerializer;
|
||||||
use pocketmine\block\utils\DyeColor;
|
use pocketmine\block\utils\DyeColor;
|
||||||
|
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||||
use pocketmine\data\bedrock\DyeColorIdMap;
|
use pocketmine\data\bedrock\DyeColorIdMap;
|
||||||
use pocketmine\item\Bed as ItemBed;
|
use pocketmine\item\Bed as ItemBed;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
@ -40,9 +41,8 @@ use pocketmine\world\BlockTransaction;
|
|||||||
use pocketmine\world\World;
|
use pocketmine\world\World;
|
||||||
|
|
||||||
class Bed extends Transparent{
|
class Bed extends Transparent{
|
||||||
|
use HorizontalFacingTrait;
|
||||||
|
|
||||||
/** @var int */
|
|
||||||
protected $facing = Facing::NORTH;
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $occupied = false;
|
protected $occupied = false;
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\block\utils\AnyFacingTrait;
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\BlockDataSerializer;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
@ -33,9 +34,8 @@ use pocketmine\world\sound\RedstonePowerOffSound;
|
|||||||
use pocketmine\world\sound\RedstonePowerOnSound;
|
use pocketmine\world\sound\RedstonePowerOnSound;
|
||||||
|
|
||||||
abstract class Button extends Flowable{
|
abstract class Button extends Flowable{
|
||||||
|
use AnyFacingTrait;
|
||||||
|
|
||||||
/** @var int */
|
|
||||||
protected $facing = Facing::DOWN;
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $pressed = false;
|
protected $pressed = false;
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\BlockDataSerializer;
|
||||||
|
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
@ -31,9 +32,7 @@ use pocketmine\player\Player;
|
|||||||
use pocketmine\world\BlockTransaction;
|
use pocketmine\world\BlockTransaction;
|
||||||
|
|
||||||
class CarvedPumpkin extends Opaque{
|
class CarvedPumpkin extends Opaque{
|
||||||
|
use HorizontalFacingTrait;
|
||||||
/** @var int */
|
|
||||||
protected $facing = Facing::NORTH;
|
|
||||||
|
|
||||||
public function readStateFromData(int $id, int $stateMeta) : void{
|
public function readStateFromData(int $id, int $stateMeta) : void{
|
||||||
$this->facing = BlockDataSerializer::readLegacyHorizontalFacing($stateMeta & 0x03);
|
$this->facing = BlockDataSerializer::readLegacyHorizontalFacing($stateMeta & 0x03);
|
||||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\BlockDataSerializer;
|
||||||
|
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
@ -31,9 +32,7 @@ use pocketmine\player\Player;
|
|||||||
use pocketmine\world\BlockTransaction;
|
use pocketmine\world\BlockTransaction;
|
||||||
|
|
||||||
final class ChemistryTable extends Opaque{
|
final class ChemistryTable extends Opaque{
|
||||||
|
use HorizontalFacingTrait;
|
||||||
/** @var int */
|
|
||||||
private $facing = Facing::NORTH;
|
|
||||||
|
|
||||||
public function readStateFromData(int $id, int $stateMeta) : void{
|
public function readStateFromData(int $id, int $stateMeta) : void{
|
||||||
$this->facing = Facing::opposite(BlockDataSerializer::readLegacyHorizontalFacing($stateMeta & 0x3));
|
$this->facing = Facing::opposite(BlockDataSerializer::readLegacyHorizontalFacing($stateMeta & 0x3));
|
||||||
|
@ -25,6 +25,7 @@ namespace pocketmine\block;
|
|||||||
|
|
||||||
use pocketmine\block\tile\Chest as TileChest;
|
use pocketmine\block\tile\Chest as TileChest;
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\BlockDataSerializer;
|
||||||
|
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
@ -33,9 +34,7 @@ use pocketmine\player\Player;
|
|||||||
use pocketmine\world\BlockTransaction;
|
use pocketmine\world\BlockTransaction;
|
||||||
|
|
||||||
class Chest extends Transparent{
|
class Chest extends Transparent{
|
||||||
|
use HorizontalFacingTrait;
|
||||||
/** @var int */
|
|
||||||
protected $facing = Facing::NORTH;
|
|
||||||
|
|
||||||
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
||||||
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(2.5, BlockToolType::AXE));
|
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(2.5, BlockToolType::AXE));
|
||||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\BlockDataSerializer;
|
||||||
|
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||||
use pocketmine\block\utils\TreeType;
|
use pocketmine\block\utils\TreeType;
|
||||||
use pocketmine\item\Fertilizer;
|
use pocketmine\item\Fertilizer;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
@ -36,9 +37,8 @@ use pocketmine\world\BlockTransaction;
|
|||||||
use function mt_rand;
|
use function mt_rand;
|
||||||
|
|
||||||
class CocoaBlock extends Transparent{
|
class CocoaBlock extends Transparent{
|
||||||
|
use HorizontalFacingTrait;
|
||||||
|
|
||||||
/** @var int */
|
|
||||||
protected $facing = Facing::NORTH;
|
|
||||||
/** @var int */
|
/** @var int */
|
||||||
protected $age = 0;
|
protected $age = 0;
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\BlockDataSerializer;
|
||||||
|
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
@ -33,8 +34,8 @@ use pocketmine\world\BlockTransaction;
|
|||||||
use pocketmine\world\sound\DoorSound;
|
use pocketmine\world\sound\DoorSound;
|
||||||
|
|
||||||
class Door extends Transparent{
|
class Door extends Transparent{
|
||||||
/** @var int */
|
use HorizontalFacingTrait;
|
||||||
protected $facing = Facing::NORTH;
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $top = false;
|
protected $top = false;
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\BlockDataSerializer;
|
||||||
|
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||||
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,9 +33,8 @@ use pocketmine\player\Player;
|
|||||||
use pocketmine\world\BlockTransaction;
|
use pocketmine\world\BlockTransaction;
|
||||||
|
|
||||||
class EndPortalFrame extends Opaque{
|
class EndPortalFrame extends Opaque{
|
||||||
|
use HorizontalFacingTrait;
|
||||||
|
|
||||||
/** @var int */
|
|
||||||
protected $facing = Facing::NORTH;
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $eye = false;
|
protected $eye = false;
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
|
use pocketmine\block\utils\AnyFacingTrait;
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\BlockDataSerializer;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
@ -32,9 +33,7 @@ use pocketmine\player\Player;
|
|||||||
use pocketmine\world\BlockTransaction;
|
use pocketmine\world\BlockTransaction;
|
||||||
|
|
||||||
class EndRod extends Flowable{
|
class EndRod extends Flowable{
|
||||||
|
use AnyFacingTrait;
|
||||||
/** @var int */
|
|
||||||
protected $facing = Facing::DOWN;
|
|
||||||
|
|
||||||
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
||||||
parent::__construct($idInfo, $name, $breakInfo ?? BlockBreakInfo::instant());
|
parent::__construct($idInfo, $name, $breakInfo ?? BlockBreakInfo::instant());
|
||||||
|
@ -25,6 +25,7 @@ namespace pocketmine\block;
|
|||||||
|
|
||||||
use pocketmine\block\tile\EnderChest as TileEnderChest;
|
use pocketmine\block\tile\EnderChest as TileEnderChest;
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\BlockDataSerializer;
|
||||||
|
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ToolTier;
|
use pocketmine\item\ToolTier;
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
@ -34,9 +35,7 @@ use pocketmine\player\Player;
|
|||||||
use pocketmine\world\BlockTransaction;
|
use pocketmine\world\BlockTransaction;
|
||||||
|
|
||||||
class EnderChest extends Transparent{
|
class EnderChest extends Transparent{
|
||||||
|
use HorizontalFacingTrait;
|
||||||
/** @var int */
|
|
||||||
protected $facing = Facing::NORTH;
|
|
||||||
|
|
||||||
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
||||||
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(22.5, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel(), 3000.0));
|
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(22.5, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel(), 3000.0));
|
||||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\BlockDataSerializer;
|
||||||
|
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
@ -33,10 +34,10 @@ use pocketmine\world\BlockTransaction;
|
|||||||
use pocketmine\world\sound\DoorSound;
|
use pocketmine\world\sound\DoorSound;
|
||||||
|
|
||||||
class FenceGate extends Transparent{
|
class FenceGate extends Transparent{
|
||||||
|
use HorizontalFacingTrait;
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $open = false;
|
protected $open = false;
|
||||||
/** @var int */
|
|
||||||
protected $facing = Facing::NORTH;
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $inWall = false;
|
protected $inWall = false;
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ namespace pocketmine\block;
|
|||||||
|
|
||||||
use pocketmine\block\tile\Furnace as TileFurnace;
|
use pocketmine\block\tile\Furnace as TileFurnace;
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\BlockDataSerializer;
|
||||||
|
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ToolTier;
|
use pocketmine\item\ToolTier;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
@ -33,11 +34,11 @@ use pocketmine\player\Player;
|
|||||||
use pocketmine\world\BlockTransaction;
|
use pocketmine\world\BlockTransaction;
|
||||||
|
|
||||||
class Furnace extends Opaque{
|
class Furnace extends Opaque{
|
||||||
|
use HorizontalFacingTrait;
|
||||||
|
|
||||||
/** @var BlockIdentifierFlattened */
|
/** @var BlockIdentifierFlattened */
|
||||||
protected $idInfo;
|
protected $idInfo;
|
||||||
|
|
||||||
/** @var int */
|
|
||||||
protected $facing = Facing::NORTH;
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $lit = false; //this is set based on the blockID
|
protected $lit = false; //this is set based on the blockID
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\BlockDataSerializer;
|
||||||
|
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ToolTier;
|
use pocketmine\item\ToolTier;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
@ -32,9 +33,7 @@ use pocketmine\player\Player;
|
|||||||
use pocketmine\world\BlockTransaction;
|
use pocketmine\world\BlockTransaction;
|
||||||
|
|
||||||
class GlazedTerracotta extends Opaque{
|
class GlazedTerracotta extends Opaque{
|
||||||
|
use HorizontalFacingTrait;
|
||||||
/** @var int */
|
|
||||||
protected $facing = Facing::NORTH;
|
|
||||||
|
|
||||||
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
||||||
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(1.4, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel()));
|
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(1.4, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel()));
|
||||||
|
@ -25,6 +25,7 @@ namespace pocketmine\block;
|
|||||||
|
|
||||||
use pocketmine\block\tile\ItemFrame as TileItemFrame;
|
use pocketmine\block\tile\ItemFrame as TileItemFrame;
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\BlockDataSerializer;
|
||||||
|
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
@ -33,10 +34,10 @@ use pocketmine\world\BlockTransaction;
|
|||||||
use function lcg_value;
|
use function lcg_value;
|
||||||
|
|
||||||
class ItemFrame extends Flowable{
|
class ItemFrame extends Flowable{
|
||||||
|
use HorizontalFacingTrait;
|
||||||
|
|
||||||
public const ROTATIONS = 8;
|
public const ROTATIONS = 8;
|
||||||
|
|
||||||
/** @var int */
|
|
||||||
protected $facing = Facing::NORTH;
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $hasMap = false; //makes frame appear large if set
|
protected $hasMap = false; //makes frame appear large if set
|
||||||
/** @var Item|null */
|
/** @var Item|null */
|
||||||
@ -86,14 +87,6 @@ class ItemFrame extends Flowable{
|
|||||||
return 0b111;
|
return 0b111;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFacing() : int{
|
|
||||||
return $this->facing;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setFacing(int $facing) : void{
|
|
||||||
$this->facing = $facing;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getFramedItem() : ?Item{
|
public function getFramedItem() : ?Item{
|
||||||
return $this->framedItem !== null ? clone $this->framedItem : null;
|
return $this->framedItem !== null ? clone $this->framedItem : null;
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\BlockDataSerializer;
|
||||||
|
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||||
use pocketmine\entity\Entity;
|
use pocketmine\entity\Entity;
|
||||||
use pocketmine\entity\Living;
|
use pocketmine\entity\Living;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
@ -34,9 +35,7 @@ use pocketmine\player\Player;
|
|||||||
use pocketmine\world\BlockTransaction;
|
use pocketmine\world\BlockTransaction;
|
||||||
|
|
||||||
class Ladder extends Transparent{
|
class Ladder extends Transparent{
|
||||||
|
use HorizontalFacingTrait;
|
||||||
/** @var int */
|
|
||||||
protected $facing = Facing::NORTH;
|
|
||||||
|
|
||||||
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
||||||
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.4, BlockToolType::AXE));
|
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.4, BlockToolType::AXE));
|
||||||
|
@ -25,6 +25,7 @@ namespace pocketmine\block;
|
|||||||
|
|
||||||
use pocketmine\block\tile\Comparator;
|
use pocketmine\block\tile\Comparator;
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\BlockDataSerializer;
|
||||||
|
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
@ -34,11 +35,11 @@ use pocketmine\world\BlockTransaction;
|
|||||||
use function assert;
|
use function assert;
|
||||||
|
|
||||||
class RedstoneComparator extends Flowable{
|
class RedstoneComparator extends Flowable{
|
||||||
|
use HorizontalFacingTrait;
|
||||||
|
|
||||||
/** @var BlockIdentifierFlattened */
|
/** @var BlockIdentifierFlattened */
|
||||||
protected $idInfo;
|
protected $idInfo;
|
||||||
|
|
||||||
/** @var int */
|
|
||||||
protected $facing = Facing::NORTH;
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $isSubtractMode = false;
|
protected $isSubtractMode = false;
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
@ -85,20 +86,6 @@ class RedstoneComparator extends Flowable{
|
|||||||
$tile->setSignalStrength($this->signalStrength);
|
$tile->setSignalStrength($this->signalStrength);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO: ad hoc, move to interface
|
|
||||||
*/
|
|
||||||
public function getFacing() : int{
|
|
||||||
return $this->facing;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO: ad hoc, move to interface
|
|
||||||
*/
|
|
||||||
public function setFacing(int $facing) : void{
|
|
||||||
$this->facing = $facing;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isSubtractMode() : bool{
|
public function isSubtractMode() : bool{
|
||||||
return $this->isSubtractMode;
|
return $this->isSubtractMode;
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\BlockDataSerializer;
|
||||||
|
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||||
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,14 +33,14 @@ use pocketmine\player\Player;
|
|||||||
use pocketmine\world\BlockTransaction;
|
use pocketmine\world\BlockTransaction;
|
||||||
|
|
||||||
class RedstoneRepeater extends Flowable{
|
class RedstoneRepeater extends Flowable{
|
||||||
|
use HorizontalFacingTrait;
|
||||||
|
|
||||||
/** @var BlockIdentifierFlattened */
|
/** @var BlockIdentifierFlattened */
|
||||||
protected $idInfo;
|
protected $idInfo;
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $powered = false;
|
protected $powered = false;
|
||||||
/** @var int */
|
/** @var int */
|
||||||
protected $facing = Facing::NORTH;
|
|
||||||
/** @var int */
|
|
||||||
protected $delay = 1;
|
protected $delay = 1;
|
||||||
|
|
||||||
public function __construct(BlockIdentifierFlattened $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
public function __construct(BlockIdentifierFlattened $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
||||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\BlockDataSerializer;
|
||||||
|
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||||
use pocketmine\block\utils\StairShape;
|
use pocketmine\block\utils\StairShape;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
@ -33,9 +34,8 @@ use pocketmine\player\Player;
|
|||||||
use pocketmine\world\BlockTransaction;
|
use pocketmine\world\BlockTransaction;
|
||||||
|
|
||||||
class Stair extends Transparent{
|
class Stair extends Transparent{
|
||||||
|
use HorizontalFacingTrait;
|
||||||
|
|
||||||
/** @var int */
|
|
||||||
protected $facing = Facing::NORTH;
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $upsideDown = false;
|
protected $upsideDown = false;
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\BlockDataSerializer;
|
||||||
|
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
@ -33,9 +34,8 @@ use pocketmine\world\BlockTransaction;
|
|||||||
use pocketmine\world\sound\DoorSound;
|
use pocketmine\world\sound\DoorSound;
|
||||||
|
|
||||||
class Trapdoor extends Transparent{
|
class Trapdoor extends Transparent{
|
||||||
|
use HorizontalFacingTrait;
|
||||||
|
|
||||||
/** @var int */
|
|
||||||
protected $facing = Facing::NORTH;
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $open = false;
|
protected $open = false;
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\BlockDataSerializer;
|
||||||
|
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
@ -31,9 +32,8 @@ use pocketmine\player\Player;
|
|||||||
use pocketmine\world\BlockTransaction;
|
use pocketmine\world\BlockTransaction;
|
||||||
|
|
||||||
class TripwireHook extends Flowable{
|
class TripwireHook extends Flowable{
|
||||||
|
use HorizontalFacingTrait;
|
||||||
|
|
||||||
/** @var int */
|
|
||||||
protected $facing = Facing::NORTH;
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $connected = false;
|
protected $connected = false;
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
|
40
src/block/utils/AnyFacingTrait.php
Normal file
40
src/block/utils/AnyFacingTrait.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?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\math\Facing;
|
||||||
|
|
||||||
|
trait AnyFacingTrait{
|
||||||
|
/** @var int */
|
||||||
|
protected $facing = Facing::DOWN;
|
||||||
|
|
||||||
|
public function getFacing() : int{ return $this->facing; }
|
||||||
|
|
||||||
|
/** @return $this */
|
||||||
|
public function setFacing(int $facing) : self{
|
||||||
|
Facing::validate($this->facing);
|
||||||
|
$this->facing = $facing;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
43
src/block/utils/HorizontalFacingTrait.php
Normal file
43
src/block/utils/HorizontalFacingTrait.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?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\math\Facing;
|
||||||
|
use function in_array;
|
||||||
|
|
||||||
|
trait HorizontalFacingTrait{
|
||||||
|
/** @var int */
|
||||||
|
protected $facing = Facing::NORTH;
|
||||||
|
|
||||||
|
public function getFacing() : int{ return $this->facing; }
|
||||||
|
|
||||||
|
/** @return $this */
|
||||||
|
public function setFacing(int $facing) : self{
|
||||||
|
if(!in_array($facing, Facing::HORIZONTAL, true)){
|
||||||
|
throw new \InvalidArgumentException("Facing must be horizontal");
|
||||||
|
}
|
||||||
|
$this->facing = $facing;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user