I am throwing a snowball and I want to spawn flame particles on the entity. My idea is a task that you foreach all the entities of a world and you check if the entity is a snowball. Then you spawn the particle in the position of the snowball entity. My question is: how to get all the entities of a world? Will my idea work?
you can just overwrite the entity you fire out there's an onupdate function on the entity which you can place particles which is way better than a task
Well, in that case I'd say you go with @Thunder33345's approach. Register a custom snowball entity that overrides and extends PocketMine's snowball entity class, then extend the onUpdate() method.
Ok, that's what my friend used: PHP: <?phpnamespace BattleGround\Arena;use BattleGround\BattleGround;use pocketmine\scheduler\PluginTask;use pocketmine\Server;use pocketmine\utils\Config;use pocketmine\level\particle\FlameParticle;use pocketmine\entity\Snowball;use pocketmine\math\Vector3;class FlameParticles extends PluginTask { public function __construct(BattleGround $plugin) { $this->plugin = $plugin; parent::__construct($plugin); } public function onRun($tick) { foreach($this->plugin->getServer()->getLevels() as $level) { foreach (glob($this->plugin->getDataFolder() . "arenas/*.yml") as $file) { $arena = new Config($file, Config::YAML); $fname = $arena->get("arena_name"); if($level->getFolderName() == $fname) { foreach($this->plugin->getServer()->getEntities() as $entity) { if($entity instanceof Snowball){ $level->addParticle(new FlameParticle(new Vector3($entity->x, $entity->y, $entity->z))); } } } } } }}