onUpdate() public method

public onUpdate ( $currentTick )
示例#1
0
 public function onUpdate($currentTick)
 {
     if ($this->closed) {
         return false;
     }
     $this->timings->startTiming();
     $hasUpdate = parent::onUpdate($currentTick);
     if ($this->isCollidedVertically && $this->isInsideOfWater()) {
         $this->motionX = 0;
         $this->motionY += 0.01;
         $this->motionZ = 0;
         $this->motionChanged = true;
         $hasUpdate = true;
     } elseif ($this->isCollided && $this->keepMovement === true) {
         $this->motionX = 0;
         $this->motionY = 0;
         $this->motionZ = 0;
         $this->motionChanged = true;
         $this->keepMovement = false;
         $hasUpdate = true;
     }
     if ($this->attractTimer === 0 && mt_rand(0, 100) <= 0.1 * 100) {
         // chance, that a fish bites
         $this->attractTimer = mt_rand(5, 10) * 20;
         // random delay when a fish bites (5-10 seconds)
     } else {
         $this->attractFish();
         $this->attractTimer--;
     }
     $this->timings->stopTiming();
     return $hasUpdate;
 }
示例#2
0
 public function onUpdate($currentTick)
 {
     if ($this->closed) {
         return false;
     }
     $this->timings->startTiming();
     $hasUpdate = parent::onUpdate($currentTick);
     if ($this->age > 1200 or $this->isCollided) {
         $this->kill();
         $hasUpdate = true;
         /*if(mt_rand(1, 8) === 1){
         			$chicken = null;
         			$chunk = $this->chunk;
         			
         			if(!($chunk instanceof FullChunk)){
         				return false;
         			}
         			
         			$nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->getX()),new DoubleTag("", $this->getY()),new DoubleTag("", $this->getZ())]),
         					"Motion" => new ListTag("Motion", [new DoubleTag("", 0),new DoubleTag("", 0),new DoubleTag("", 0)]),"Rotation" => new ListTag("Rotation", [new FloatTag("", mt_rand(0, 360)),new FloatTag("", 0)])]);
         			$nbt->Age = new StringTag("Age", 0);
         			$chicken = Entity::createEntity("Chicken", $chunk, $nbt);
         			if($chicken instanceof Entity){
         				$chicken->setDataProperty(14, self::DATA_TYPE_BYTE, 0);
         				$chicken->spawnToAll();
         			}
         		}*/
     }
     $this->timings->stopTiming();
     return $hasUpdate;
 }
示例#3
0
文件: Arrow.php 项目: iTXTech/Genisys
 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;
 }
示例#4
0
 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->age > 1200 or $this->isCollided) {
         $hasUpdate = true;
         if ($this->isCollided and $this->canExplode) {
             $this->server->getPluginManager()->callEvent($ev = new ExplosionPrimeEvent($this, 2.8));
             if (!$ev->isCancelled()) {
                 $explosion = new Explosion($this, $ev->getForce(), $this->shootingEntity);
                 if ($ev->isBlockBreaking()) {
                     $explosion->explodeA();
                 }
                 $explosion->explodeB();
             }
         }
         $this->kill();
     }
     $this->timings->stopTiming();
     return $hasUpdate;
 }
示例#5
0
 public function onUpdate($currentTick)
 {
     if ($this->closed) {
         return false;
     }
     $this->timings->startTiming();
     $hasUpdate = parent::onUpdate($currentTick);
     if ($this->age > 1200 or $this->isCollided) {
         $this->kill();
         $hasUpdate = true;
     }
     $this->timings->stopTiming();
     return $hasUpdate;
 }
示例#6
0
 public function onUpdate($currentTick)
 {
     if ($this->closed) {
         return false;
     }
     $this->timings->startTiming();
     $hasUpdate = parent::onUpdate($currentTick);
     if (($this->isCollided || $this->isCollidedVertically) && !$this->isInsideOfWater()) {
         $this->kill();
         $this->close();
         //Is this needed?
     }
     if ($this->isCollidedVertically && $this->isInsideOfWater()) {
         $this->motionX = 0;
         $this->motionY += 0.01;
         $this->motionZ = 0;
         $this->motionChanged = true;
         $hasUpdate = true;
     } elseif ($this->isCollided && $this->keepMovement === true) {
         $this->motionX = 0;
         $this->motionY = 0;
         $this->motionZ = 0;
         $this->motionChanged = true;
         $this->keepMovement = false;
         $hasUpdate = true;
     }
     if ($this->attractTimer === 0 && mt_rand(0, 100) <= 30) {
         // chance, that a fish bites
         $this->coughtTimer = mt_rand(5, 10) * 20;
         // random delay to catch fish
         $this->attractTimer = mt_rand(30, 100) * 20;
         // reset timer
         $this->attractFish();
         if ($this->shootingEntity !== null) {
             $this->shootingEntity->sendTip("A fish bites!");
         }
     } elseif ($this->attractTimer > 0) {
         $this->attractTimer--;
     }
     if ($this->coughtTimer > 0) {
         $this->coughtTimer--;
         $this->fishBites();
     }
     $this->timings->stopTiming();
     return $hasUpdate;
 }
示例#7
0
 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->age > 1200) {
         $this->kill();
         $hasUpdate = \true;
     }
     $this->timings->stopTiming();
     return $hasUpdate;
 }
示例#8
0
 public function onUpdate($currentTick)
 {
     if ($this->closed) {
         return false;
     }
     $this->timings->startTiming();
     $hasUpdate = parent::onUpdate($currentTick);
     if ($this->age > 1200 or $this->isCollided) {
         if ($this->isCollided && $this->shootingEntity !== null && $this->shootingEntity instanceof Player) {
             if ($this->getLevel()->getServer()->getPlayer($this->shootingEntity->getName())->isOnline()) {
                 $this->shootingEntity->teleport($this->getPosition());
             }
         }
         $this->kill();
         $hasUpdate = true;
     }
     $this->timings->stopTiming();
     return $hasUpdate;
 }
 public function onUpdate($currentTick)
 {
     if ($this->closed) {
         return false;
     }
     $this->timings->startTiming();
     $hasUpdate = parent::onUpdate($currentTick);
     if ($this->age > 1200 or $this->isCollided) {
         $this->kill();
         $this->close();
         $hasUpdate = true;
     }
     if ($this->onGround) {
         $this->kill();
         $this->close();
         $this->getLevel()->spawnExperienceOrb($this->add(0, 1, 0), mt_rand(3, 11));
     }
     $this->timings->stopTiming();
     return $hasUpdate;
 }
示例#10
0
 public function onUpdate($currentTick)
 {
     if ($this->closed) {
         return false;
     }
     $this->timings->startTiming();
     $hasUpdate = parent::onUpdate($currentTick);
     $this->age++;
     if ($this->age > 1200 or $this->isCollided) {
         $this->kill();
         $this->close();
         $this->getLevel()->addParticle(new SpellParticle($this, 46, 82, 153));
         if ($this->getLevel()->getServer()->expEnabled) {
             $this->getLevel()->addExperienceOrb($this->add(0, 0.2, 0), mt_rand(1, 4));
             $this->getLevel()->addExperienceOrb($this->add(-0.1, 0.2, 0), mt_rand(1, 4));
             $this->getLevel()->addExperienceOrb($this->add(0, 0.2, -0.1), mt_rand(1, 4));
         }
         $hasUpdate = true;
     }
     $this->timings->stopTiming();
     return $hasUpdate;
 }
示例#11
0
文件: Gun.php 项目: Skull3x/MineBlock
 public function onUpdate($currentTick)
 {
     if ($this->closed) {
         return false;
     }
     $this->timings->startTiming();
     $hasUpdate = parent::onUpdate($currentTick);
     $bb = new AxisAlignedBB($x = $this->x - 0.5, $y = $this->y, $z = $this->z - 0.5, $x + 1, $y + 1, $z + 1);
     if ($this->age > 100 || count($this->level->getCollisionBlocks($bb = $this->getBoundingBox())) > 0) {
         $this->kill();
         $this->close();
         $hasUpdate = true;
     } else {
         $se = $this->shootingEntity;
         $list = $this->server->getOnlinePlayers();
         foreach ($list as $p) {
             if ($p !== $se && $bb->intersectsWith($p->getBoundingBox())) {
                 $armorTable = [Item::LEATHER_CAP => 1, Item::LEATHER_TUNIC => 3, Item::LEATHER_PANTS => 2, Item::LEATHER_BOOTS => 1, Item::CHAIN_HELMET => 1, Item::CHAIN_CHESTPLATE => 5, Item::CHAIN_LEGGINGS => 4, Item::CHAIN_BOOTS => 1, Item::GOLD_HELMET => 1, Item::GOLD_CHESTPLATE => 5, Item::GOLD_LEGGINGS => 3, Item::GOLD_BOOTS => 1, Item::IRON_HELMET => 2, Item::IRON_CHESTPLATE => 6, Item::IRON_LEGGINGS => 5, Item::IRON_BOOTS => 2, Item::DIAMOND_HELMET => 3, Item::DIAMOND_CHESTPLATE => 8, Item::DIAMOND_LEGGINGS => 6, Item::DIAMOND_BOOTS => 3];
                 $points = 0;
                 foreach ($p->getInventory()->getArmorContents() as $index => $armor) {
                     if (isset($armorTable[$armor->getID()])) {
                         $points += $armorTable[$armor->getID()];
                     }
                 }
                 $p->knockBack($se, $finalDamage = 5 - floor(5 * $points * 0.04), sin($yaw = atan2($p->x - $se->x, $p->z - $se->z)), cos($yaw), 0.4);
                 $p->attack($finalDamage);
                 $this->kill();
                 $this->close();
                 $hasUpdate = true;
                 break;
             }
         }
     }
     $this->timings->stopTiming();
     return $hasUpdate;
 }
示例#12
0
 public function onUpdate($currentTick)
 {
     if ($this->closed) {
         return false;
     }
     $this->timings->startTiming();
     $hasUpdate = parent::onUpdate($currentTick);
     $bb = new AxisAlignedBB($x = $this->x - 0.5, $y = $this->y, $z = $this->z - 0.5, $x + 1, $y + 1, $z + 1);
     if ($this->age > 100) {
         $this->kill();
         $this->explode();
         $this->close();
         $hasUpdate = true;
     } elseif (count($this->level->getCollisionBlocks($bb = $this->getBoundingBox())) > 0) {
         if ($this->motionX < 0) {
             $this->motionX = -$this->motionX * 0.5;
         }
         if ($this->motionY < 0) {
             $this->motionY = -$this->motionY * 0.1;
         }
         if ($this->motionZ < 0) {
             $this->motionZ = -$this->motionZ * 0.5;
         }
     }
     $this->timings->stopTiming();
     return $hasUpdate;
 }