diff --git a/src/entity/EntityFactory.php b/src/entity/EntityFactory.php index 4724e4ebc..f40c7ce35 100644 --- a/src/entity/EntityFactory.php +++ b/src/entity/EntityFactory.php @@ -41,6 +41,7 @@ use pocketmine\entity\projectile\ExperienceBottle; use pocketmine\entity\projectile\Snowball; use pocketmine\entity\projectile\SplashPotion; use pocketmine\item\Item; +use pocketmine\item\Potion; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\nbt\NbtDataException; @@ -147,7 +148,8 @@ final class EntityFactory{ }, ['Snowball', 'minecraft:snowball'], EntityLegacyIds::SNOWBALL); $this->register(SplashPotion::class, function(World $world, CompoundTag $nbt) : SplashPotion{ - return new SplashPotion(EntityDataHelper::parseLocation($nbt, $world), null, $nbt); + $potionType = $nbt->getShort("PotionId", Potion::WATER); + return new SplashPotion(EntityDataHelper::parseLocation($nbt, $world), null, $potionType, $nbt); }, ['ThrownPotion', 'minecraft:potion', 'thrownpotion'], EntityLegacyIds::SPLASH_POTION); $this->register(Squid::class, function(World $world, CompoundTag $nbt) : Squid{ diff --git a/src/entity/projectile/SplashPotion.php b/src/entity/projectile/SplashPotion.php index 7fea391af..8cde81282 100644 --- a/src/entity/projectile/SplashPotion.php +++ b/src/entity/projectile/SplashPotion.php @@ -28,7 +28,9 @@ use pocketmine\block\VanillaBlocks; use pocketmine\color\Color; use pocketmine\entity\effect\EffectInstance; use pocketmine\entity\effect\InstantEffect; +use pocketmine\entity\Entity; use pocketmine\entity\Living; +use pocketmine\entity\Location; use pocketmine\event\entity\ProjectileHitBlockEvent; use pocketmine\event\entity\ProjectileHitEntityEvent; use pocketmine\event\entity\ProjectileHitEvent; @@ -54,12 +56,11 @@ class SplashPotion extends Throwable{ /** @var bool */ protected $linger = false; /** @var int */ - protected $potionId = Potion::WATER; + protected $potionId; - protected function initEntity(CompoundTag $nbt) : void{ - parent::initEntity($nbt); - - $this->setPotionId($nbt->getShort("PotionId", Potion::WATER)); + public function __construct(Location $location, ?Entity $shootingEntity, int $potionId, ?CompoundTag $nbt = null){ + $this->potionId = $potionId; + parent::__construct($location, $shootingEntity, $nbt); } public function saveNBT() : CompoundTag{ diff --git a/src/item/SplashPotion.php b/src/item/SplashPotion.php index 72d553e2f..b1330875a 100644 --- a/src/item/SplashPotion.php +++ b/src/item/SplashPotion.php @@ -43,9 +43,7 @@ class SplashPotion extends ProjectileItem{ } protected function createEntity(Location $location, Player $thrower) : Throwable{ - $projectile = new SplashPotionEntity($location, $thrower); - $projectile->setPotionId($this->potionId); - return $projectile; + return new SplashPotionEntity($location, $thrower, $this->potionId); } public function getThrowForce() : float{