Inheritance: extends EntityEvent
Esempio n. 1
0
 public function onSpawn(EntitySpawnEvent $ev)
 {
     if ($ev->getEntity() instanceof Creature && !$ev->getEntity() instanceof Player) {
         $ev->getEntity()->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_NO_AI, true);
         $this->getLevel()->getServer()->broadcastPopup(TextFormat::RED . "Mob AI isn't implemented yet!");
     }
 }
Esempio n. 2
0
 public function onEntitySpawn(EntitySpawnEvent $event)
 {
     $e = $event->getEntity();
     if ($e instanceof Item && $this->ce["Item"] < 300 || $e instanceof Arrow && $this->ce["Item"] < 60) {
         $this->getServer()->getScheduler()->scheduleDelayedTask(new CallbackTask([$this, "kill"], [$e]), $this->ce[$e instanceof Item ? "Item" : "Arrow"] * 20);
     }
 }
Esempio n. 3
0
 public function onEntitySpawn(EntitySpawnEvent $ev)
 {
     $entity = $ev->getEntity();
     if ($entity instanceof SlapperEntity) {
         $clearLagg = $this->getServer()->getPluginManager()->getPlugin("ClearLagg");
         if ($clearLagg === null) {
             return;
         }
         $clearLagg->exemptEntity($entity);
     }
 }
Esempio n. 4
0
 public function onEntitySpawn(EntitySpawnEvent $event)
 {
     $e = $event->getEntity();
     if ($e instanceof Item || $e instanceof Arrow) {
         $this->getServer()->getScheduler()->scheduleDelayedTask(new CallbackTask([$this, "kill"], [$e]), $this->clearEntities->get($e instanceof Arrow ? "Arrow" : "Item") * 20);
     }
 }
Esempio n. 5
0
 public function EntitySpawnEvent(EntitySpawnEvent $ev)
 {
     $entity = $ev->getEntity();
     if (is_a($entity, BaseEntity::class, true) && !$entity->closed) {
         self::$entities[$entity->getId()] = $entity;
     }
 }
Esempio n. 6
0
 public function onUpdate()
 {
     if ($this->closed === true) {
         return false;
     }
     $this->timings->startTiming();
     if (!$this->chunk instanceof FullChunk) {
         return false;
     }
     if ($this->canUpdate()) {
         if ($this->getDelay() == 0) {
             $success = 0;
             for ($i = 0; $i < $this->getSpawnCount(); $i++) {
                 $pos = $this->add(mt_rand() / mt_getrandmax() * $this->getSpawnRange(), mt_rand(-1, 1), mt_rand() / mt_getrandmax() * $this->getSpawnRange());
                 $target = $this->getLevel()->getBlock($pos);
                 $ground = $target->getSide(Vector3::SIDE_DOWN);
                 if ($target->getId() == Item::AIR && $ground->isTopFacingSurfaceSolid()) {
                     $success++;
                     #$this->getLevel()->getServer()->getPluginManager()->callEvent($ev = new EntityGenerateEvent($pos, $this->getEntityId(), EntityGenerateEvent::CAUSE_MOB_SPAWNER));
                     $nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $pos->x), new DoubleTag("", $pos->y), new DoubleTag("", $pos->z)]), "Motion" => new ListTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", mt_rand() / mt_getrandmax() * 360), new FloatTag("", 0)])]);
                     $entity = Entity::createEntity($this->getEntityId(), $this->chunk, $nbt);
                     $this->getLevel()->getServer()->getPluginManager()->callEvent($ev = new EntitySpawnEvent($entity));
                     if (!$ev->isCancelled()) {
                         $entity->spawnToAll();
                     }
                 }
             }
             if ($success > 0) {
                 $this->setDelay(mt_rand($this->getMinSpawnDelay(), $this->getMaxSpawnDelay()));
             }
         } else {
             $this->setDelay($this->getDelay() - 1);
         }
     }
     $this->timings->stopTiming();
     return true;
 }