예제 #1
0
 public function spawnDiscourager()
 {
     $dir = $this->player->getDirectionVector();
     if ($this->player->pitch > 45 or $this->player->pitch < -45) {
         $face = 0;
         // y
     } else {
         $face = self::$conversionTable[$this->player->getDirection()];
     }
     $center = $this->player->subtract($dir->multiply($this->main->getDistance()))->add(0, $this->player->eyeHeight)->floor();
     $l = $this->player->getLevel();
     if ($face === self::Y) {
         $this->overridenBlocks = [$l->getBlock($center->add(1, 0, 1)), $l->getBlock($center->add(1, 0, 0)), $l->getBlock($center->add(1, 0, -1)), $l->getBlock($center->add(0, 0, 1)), $l->getBlock($center), $l->getBlock($center->add(0, 0, -1)), $l->getBlock($center->add(-1, 0, 1)), $l->getBlock($center->add(-1, 0, 0)), $l->getBlock($center->add(-1, 0, -1))];
     } elseif ($face === self::X) {
         $this->overridenBlocks = [$l->getBlock($center->add(0, 1, 1)), $l->getBlock($center->add(0, 1, 0)), $l->getBlock($center->add(0, 1, -1)), $l->getBlock($center->add(0, 0, 1)), $l->getBlock($center), $l->getBlock($center->add(0, 0, -1)), $l->getBlock($center->add(0, -1, 1)), $l->getBlock($center->add(0, -1, 0)), $l->getBlock($center->add(0, -1, -1))];
     } elseif ($face === self::Z) {
         $this->overridenBlocks = [$l->getBlock($center->add(1, 1, 0)), $l->getBlock($center->add(1, 0, 0)), $l->getBlock($center->add(1, -1, 0)), $l->getBlock($center->add(0, 1, 0)), $l->getBlock($center), $l->getBlock($center->add(0, -1, 0)), $l->getBlock($center->add(-1, 1, 0)), $l->getBlock($center->add(-1, 0, 0)), $l->getBlock($center->add(-1, -1, 0))];
     }
     foreach ($this->overridenBlocks as $b) {
         $pk = new UpdateBlockPacket();
         $pk->x = $b->x;
         $pk->y = $b->y;
         $pk->z = $b->z;
         $pk->block = $this->main->getBlockType()->getId();
         $pk->meta = $this->main->getBlockType()->getDamage();
         $this->player->dataPacket($pk);
     }
 }
예제 #2
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if ($player === null or $player->isSurvival() !== true) {
         return false;
     }
     if ($target->getId() === Block::STILL_WATER or $target->getId() === Block::WATER) {
         $player->getServer()->getPluginManager()->callEvent($ev = new PlayerGlassBottleEvent($player, $target, $this));
         if ($ev->isCancelled()) {
             return false;
         } else {
             if ($this->count <= 1) {
                 $player->getInventory()->setItemInHand(Item::get(Item::POTION, 0, 1));
                 return true;
             } else {
                 $this->count--;
                 $player->getInventory()->setItemInHand($this);
             }
             if ($player->getInventory()->canAddItem(Item::get(Item::POTION, 0, 1)) === true) {
                 $player->getInventory()->AddItem(Item::get(Item::POTION, 0, 1));
             } else {
                 $motion = $player->getDirectionVector()->multiply(0.4);
                 $position = clone $player->getPosition();
                 $player->getLevel()->dropItem($position->add(0, 0.5, 0), Item::get(Item::POTION, 0, 1), $motion, 40);
             }
             return true;
         }
     }
     return false;
 }
예제 #3
0
 public function onShootRun(array $args, Player $player)
 {
     if (!isset($args[0]) or !is_numeric($args[0])) {
         return self::WRONG_USE;
     }
     $length = floatval(array_shift($args));
     $p1 = $player->getPosition()->floor();
     $p2 = $player->add($player->getDirectionVector()->multiply($length))->floor();
     if ($p1->y < 0 or $p1->y > (defined($path = "pemapmodder\\worldeditart\\MAX_WORLD_HEIGHT") ? constant($path) : 127)) {
         return "You must be inside the building height!";
     } elseif ($p2->y < 0 or $p2->y > (defined($path = "pemapmodder\\worldeditart\\MAX_WORLD_HEIGHT") ? constant($path) : 127)) {
         return "The selected area exceeded the world height limit!";
     }
     $player->getLevel()->loadChunk($p2->x >> 4, $p2->z >> 4);
     while (isset($args[0])) {
         $arg = array_shift($args);
         switch ($arg) {
             case "a":
             case "adverse":
                 $cache = [$p1, $p2];
                 $p1 = $cache[1];
                 $p2 = $cache[0];
                 break;
         }
     }
     $level = $player->getLevel();
     $this->getMain()->setSelection($player, $sel = new CuboidSpace($p1 = Position::fromObject($p1, $level), $p2 = Position::fromObject($p2, $level)));
     return "Cuboid selection set: {$sel} (" . count($sel->getPosList()) . " blocks)";
 }
예제 #4
0
 public function launch(Player $player)
 {
     $dir = $player->getDirectionVector();
     $frontPos = $player->add($dir->multiply(1.1));
     $nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $frontPos->x), new Double("", $frontPos->y + $player->getEyeHeight()), new Double("", $frontPos->z)]), "Motion" => new Enum("Motion", [new Double("", $dir->x), new Double("", $dir->y), new Double("", $dir->z)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)])]);
     $f = $this->f;
     $launched = Entity::createEntity($this->getEntityName(), $player->chunk, $nbt);
     $launched->setMotion($launched->getMotion()->multiply($f));
     if ($launched instanceof Projectile) {
         $player->server->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($launched));
         if ($projectileEv->isCancelled()) {
             $launched->kill();
         } else {
             $launched->spawnToAll();
             $player->level->addSound(new LaunchSound($player), $player->getViewers());
         }
     } else {
         $launched->spawnToAll();
     }
 }
예제 #5
0
 private function fire(Player $c, $fuse, $speed)
 {
     $pos = $c->getPosition();
     $pos->y += $c->getEyeHeight();
     $dir = $c->getDirectionVector();
     $dir->x = $dir->x * $speed;
     $dir->y = $dir->y * $speed;
     $dir->z = $dir->z * $speed;
     $this->scorchit($pos, $dir, $fuse);
 }
예제 #6
0
 public function addItem(Item $item, Player $player, Item $result)
 {
     if ($item->getCount() <= 1) {
         $player->getInventory()->setItemInHand($result);
     } else {
         $item->setCount($item->getCount() - 1);
         if ($player->getInventory()->canAddItem($result) === true) {
             $player->getInventory()->addItem($result);
         } else {
             $motion = $player->getDirectionVector()->multiply(0.4);
             $position = clone $player->getPosition();
             $player->getLevel()->dropItem($position->add(0, 0.5, 0), $result, $motion, 40);
         }
     }
 }