Promote some constructors

This commit is contained in:
Dylan K. Taylor
2022-05-17 22:34:58 +01:00
parent 8e767da29e
commit d4b7f66e15
30 changed files with 144 additions and 218 deletions

View File

@ -38,18 +38,17 @@ class BlockBreakInfo{
*/
public const INCOMPATIBLE_TOOL_MULTIPLIER = 5.0;
private float $hardness;
private float $blastResistance;
private int $toolType;
private int $toolHarvestLevel;
/**
* @param float|null $blastResistance default 5x hardness
*/
public function __construct(float $hardness, int $toolType = BlockToolType::NONE, int $toolHarvestLevel = 0, ?float $blastResistance = null){
$this->hardness = $hardness;
$this->toolType = $toolType;
$this->toolHarvestLevel = $toolHarvestLevel;
public function __construct(
private float $hardness,
private int $toolType = BlockToolType::NONE,
private int $toolHarvestLevel = 0,
?float $blastResistance = null
){
$this->blastResistance = $blastResistance ?? $hardness * 5;
}

View File

@ -27,25 +27,18 @@ use pocketmine\block\tile\Tile;
use pocketmine\utils\Utils;
class BlockIdentifier{
private int $blockId;
private int $variant;
private ?int $itemId;
/** @phpstan-var class-string<Tile>|null */
private ?string $tileClass;
/**
* @phpstan-param class-string<Tile>|null $tileClass
*/
public function __construct(int $blockId, int $variant, ?int $itemId = null, ?string $tileClass = null){
$this->blockId = $blockId;
$this->variant = $variant;
$this->itemId = $itemId;
public function __construct(
private int $blockId,
private int $variant,
private ?int $itemId = null,
private ?string $tileClass = null
){
if($tileClass !== null){
Utils::testValidInstance($tileClass, Tile::class);
}
$this->tileClass = $tileClass;
}
public function getBlockId() : int{

View File

@ -24,16 +24,15 @@ declare(strict_types=1);
namespace pocketmine\block;
class Element extends Opaque{
private int $atomicWeight;
private int $group;
private string $symbol;
public function __construct(BlockIdentifier $idInfo, string $name, BlockBreakInfo $breakInfo, string $symbol, int $atomicWeight, int $group){
public function __construct(
BlockIdentifier $idInfo,
string $name,
BlockBreakInfo $breakInfo,
private string $symbol,
private int $atomicWeight,
private int $group
){
parent::__construct($idInfo, $name, $breakInfo);
$this->atomicWeight = $atomicWeight;
$this->group = $group;
$this->symbol = $symbol;
}
public function getAtomicWeight() : int{

View File

@ -33,12 +33,10 @@ use pocketmine\world\sound\Sound;
class DoubleChestInventory extends BaseInventory implements BlockInventory, InventoryHolder{
use AnimatedBlockInventoryTrait;
private ChestInventory $left;
private ChestInventory $right;
public function __construct(ChestInventory $left, ChestInventory $right){
$this->left = $left;
$this->right = $right;
public function __construct(
private ChestInventory $left,
private ChestInventory $right
){
$this->holder = $this->left->getHolder();
parent::__construct();
}

View File

@ -43,12 +43,12 @@ class EnderChestInventory extends DelegateInventory implements BlockInventory{
onClose as animatedBlockInventoryTrait_onClose;
}
private PlayerEnderInventory $inventory;
public function __construct(Position $holder, PlayerEnderInventory $inventory){
public function __construct(
Position $holder,
private PlayerEnderInventory $inventory
){
parent::__construct($inventory);
$this->holder = $holder;
$this->inventory = $inventory;
}
public function getEnderInventory() : PlayerEnderInventory{

View File

@ -35,11 +35,11 @@ class FurnaceInventory extends SimpleInventory implements BlockInventory{
public const SLOT_FUEL = 1;
public const SLOT_RESULT = 2;
private FurnaceType $furnaceType;
public function __construct(Position $holder, FurnaceType $furnaceType){
public function __construct(
Position $holder,
private FurnaceType $furnaceType
){
$this->holder = $holder;
$this->furnaceType = $furnaceType;
parent::__construct(3);
}