Merge branch 'next-major' into modern-world-support

This commit is contained in:
Dylan K. Taylor
2022-04-28 21:06:44 +01:00
173 changed files with 692 additions and 1339 deletions

View File

@ -152,7 +152,7 @@ class Block{
$oldTile->close();
$oldTile = null;
}elseif($oldTile instanceof Spawnable){
$oldTile->setDirty(); //destroy old network cache
$oldTile->clearSpawnCompoundCache(); //destroy old network cache
}
}
if($oldTile === null && $tileType !== null){

View File

@ -33,10 +33,8 @@ use pocketmine\world\sound\Sound;
class DoubleChestInventory extends BaseInventory implements BlockInventory, InventoryHolder{
use AnimatedBlockInventoryTrait;
/** @var ChestInventory */
private $left;
/** @var ChestInventory */
private $right;
private ChestInventory $left;
private ChestInventory $right;
public function __construct(ChestInventory $left, ChestInventory $right){
$this->left = $left;

View File

@ -44,14 +44,13 @@ class Banner extends Spawnable{
public const TAG_PATTERN_COLOR = "Color";
public const TAG_PATTERN_NAME = "Pattern";
/** @var DyeColor */
private $baseColor;
private DyeColor $baseColor;
/**
* @var BannerPatternLayer[]
* @phpstan-var list<BannerPatternLayer>
*/
private $patterns = [];
private array $patterns = [];
public function __construct(World $world, Vector3 $pos){
$this->baseColor = DyeColor::BLACK();

View File

@ -29,10 +29,8 @@ final class Beacon extends Spawnable{
private const TAG_PRIMARY = "primary"; //TAG_Int
private const TAG_SECONDARY = "secondary"; //TAG_Int
/** @var int */
private $primaryEffect = 0;
/** @var int */
private $secondaryEffect = 0;
private int $primaryEffect = 0;
private int $secondaryEffect = 0;
protected function addAdditionalSpawnData(CompoundTag $nbt) : void{
$nbt->setInt(self::TAG_PRIMARY, $this->primaryEffect);

View File

@ -32,8 +32,8 @@ use pocketmine\world\World;
class Bed extends Spawnable{
public const TAG_COLOR = "color";
/** @var DyeColor */
private $color;
private DyeColor $color;
public function __construct(World $world, Vector3 $pos){
$this->color = DyeColor::RED();

View File

@ -49,10 +49,8 @@ class Chest extends Spawnable implements Container, Nameable{
/** @var DoubleChestInventory|null */
protected $doubleInventory = null;
/** @var int|null */
private $pairX;
/** @var int|null */
private $pairZ;
private ?int $pairX = null;
private ?int $pairZ = null;
public function __construct(World $world, Vector3 $pos){
parent::__construct($world, $pos);
@ -188,8 +186,8 @@ class Chest extends Spawnable implements Container, Nameable{
$this->createPair($tile);
$this->setDirty();
$tile->setDirty();
$this->clearSpawnCompoundCache();
$tile->clearSpawnCompoundCache();
$this->checkPairing();
return true;
@ -211,12 +209,12 @@ class Chest extends Spawnable implements Container, Nameable{
$tile = $this->getPair();
$this->pairX = $this->pairZ = null;
$this->setDirty();
$this->clearSpawnCompoundCache();
if($tile instanceof Chest){
$tile->pairX = $tile->pairZ = null;
$tile->checkPairing();
$tile->setDirty();
$tile->clearSpawnCompoundCache();
}
$this->checkPairing();

View File

@ -38,8 +38,7 @@ class FlowerPot extends Spawnable{
private const TAG_ITEM = "item";
private const TAG_ITEM_DATA = "mData";
/** @var Block|null */
private $plant = null;
private ?Block $plant = null;
public function readSaveData(CompoundTag $nbt) : void{
if(($itemIdTag = $nbt->getTag(self::TAG_ITEM)) instanceof ShortTag && ($itemMetaTag = $nbt->getTag(self::TAG_ITEM_DATA)) instanceof IntTag){

View File

@ -50,12 +50,9 @@ abstract class Furnace extends Spawnable implements Container, Nameable{
/** @var FurnaceInventory */
protected $inventory;
/** @var int */
private $remainingFuelTime = 0;
/** @var int */
private $cookTime = 0;
/** @var int */
private $maxFuelTime = 0;
private int $remainingFuelTime = 0;
private int $cookTime = 0;
private int $maxFuelTime = 0;
public function __construct(World $world, Vector3 $pos){
parent::__construct($world, $pos);

View File

@ -35,11 +35,8 @@ class Hopper extends Spawnable implements Container, Nameable{
private const TAG_TRANSFER_COOLDOWN = "TransferCooldown";
/** @var HopperInventory */
private $inventory;
/** @var int */
private $transferCooldown = 0;
private HopperInventory $inventory;
private int $transferCooldown = 0;
public function __construct(World $world, Vector3 $pos){
parent::__construct($world, $pos);

View File

@ -38,12 +38,9 @@ class ItemFrame extends Spawnable{
public const TAG_ITEM_DROP_CHANCE = "ItemDropChance";
public const TAG_ITEM = "Item";
/** @var Item */
private $item;
/** @var int */
private $itemRotation = 0;
/** @var float */
private $itemDropChance = 1.0;
private Item $item;
private int $itemRotation = 0;
private float $itemDropChance = 1.0;
public function __construct(World $world, Vector3 $pos){
$this->item = VanillaItems::AIR();

View File

@ -30,8 +30,7 @@ use pocketmine\nbt\tag\CompoundTag;
class Jukebox extends Spawnable{
private const TAG_RECORD = "RecordItem"; //Item CompoundTag
/** @var Record|null */
private $record = null;
private ?Record $record = null;
public function getRecord() : ?Record{
return $this->record;

View File

@ -56,43 +56,24 @@ class MonsterSpawner extends Spawnable{
public const DEFAULT_SPAWN_RANGE = 4; //blocks
public const DEFAULT_REQUIRED_PLAYER_RANGE = 16;
/**
* @var string
* TODO: replace this with a cached entity or something of that nature
*/
private $entityTypeId = ":";
/**
* @var ListTag|null
* TODO: deserialize this properly and drop the NBT (PC and PE formats are different, just for fun)
*/
private $spawnPotentials = null;
/**
* @var CompoundTag|null
* TODO: deserialize this properly and drop the NBT (PC and PE formats are different, just for fun)
*/
private $spawnData = null;
/** TODO: replace this with a cached entity or something of that nature */
private string $entityTypeId = ":";
/** TODO: deserialize this properly and drop the NBT (PC and PE formats are different, just for fun) */
private ?ListTag $spawnPotentials = null;
/** TODO: deserialize this properly and drop the NBT (PC and PE formats are different, just for fun) */
private ?CompoundTag $spawnData = null;
/** @var float */
private $displayEntityWidth = 1;
/** @var float */
private $displayEntityHeight = 1;
/** @var float */
private $displayEntityScale = 1;
private float $displayEntityWidth = 1.0;
private float $displayEntityHeight = 1.0;
private float $displayEntityScale = 1.0;
/** @var int */
private $spawnDelay = self::DEFAULT_MIN_SPAWN_DELAY;
/** @var int */
private $minSpawnDelay = self::DEFAULT_MIN_SPAWN_DELAY;
/** @var int */
private $maxSpawnDelay = self::DEFAULT_MAX_SPAWN_DELAY;
/** @var int */
private $spawnPerAttempt = 1;
/** @var int */
private $maxNearbyEntities = self::DEFAULT_MAX_NEARBY_ENTITIES;
/** @var int */
private $spawnRange = self::DEFAULT_SPAWN_RANGE;
/** @var int */
private $requiredPlayerRange = self::DEFAULT_REQUIRED_PLAYER_RANGE;
private int $spawnDelay = self::DEFAULT_MIN_SPAWN_DELAY;
private int $minSpawnDelay = self::DEFAULT_MIN_SPAWN_DELAY;
private int $maxSpawnDelay = self::DEFAULT_MAX_SPAWN_DELAY;
private int $spawnPerAttempt = 1;
private int $maxNearbyEntities = self::DEFAULT_MAX_NEARBY_ENTITIES;
private int $spawnRange = self::DEFAULT_SPAWN_RANGE;
private int $requiredPlayerRange = self::DEFAULT_REQUIRED_PLAYER_RANGE;
public function readSaveData(CompoundTag $nbt) : void{
if(($legacyIdTag = $nbt->getTag(self::TAG_LEGACY_ENTITY_TYPE_ID)) instanceof IntTag){

View File

@ -30,8 +30,7 @@ use pocketmine\nbt\tag\CompoundTag;
* @deprecated
*/
class Note extends Tile{
/** @var int */
private $pitch = 0;
private int $pitch = 0;
public function readSaveData(CompoundTag $nbt) : void{
if(($pitch = $nbt->getByte("note", $this->pitch)) > BlockNote::MIN_PITCH && $pitch <= BlockNote::MAX_PITCH){

View File

@ -40,10 +40,8 @@ class Skull extends Spawnable{
private const TAG_MOUTH_MOVING = "MouthMoving"; //TAG_Byte
private const TAG_MOUTH_TICK_COUNT = "MouthTickCount"; //TAG_Int
/** @var SkullType */
private $skullType;
/** @var int */
private $skullRotation = 0;
private SkullType $skullType;
private int $skullRotation = 0;
public function __construct(World $world, Vector3 $pos){
$this->skullType = SkullType::SKELETON();

View File

@ -28,26 +28,25 @@ use pocketmine\network\mcpe\protocol\types\CacheableNbt;
use function get_class;
abstract class Spawnable extends Tile{
/**
* @var CacheableNbt|null
* @phpstan-var CacheableNbt<\pocketmine\nbt\tag\CompoundTag>|null
*/
private $spawnCompoundCache = null;
/** @var bool */
private $dirty = true; //default dirty, until it's been spawned appropriately on the world
/** @phpstan-var CacheableNbt<\pocketmine\nbt\tag\CompoundTag>|null */
private ?CacheableNbt $spawnCompoundCache = null;
/**
* Returns whether the tile needs to be respawned to viewers.
* @deprecated
*/
public function isDirty() : bool{
return $this->dirty;
return $this->spawnCompoundCache === null;
}
/**
* @deprecated
*/
public function setDirty(bool $dirty = true) : void{
if($dirty){
$this->spawnCompoundCache = null;
}
$this->dirty = $dirty;
$this->clearSpawnCompoundCache();
}
public function clearSpawnCompoundCache() : void{
$this->spawnCompoundCache = null;
}
/**

View File

@ -42,12 +42,12 @@ final class TileFactory{
* @var string[] classes that extend Tile
* @phpstan-var array<string, class-string<Tile>>
*/
private $knownTiles = [];
private array $knownTiles = [];
/**
* @var string[]
* @phpstan-var array<class-string<Tile>, string>
*/
private $saveNames = [];
private array $saveNames = [];
public function __construct(){
$this->register(Barrel::class, ["Barrel", "minecraft:barrel"]);

View File

@ -30,14 +30,10 @@ use pocketmine\block\BaseBanner;
* @see BaseBanner
*/
class BannerPatternLayer{
private BannerPatternType $type;
/** @var DyeColor */
private $color;
public function __construct(BannerPatternType $type, DyeColor $color){
$this->type = $type;
$this->color = $color;
}
public function __construct(
private BannerPatternType $type,
private DyeColor $color
){}
public function getType() : BannerPatternType{ return $this->type; }

View File

@ -42,9 +42,6 @@ final class CoralType{
__construct as Enum___construct;
}
/** @var string */
private $displayName;
protected static function setup() : void{
self::registerAll(
new self("tube", "Tube"),
@ -55,9 +52,11 @@ final class CoralType{
);
}
private function __construct(string $name, string $displayName){
private function __construct(
string $name,
private string $displayName
){
$this->Enum___construct($name);
$this->displayName = $displayName;
}
public function getDisplayName() : string{ return $this->displayName; }

View File

@ -75,15 +75,12 @@ final class DyeColor{
);
}
/** @var string */
private $displayName;
/** @var Color */
private $rgbValue;
private function __construct(string $enumName, string $displayName, Color $rgbValue){
private function __construct(
string $enumName,
private string $displayName,
private Color $rgbValue
){
$this->Enum___construct($enumName);
$this->displayName = $displayName;
$this->rgbValue = $rgbValue;
}
public function getDisplayName() : string{

View File

@ -70,15 +70,13 @@ final class RecordType{
);
}
/** @var string */
private $soundName;
/** @var int */
private $soundId;
private function __construct(string $enumName, string $soundName, int $soundId, private Translatable $translatableName){
private function __construct(
string $enumName,
private string $soundName,
private int $soundId,
private Translatable $translatableName
){
$this->Enum___construct($enumName);
$this->soundName = $soundName;
$this->soundId = $soundId;
}
public function getSoundName() : string{

View File

@ -36,7 +36,7 @@ class SignText{
public const LINE_COUNT = 4;
/** @var string[] */
private $lines;
private array $lines;
/**
* @param string[]|null $lines index-sensitive; omitting an index will leave it unchanged

View File

@ -45,7 +45,7 @@ final class SkullType{
}
/** @var SkullType[] */
private static $numericIdMap = [];
private static array $numericIdMap = [];
protected static function setup() : void{
self::registerAll(
@ -75,15 +75,12 @@ final class SkullType{
return self::$numericIdMap[$magicNumber];
}
/** @var string */
private $displayName;
/** @var int */
private $magicNumber;
private function __construct(string $enumName, string $displayName, int $magicNumber){
private function __construct(
string $enumName,
private string $displayName,
private int $magicNumber
){
$this->Enum___construct($enumName);
$this->displayName = $displayName;
$this->magicNumber = $magicNumber;
}
public function getDisplayName() : string{

View File

@ -45,7 +45,7 @@ final class TreeType{
}
/** @var TreeType[] */
private static $numericIdMap = [];
private static array $numericIdMap = [];
protected static function setup() : void{
self::registerAll(
@ -76,15 +76,12 @@ final class TreeType{
return self::$numericIdMap[$magicNumber];
}
/** @var string */
private $displayName;
/** @var int */
private $magicNumber;
private function __construct(string $enumName, string $displayName, int $magicNumber){
private function __construct(
string $enumName,
private string $displayName,
private int $magicNumber
){
$this->Enum___construct($enumName);
$this->displayName = $displayName;
$this->magicNumber = $magicNumber;
}
public function getDisplayName() : string{