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

@@ -28,20 +28,16 @@ use pocketmine\math\Vector3;
use pocketmine\utils\Utils;
class BlockTransaction{
/** @var ChunkManager */
private $world;
/** @var Block[][][] */
private $blocks = [];
private array $blocks = [];
/**
* @var \Closure[]
* @phpstan-var (\Closure(ChunkManager $world, int $x, int $y, int $z) : bool)[]
*/
private $validators = [];
private array $validators = [];
public function __construct(ChunkManager $world){
$this->world = $world;
public function __construct(private ChunkManager $world){
$this->addValidator(static function(ChunkManager $world, int $x, int $y, int $z) : bool{
return $world->isInWorld($x, $y, $z);
});

View File

@@ -46,8 +46,7 @@ use function mt_rand;
use function sqrt;
class Explosion{
/** @var int */
private $rays = 16;
private int $rays = 16;
/** @var World */
public $world;
/** @var Position */
@@ -59,16 +58,12 @@ class Explosion{
public $affectedBlocks = [];
/** @var float */
public $stepLen = 0.3;
/** @var Entity|Block|null */
private $what;
/** @var SubChunkExplorer */
private $subChunkExplorer;
private Entity|Block|null $what;
/**
* @param Entity|Block|null $what
*/
public function __construct(Position $center, float $size, $what = null){
private SubChunkExplorer $subChunkExplorer;
public function __construct(Position $center, float $size, Entity|Block|null $what = null){
if(!$center->isValid()){
throw new \InvalidArgumentException("Position does not have a valid world");
}

View File

@@ -34,15 +34,10 @@ class SimpleChunkManager implements ChunkManager{
/** @var Chunk[] */
protected $chunks = [];
/** @var int */
private $minY;
/** @var int */
private $maxY;
public function __construct(int $minY, int $maxY){
$this->minY = $minY;
$this->maxY = $maxY;
}
public function __construct(
private int $minY,
private int $maxY
){}
public function getBlockAt(int $x, int $y, int $z) : Block{
if($this->isInWorld($x, $y, $z) && ($chunk = $this->getChunk($x >> Chunk::COORD_BIT_SIZE, $z >> Chunk::COORD_BIT_SIZE)) !== null){

View File

@@ -131,8 +131,7 @@ use const PHP_INT_MIN;
class World implements ChunkManager{
/** @var int */
private static $worldIdCounter = 1;
private static int $worldIdCounter = 1;
public const Y_MAX = 320;
public const Y_MIN = -64;
@@ -154,15 +153,15 @@ class World implements ChunkManager{
public const DEFAULT_TICKED_BLOCKS_PER_SUBCHUNK_PER_TICK = 3;
/** @var Player[] */
private $players = [];
private array $players = [];
/** @var Entity[] */
private $entities = [];
private array $entities = [];
/**
* @var Vector3[]
* @phpstan-var array<int, Vector3>
*/
private $entityLastKnownPositions = [];
private array $entityLastKnownPositions = [];
/**
* @var Entity[][]
@@ -173,88 +172,66 @@ class World implements ChunkManager{
/** @var Entity[] */
public $updateEntities = [];
/** @var Block[][] */
private $blockCache = [];
private array $blockCache = [];
/** @var int */
private $sendTimeTicker = 0;
private int $sendTimeTicker = 0;
/** @var Server */
private $server;
private int $worldId;
/** @var int */
private $worldId;
private int $providerGarbageCollectionTicker = 0;
/** @var WritableWorldProvider */
private $provider;
/** @var int */
private $providerGarbageCollectionTicker = 0;
/** @var int */
private $minY;
/** @var int */
private $maxY;
private int $minY;
private int $maxY;
/** @var TickingChunkLoader[] */
private $tickingLoaders = [];
private array $tickingLoaders = [];
/** @var int[] */
private $tickingLoaderCounter = [];
private array $tickingLoaderCounter = [];
/** @var ChunkLoader[][] */
private $chunkLoaders = [];
private array $chunkLoaders = [];
/** @var ChunkListener[][] */
private $chunkListeners = [];
private array $chunkListeners = [];
/** @var Player[][] */
private $playerChunkListeners = [];
private array $playerChunkListeners = [];
/** @var ClientboundPacket[][] */
private $packetBuffersByChunk = [];
private array $packetBuffersByChunk = [];
/** @var float[] */
private $unloadQueue = [];
private array $unloadQueue = [];
/** @var int */
private $time;
private int $time;
/** @var bool */
public $stopTime = false;
/** @var float */
private $sunAnglePercentage = 0.0;
/** @var int */
private $skyLightReduction = 0;
private float $sunAnglePercentage = 0.0;
private int $skyLightReduction = 0;
/** @var string */
private $folderName;
/** @var string */
private $displayName;
private string $folderName;
private string $displayName;
/** @var Chunk[] */
private $chunks = [];
private array $chunks = [];
/** @var Vector3[][] */
private $changedBlocks = [];
private array $changedBlocks = [];
/**
* @var ReversePriorityQueue
* @phpstan-var ReversePriorityQueue<int, Vector3>
*/
private $scheduledBlockUpdateQueue;
/** @phpstan-var ReversePriorityQueue<int, Vector3> */
private ReversePriorityQueue $scheduledBlockUpdateQueue;
/** @var int[] */
private $scheduledBlockUpdateQueueIndex = [];
private array $scheduledBlockUpdateQueueIndex = [];
/**
* @var \SplQueue
* @phpstan-var \SplQueue<int>
*/
private $neighbourBlockUpdateQueue;
/** @phpstan-var \SplQueue<int> */
private \SplQueue $neighbourBlockUpdateQueue;
/** @var bool[] blockhash => dummy */
private $neighbourBlockUpdateQueueIndex = [];
private array $neighbourBlockUpdateQueueIndex = [];
/** @var bool[] */
private $activeChunkPopulationTasks = [];
private array $activeChunkPopulationTasks = [];
/** @var ChunkLockId[] */
private $chunkLock = [];
/** @var int */
private $maxConcurrentChunkPopulationTasks = 2;
private array $chunkLock = [];
private int $maxConcurrentChunkPopulationTasks = 2;
/**
* @var PromiseResolver[] chunkHash => promise
* @phpstan-var array<int, PromiseResolver<Chunk>>
@@ -272,22 +249,17 @@ class World implements ChunkManager{
private array $chunkPopulationRequestQueueIndex = [];
/** @var bool[] */
private $generatorRegisteredWorkers = [];
private array $generatorRegisteredWorkers = [];
/** @var bool */
private $autoSave = true;
private bool $autoSave = true;
/** @var int */
private $sleepTicks = 0;
private int $sleepTicks = 0;
/** @var int */
private $chunkTickRadius;
/** @var int */
private $chunksPerTick;
/** @var int */
private $tickedBlocksPerSubchunkPerTick = self::DEFAULT_TICKED_BLOCKS_PER_SUBCHUNK_PER_TICK;
private int $chunkTickRadius;
private int $chunksPerTick;
private int $tickedBlocksPerSubchunkPerTick = self::DEFAULT_TICKED_BLOCKS_PER_SUBCHUNK_PER_TICK;
/** @var bool[] */
private $randomTickBlocks = [];
private array $randomTickBlocks = [];
/** @var WorldTimings */
public $timings;
@@ -295,33 +267,22 @@ class World implements ChunkManager{
/** @var float */
public $tickRateTime = 0;
/** @var bool */
private $doingTick = false;
private bool $doingTick = false;
/**
* @var string
* @phpstan-var class-string<\pocketmine\world\generator\Generator>
*/
private $generator;
/** @phpstan-var class-string<\pocketmine\world\generator\Generator> */
private string $generator;
/** @var bool */
private $unloaded = false;
private bool $unloaded = false;
/**
* @var \Closure[]
* @phpstan-var array<int, \Closure() : void>
*/
private $unloadCallbacks = [];
private array $unloadCallbacks = [];
/** @var BlockLightUpdate|null */
private $blockLightUpdate = null;
/** @var SkyLightUpdate|null */
private $skyLightUpdate = null;
private ?BlockLightUpdate $blockLightUpdate = null;
private ?SkyLightUpdate $skyLightUpdate = null;
/** @var \Logger */
private $logger;
/** @var AsyncPool */
private $workerPool;
private \Logger $logger;
public static function chunkHash(int $x, int $z) : int{
return morton2d_encode($x, $z);
@@ -407,12 +368,14 @@ class World implements ChunkManager{
/**
* Init the default world data
*/
public function __construct(Server $server, string $name, WritableWorldProvider $provider, AsyncPool $workerPool){
public function __construct(
private Server $server,
string $name, //TODO: this should be folderName (named arguments BC break)
private WritableWorldProvider $provider,
private AsyncPool $workerPool
){
$this->folderName = $name;
$this->worldId = self::$worldIdCounter++;
$this->server = $server;
$this->provider = $provider;
$this->workerPool = $workerPool;
$this->displayName = $this->provider->getWorldData()->getName();
$this->logger = new \PrefixedLogger($server->getLogger(), "World: $this->displayName");
@@ -440,8 +403,6 @@ class World implements ChunkManager{
}
});
$this->folderName = $name;
$this->scheduledBlockUpdateQueue = new ReversePriorityQueue();
$this->scheduledBlockUpdateQueue->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);
@@ -2653,8 +2614,13 @@ class World implements ChunkManager{
unset($this->changedBlocks[$chunkHash]);
if(array_key_exists($chunkHash, $this->chunkPopulationRequestMap)){
$this->logger->debug("Rejecting population promise for chunk $x $z");
$this->chunkPopulationRequestMap[$chunkHash]->reject();
unset($this->chunkPopulationRequestMap[$chunkHash]);
if(isset($this->activeChunkPopulationTasks[$chunkHash])){
$this->logger->debug("Marking population task for chunk $x $z as orphaned");
$this->activeChunkPopulationTasks[$chunkHash] = false;
}
}
$this->timings->doChunkUnload->stopTiming();
@@ -2830,7 +2796,7 @@ class World implements ChunkManager{
unset($this->chunkPopulationRequestQueueIndex[$nextChunkHash]);
World::getXZ($nextChunkHash, $nextChunkX, $nextChunkZ);
if(isset($this->chunkPopulationRequestMap[$nextChunkHash])){
assert(!isset($this->activeChunkPopulationTasks[$nextChunkHash]), "Population for chunk $nextChunkX $nextChunkZ already running");
assert(!($this->activeChunkPopulationTasks[$nextChunkHash] ?? false), "Population for chunk $nextChunkX $nextChunkZ already running");
if(
!$this->orderChunkPopulation($nextChunkX, $nextChunkZ, null)->isResolved() &&
!isset($this->activeChunkPopulationTasks[$nextChunkHash])
@@ -2999,10 +2965,13 @@ class World implements ChunkManager{
}
$index = World::chunkHash($x, $z);
if(!isset($this->chunkPopulationRequestMap[$index])){
$this->logger->debug("Discarding population result for chunk x=$x,z=$z - promise was already broken");
if(!isset($this->activeChunkPopulationTasks[$index])){
throw new AssumptionFailedError("This should always be set, regardless of whether the task was orphaned or not");
}
if(!$this->activeChunkPopulationTasks[$index]){
$this->logger->debug("Discarding orphaned population result for chunk x=$x,z=$z");
unset($this->activeChunkPopulationTasks[$index]);
}elseif(isset($this->activeChunkPopulationTasks[$index])){
}else{
if($dirtyChunks === 0){
$oldChunk = $this->loadChunk($x, $z);
$this->setChunk($x, $z, $chunk);

View File

@@ -55,33 +55,19 @@ use function strval;
use function trim;
class WorldManager{
/** @var string */
private $dataPath;
/** @var WorldProviderManager */
private $providerManager;
/** @var World[] */
private $worlds = [];
/** @var World|null */
private $defaultWorld;
private array $worlds = [];
private ?World $defaultWorld = null;
/** @var Server */
private $server;
private bool $autoSave = true;
private int $autoSaveTicks = 6000;
private int $autoSaveTicker = 0;
/** @var bool */
private $autoSave = true;
/** @var int */
private $autoSaveTicks = 6000;
/** @var int */
private $autoSaveTicker = 0;
public function __construct(Server $server, string $dataPath, WorldProviderManager $providerManager){
$this->server = $server;
$this->dataPath = $dataPath;
$this->providerManager = $providerManager;
}
public function __construct(
private Server $server,
private string $dataPath,
private WorldProviderManager $providerManager
){}
public function getProviderManager() : WorldProviderManager{
return $this->providerManager;

View File

@@ -32,21 +32,17 @@ abstract class Biome{
public const MAX_BIOMES = 256;
/** @var int */
private $id;
/** @var bool */
private $registered = false;
private int $id;
private bool $registered = false;
/** @var Populator[] */
private $populators = [];
private array $populators = [];
/** @var int */
private $minElevation;
/** @var int */
private $maxElevation;
private int $minElevation;
private int $maxElevation;
/** @var Block[] */
private $groundCover = [];
private array $groundCover = [];
/** @var float */
protected $rainfall = 0.5;

View File

@@ -34,7 +34,7 @@ final class BiomeRegistry{
* @var Biome[]|\SplFixedArray
* @phpstan-var \SplFixedArray<Biome>
*/
private $biomes;
private \SplFixedArray $biomes;
public function __construct(){
$this->biomes = new \SplFixedArray(Biome::MAX_BIOMES);

View File

@@ -28,9 +28,7 @@ use pocketmine\world\generator\populator\TallGrass;
use pocketmine\world\generator\populator\Tree;
class ForestBiome extends GrassyBiome{
/** @var TreeType */
private $type;
private TreeType $type;
public function __construct(?TreeType $type = null){
parent::__construct();

View File

@@ -29,9 +29,7 @@ use function str_repeat;
use function strlen;
final class BiomeArray{
/** @var string */
private $payload;
private string $payload;
/**
* @param string $payload ZZZZXXXX key bits

View File

@@ -43,8 +43,7 @@ class Chunk{
public const COORD_BIT_SIZE = SubChunk::COORD_BIT_SIZE;
public const COORD_MASK = SubChunk::COORD_MASK;
/** @var int */
private $terrainDirtyFlags = 0;
private int $terrainDirtyFlags = 0;
/** @var bool|null */
protected $lightPopulated = false;

View File

@@ -32,7 +32,7 @@ final class HeightArray{
* @var \SplFixedArray|int[]
* @phpstan-var \SplFixedArray<int>
*/
private $array;
private \SplFixedArray $array;
/**
* @param int[] $values ZZZZXXXX key bit order

View File

@@ -32,27 +32,21 @@ class SubChunk{
public const COORD_MASK = ~(~0 << self::COORD_BIT_SIZE);
public const EDGE_LENGTH = 1 << self::COORD_BIT_SIZE;
/** @var int */
private $emptyBlockId;
/** @var PalettedBlockArray[] */
private $blockLayers;
/** @var LightArray|null */
private $blockLight;
/** @var LightArray|null */
private $skyLight;
private array $blockLayers;
/**
* SubChunk constructor.
*
* @param PalettedBlockArray[] $blocks
*/
public function __construct(int $emptyBlockId, array $blocks, ?LightArray $skyLight = null, ?LightArray $blockLight = null){
$this->emptyBlockId = $emptyBlockId;
public function __construct(
private int $emptyBlockId,
array $blocks, //TODO: promote this once we can break BC again (needs a name change)
private ?LightArray $skyLight = null,
private ?LightArray $blockLight = null
){
$this->blockLayers = $blocks;
$this->skyLight = $skyLight;
$this->blockLight = $blockLight;
}
/**

View File

@@ -41,26 +41,17 @@ use function rtrim;
use const DIRECTORY_SEPARATOR;
class FormatConverter{
private string $backupPath;
private \Logger $logger;
/** @var WorldProvider */
private $oldProvider;
/** @var WritableWorldProviderManagerEntry */
private $newProvider;
/** @var string */
private $backupPath;
/** @var \Logger */
private $logger;
/** @var int */
private $chunksPerProgressUpdate;
public function __construct(WorldProvider $oldProvider, WritableWorldProviderManagerEntry $newProvider, string $backupPath, \Logger $logger, int $chunksPerProgressUpdate = 256){
$this->oldProvider = $oldProvider;
$this->newProvider = $newProvider;
public function __construct(
private WorldProvider $oldProvider,
private WritableWorldProviderManagerEntry $newProvider,
string $backupPath,
\Logger $logger,
private int $chunksPerProgressUpdate = 256
){
$this->logger = new \PrefixedLogger($logger, "World Converter: " . $this->oldProvider->getWorldData()->getName());
$this->chunksPerProgressUpdate = $chunksPerProgressUpdate;
if(!file_exists($backupPath)){
@mkdir($backupPath, 0777, true);

View File

@@ -32,9 +32,8 @@ use const SORT_NUMERIC;
final class RegionGarbageMap{
/** @var RegionLocationTableEntry[] */
private $entries = [];
/** @var bool */
private $clean = false;
private array $entries = [];
private bool $clean = false;
/**
* @param RegionLocationTableEntry[] $entries

View File

@@ -26,13 +26,9 @@ namespace pocketmine\world\format\io\region;
use function range;
class RegionLocationTableEntry{
/** @var int */
private $firstSector;
/** @var int */
private $sectorCount;
/** @var int */
private $timestamp;
private int $firstSector;
private int $sectorCount;
private int $timestamp;
/**
* @throws \InvalidArgumentException

View File

@@ -34,11 +34,9 @@ use pocketmine\world\generator\populator\Populator;
use function count;
class Flat extends Generator{
/** @var Chunk */
private $chunk;
private Chunk $chunk;
/** @var Populator[] */
private $populators = [];
private array $populators = [];
private FlatGeneratorOptions $options;

View File

@@ -26,11 +26,9 @@ namespace pocketmine\world\generator;
use function exp;
final class Gaussian{
/** @var int */
public $smoothSize;
public int $smoothSize;
/** @var float[][] */
public $kernel = [];
public array $kernel = [];
public function __construct(int $smoothSize){
$this->smoothSize = $smoothSize;

View File

@@ -37,7 +37,7 @@ final class GeneratorManager{
* @var GeneratorManagerEntry[] name => classname mapping
* @phpstan-var array<string, GeneratorManagerEntry>
*/
private $list = [];
private array $list = [];
public function __construct(){
$this->addGenerator(Flat::class, "flat", \Closure::fromCallable(function(string $preset) : ?InvalidGeneratorOptionsException{

View File

@@ -31,7 +31,7 @@ final class ThreadLocalGeneratorContext{
* @var self[]
* @phpstan-var array<int, self>
*/
private static $contexts = [];
private static array $contexts = [];
public static function register(self $context, int $worldId) : void{
self::$contexts[$worldId] = $context;
@@ -45,19 +45,11 @@ final class ThreadLocalGeneratorContext{
return self::$contexts[$worldId] ?? null;
}
/** @var Generator */
private $generator;
/** @var int */
private $worldMinY;
/** @var int */
private $worldMaxY;
public function __construct(Generator $generator, int $worldMinY, int $worldMaxY){
$this->generator = $generator;
$this->worldMinY = $worldMinY;
$this->worldMaxY = $worldMaxY;
}
public function __construct(
private Generator $generator,
private int $worldMinY,
private int $worldMaxY
){}
public function getGenerator() : Generator{ return $this->generator; }

View File

@@ -30,16 +30,14 @@ use pocketmine\world\biome\UnknownBiome;
use pocketmine\world\generator\noise\Simplex;
abstract class BiomeSelector{
/** @var Simplex */
private $temperature;
/** @var Simplex */
private $rainfall;
private Simplex $temperature;
private Simplex $rainfall;
/**
* @var Biome[]|\SplFixedArray
* @phpstan-var \SplFixedArray<Biome>
*/
private $map = null;
private \SplFixedArray $map;
public function __construct(Random $random){
$this->temperature = new Simplex($random, 2, 1 / 16, 1 / 512);

View File

@@ -38,21 +38,16 @@ use function abs;
class Nether extends Generator{
/** @var Populator[] */
private $populators = [];
/** @var int */
private $waterHeight = 32;
/** @var int */
private $emptyHeight = 64;
/** @var int */
private $emptyAmplitude = 1;
/** @var float */
private $density = 0.5;
private int $waterHeight = 32;
private int $emptyHeight = 64;
private int $emptyAmplitude = 1;
private float $density = 0.5;
/** @var Populator[] */
private $generationPopulators = [];
/** @var Simplex */
private $noiseBase;
private array $populators = [];
/** @var Populator[] */
private array $generationPopulators = [];
private Simplex $noiseBase;
/**
* @throws InvalidGeneratorOptionsException

View File

@@ -42,21 +42,14 @@ use pocketmine\world\World;
class Normal extends Generator{
private int $waterHeight = 62;
/** @var Populator[] */
private $populators = [];
/** @var int */
private $waterHeight = 62;
private array $populators = [];
/** @var Populator[] */
private $generationPopulators = [];
/** @var Simplex */
private $noiseBase;
/** @var BiomeSelector */
private $selector;
/** @var Gaussian */
private $gaussian;
private array $generationPopulators = [];
private Simplex $noiseBase;
private BiomeSelector $selector;
private Gaussian $gaussian;
/**
* @throws InvalidGeneratorOptionsException

View File

@@ -30,8 +30,7 @@ use function sin;
use const M_PI;
class Ore{
/** @var Random */
private $random;
private Random $random;
/** @var OreType */
public $type;

View File

@@ -31,7 +31,7 @@ use pocketmine\world\generator\object\OreType;
class Ore implements Populator{
/** @var OreType[] */
private $oreTypes = [];
private array $oreTypes = [];
public function populate(ChunkManager $world, int $chunkX, int $chunkZ, Random $random) : void{
foreach($this->oreTypes as $type){

View File

@@ -30,10 +30,8 @@ use pocketmine\world\ChunkManager;
use pocketmine\world\format\Chunk;
class TallGrass implements Populator{
/** @var int */
private $randomAmount = 1;
/** @var int */
private $baseAmount = 0;
private int $randomAmount = 1;
private int $baseAmount = 0;
public function setRandomAmount(int $amount) : void{
$this->randomAmount = $amount;

View File

@@ -31,13 +31,9 @@ use pocketmine\world\format\Chunk;
use pocketmine\world\generator\object\TreeFactory;
class Tree implements Populator{
/** @var int */
private $randomAmount = 1;
/** @var int */
private $baseAmount = 0;
/** @var TreeType */
private $type;
private int $randomAmount = 1;
private int $baseAmount = 0;
private TreeType $type;
/**
* @param TreeType|null $type default oak

View File

@@ -30,22 +30,18 @@ use pocketmine\world\utils\SubChunkExplorerStatus;
use function max;
class BlockLightUpdate extends LightUpdate{
/**
* @var int[]
* @phpstan-var array<int, int>
*/
private $lightEmitters;
/**
* @param int[] $lightFilters
* @param int[] $lightEmitters
* @phpstan-param array<int, int> $lightFilters
* @phpstan-param array<int, int> $lightEmitters
*/
public function __construct(SubChunkExplorer $subChunkExplorer, array $lightFilters, array $lightEmitters){
public function __construct(
SubChunkExplorer $subChunkExplorer,
array $lightFilters,
private array $lightEmitters
){
parent::__construct($subChunkExplorer, $lightFilters);
$this->lightEmitters = $lightEmitters;
}
protected function getCurrentLightArray() : LightArray{

View File

@@ -33,22 +33,18 @@ use pocketmine\world\World;
use function max;
class SkyLightUpdate extends LightUpdate{
/**
* @var true[]
* @phpstan-var array<int, true>
*/
private $directSkyLightBlockers;
/**
* @param int[] $lightFilters
* @param true[] $directSkyLightBlockers
* @phpstan-param array<int, int> $lightFilters
* @phpstan-param array<int, true> $directSkyLightBlockers
*/
public function __construct(SubChunkExplorer $subChunkExplorer, array $lightFilters, array $directSkyLightBlockers){
public function __construct(
SubChunkExplorer $subChunkExplorer,
array $lightFilters,
private array $directSkyLightBlockers
){
parent::__construct($subChunkExplorer, $lightFilters);
$this->directSkyLightBlockers = $directSkyLightBlockers;
}
protected function getCurrentLightArray() : LightArray{

View File

@@ -30,15 +30,10 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\types\LevelEvent;
class BlockBreakParticle implements Particle{
/** @var Block */
private $block;
public function __construct(Block $b){
$this->block = $b;
}
//TODO: rename this parameter when we can break BC
public function __construct(private Block $b){}
public function encode(Vector3 $pos) : array{
return [LevelEventPacket::create(LevelEvent::PARTICLE_DESTROY, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getFullId()), $pos)];
return [LevelEventPacket::create(LevelEvent::PARTICLE_DESTROY, RuntimeBlockMapping::getInstance()->toRuntimeId($this->b->getFullId()), $pos)];
}
}

View File

@@ -28,13 +28,8 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\types\ParticleIds;
class BlockForceFieldParticle implements Particle{
/** @var int */
private $data;
public function __construct(int $data = 0){
$this->data = $data; //TODO: proper encode/decode of data
}
//TODO: proper encode/decode of data
public function __construct(private int $data = 0){}
public function encode(Vector3 $pos) : array{
return [LevelEventPacket::standardParticle(ParticleIds::BLOCK_FORCE_FIELD, $this->data, $pos)];

View File

@@ -33,16 +33,10 @@ use pocketmine\network\mcpe\protocol\types\LevelEvent;
* This particle appears when a player is attacking a block face in survival mode attempting to break it.
*/
class BlockPunchParticle implements Particle{
/** @var Block */
private $block;
/** @var int */
private $face;
public function __construct(Block $block, int $face){
$this->block = $block;
$this->face = $face;
}
public function __construct(
private Block $block,
private int $face
){}
public function encode(Vector3 $pos) : array{
return [LevelEventPacket::create(LevelEvent::PARTICLE_PUNCH_BLOCK, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getFullId()) | ($this->face << 24), $pos)];

View File

@@ -28,12 +28,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\types\ParticleIds;
class CriticalParticle implements Particle{
/** @var int */
private $scale;
public function __construct(int $scale = 2){
$this->scale = $scale;
}
public function __construct(private int $scale = 2){}
public function encode(Vector3 $pos) : array{
return [LevelEventPacket::standardParticle(ParticleIds::CRITICAL, $this->scale, $pos)];

View File

@@ -30,12 +30,9 @@ use function abs;
class DragonEggTeleportParticle implements Particle{
/** @var int */
private $xDiff;
/** @var int */
private $yDiff;
/** @var int */
private $zDiff;
private int $xDiff;
private int $yDiff;
private int $zDiff;
public function __construct(int $xDiff, int $yDiff, int $zDiff){
$this->xDiff = self::boundOrThrow($xDiff);

View File

@@ -29,12 +29,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\types\ParticleIds;
class DustParticle implements Particle{
/** @var Color */
private $color;
public function __construct(Color $color){
$this->color = $color;
}
public function __construct(private Color $color){}
public function encode(Vector3 $pos) : array{
return [LevelEventPacket::standardParticle(ParticleIds::DUST, $this->color->toARGB(), $pos)];

View File

@@ -29,13 +29,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\types\ParticleIds;
class EnchantParticle implements Particle{
/** @var Color */
private $color;
public function __construct(Color $color){
$this->color = $color;
}
public function __construct(private Color $color){}
public function encode(Vector3 $pos) : array{
return [LevelEventPacket::standardParticle(ParticleIds::MOB_SPELL, $this->color->toARGB(), $pos)];

View File

@@ -28,12 +28,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\types\ParticleIds;
class HeartParticle implements Particle{
/** @var int */
private $scale;
public function __construct(int $scale = 0){
$this->scale = $scale;
}
public function __construct(private int $scale = 0){}
public function encode(Vector3 $pos) : array{
return [LevelEventPacket::standardParticle(ParticleIds::HEART, $this->scale, $pos)];

View File

@@ -28,12 +28,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\types\ParticleIds;
class InkParticle implements Particle{
/** @var int */
private $scale;
public function __construct(int $scale = 0){
$this->scale = $scale;
}
public function __construct(private int $scale = 0){}
public function encode(Vector3 $pos) : array{
return [LevelEventPacket::standardParticle(ParticleIds::INK, $this->scale, $pos)];

View File

@@ -29,12 +29,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\types\ParticleIds;
class InstantEnchantParticle implements Particle{
/** @var Color */
private $color;
public function __construct(Color $color){
$this->color = $color;
}
public function __construct(private Color $color){}
public function encode(Vector3 $pos) : array{
return [LevelEventPacket::standardParticle(ParticleIds::MOB_SPELL_INSTANTANEOUS, $this->color->toARGB(), $pos)];

View File

@@ -29,12 +29,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\types\ParticleIds;
class ItemBreakParticle implements Particle{
/** @var Item */
private $item;
public function __construct(Item $item){
$this->item = $item;
}
public function __construct(private Item $item){}
public function encode(Vector3 $pos) : array{
return [LevelEventPacket::standardParticle(ParticleIds::ITEM_BREAK, ($this->item->getId() << 16) | $this->item->getMeta(), $pos)];

View File

@@ -29,13 +29,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\types\LevelEvent;
class PotionSplashParticle implements Particle{
/** @var Color */
private $color;
public function __construct(Color $color){
$this->color = $color;
}
public function __construct(private Color $color){}
/**
* Returns the default water-bottle splash colour.

View File

@@ -28,12 +28,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\types\ParticleIds;
class RedstoneParticle implements Particle{
/** @var int */
private $lifetime;
public function __construct(int $lifetime = 1){
$this->lifetime = $lifetime;
}
public function __construct(private int $lifetime = 1){}
public function encode(Vector3 $pos) : array{
return [LevelEventPacket::standardParticle(ParticleIds::REDSTONE, $this->lifetime, $pos)];

View File

@@ -28,12 +28,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\types\ParticleIds;
class SmokeParticle implements Particle{
/** @var int */
private $scale;
public function __construct(int $scale = 0){
$this->scale = $scale;
}
public function __construct(private int $scale = 0){}
public function encode(Vector3 $pos) : array{
return [LevelEventPacket::standardParticle(ParticleIds::SMOKE, $this->scale, $pos)];

View File

@@ -30,14 +30,9 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\types\ParticleIds;
class TerrainParticle implements Particle{
/** @var Block */
private $block;
public function __construct(Block $b){
$this->block = $b;
}
public function __construct(private Block $b){}
public function encode(Vector3 $pos) : array{
return [LevelEventPacket::standardParticle(ParticleIds::TERRAIN, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getFullId()), $pos)];
return [LevelEventPacket::standardParticle(ParticleIds::TERRAIN, RuntimeBlockMapping::getInstance()->toRuntimeId($this->b->getFullId()), $pos)];
}
}

View File

@@ -30,13 +30,7 @@ use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\network\mcpe\protocol\types\LevelSoundEvent;
class BlockBreakSound implements Sound{
/** @var Block */
private $block;
public function __construct(Block $block){
$this->block = $block;
}
public function __construct(private Block $block){}
public function encode(Vector3 $pos) : array{
return [LevelSoundEventPacket::nonActorSound(LevelSoundEvent::BREAK, $pos, false, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getFullId()))];

View File

@@ -30,13 +30,7 @@ use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\network\mcpe\protocol\types\LevelSoundEvent;
class BlockPlaceSound implements Sound{
/** @var Block */
private $block;
public function __construct(Block $block){
$this->block = $block;
}
public function __construct(private Block $block){}
public function encode(Vector3 $pos) : array{
return [LevelSoundEventPacket::nonActorSound(LevelSoundEvent::PLACE, $pos, false, RuntimeBlockMapping::getInstance()->toRuntimeId($this->block->getFullId()))];

View File

@@ -33,13 +33,7 @@ use pocketmine\network\mcpe\protocol\types\LevelSoundEvent;
* Played when a player attacks a block in survival, attempting to break it.
*/
class BlockPunchSound implements Sound{
/** @var Block */
private $block;
public function __construct(Block $block){
$this->block = $block;
}
public function __construct(private Block $block){}
public function encode(Vector3 $pos) : array{
return [LevelSoundEventPacket::nonActorSound(

View File

@@ -28,13 +28,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\types\LevelEvent;
class ClickSound implements Sound{
/** @var float */
private $pitch;
public function __construct(float $pitch = 0){
$this->pitch = $pitch;
}
public function __construct(private float $pitch = 0){}
public function getPitch() : float{
return $this->pitch;

View File

@@ -28,13 +28,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\types\LevelEvent;
class DoorSound implements Sound{
/** @var float */
private $pitch;
public function __construct(float $pitch = 0){
$this->pitch = $pitch;
}
public function __construct(private float $pitch = 0){}
public function getPitch() : float{
return $this->pitch;

View File

@@ -34,16 +34,10 @@ use pocketmine\network\mcpe\protocol\types\LevelSoundEvent;
* Played when an entity hits the ground after falling a distance that doesn't cause damage, e.g. due to jumping.
*/
class EntityLandSound implements Sound{
/** @var Entity */
private $entity;
/** @var Block */
private $blockLandedOn;
public function __construct(Entity $entity, Block $blockLandedOn){
$this->entity = $entity;
$this->blockLandedOn = $blockLandedOn;
}
public function __construct(
private Entity $entity,
private Block $blockLandedOn
){}
public function encode(Vector3 $pos) : array{
return [LevelSoundEventPacket::create(

View File

@@ -33,13 +33,7 @@ use pocketmine\network\mcpe\protocol\types\LevelSoundEvent;
* This is the bone-breaker "crunch" sound.
*/
class EntityLongFallSound implements Sound{
/** @var Entity */
private $entity;
public function __construct(Entity $entity){
$this->entity = $entity;
}
public function __construct(private Entity $entity){}
public function encode(Vector3 $pos) : array{
return [LevelSoundEventPacket::create(

View File

@@ -32,13 +32,7 @@ use pocketmine\network\mcpe\protocol\types\LevelSoundEvent;
* Played when an entity hits the ground after falling a short distance.
*/
class EntityShortFallSound implements Sound{
/** @var Entity */
private $entity;
public function __construct(Entity $entity){
$this->entity = $entity;
}
public function __construct(private Entity $entity){}
public function encode(Vector3 $pos) : array{
return [LevelSoundEventPacket::create(

View File

@@ -28,13 +28,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\types\LevelEvent;
class FizzSound implements Sound{
/** @var float */
private $pitch;
public function __construct(float $pitch = 0){
$this->pitch = $pitch;
}
public function __construct(private float $pitch = 0){}
public function getPitch() : float{
return $this->pitch;

View File

@@ -28,13 +28,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\types\LevelEvent;
class LaunchSound implements Sound{
/** @var float */
private $pitch;
public function __construct(float $pitch = 0){
$this->pitch = $pitch;
}
public function __construct(private float $pitch = 0){}
public function getPitch() : float{
return $this->pitch;

View File

@@ -52,12 +52,11 @@ final class NoteInstrument{
);
}
/** @var int */
private $magicNumber;
private function __construct(string $name, int $magicNumber){
private function __construct(
string $name,
private int $magicNumber
){
$this->Enum___construct($name);
$this->magicNumber = $magicNumber;
}
public function getMagicNumber() : int{

View File

@@ -28,18 +28,13 @@ use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
use pocketmine\network\mcpe\protocol\types\LevelSoundEvent;
class NoteSound implements Sound{
/** @var NoteInstrument */
private $instrument;
/** @var int */
private $note;
public function __construct(NoteInstrument $instrument, int $note){
if($note < 0 || $note > 255){
public function __construct(
private NoteInstrument $instrument,
private int $note
){
if($this->note < 0 || $this->note > 255){
throw new \InvalidArgumentException("Note $note is outside accepted range");
}
$this->instrument = $instrument;
$this->note = $note;
}
public function encode(Vector3 $pos) : array{

View File

@@ -28,13 +28,7 @@ use pocketmine\network\mcpe\protocol\LevelEventPacket;
use pocketmine\network\mcpe\protocol\types\LevelEvent;
class PopSound implements Sound{
/** @var float */
private $pitch;
public function __construct(float $pitch = 0){
$this->pitch = $pitch;
}
public function __construct(private float $pitch = 0){}
public function getPitch() : float{
return $this->pitch;

View File

@@ -28,13 +28,7 @@ use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
class RecordSound implements Sound{
/** @var RecordType */
private $recordType;
public function __construct(RecordType $recordType){
$this->recordType = $recordType;
}
public function __construct(private RecordType $recordType){}
public function encode(Vector3 $pos) : array{
return [LevelSoundEventPacket::nonActorSound($this->recordType->getSoundId(), $pos, false)];

View File

@@ -30,13 +30,7 @@ use function intdiv;
use function min;
class XpLevelUpSound implements Sound{
/** @var int */
private $xpLevel;
public function __construct(int $xpLevel){
$this->xpLevel = $xpLevel;
}
public function __construct(private int $xpLevel){}
public function getXpLevel() : int{
return $this->xpLevel;