public function onUpdate($currentTick) { if ($this->closed) { return false; } $this->timings->startTiming(); $hasUpdate = parent::onUpdate($currentTick); if (!$this->hadCollision and $this->isCritical) { $this->level->addParticle(new CriticalParticle($this->add($this->width / 2 + mt_rand(-100, 100) / 500, $this->height / 2 + mt_rand(-100, 100) / 500, $this->width / 2 + mt_rand(-100, 100) / 500))); } elseif ($this->onGround) { $this->isCritical = false; } if ($this->potionId != 0) { if (!$this->onGround or $this->onGround and $currentTick % 4 == 0) { $color = Potion::getColor($this->potionId - 1); $this->level->addParticle(new MobSpellParticle($this->add($this->width / 2 + mt_rand(-100, 100) / 500, $this->height / 2 + mt_rand(-100, 100) / 500, $this->width / 2 + mt_rand(-100, 100) / 500), $color[0], $color[1], $color[2])); } $hasUpdate = true; } if ($this->age > 1200) { $this->kill(); $hasUpdate = true; } $this->timings->stopTiming(); return $hasUpdate; }
public function kill() { $color = Potion::getColor($this->getPotionId()); $this->getLevel()->addParticle(new SpellParticle($this, $color[0], $color[1], $color[2])); $players = $this->getViewers(); foreach ($players as $p) { if ($p->distance($this) <= 6) { foreach (Potion::getEffectsById($this->getPotionId()) as $effect) { $p->addEffect($effect); } } } parent::kill(); }
public function kill() { $color = Potion::getColor($this->getData()); $this->getLevel()->addParticle(new SpellParticle($this, $color[0], $color[1], $color[2])); $players = $this->getViewers(); foreach ($players as $p) { if ($p->distance($this) <= 6) { switch ($this->getData()) { case Potion::NIGHT_VISION: $p->addEffect(Effect::getEffect(Effect::NIGHT_VISION)->setAmplifier(0)->setDuration(3 * 60 * 20)); break; case Potion::NIGHT_VISION_T: $p->addEffect(Effect::getEffect(Effect::NIGHT_VISION)->setAmplifier(0)->setDuration(8 * 60 * 20)); break; case Potion::INVISIBILITY: $p->addEffect(Effect::getEffect(Effect::INVISIBILITY)->setAmplifier(0)->setDuration(3 * 60 * 20)); break; case Potion::INVISIBILITY_T: $p->addEffect(Effect::getEffect(Effect::INVISIBILITY)->setAmplifier(0)->setDuration(8 * 60 * 20)); break; case Potion::LEAPING: $p->addEffect(Effect::getEffect(Effect::JUMP)->setAmplifier(0)->setDuration(3 * 60 * 20)); break; case Potion::LEAPING_T: $p->addEffect(Effect::getEffect(Effect::JUMP)->setAmplifier(0)->setDuration(8 * 60 * 20)); break; case Potion::LEAPING_TWO: $p->addEffect(Effect::getEffect(Effect::JUMP)->setAmplifier(1)->setDuration(1.5 * 60 * 20)); break; case Potion::FIRE_RESISTANCE: $p->addEffect(Effect::getEffect(Effect::FIRE_RESISTANCE)->setAmplifier(0)->setDuration(3 * 60 * 20)); break; case Potion::FIRE_RESISTANCE_T: $p->addEffect(Effect::getEffect(Effect::FIRE_RESISTANCE)->setAmplifier(0)->setDuration(8 * 60 * 20)); break; case Potion::SPEED: $p->addEffect(Effect::getEffect(Effect::SPEED)->setAmplifier(0)->setDuration(3 * 60 * 20)); break; case Potion::SPEED_T: $p->addEffect(Effect::getEffect(Effect::SPEED)->setAmplifier(0)->setDuration(8 * 60 * 20)); break; case Potion::SPEED_TWO: $p->addEffect(Effect::getEffect(Effect::SPEED)->setAmplifier(1)->setDuration(1.5 * 60 * 20)); break; case Potion::SLOWNESS: $p->addEffect(Effect::getEffect(Effect::SLOWNESS)->setAmplifier(0)->setDuration(1 * 60 * 20)); break; case Potion::SLOWNESS_T: $p->addEffect(Effect::getEffect(Effect::SLOWNESS)->setAmplifier(0)->setDuration(4 * 60 * 20)); break; case Potion::WATER_BREATHING: $p->addEffect(Effect::getEffect(Effect::WATER_BREATHING)->setAmplifier(0)->setDuration(3 * 60 * 20)); break; case Potion::WATER_BREATHING_T: $p->addEffect(Effect::getEffect(Effect::WATER_BREATHING)->setAmplifier(0)->setDuration(8 * 60 * 20)); break; case Potion::POISON: $p->addEffect(Effect::getEffect(Effect::POISON)->setAmplifier(0)->setDuration(45 * 20)); break; case Potion::POISON_T: $p->addEffect(Effect::getEffect(Effect::POISON)->setAmplifier(0)->setDuration(2 * 60 * 20)); break; case Potion::POISON_TWO: $p->addEffect(Effect::getEffect(Effect::POISON)->setAmplifier(0)->setDuration(22 * 20)); break; case Potion::REGENERATION: $p->addEffect(Effect::getEffect(Effect::REGENERATION)->setAmplifier(0)->setDuration(45 * 20)); break; case Potion::REGENERATION_T: $p->addEffect(Effect::getEffect(Effect::REGENERATION)->setAmplifier(0)->setDuration(2 * 60 * 20)); break; case Potion::REGENERATION_TWO: $p->addEffect(Effect::getEffect(Effect::REGENERATION)->setAmplifier(1)->setDuration(22 * 20)); break; case Potion::STRENGTH: $p->addEffect(Effect::getEffect(Effect::STRENGTH)->setAmplifier(0)->setDuration(3 * 60 * 20)); break; case Potion::STRENGTH_T: $p->addEffect(Effect::getEffect(Effect::STRENGTH)->setAmplifier(0)->setDuration(8 * 60 * 20)); break; case Potion::STRENGTH_TWO: $p->addEffect(Effect::getEffect(Effect::STRENGTH)->setAmplifier(1)->setDuration(1.5 * 60 * 20)); break; case Potion::WEAKNESS: $p->addEffect(Effect::getEffect(Effect::WEAKNESS)->setAmplifier(0)->setDuration(1.5 * 60 * 20)); break; case Potion::WEAKNESS_T: $p->addEffect(Effect::getEffect(Effect::WEAKNESS)->setAmplifier(0)->setDuration(4 * 60 * 20)); break; case Potion::HEALING: $p->addEffect(Effect::getEffect(Effect::HEALING)->setAmplifier(0)->setDuration(1)); break; case Potion::HEALING_TWO: $p->addEffect(Effect::getEffect(Effect::HEALING)->setAmplifier(1)->setDuration(1)); break; case Potion::HARMING: $p->addEffect(Effect::getEffect(Effect::HARMING)->setAmplifier(0)->setDuration(1)); break; case Potion::HARMING_TWO: $p->addEffect(Effect::getEffect(Effect::HARMING)->setAmplifier(1)->setDuration(1)); break; } } } parent::kill(); }
public function onActivate(Item $item, Player $player = null) { $tile = $this->getLevel()->getTile($this); if (!$tile instanceof Cauldron) { return false; } switch ($item->getId()) { case Item::BUCKET: if ($item->getDamage() === 0) { //empty bucket if (!$this->isFull() or $tile->isCustomColor() or $tile->hasPotion()) { break; } $bucket = clone $item; $bucket->setDamage(8); //water bucket Server::getInstance()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $this, 0, $item, $bucket)); if (!$ev->isCancelled()) { if ($player->isSurvival()) { $player->getInventory()->setItemInHand($ev->getItem(), $player); } $this->meta = 0; //empty $this->getLevel()->setBlock($this, $this, true); $tile->clearCustomColor(); $this->getLevel()->addSound(new SplashSound($this->add(0.5, 1, 0.5))); } } elseif ($item->getDamage() === 8) { //water bucket if ($this->isFull() and !$tile->isCustomColor() and !$tile->hasPotion()) { break; } $bucket = clone $item; $bucket->setDamage(0); //empty bucket Server::getInstance()->getPluginManager()->callEvent($ev = new PlayerBucketEmptyEvent($player, $this, 0, $item, $bucket)); if (!$ev->isCancelled()) { if ($player->isSurvival()) { $player->getInventory()->setItemInHand($ev->getItem(), $player); } if ($tile->hasPotion()) { //if has potion $this->meta = 0; //empty $this->getLevel()->setBlock($this, $this, true); $tile->setPotionId(0xffff); //reset potion $tile->clearCustomColor(); $this->getLevel()->addSound(new ExplodeSound($this->add(0.5, 0, 0.5))); } else { $this->meta = 6; //fill $this->getLevel()->setBlock($this, $this, true); $tile->clearCustomColor(); $this->getLevel()->addSound(new SplashSound($this->add(0.5, 1, 0.5))); } $this->update(); } } break; case Item::DYE: if ($tile->hasPotion()) { break; } $color = Color::getDyeColor($item->getDamage()); if ($tile->isCustomColor()) { $color = Color::averageColor($color, $tile->getCustomColor()); } if ($player->isSurvival()) { $item->setCount($item->getCount() - 1); /*if($item->getCount() <= 0){ $player->getInventory()->setItemInHand(Item::get(Item::AIR)); }*/ } $tile->setCustomColor($color); $this->getLevel()->addSound(new SplashSound($this->add(0.5, 1, 0.5))); $this->update(); break; case Item::LEATHER_CAP: case Item::LEATHER_TUNIC: case Item::LEATHER_PANTS: case Item::LEATHER_BOOTS: if ($this->isEmpty()) { break; } if ($tile->isCustomColor()) { --$this->meta; $this->getLevel()->setBlock($this, $this, true); $newItem = clone $item; Utils::setCustomColorToArmor($newItem, $tile->getCustomColor()); $player->getInventory()->setItemInHand($newItem); $this->getLevel()->addSound(new SplashSound($this->add(0.5, 1, 0.5))); if ($this->isEmpty()) { $tile->clearCustomColor(); } } else { --$this->meta; $this->getLevel()->setBlock($this, $this, true); $newItem = clone $item; Utils::clearCustomColorToArmor($newItem); $player->getInventory()->setItemInHand($newItem); $this->getLevel()->addSound(new SplashSound($this->add(0.5, 1, 0.5))); } break; case Item::POTION: case Item::SPLASH_POTION: if (!$this->isEmpty() and ($tile->getPotionId() !== $item->getDamage() and $item->getDamage() !== Potion::WATER_BOTTLE or $item->getId() === Item::POTION and $tile->getSplashPotion() or $item->getId() === Item::SPLASH_POTION and !$tile->getSplashPotion() or $item->getDamage() === Potion::WATER_BOTTLE and $tile->hasPotion())) { //long... $this->meta = 0x0; $this->getLevel()->setBlock($this, $this, true); $tile->setPotionId(0xffff); //reset $tile->setSplashPotion(false); if ($player->isSurvival()) { $player->getInventory()->setItemInHand(Item::get(Item::GLASS_BOTTLE)); } $this->getLevel()->addSound(new ExplodeSound($this->add(0.5, 0, 0.5))); } elseif ($item->getDamage() === Potion::WATER_BOTTLE) { //water bottle $this->meta += 2; if ($this->meta > 0x6) { $this->meta = 0x6; } $this->getLevel()->setBlock($this, $this, true); if ($player->isSurvival()) { $player->getInventory()->setItemInHand(Item::get(Item::GLASS_BOTTLE)); } $tile->setPotionId(0xffff); $tile->setSplashPotion(false); $tile->clearCustomColor(); $this->getLevel()->addSound(new SplashSound($this->add(0.5, 1, 0.5))); } elseif (!$this->isFull()) { $this->meta += 2; if ($this->meta > 0x6) { $this->meta = 0x6; } $this->getLevel()->setBlock($this, $this, true); $tile->setPotionId($item->getDamage()); $tile->setSplashPotion($item->getId() === Item::SPLASH_POTION); $tile->clearCustomColor(); if ($player->isSurvival()) { $player->getInventory()->setItemInHand(Item::get(Item::GLASS_BOTTLE)); } $color = Potion::getColor($item->getDamage()); $this->getLevel()->addSound(new SpellSound($this->add(0.5, 1, 0.5), $color[0], $color[1], $color[2])); } break; case Item::GLASS_BOTTLE: if ($this->meta < 2) { break; } if ($tile->hasPotion()) { $this->meta -= 2; if ($this->meta < 0x0) { $this->meta = 0x0; } $this->getLevel()->setBlock($this, $this, true); if ($player->isSurvival()) { $result = Item::get(Item::POTION, $tile->getPotionId()); if ($item->getCount() === 1) { $player->getInventory()->setItemInHand($result); } else { $player->getInventory()->addItem($result); } } if ($this->isEmpty()) { $tile->setPotionId(0xffff); //reset $tile->setSplashPotion(false); } $color = Potion::getColor($result->getDamage()); $this->getLevel()->addSound(new SpellSound($this->add(0.5, 1, 0.5), $color[0], $color[1], $color[2])); } else { $this->meta -= 2; if ($this->meta < 0x0) { $this->meta = 0x0; } $this->getLevel()->setBlock($this, $this, true); if ($player->isSurvival()) { $result = Item::get(Item::POTION, Potion::WATER_BOTTLE); if ($item->getCount() > 1 and $player->getInventory()->canAddItem($result)) { $player->getInventory()->addItem($result); } else { $player->getInventory()->setItemInHand($result); } } $this->getLevel()->addSound(new GraySplashSound($this->add(0.5, 1, 0.5))); } break; } return true; }
public function __construct(Entity $entity, Potion $potion) { $this->entity = $entity; $this->potion = $potion; $this->effects = $potion->getEffects(); }
public function onUpdate($currentTick) { if ($this->closed) { return false; } $tickDiff = $currentTick - $this->lastUpdate; if ($tickDiff <= 0 and !$this->justCreated) { return true; } $this->lastUpdate = $currentTick; $hasUpdate = $this->entityBaseTick($tickDiff); if ($this->isAlive()) { $movingObjectPosition = null; if (!$this->isCollided) { $this->motionY -= $this->gravity; } $moveVector = new Vector3($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ); $list = $this->getLevel()->getCollidingEntities($this->boundingBox->addCoord($this->motionX, $this->motionY, $this->motionZ)->expand(1, 1, 1), $this); $nearDistance = PHP_INT_MAX; $nearEntity = null; foreach ($list as $entity) { if ($entity === $this->shootingEntity and $this->ticksLived < 5) { continue; } $axisalignedbb = $entity->boundingBox->grow(0.3, 0.3, 0.3); $ob = $axisalignedbb->calculateIntercept($this, $moveVector); if ($ob === null) { continue; } $distance = $this->distanceSquared($ob->hitVector); if ($distance < $nearDistance) { $nearDistance = $distance; $nearEntity = $entity; } } if ($nearEntity !== null) { $movingObjectPosition = MovingObjectPosition::fromEntity($nearEntity); } if ($movingObjectPosition !== null) { if ($movingObjectPosition->entityHit !== null) { $this->server->getPluginManager()->callEvent(new ProjectileHitEvent($this)); $motion = sqrt($this->motionX ** 2 + $this->motionY ** 2 + $this->motionZ ** 2); $damage = ceil($motion * $this->damage); if ($this instanceof Arrow and $this->isCritical) { $damage += mt_rand(0, (int) ($damage / 2) + 1); } if ($this->shootingEntity === null) { $ev = new EntityDamageByEntityEvent($this, $movingObjectPosition->entityHit, EntityDamageEvent::CAUSE_PROJECTILE, $damage); } else { $ev = new EntityDamageByChildEntityEvent($this->shootingEntity, $this, $movingObjectPosition->entityHit, EntityDamageEvent::CAUSE_PROJECTILE, $damage); } if ($movingObjectPosition->entityHit->attack($ev->getFinalDamage(), $ev) === true) { if ($this instanceof Arrow and $this->getPotionId() != 0) { foreach (Potion::getEffectsById($this->potionId - 1) as $effect) { $movingObjectPosition->entityHit->addEffect($effect->setDuration($effect->getDuration() / 8)); } } $ev->useArmors(); } $this->hadCollision = true; if ($this->fireTicks > 0) { $ev = new EntityCombustByEntityEvent($this, $movingObjectPosition->entityHit, 5); $this->server->getPluginManager()->callEvent($ev); if (!$ev->isCancelled()) { $movingObjectPosition->entityHit->setOnFire($ev->getDuration()); } } $this->kill(); return true; } } $this->move($this->motionX, $this->motionY, $this->motionZ); if ($this->isCollided and !$this->hadCollision) { $this->hadCollision = true; $this->motionX = 0; $this->motionY = 0; $this->motionZ = 0; $this->server->getPluginManager()->callEvent(new ProjectileHitEvent($this)); } elseif (!$this->isCollided and $this->hadCollision) { $this->hadCollision = false; } if (!$this->onGround or abs($this->motionX) > 1.0E-5 or abs($this->motionY) > 1.0E-5 or abs($this->motionZ) > 1.0E-5) { $f = sqrt($this->motionX ** 2 + $this->motionZ ** 2); $this->yaw = atan2($this->motionX, $this->motionZ) * 180 / M_PI; $this->pitch = atan2($this->motionY, $f) * 180 / M_PI; $hasUpdate = true; } $this->updateMovement(); } return $hasUpdate; }