diff --git a/src/block/TNT.php b/src/block/TNT.php index da57818a84..a07634d54d 100644 --- a/src/block/TNT.php +++ b/src/block/TNT.php @@ -32,7 +32,6 @@ use pocketmine\item\enchantment\Enchantment; use pocketmine\item\FlintSteel; use pocketmine\item\Item; use pocketmine\math\Vector3; -use pocketmine\nbt\tag\CompoundTag; use pocketmine\player\Player; use pocketmine\utils\Random; use function cos; @@ -95,7 +94,7 @@ class TNT extends Opaque{ $mot = (new Random())->nextSignedFloat() * M_PI * 2; - $tnt = new PrimedTNT(Location::fromObject($this->pos->add(0.5, 0, 0.5), $this->pos->getWorldNonNull()), new CompoundTag()); + $tnt = new PrimedTNT(Location::fromObject($this->pos->add(0.5, 0, 0.5), $this->pos->getWorldNonNull())); $tnt->setFuse($fuse); $tnt->setMotion(new Vector3(-sin($mot) * 0.02, 0.2, -cos($mot) * 0.02)); diff --git a/src/block/utils/FallableTrait.php b/src/block/utils/FallableTrait.php index fe88647672..be51117a0a 100644 --- a/src/block/utils/FallableTrait.php +++ b/src/block/utils/FallableTrait.php @@ -31,7 +31,6 @@ use pocketmine\block\VanillaBlocks; use pocketmine\entity\Location; use pocketmine\entity\object\FallingBlock; use pocketmine\math\Facing; -use pocketmine\nbt\tag\CompoundTag; use pocketmine\utils\AssumptionFailedError; use pocketmine\world\Position; @@ -57,7 +56,7 @@ trait FallableTrait{ $block = $this; if(!($block instanceof Block)) throw new AssumptionFailedError(__TRAIT__ . " should only be used by Blocks"); - $fall = new FallingBlock(Location::fromObject($pos->add(0.5, 0, 0.5), $pos->getWorldNonNull()), $block, new CompoundTag()); + $fall = new FallingBlock(Location::fromObject($pos->add(0.5, 0, 0.5), $pos->getWorldNonNull()), $block); $fall->spawnToAll(); } } diff --git a/src/entity/Entity.php b/src/entity/Entity.php index b40977450c..f44ba784cb 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -213,7 +213,7 @@ abstract class Entity{ /** @var int|null */ protected $targetId = null; - public function __construct(Location $location, CompoundTag $nbt){ + public function __construct(Location $location, ?CompoundTag $nbt = null){ $this->timings = Timings::getEntityTimings($this); $this->temporalVector = new Vector3(); @@ -241,7 +241,7 @@ abstract class Entity{ } $this->motion = new Vector3(0, 0, 0); - if($nbt->hasTag("Motion", ListTag::class)){ + if($nbt !== null and $nbt->hasTag("Motion", ListTag::class)){ /** @var float[] $motion */ $motion = $nbt->getListTag("Motion")->getAllValues(); $this->setMotion($this->temporalVector->setComponents(...$motion)); @@ -254,7 +254,7 @@ abstract class Entity{ $this->attributeMap = new AttributeMap(); $this->addAttributes(); - $this->initEntity($nbt); + $this->initEntity($nbt ?? new CompoundTag()); $this->chunk->addEntity($this); $this->getWorld()->addEntity($this); diff --git a/src/entity/Human.php b/src/entity/Human.php index 77b37d618f..04c5a38e40 100644 --- a/src/entity/Human.php +++ b/src/entity/Human.php @@ -93,7 +93,7 @@ class Human extends Living implements ProjectileSource, InventoryHolder{ protected $baseOffset = 1.62; - public function __construct(Location $location, Skin $skin, CompoundTag $nbt){ + public function __construct(Location $location, Skin $skin, ?CompoundTag $nbt = null){ $this->skin = $skin; parent::__construct($location, $nbt); } diff --git a/src/entity/object/FallingBlock.php b/src/entity/object/FallingBlock.php index fef9b434ac..a3d78e785e 100644 --- a/src/entity/object/FallingBlock.php +++ b/src/entity/object/FallingBlock.php @@ -55,7 +55,7 @@ class FallingBlock extends Entity{ public $canCollide = false; - public function __construct(Location $location, Block $block, CompoundTag $nbt){ + public function __construct(Location $location, Block $block, ?CompoundTag $nbt = null){ $this->block = $block; parent::__construct($location, $nbt); } diff --git a/src/entity/object/ItemEntity.php b/src/entity/object/ItemEntity.php index 778a363fa0..3c835c0f4a 100644 --- a/src/entity/object/ItemEntity.php +++ b/src/entity/object/ItemEntity.php @@ -65,7 +65,7 @@ class ItemEntity extends Entity{ /** @var int */ protected $despawnDelay = self::DEFAULT_DESPAWN_DELAY; - public function __construct(Location $location, Item $item, CompoundTag $nbt){ + public function __construct(Location $location, Item $item, ?CompoundTag $nbt = null){ if($item->isNull()){ throw new \InvalidArgumentException("Item entity must have a non-air item with a count of at least 1"); } diff --git a/src/entity/object/Painting.php b/src/entity/object/Painting.php index ac69cd3a04..9282199f10 100644 --- a/src/entity/object/Painting.php +++ b/src/entity/object/Painting.php @@ -73,7 +73,7 @@ class Painting extends Entity{ /** @var string */ protected $motive; - public function __construct(Location $location, Vector3 $blockIn, int $facing, PaintingMotive $motive, CompoundTag $nbt){ + public function __construct(Location $location, Vector3 $blockIn, int $facing, PaintingMotive $motive, ?CompoundTag $nbt = null){ $this->motive = $motive->getName(); //TODO: use motive directly $this->blockIn = $blockIn->asVector3(); $this->facing = $facing; diff --git a/src/entity/projectile/Arrow.php b/src/entity/projectile/Arrow.php index a5b631cc53..d94679747e 100644 --- a/src/entity/projectile/Arrow.php +++ b/src/entity/projectile/Arrow.php @@ -71,7 +71,7 @@ class Arrow extends Projectile{ /** @var bool */ protected $critical = false; - public function __construct(Location $location, ?Entity $shootingEntity, bool $critical, CompoundTag $nbt){ + public function __construct(Location $location, ?Entity $shootingEntity, bool $critical, ?CompoundTag $nbt = null){ parent::__construct($location, $shootingEntity, $nbt); $this->setCritical($critical); } diff --git a/src/entity/projectile/Projectile.php b/src/entity/projectile/Projectile.php index 9f2dee5c8a..f4aa9aa1b3 100644 --- a/src/entity/projectile/Projectile.php +++ b/src/entity/projectile/Projectile.php @@ -57,7 +57,7 @@ abstract class Projectile extends Entity{ /** @var Block|null */ protected $blockHit; - public function __construct(Location $location, ?Entity $shootingEntity, CompoundTag $nbt){ + public function __construct(Location $location, ?Entity $shootingEntity, ?CompoundTag $nbt = null){ parent::__construct($location, $nbt); if($shootingEntity !== null){ $this->setOwningEntity($shootingEntity); diff --git a/src/item/Bow.php b/src/item/Bow.php index d54d194d8c..0f68e1410e 100644 --- a/src/item/Bow.php +++ b/src/item/Bow.php @@ -29,7 +29,6 @@ use pocketmine\entity\projectile\Projectile; use pocketmine\event\entity\EntityShootBowEvent; use pocketmine\event\entity\ProjectileLaunchEvent; use pocketmine\item\enchantment\Enchantment; -use pocketmine\nbt\tag\CompoundTag; use pocketmine\player\Player; use pocketmine\world\sound\BowShootSound; use function intdiv; @@ -62,7 +61,7 @@ class Bow extends Tool{ $player->getWorld(), ($location->yaw > 180 ? 360 : 0) - $location->yaw, -$location->pitch - ), $player, $baseForce >= 1, new CompoundTag()); + ), $player, $baseForce >= 1); $entity->setMotion($player->getDirectionVector()); $infinity = $this->hasEnchantment(Enchantment::INFINITY()); diff --git a/src/item/ItemFactory.php b/src/item/ItemFactory.php index 23b63f604f..e06094da1c 100644 --- a/src/item/ItemFactory.php +++ b/src/item/ItemFactory.php @@ -319,17 +319,17 @@ class ItemFactory{ //TODO: the meta values should probably be hardcoded; they won't change, but the EntityLegacyIds might $this->register(new class(ItemIds::SPAWN_EGG, EntityLegacyIds::ZOMBIE, "Zombie Spawn Egg") extends SpawnEgg{ protected function createEntity(World $world, Vector3 $pos, float $yaw, float $pitch) : Entity{ - return new Zombie(Location::fromObject($pos, $world, $yaw, $pitch), new CompoundTag()); + return new Zombie(Location::fromObject($pos, $world, $yaw, $pitch)); } }); $this->register(new class(ItemIds::SPAWN_EGG, EntityLegacyIds::SQUID, "Squid Spawn Egg") extends SpawnEgg{ public function createEntity(World $world, Vector3 $pos, float $yaw, float $pitch) : Entity{ - return new Squid(Location::fromObject($pos, $world, $yaw, $pitch), new CompoundTag()); + return new Squid(Location::fromObject($pos, $world, $yaw, $pitch)); } }); $this->register(new class(ItemIds::SPAWN_EGG, EntityLegacyIds::VILLAGER, "Villager Spawn Egg") extends SpawnEgg{ public function createEntity(World $world, Vector3 $pos, float $yaw, float $pitch) : Entity{ - return new Villager(Location::fromObject($pos, $world, $yaw, $pitch), new CompoundTag()); + return new Villager(Location::fromObject($pos, $world, $yaw, $pitch)); } }); } diff --git a/src/item/PaintingItem.php b/src/item/PaintingItem.php index c4442a8f94..6c6b1f25e4 100644 --- a/src/item/PaintingItem.php +++ b/src/item/PaintingItem.php @@ -29,7 +29,6 @@ use pocketmine\entity\object\Painting; use pocketmine\entity\object\PaintingMotive; use pocketmine\math\Facing; use pocketmine\math\Vector3; -use pocketmine\nbt\tag\CompoundTag; use pocketmine\player\Player; use pocketmine\world\sound\PaintingPlaceSound; use function array_rand; @@ -76,7 +75,7 @@ class PaintingItem extends Item{ $replacePos = $blockReplace->getPos(); $clickedPos = $blockClicked->getPos(); - $entity = new Painting(Location::fromObject($replacePos, $replacePos->getWorldNonNull()), $clickedPos, $face, $motive, new CompoundTag()); + $entity = new Painting(Location::fromObject($replacePos, $replacePos->getWorldNonNull()), $clickedPos, $face, $motive); $this->pop(); $entity->spawnToAll(); diff --git a/src/player/Player.php b/src/player/Player.php index ec67c09e54..9c3abb9c77 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -295,7 +295,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, $world->registerChunkListener($this, $spawn->getFloorX() >> 4, $spawn->getFloorZ() >> 4); $this->usedChunks[World::chunkHash($spawn->getFloorX() >> 4, $spawn->getFloorZ() >> 4)] = UsedChunkStatus::NEEDED(); - parent::__construct($spawn, $this->playerInfo->getSkin(), $namedtag ?? new CompoundTag()); + parent::__construct($spawn, $this->playerInfo->getSkin(), $namedtag); $this->onGround = $onGround; //TODO: this hack is needed for new players in-air ticks - they don't get detected as on-ground until they move $ev = new PlayerLoginEvent($this, "Plugin reason"); diff --git a/src/world/World.php b/src/world/World.php index 2154b94cca..1b29d812fd 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -52,7 +52,6 @@ use pocketmine\item\ItemUseResult; use pocketmine\item\LegacyStringToItemParser; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Vector3; -use pocketmine\nbt\tag\CompoundTag; use pocketmine\network\mcpe\protocol\BlockActorDataPacket; use pocketmine\network\mcpe\protocol\ClientboundPacket; use pocketmine\network\mcpe\protocol\UpdateBlockPacket; @@ -1386,7 +1385,7 @@ class World implements ChunkManager{ return null; } - $itemEntity = new ItemEntity(Location::fromObject($source, $this, lcg_value() * 360, 0), $item, new CompoundTag()); + $itemEntity = new ItemEntity(Location::fromObject($source, $this, lcg_value() * 360, 0), $item); $itemEntity->setPickupDelay($delay); $itemEntity->setMotion($motion ?? new Vector3(lcg_value() * 0.2 - 0.1, 0.2, lcg_value() * 0.2 - 0.1)); @@ -1405,7 +1404,7 @@ class World implements ChunkManager{ $orbs = []; foreach(ExperienceOrb::splitIntoOrbSizes($amount) as $split){ - $orb = new ExperienceOrb(Location::fromObject($pos, $this,lcg_value() * 360, 0), new CompoundTag()); + $orb = new ExperienceOrb(Location::fromObject($pos, $this, lcg_value() * 360, 0)); $orb->setXpValue($split); $orb->setMotion($this->temporalVector->setComponents((lcg_value() * 0.2 - 0.1) * 2, lcg_value() * 0.4, (lcg_value() * 0.2 - 0.1) * 2));