mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-19 04:15:04 +00:00
Removed pocketmine subdirectory, map PSR-4 style
This commit is contained in:
95
src/block/utils/BannerPattern.php
Normal file
95
src/block/utils/BannerPattern.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?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\block\Banner;
|
||||
|
||||
/**
|
||||
* Contains information about a pattern layer on a banner.
|
||||
* @see Banner
|
||||
*/
|
||||
class BannerPattern{
|
||||
public const BORDER = "bo";
|
||||
public const BRICKS = "bri";
|
||||
public const CIRCLE = "mc";
|
||||
public const CREEPER = "cre";
|
||||
public const CROSS = "cr";
|
||||
public const CURLY_BORDER = "cbo";
|
||||
public const DIAGONAL_LEFT = "lud";
|
||||
public const DIAGONAL_RIGHT = "rd";
|
||||
public const DIAGONAL_UP_LEFT = "ld";
|
||||
public const DIAGONAL_UP_RIGHT = "rud";
|
||||
public const FLOWER = "flo";
|
||||
public const GRADIENT = "gra";
|
||||
public const GRADIENT_UP = "gru";
|
||||
public const HALF_HORIZONTAL = "hh";
|
||||
public const HALF_HORIZONTAL_BOTTOM = "hhb";
|
||||
public const HALF_VERTICAL = "vh";
|
||||
public const HALF_VERTICAL_RIGHT = "vhr";
|
||||
public const MOJANG = "moj";
|
||||
public const RHOMBUS = "mr";
|
||||
public const SKULL = "sku";
|
||||
public const SMALL_STRIPES = "ss";
|
||||
public const SQUARE_BOTTOM_LEFT = "bl";
|
||||
public const SQUARE_BOTTOM_RIGHT = "br";
|
||||
public const SQUARE_TOP_LEFT = "tl";
|
||||
public const SQUARE_TOP_RIGHT = "tr";
|
||||
public const STRAIGHT_CROSS = "sc";
|
||||
public const STRIPE_BOTTOM = "bs";
|
||||
public const STRIPE_CENTER = "cs";
|
||||
public const STRIPE_DOWNLEFT = "dls";
|
||||
public const STRIPE_DOWNRIGHT = "drs";
|
||||
public const STRIPE_LEFT = "ls";
|
||||
public const STRIPE_MIDDLE = "ms";
|
||||
public const STRIPE_RIGHT = "rs";
|
||||
public const STRIPE_TOP = "ts";
|
||||
public const TRIANGLE_BOTTOM = "bt";
|
||||
public const TRIANGLE_TOP = "tt";
|
||||
public const TRIANGLES_BOTTOM = "bts";
|
||||
public const TRIANGLES_TOP = "tts";
|
||||
|
||||
/** @var string */
|
||||
private $id;
|
||||
/** @var DyeColor */
|
||||
private $color;
|
||||
|
||||
public function __construct(string $id, DyeColor $color){
|
||||
$this->id = $id;
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getId() : string{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DyeColor
|
||||
*/
|
||||
public function getColor() : DyeColor{
|
||||
return $this->color;
|
||||
}
|
||||
}
|
143
src/block/utils/BlockDataSerializer.php
Normal file
143
src/block/utils/BlockDataSerializer.php
Normal file
@@ -0,0 +1,143 @@
|
||||
<?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;
|
||||
|
||||
final class BlockDataSerializer{
|
||||
|
||||
private function __construct(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $raw
|
||||
*
|
||||
* @return int
|
||||
* @throws InvalidBlockStateException
|
||||
*/
|
||||
public static function readFacing(int $raw) : int{
|
||||
static $map = [ //this is for redundancy, for when/if the FACING constant values change
|
||||
0 => Facing::DOWN,
|
||||
1 => Facing::UP,
|
||||
2 => Facing::NORTH,
|
||||
3 => Facing::SOUTH,
|
||||
4 => Facing::WEST,
|
||||
5 => Facing::EAST
|
||||
];
|
||||
if(!isset($map[$raw])){
|
||||
throw new InvalidBlockStateException("Invalid facing $raw");
|
||||
}
|
||||
return $map[$raw];
|
||||
}
|
||||
|
||||
public static function writeFacing(int $facing) : int{
|
||||
static $map = [ //again, for redundancy
|
||||
Facing::DOWN => 0,
|
||||
Facing::UP => 1,
|
||||
Facing::NORTH => 2,
|
||||
Facing::SOUTH => 3,
|
||||
Facing::WEST => 4,
|
||||
Facing::EAST => 5
|
||||
];
|
||||
if(!isset($map[$facing])){
|
||||
throw new \InvalidArgumentException("Invalid facing $facing");
|
||||
}
|
||||
return $map[$facing];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $facing
|
||||
*
|
||||
* @return int
|
||||
* @throws InvalidBlockStateException
|
||||
*/
|
||||
public static function readHorizontalFacing(int $facing) : int{
|
||||
$facing = self::readFacing($facing);
|
||||
if(Facing::axis($facing) === Facing::AXIS_Y){
|
||||
throw new InvalidBlockStateException("Invalid Y-axis facing $facing");
|
||||
}
|
||||
return $facing;
|
||||
}
|
||||
|
||||
public static function writeHorizontalFacing(int $facing) : int{
|
||||
if(Facing::axis($facing) === Facing::AXIS_Y){
|
||||
throw new \InvalidArgumentException("Invalid Y-axis facing");
|
||||
}
|
||||
return self::writeFacing($facing);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $raw
|
||||
*
|
||||
* @return int
|
||||
* @throws InvalidBlockStateException
|
||||
*/
|
||||
public static function readLegacyHorizontalFacing(int $raw) : int{
|
||||
static $map = [ //again, for redundancy
|
||||
0 => Facing::SOUTH,
|
||||
1 => Facing::WEST,
|
||||
2 => Facing::NORTH,
|
||||
3 => Facing::EAST
|
||||
];
|
||||
if(!isset($map[$raw])){
|
||||
throw new InvalidBlockStateException("Invalid legacy facing $raw");
|
||||
}
|
||||
return $map[$raw];
|
||||
}
|
||||
|
||||
public static function writeLegacyHorizontalFacing(int $facing) : int{
|
||||
static $map = [
|
||||
Facing::SOUTH => 0,
|
||||
Facing::WEST => 1,
|
||||
Facing::NORTH => 2,
|
||||
Facing::EAST => 3
|
||||
];
|
||||
if(!isset($map[$facing])){
|
||||
throw new \InvalidArgumentException("Invalid Y-axis facing");
|
||||
}
|
||||
return $map[$facing];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
*
|
||||
* @return int
|
||||
* @throws InvalidBlockStateException
|
||||
*/
|
||||
public static function read5MinusHorizontalFacing(int $value) : int{
|
||||
return self::readHorizontalFacing(5 - ($value & 0x03));
|
||||
}
|
||||
|
||||
public static function write5MinusHorizontalFacing(int $value) : int{
|
||||
return 5 - self::writeHorizontalFacing($value);
|
||||
}
|
||||
|
||||
public static function readBoundedInt(string $name, int $v, int $min, int $max) : int{
|
||||
if($v < $min or $v > $max){
|
||||
throw new InvalidBlockStateException("$name should be in range $min - $max, got $v");
|
||||
}
|
||||
return $v;
|
||||
}
|
||||
}
|
146
src/block/utils/DyeColor.php
Normal file
146
src/block/utils/DyeColor.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?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\Color;
|
||||
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 WHITE()
|
||||
* @method static self ORANGE()
|
||||
* @method static self MAGENTA()
|
||||
* @method static self LIGHT_BLUE()
|
||||
* @method static self YELLOW()
|
||||
* @method static self LIME()
|
||||
* @method static self PINK()
|
||||
* @method static self GRAY()
|
||||
* @method static self LIGHT_GRAY()
|
||||
* @method static self CYAN()
|
||||
* @method static self PURPLE()
|
||||
* @method static self BLUE()
|
||||
* @method static self BROWN()
|
||||
* @method static self GREEN()
|
||||
* @method static self RED()
|
||||
* @method static self BLACK()
|
||||
*/
|
||||
final class DyeColor{
|
||||
use EnumTrait {
|
||||
register as Enum_register;
|
||||
__construct as Enum___construct;
|
||||
}
|
||||
|
||||
/** @var DyeColor[] */
|
||||
private static $numericIdMap = [];
|
||||
|
||||
protected static function setup() : iterable{
|
||||
return [
|
||||
new DyeColor("white", "White", 0, new Color(0xf0, 0xf0, 0xf0)),
|
||||
new DyeColor("orange", "Orange", 1, new Color(0xf9, 0x80, 0x1d)),
|
||||
new DyeColor("magenta", "Magenta", 2, new Color(0xc7, 0x4e, 0xbd)),
|
||||
new DyeColor("light_blue", "Light Blue", 3, new Color(0x3a, 0xb3, 0xda)),
|
||||
new DyeColor("yellow", "Yellow", 4, new Color(0xfe, 0xd8, 0x3d)),
|
||||
new DyeColor("lime", "Lime", 5, new Color(0x80, 0xc7, 0x1f)),
|
||||
new DyeColor("pink", "Pink", 6, new Color(0xf3, 0x8b, 0xaa)),
|
||||
new DyeColor("gray", "Gray", 7, new Color(0x47, 0x4f, 0x52)),
|
||||
new DyeColor("light_gray", "Light Gray", 8, new Color(0x9d, 0x9d, 0x97)),
|
||||
new DyeColor("cyan", "Cyan", 9, new Color(0x16, 0x9c, 0x9c)),
|
||||
new DyeColor("purple", "Purple", 10, new Color(0x89, 0x32, 0xb8)),
|
||||
new DyeColor("blue", "Blue", 11, new Color(0x3c, 0x44, 0xaa)),
|
||||
new DyeColor("brown", "Brown", 12, new Color(0x83, 0x54, 0x32)),
|
||||
new DyeColor("green", "Green", 13, new Color(0x5e, 0x7c, 0x16)),
|
||||
new DyeColor("red", "Red", 14, new Color(0xb0, 0x2e, 0x26)),
|
||||
new DyeColor("black", "Black", 15, new Color(0x1d, 0x1d, 0x21)),
|
||||
];
|
||||
}
|
||||
|
||||
protected static function register(DyeColor $color) : void{
|
||||
self::Enum_register($color);
|
||||
self::$numericIdMap[$color->getMagicNumber()] = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a DyeColor object matching the given magic number
|
||||
* @internal
|
||||
*
|
||||
* @param int $magicNumber
|
||||
* @param bool $inverted Invert the ID before using it (useful for actual dye magic IDs)
|
||||
*
|
||||
* @return DyeColor
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public static function fromMagicNumber(int $magicNumber, bool $inverted = false) : DyeColor{
|
||||
self::checkInit();
|
||||
$real = $inverted ? ~$magicNumber & 0xf : $magicNumber;
|
||||
if(!isset(self::$numericIdMap[$real])){
|
||||
throw new \InvalidArgumentException("Unknown dye colour magic number $magicNumber");
|
||||
}
|
||||
return self::$numericIdMap[$real];
|
||||
}
|
||||
|
||||
/** @var string */
|
||||
private $displayName;
|
||||
/** @var int */
|
||||
private $magicNumber;
|
||||
/** @var Color */
|
||||
private $rgbValue;
|
||||
|
||||
private function __construct(string $enumName, string $displayName, int $magicNumber, Color $rgbValue){
|
||||
$this->Enum___construct($enumName);
|
||||
$this->displayName = $displayName;
|
||||
$this->magicNumber = $magicNumber;
|
||||
$this->rgbValue = $rgbValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDisplayName() : string{
|
||||
return $this->displayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Color
|
||||
*/
|
||||
public function getRgbValue() : Color{
|
||||
return $this->rgbValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMagicNumber() : int{
|
||||
return $this->magicNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getInvertedMagicNumber() : int{
|
||||
return ~$this->magicNumber & 0xf;
|
||||
}
|
||||
}
|
38
src/block/utils/Fallable.php
Normal file
38
src/block/utils/Fallable.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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\block\Block;
|
||||
|
||||
interface Fallable{
|
||||
|
||||
/**
|
||||
* Called every tick by FallingBlock to update the falling state of this block. Used by concrete to check when it
|
||||
* hits water.
|
||||
* Return null if you don't want to change the usual behaviour.
|
||||
*
|
||||
* @return Block|null
|
||||
*/
|
||||
public function tickFalling() : ?Block;
|
||||
}
|
63
src/block/utils/FallableTrait.php
Normal file
63
src/block/utils/FallableTrait.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?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\block\BlockLegacyIds;
|
||||
use pocketmine\block\Fire;
|
||||
use pocketmine\block\Liquid;
|
||||
use pocketmine\block\VanillaBlocks;
|
||||
use pocketmine\entity\EntityFactory;
|
||||
use pocketmine\entity\object\FallingBlock;
|
||||
use pocketmine\math\Facing;
|
||||
use pocketmine\world\Position;
|
||||
|
||||
/**
|
||||
* This trait handles falling behaviour for blocks that need them.
|
||||
* TODO: convert this into a dynamic component
|
||||
* @see Fallable
|
||||
*/
|
||||
trait FallableTrait{
|
||||
|
||||
abstract protected function asPosition() : Position;
|
||||
|
||||
abstract protected function getId() : int;
|
||||
|
||||
abstract protected function getMeta() : int;
|
||||
|
||||
public function onNearbyBlockChange() : void{
|
||||
$pos = $this->asPosition();
|
||||
$down = $pos->world->getBlock($pos->getSide(Facing::DOWN));
|
||||
if($down->getId() === BlockLegacyIds::AIR or $down instanceof Liquid or $down instanceof Fire){
|
||||
$pos->world->setBlock($pos, VanillaBlocks::AIR());
|
||||
|
||||
$nbt = EntityFactory::createBaseNBT($pos->add(0.5, 0, 0.5));
|
||||
$nbt->setInt("TileID", $this->getId());
|
||||
$nbt->setByte("Data", $this->getMeta());
|
||||
|
||||
/** @var FallingBlock $fall */
|
||||
$fall = EntityFactory::create(FallingBlock::class, $pos->getWorld(), $nbt);
|
||||
$fall->spawnToAll();
|
||||
}
|
||||
}
|
||||
}
|
28
src/block/utils/InvalidBlockStateException.php
Normal file
28
src/block/utils/InvalidBlockStateException.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?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;
|
||||
|
||||
class InvalidBlockStateException extends \UnexpectedValueException{
|
||||
|
||||
}
|
108
src/block/utils/PillarRotationTrait.php
Normal file
108
src/block/utils/PillarRotationTrait.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?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\block\Block;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\math\Facing;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\world\BlockTransaction;
|
||||
|
||||
trait PillarRotationTrait{
|
||||
|
||||
/** @var int */
|
||||
protected $axis = Facing::AXIS_Y;
|
||||
|
||||
protected function getAxisMetaShift() : int{
|
||||
return 2; //default
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Block::writeStateToMeta()
|
||||
* @return int
|
||||
*/
|
||||
protected function writeStateToMeta() : int{
|
||||
return $this->writeAxisToMeta();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Block::readStateFromData()
|
||||
*
|
||||
* @param int $id
|
||||
* @param int $stateMeta
|
||||
*/
|
||||
public function readStateFromData(int $id, int $stateMeta) : void{
|
||||
$this->readAxisFromMeta($stateMeta);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Block::getStateBitmask()
|
||||
* @return int
|
||||
*/
|
||||
public function getStateBitmask() : int{
|
||||
return 0b11 << $this->getAxisMetaShift();
|
||||
}
|
||||
|
||||
protected function readAxisFromMeta(int $meta) : void{
|
||||
static $map = [
|
||||
0 => Facing::AXIS_Y,
|
||||
1 => Facing::AXIS_X,
|
||||
2 => Facing::AXIS_Z
|
||||
];
|
||||
$axis = $meta >> $this->getAxisMetaShift();
|
||||
if(!isset($map[$axis])){
|
||||
throw new InvalidBlockStateException("Invalid axis meta $axis");
|
||||
}
|
||||
$this->axis = $map[$axis];
|
||||
}
|
||||
|
||||
protected function writeAxisToMeta() : int{
|
||||
static $bits = [
|
||||
Facing::AXIS_Y => 0,
|
||||
Facing::AXIS_Z => 2,
|
||||
Facing::AXIS_X => 1
|
||||
];
|
||||
return $bits[$this->axis] << $this->getAxisMetaShift();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Block::place()
|
||||
*
|
||||
* @param BlockTransaction $tx
|
||||
* @param Item $item
|
||||
* @param Block $blockReplace
|
||||
* @param Block $blockClicked
|
||||
* @param int $face
|
||||
* @param Vector3 $clickVector
|
||||
* @param Player|null $player
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||
$this->axis = Facing::axis($face);
|
||||
/** @see Block::place() */
|
||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||
}
|
||||
}
|
130
src/block/utils/SignText.php
Normal file
130
src/block/utils/SignText.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?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 function array_fill;
|
||||
use function array_pad;
|
||||
use function array_slice;
|
||||
use function count;
|
||||
use function explode;
|
||||
use function is_int;
|
||||
use function strpos;
|
||||
|
||||
class SignText{
|
||||
public const LINE_COUNT = 4;
|
||||
|
||||
/** @var string[] */
|
||||
private $lines;
|
||||
|
||||
/**
|
||||
* @param string[] $lines
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct(?array $lines = null){
|
||||
$this->setLines($lines ?? array_fill(0, self::LINE_COUNT, ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses sign lines from the given string blob.
|
||||
* TODO: add a strict mode for this
|
||||
*
|
||||
* @param string $blob
|
||||
*
|
||||
* @return SignText
|
||||
* @throws \InvalidArgumentException if the text is not valid UTF-8
|
||||
*/
|
||||
public static function fromBlob(string $blob) : SignText{
|
||||
return new self(array_slice(array_pad(explode("\n", $blob), self::LINE_COUNT, ""), 0, self::LINE_COUNT));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of lines currently on the sign.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getLines() : array{
|
||||
return $this->lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sign text.
|
||||
*
|
||||
* @param string[] $lines index-sensitive; omitting an index will leave it unchanged
|
||||
*
|
||||
* @throws \InvalidArgumentException if the array size is greater than 4
|
||||
* @throws \InvalidArgumentException if invalid keys (out of bounds or string) are found in the array
|
||||
*/
|
||||
public function setLines(array $lines) : void{
|
||||
if(count($lines) > self::LINE_COUNT){
|
||||
throw new \InvalidArgumentException("Expected at most 4 lines, got " . count($lines));
|
||||
}
|
||||
foreach($lines as $k => $line){
|
||||
$this->checkLineIndex($k);
|
||||
$this->setLine($k, $line);
|
||||
}
|
||||
}
|
||||
|
||||
private function checkLineIndex($index) : void{
|
||||
if(!is_int($index)){
|
||||
throw new \InvalidArgumentException("Index must be an integer");
|
||||
}
|
||||
if($index < 0 or $index >= self::LINE_COUNT){
|
||||
throw new \InvalidArgumentException("Line index is out of bounds");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sign line at the given offset.
|
||||
*
|
||||
* @param int $index
|
||||
*
|
||||
* @return string
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function getLine(int $index) : string{
|
||||
$this->checkLineIndex($index);
|
||||
return $this->lines[$index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the line at the given offset.
|
||||
*
|
||||
* @param int $index
|
||||
* @param string $line
|
||||
*
|
||||
* @throws \InvalidArgumentException if the text is not valid UTF-8
|
||||
* @throws \InvalidArgumentException if the text contains a newline
|
||||
*/
|
||||
public function setLine(int $index, string $line) : void{
|
||||
$this->checkLineIndex($index);
|
||||
if(!mb_check_encoding($line, 'UTF-8')){
|
||||
throw new \InvalidArgumentException("Line must be valid UTF-8 text");
|
||||
}
|
||||
if(strpos($line, "\n") !== false){
|
||||
throw new \InvalidArgumentException("Line must not contain newlines");
|
||||
}
|
||||
//TODO: add length checks
|
||||
$this->lines[$index] = $line;
|
||||
}
|
||||
}
|
103
src/block/utils/SkullType.php
Normal file
103
src/block/utils/SkullType.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?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 SKELETON()
|
||||
* @method static self WITHER_SKELETON()
|
||||
* @method static self ZOMBIE()
|
||||
* @method static self PLAYER()
|
||||
* @method static self CREEPER()
|
||||
* @method static self DRAGON()
|
||||
*/
|
||||
final class SkullType{
|
||||
use EnumTrait {
|
||||
register as Enum_register;
|
||||
__construct as Enum___construct;
|
||||
}
|
||||
|
||||
/** @var SkullType[] */
|
||||
private static $numericIdMap = [];
|
||||
|
||||
protected static function setup() : iterable{
|
||||
return [
|
||||
new SkullType("skeleton", "Skeleton Skull", 0),
|
||||
new SkullType("wither_skeleton", "Wither Skeleton Skull", 1),
|
||||
new SkullType("zombie", "Zombie Head", 2),
|
||||
new SkullType("player", "Player Head", 3),
|
||||
new SkullType("creeper", "Creeper Head", 4),
|
||||
new SkullType("dragon", "Dragon Head", 5)
|
||||
];
|
||||
}
|
||||
|
||||
protected static function register(SkullType $type) : void{
|
||||
self::Enum_register($type);
|
||||
self::$numericIdMap[$type->getMagicNumber()] = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @param int $magicNumber
|
||||
*
|
||||
* @return SkullType
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public static function fromMagicNumber(int $magicNumber) : SkullType{
|
||||
if(!isset(self::$numericIdMap[$magicNumber])){
|
||||
throw new \InvalidArgumentException("Unknown skull type magic number $magicNumber");
|
||||
}
|
||||
return self::$numericIdMap[$magicNumber];
|
||||
}
|
||||
|
||||
/** @var string */
|
||||
private $displayName;
|
||||
/** @var int */
|
||||
private $magicNumber;
|
||||
|
||||
private function __construct(string $enumName, string $displayName, int $magicNumber){
|
||||
$this->Enum___construct($enumName);
|
||||
$this->displayName = $displayName;
|
||||
$this->magicNumber = $magicNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDisplayName() : string{
|
||||
return $this->displayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMagicNumber() : int{
|
||||
return $this->magicNumber;
|
||||
}
|
||||
}
|
47
src/block/utils/SlabType.php
Normal file
47
src/block/utils/SlabType.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?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 BOTTOM()
|
||||
* @method static self TOP()
|
||||
* @method static self DOUBLE()
|
||||
*/
|
||||
final class SlabType{
|
||||
use EnumTrait;
|
||||
|
||||
protected static function setup() : iterable{
|
||||
return [
|
||||
new self("bottom"),
|
||||
new self("top"),
|
||||
new self("double")
|
||||
];
|
||||
}
|
||||
}
|
51
src/block/utils/StairShape.php
Normal file
51
src/block/utils/StairShape.php
Normal 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")
|
||||
];
|
||||
}
|
||||
}
|
110
src/block/utils/TreeType.php
Normal file
110
src/block/utils/TreeType.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?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 OAK()
|
||||
* @method static self SPRUCE()
|
||||
* @method static self BIRCH()
|
||||
* @method static self JUNGLE()
|
||||
* @method static self ACACIA()
|
||||
* @method static self DARK_OAK()
|
||||
*/
|
||||
final class TreeType{
|
||||
use EnumTrait {
|
||||
register as Enum_register;
|
||||
__construct as Enum___construct;
|
||||
}
|
||||
|
||||
/** @var TreeType[] */
|
||||
private static $numericIdMap = [];
|
||||
|
||||
protected static function setup() : iterable{
|
||||
return [
|
||||
new TreeType("oak", "Oak", 0),
|
||||
new TreeType("spruce", "Spruce", 1),
|
||||
new TreeType("birch", "Birch", 2),
|
||||
new TreeType("jungle", "Jungle", 3),
|
||||
new TreeType("acacia", "Acacia", 4),
|
||||
new TreeType("dark_oak", "Dark Oak", 5)
|
||||
];
|
||||
}
|
||||
|
||||
protected static function register(TreeType $type) : void{
|
||||
self::Enum_register($type);
|
||||
self::$numericIdMap[$type->getMagicNumber()] = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @param int $magicNumber
|
||||
*
|
||||
* @return TreeType
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public static function fromMagicNumber(int $magicNumber) : TreeType{
|
||||
self::checkInit();
|
||||
if(!isset(self::$numericIdMap[$magicNumber])){
|
||||
throw new \InvalidArgumentException("Unknown tree type magic number $magicNumber");
|
||||
}
|
||||
return self::$numericIdMap[$magicNumber];
|
||||
}
|
||||
|
||||
/** @var string */
|
||||
private $displayName;
|
||||
/** @var int */
|
||||
private $magicNumber;
|
||||
|
||||
/**
|
||||
* @param string $enumName
|
||||
* @param string $displayName
|
||||
* @param int $magicNumber
|
||||
*/
|
||||
private function __construct(string $enumName, string $displayName, int $magicNumber){
|
||||
$this->Enum___construct($enumName);
|
||||
$this->displayName = $displayName;
|
||||
$this->magicNumber = $magicNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDisplayName() : string{
|
||||
return $this->displayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMagicNumber() : int{
|
||||
return $this->magicNumber;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user