isSurvival() публичный Метод

public isSurvival ( ) : boolean
Результат boolean
Пример #1
15
 private function checkInVIP(Player $player)
 {
     //if ($player->getLevel ()->getName () === $this->plugin->vipLevelName) {
     if (isset($this->vips[$player->getName()])) {
         $this->plugin->log("[HG] VIPPlayerListener->VIPCheck-IN: " . $player->getName());
         return true;
     } else {
         $vip = $this->plugin->profileManager->isPlayerVIP($player->getName());
         if (!$vip) {
             return false;
         }
         if (!$player->isOp()) {
             if (!$player->isSurvival()) {
                 $player->setGamemode(Player::SURVIVAL);
             }
         }
         $this->vips[$player->getName()] = $player->getName();
         $this->plugin->log("[HG] VIPPlayerListener->VIPCheck-IN: " . $player->getName());
         return true;
     }
     //}
     return false;
 }
Пример #2
10
 /**
  * Tries to break a block using a item, including Player time checks if available
  * It'll try to lower the durability if Item is a tool, and set it to Air if broken.
  *
  * @param Vector3 $vector
  * @param Item    &$item (if null, can break anything)
  * @param Player  $player
  * @param bool    $createParticles
  *
  * @return boolean
  */
 public function useBreakOn(Vector3 $vector, Item &$item = null, Player $player = null, $createParticles = false)
 {
     $target = $this->getBlock($vector);
     //TODO: Adventure mode checks
     if ($item === null) {
         $item = Item::get(Item::AIR, 0, 0);
     }
     if ($player !== null) {
         $ev = new BlockBreakEvent($player, $target, $item, $player->isCreative() ? true : false);
         if ($player->isSurvival() and $item instanceof Item and !$target->isBreakable($item)) {
             $ev->setCancelled();
         } elseif (!$player->isOp() and ($distance = $this->server->getSpawnRadius()) > -1) {
             $t = new Vector2($target->x, $target->z);
             $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z);
             if (count($this->server->getOps()->getAll()) > 0 and $t->distance($s) <= $distance) {
                 //set it to cancelled so plugins can bypass this
                 $ev->setCancelled();
             }
         }
         $this->server->getPluginManager()->callEvent($ev);
         if ($ev->isCancelled()) {
             return false;
         }
         $breakTime = $target->getBreakTime($item);
         if ($player->isCreative() and $breakTime > 0.15) {
             $breakTime = 0.15;
         }
         if ($player->hasEffect(Effect::SWIFTNESS)) {
             $breakTime *= 1 - 0.2 * ($player->getEffect(Effect::SWIFTNESS)->getAmplifier() + 1);
         }
         if ($player->hasEffect(Effect::MINING_FATIGUE)) {
             $breakTime *= 1 + 0.3 * ($player->getEffect(Effect::MINING_FATIGUE)->getAmplifier() + 1);
         }
         $breakTime -= 0.05;
         //1 tick compensation
         if (!$ev->getInstaBreak() and $player->lastBreak + $breakTime > microtime(true)) {
             return false;
         }
         $player->lastBreak = microtime(true);
         $drops = $ev->getDrops();
     } elseif ($item !== null and !$target->isBreakable($item)) {
         return false;
     } else {
         $drops = $target->getDrops($item);
         //Fixes tile entities being deleted before getting drops
         foreach ($drops as $k => $i) {
             $drops[$k] = Item::get($i[0], $i[1], $i[2]);
         }
     }
     $above = $this->getBlock(new Vector3($target->x, $target->y + 1, $target->z));
     if ($above !== null) {
         if ($above->getId() === Item::FIRE) {
             $this->setBlock($above, new Air(), true);
         }
     }
     $tag = $item->getNamedTagEntry("CanDestroy");
     if ($tag instanceof Enum) {
         $canBreak = false;
         foreach ($tag as $v) {
             if ($v instanceof String) {
                 $entry = Item::fromString($v->getValue());
                 if ($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()) {
                     $canBreak = true;
                     break;
                 }
             }
         }
         if (!$canBreak) {
             return false;
         }
     }
     if ($createParticles) {
         $players = $this->getChunkPlayers($target->x >> 4, $target->z >> 4);
         if ($player !== null) {
             unset($players[$player->getLoaderId()]);
         }
         $this->addParticle(new DestroyBlockParticle($target->add(0.5), $target), $players);
     }
     $target->onBreak($item);
     $tile = $this->getTile($target);
     if ($tile !== null) {
         if ($tile instanceof InventoryHolder) {
             if ($tile instanceof Chest) {
                 $tile->unpair();
             }
             foreach ($tile->getInventory()->getContents() as $chestItem) {
                 $this->dropItem($target, $chestItem);
             }
         }
         $tile->close();
     }
     if ($item !== null) {
         $item->useOn($target);
         if ($item->isTool() and $item->getDamage() >= $item->getMaxDurability()) {
             $item = Item::get(Item::AIR, 0, 0);
         }
     }
     if ($player === null or $player->isSurvival()) {
         foreach ($drops as $drop) {
             if ($drop->getCount() > 0) {
                 $this->dropItem($vector->add(0.5, 0.5, 0.5), $drop);
             }
         }
     }
     return true;
 }
Пример #3
4
 public function onActivate(Item $item, Player $player = null)
 {
     $tile = $this->getLevel()->getTile($this);
     if (!$tile instanceof ItemFrameTile) {
         $nbt = new CompoundTag("", [new StringTag("id", Tile::ITEM_FRAME), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z), new ByteTag("ItemRotation", 0), new FloatTag("ItemDropChance", 1.0)]);
         Tile::createTile(Tile::ITEM_FRAME, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
     }
     $tile = $this->getLevel()->getTile($this);
     if (!$tile instanceof ItemFrameTile) {
         return false;
     }
     if ($tile->getItem()->getId() === 0) {
         $tile->setItem(Item::get($item->getId(), $item->getDamage(), 1));
         if ($player instanceof Player) {
             if ($player->isSurvival()) {
                 $count = $item->getCount();
                 if (--$count <= 0) {
                     $player->getInventory()->setItemInHand(Item::get(Item::AIR));
                     return true;
                 }
                 $item->setCount($count);
                 $player->getInventory()->setItemInHand($item);
             }
         }
     } else {
         $itemRot = $tile->getItemRotation();
         if ($itemRot === 7) {
             $itemRot = 0;
         } else {
             $itemRot++;
         }
         $tile->setItemRotation($itemRot);
     }
     return true;
 }
Пример #4
2
 public function onActivate(Item $item, Player $player = null)
 {
     $tile = $this->getLevel()->getTile($this);
     if ($this->meta == 0) {
         switch ($item->getId()) {
             case Item::BUCKET:
                 if ($item->getDamage() === 8) {
                     $this->meta = 6;
                     $this->getLevel()->setBlock($this, $this, true, false);
                     if ($player->isSurvival()) {
                         $item->setDamage(0);
                         $player->getInventory()->setItemInHand($item(), $player);
                     }
                 }
                 return true;
                 break;
         }
     }
     return false;
 }
Пример #5
1
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $entity = null;
     $chunk = $level->getChunk($block->getX() >> 4, $block->getZ() >> 4);
     if (!$chunk instanceof FullChunk) {
         return false;
     }
     $nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $block->getX() + 0.5), new Double("", $block->getY()), new Double("", $block->getZ() + 0.5)]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", lcg_value() * 360), new Float("", 0)])]);
     $entity = Entity::createEntity($this->meta, $chunk, $nbt);
     if ($entity instanceof Entity) {
         if ($player->isSurvival()) {
             --$this->count;
         }
         $entity->spawnToAll();
         return true;
     }
     return false;
 }
Пример #6
1
 public function onActivate(Item $item, Player $player = null)
 {
     if ($this->meta < 0x7 && $item->getID() === Item::DYE && $item->getDamage() === 0xf) {
         //Bonemeal
         $block = clone $this;
         $block->meta += mt_rand(2, 5);
         if ($block->meta > 0x7) {
             $block->meta = 0x7;
         }
         Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block));
         if (!$ev->isCancelled()) {
             $this->getLevel()->setBlock($this, $ev->getNewState(), true, true);
             if ($player->isSurvival()) {
                 $item->count--;
             }
             return true;
         }
     }
     return false;
 }
Пример #7
1
 public function targetOption(Player $player, $distance)
 {
     return $player->spawned && $player->isAlive() && !$player->closed && $player->isSurvival() && $distance <= 81;
 }
Пример #8
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if ($target->isTransparent() === false and $face > 1 and $block->isSolid() === false) {
         $faces = [2 => 0, 3 => 2, 4 => 1, 5 => 3];
         $motives = [["Kebab", 1, 1], ["Aztec", 1, 1], ["Alban", 1, 1], ["Aztec2", 1, 1], ["Bomb", 1, 1], ["Plant", 1, 1], ["Wasteland", 1, 1], ["Wanderer", 1, 2], ["Graham", 1, 2], ["Pool", 2, 1], ["Courbet", 2, 1], ["Sunset", 2, 1], ["Sea", 2, 1], ["Creebet", 2, 1], ["Match", 2, 2], ["Bust", 2, 2], ["Stage", 2, 2], ["Void", 2, 2], ["SkullAndRoses", 2, 2], ["Fighters", 4, 2], ["Skeleton", 4, 3], ["DonkeyKong", 4, 3], ["Pointer", 4, 4], ["Pigscene", 4, 4], ["Flaming Skull", 4, 4]];
         $motive = $motives[mt_rand(0, count($motives) - 1)];
         $data = ["x" => $target->x, "y" => $target->y + 0.4, "z" => $target->z, "yaw" => $faces[$face] * 90, "Motive" => $motive[0]];
         $nbt = new CompoundTag("", ["Motive" => new StringTag("Motive", $data["Motive"]), "Pos" => new EnumTag("Pos", [new DoubleTag("", $data["x"]), new DoubleTag("", $data["y"]), new DoubleTag("", $data["z"])]), "Motion" => new EnumTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new EnumTag("Rotation", [new FloatTag("", $data["yaw"]), new FloatTag("", 0)])]);
         $painting = new PaintingEntity($player->getLevel()->getChunk($block->getX() >> 4, $block->getZ() >> 4), $nbt);
         $painting->spawnToAll();
         if ($player->isSurvival()) {
             $item = $player->getInventory()->getItemInHand();
             $count = $item->getCount();
             if (--$count <= 0) {
                 $player->getInventory()->setItemInHand(Item::get(Item::AIR));
                 return;
             }
             $item->setCount($count);
             $player->getInventory()->setItemInHand($item);
         }
         //TODO
         //$e = $server->api->entity->add($level, ENTITY_OBJECT, OBJECT_PAINTING, $data);
         //$e->spawnToAll();
         /*if(($player->gamemode & 0x01) === 0x00){
         			$player->removeItem(Item::get($this->getId(), $this->getDamage(), 1));
         		}*/
         return true;
     }
     return false;
 }
Пример #9
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if ($target->getId() == Block::MONSTER_SPAWNER) {
         return true;
     } else {
         $entity = null;
         $chunk = $level->getChunk($block->getX() >> 4, $block->getZ() >> 4);
         if (!$chunk instanceof FullChunk) {
             return false;
         }
         $nbt = new CompoundTag("", ["Pos" => new EnumTag("Pos", [new DoubleTag("", $block->getX() + 0.5), new DoubleTag("", $block->getY()), new DoubleTag("", $block->getZ() + 0.5)]), "Motion" => new EnumTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new EnumTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)])]);
         if ($this->hasCustomName()) {
             $nbt->CustomName = new StringTag("CustomName", $this->getCustomName());
         }
         $entity = Entity::createEntity($this->meta, $chunk, $nbt);
         if ($entity instanceof Entity) {
             if ($player->isSurvival()) {
                 --$this->count;
             }
             $entity->spawnToAll();
             return true;
         }
     }
     return false;
 }
Пример #10
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($item->getId() === Item::DYE and $item->getDamage() === Dye::BONEMEAL) {
         $grow = false;
         if ($this->getSide(0)->getId() !== self::SUGARCANE_BLOCK && $this->getSide(0, 2)->getId() !== self::SUGARCANE_BLOCK) {
             for ($y = 1; $y < 2; $y++) {
                 $b = $this->getSide(1, $y);
                 if ($b->getId() === self::AIR) {
                     Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, new Sugarcane()));
                     if (!$ev->isCancelled()) {
                         $this->getLevel()->setBlock($b, $ev->getNewState(), true);
                         $grow = true;
                     }
                     break;
                 } else {
                     break;
                 }
             }
             $this->meta = 0;
             $this->getLevel()->setBlock($this, $this, true);
         }
         if ($grow && $player->isSurvival()) {
             $item->count--;
         }
         return true;
     }
     return false;
 }
Пример #11
0
 public function onActivate(Item $item, Player $player = null)
 {
     $tile = $this->getLevel()->getTile($this);
     if ($tile instanceof FlowerPotTile) {
         if ($tile->getFlowerPotItem() === Item::AIR) {
             switch ($item->getId()) {
                 case Item::TALL_GRASS:
                     if ($item->getDamage() === 1) {
                         break;
                     }
                 case Item::SAPLING:
                 case Item::DEAD_BUSH:
                 case Item::DANDELION:
                 case Item::RED_FLOWER:
                 case Item::BROWN_MUSHROOM:
                 case Item::RED_MUSHROOM:
                 case Item::CACTUS:
                     $tile->setFlowerPotData($item->getId(), $item->getDamage());
                     $this->setDamage($item->getId());
                     $this->getLevel()->setBlock($this, $this, true, false);
                     if ($player->isSurvival()) {
                         $item->count--;
                     }
                     return true;
                     break;
             }
         }
     }
     return false;
 }
Пример #12
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;
 }
Пример #13
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $realPos = $target->getSide($face)->add(0.5, 0.4, 0.5);
     $camera = new TripoidCamera($player->getLevel()->getChunk($realPos->getX() >> 4, $realPos->getZ() >> 4), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $realPos->getX()), new DoubleTag("", $realPos->getY()), new DoubleTag("", $realPos->getZ())]), "Motion" => new ListTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)])]));
     $camera->spawnToAll();
     if ($player->isSurvival()) {
         --$this->count;
     }
     return true;
 }
Пример #14
0
 public function __construct(Player $player, Block $block, Item $item, $instaBreak = \false)
 {
     $this->block = $block;
     $this->item = $item;
     $this->player = $player;
     $this->instaBreak = (bool) $instaBreak;
     $drops = $player->isSurvival() ? $block->getDrops($item) : [];
     foreach ($drops as $i) {
         $this->blockDrops[] = Item::get($i[0], $i[1], $i[2]);
     }
 }
Пример #15
0
 public function __construct(Player $player, Block $block, Item $item, int $xpAmount = 0, bool $instaBreak = false, bool $speed = false)
 {
     $this->block = $block;
     $this->item = $item;
     $this->player = $player;
     $this->instaBreak = (bool) $instaBreak;
     $this->xpAmount = (int) $xpAmount;
     $this->blocked = (bool) $speed;
     $drops = $player->isSurvival() ? $block->getDrops($item) : [];
     foreach ($drops as $i) {
         $this->blockDrops[] = Item::get($i[0], $i[1], $i[2]);
     }
 }
Пример #16
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if (!in_array($target->getId(), array(Block::RAIL, Block::ACTIVATOR_RAIL, Block::DETECTOR_RAIL, Block::POWERED_RAIL))) {
         return false;
     }
     $realPos = $target->add(0.5, 0, 0.5);
     $cart = new MinecartHopperEntity($player->getLevel()->getChunk($realPos->getX() >> 4, $realPos->getZ() >> 4), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $realPos->getX()), new DoubleTag("", $realPos->getY()), new DoubleTag("", $realPos->getZ())]), "Motion" => new ListTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)])]));
     $cart->spawnToAll();
     if ($player->isSurvival()) {
         --$this->count;
     }
     return true;
 }
Пример #17
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $bucketContents = Block::get($this->meta);
     if ($bucketContents instanceof Air) {
         // Bucket Empty so pick up block
         if ($target instanceof Liquid and $target->getDamage() === 0) {
             $result = clone $this;
             if ($target instanceof StillWater) {
                 $toStore = Block::WATER;
             } elseif ($target instanceof StillLava) {
                 $toStore = Block::LAVA;
             } else {
                 return false;
             }
             $result->setDamage($toStore);
             $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
             if (!$ev->isCancelled()) {
                 $player->getLevel()->setBlock($target, new Air(), true, true);
                 if ($player->isSurvival()) {
                     $player->getInventory()->setItemInHand($ev->getItem(), $player);
                 }
                 return true;
             } else {
                 $player->getInventory()->sendContents($player);
             }
         }
     } elseif ($bucketContents instanceof Liquid) {
         // Bucket Full, so empty
         $result = clone $this;
         $result->setDamage(0);
         if ($bucketContents instanceof Water) {
             $toCreate = Block::STILL_WATER;
         } elseif ($bucketContents instanceof Lava) {
             $toCreate = Block::STILL_LAVA;
         } else {
             return false;
         }
         $bucketContents = Block::get($toCreate);
         $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
         if (!$ev->isCancelled()) {
             $player->getLevel()->setBlock($block, $bucketContents, true, true);
             if ($player->isSurvival()) {
                 $player->getInventory()->setItemInHand($ev->getItem(), $player);
             }
             return true;
         } else {
             $player->getInventory()->sendContents($player);
         }
     }
     return false;
 }
Пример #18
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $minecart = new MinecartEntity($player->getLevel()->getChunk($block->getX() >> 4, $block->getZ() >> 4), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $block->getX()), new DoubleTag("", $block->getY() + 0.8), new DoubleTag("", $block->getZ())]), "Motion" => new ListTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)])]));
     $minecart->spawnToAll();
     if ($player->isSurvival()) {
         $item = $player->getInventory()->getItemInHand();
         $count = $item->getCount();
         if (--$count <= 0) {
             $player->getInventory()->setItemInHand(Item::get(Item::AIR));
             return true;
         }
         $item->setCount($count);
         $player->getInventory()->setItemInHand($item);
     }
     return true;
 }
Пример #19
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $realPos = $block->getSide($face);
     $boat = new BoatEntity($player->getLevel()->getChunk($realPos->getX() >> 4, $realPos->getZ() >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $realPos->getX()), new Double("", $realPos->getY()), new Double("", $realPos->getZ())]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)])]));
     $boat->spawnToAll();
     if ($player->isSurvival()) {
         $item = $player->getInventory()->getItemInHand();
         $count = $item->getCount();
         if (--$count <= 0) {
             $player->getInventory()->setItemInHand(Item::get(Item::AIR));
             return;
         }
         $item->setCount($count);
         $player->getInventory()->setItemInHand($item);
     }
     return true;
 }
Пример #20
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $targetBlock = Block::get($this->meta);
     if ($targetBlock instanceof Air) {
         if ($target instanceof Liquid and $target->getDamage() === 0) {
             $result = clone $this;
             $id = $target->getId();
             if ($id == self::STILL_WATER) {
                 $id = self::WATER;
             }
             if ($id == self::STILL_LAVA) {
                 $id = self::LAVA;
             }
             $result->setDamage($id);
             $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
             if (!$ev->isCancelled()) {
                 $player->getLevel()->setBlock($target, new Air(), true, true);
                 if ($player->isSurvival()) {
                     $player->getInventory()->setItemInHand($ev->getItem());
                 }
                 return true;
             } else {
                 $player->getInventory()->sendContents($player);
             }
         }
     } elseif ($targetBlock instanceof Liquid) {
         $result = clone $this;
         $result->setDamage(0);
         $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketEmptyEvent($player, $block, $face, $this, $result));
         if (!$ev->isCancelled()) {
             //Only disallow water placement in the Nether, allow other liquids to be placed
             //In vanilla, water buckets are emptied when used in the Nether, but no water placed.
             if (!($player->getLevel()->getDimension() === Level::DIMENSION_NETHER and $targetBlock->getID() === self::WATER)) {
                 $player->getLevel()->setBlock($block, $targetBlock, true, true);
             }
             if ($player->isSurvival()) {
                 $player->getInventory()->setItemInHand($ev->getItem());
             }
             return true;
         } else {
             $player->getInventory()->sendContents($player);
         }
     }
     return false;
 }
Пример #21
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $blockTemp = $level->getBlock($block->add(0, -1, 0));
     //if($blockTemp->getId() != self::RAIL and $blockTemp->getId() != self::POWERED_RAIL) return;
     $minecart = new MinecartEntity($player->getLevel()->getChunk($block->getX() >> 4, $block->getZ() >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $block->getX()), new Double("", $block->getY() + 1), new Double("", $block->getZ())]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)])]));
     $minecart->spawnToAll();
     if ($player->isSurvival()) {
         $item = $player->getInventory()->getItemInHand();
         $count = $item->getCount();
         if (--$count <= 0) {
             $player->getInventory()->setItemInHand(Item::get(Item::AIR));
             return;
         }
         $item->setCount($count);
         $player->getInventory()->setItemInHand($item);
     }
     return true;
 }
Пример #22
0
 /**
  * Tries to break a block using a item, including Player time checks if available
  * It'll try to lower the durability if Item is a tool, and set it to Air if broken.
  *
  * @param Vector3 $vector
  * @param Item    &$item (if null, can break anything)
  * @param Player  $player
  * @param bool    $createParticles
  *
  * @return bool
  */
 public function useBreakOn(Vector3 $vector, Item &$item = null, Player $player = null, bool $createParticles = false) : bool
 {
     $target = $this->getBlock($vector);
     if ($item === null) {
         $item = Item::get(Item::AIR, 0, 0);
     }
     if ($player !== null) {
         $ev = new BlockBreakEvent($player, $target, $item, $player->isCreative() ? true : false);
         if ($player->isAdventure() or $player->isSpectator() or $player->isSurvival() and $item instanceof Item and !$target->isBreakable($item)) {
             $ev->setCancelled();
         } elseif (!$player->isOp() and ($distance = $this->server->getSpawnRadius()) > -1) {
             $t = new Vector2($target->x, $target->z);
             $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z);
             if (count($this->server->getOps()->getAll()) > 0 and $t->distance($s) <= $distance) {
                 //set it to cancelled so plugins can bypass this
                 $ev->setCancelled();
             }
         }
         $this->server->getPluginManager()->callEvent($ev);
         if ($ev->isCancelled()) {
             return false;
         }
         /*$breakTime = $target->getBreakTime($item);
         
         			if($player->isCreative() and $breakTime > 0.15){
         				$breakTime = 0.15;
         			}
         
         			if($player->hasEffect(Effect::SWIFTNESS)){
         				$breakTime *= 1 - (0.2 * ($player->getEffect(Effect::SWIFTNESS)->getAmplifier() + 1));
         			}
         
         			if($player->hasEffect(Effect::MINING_FATIGUE)){
         				$breakTime *= 1 + (0.3 * ($player->getEffect(Effect::MINING_FATIGUE)->getAmplifier() + 1));
         			}
         
         			$breakTime -= 0.05; //1 tick compensation
         
         			if(!$ev->getInstaBreak() and ($player->lastBreak + $breakTime) > microtime(true)){
         				return false;
         			}*/
         $player->lastBreak = microtime(true);
         $drops = $ev->getDrops();
         if ($player->isSurvival() and $this->getServer()->expEnabled) {
             $exp = 0;
             if ($item->getEnchantmentLevel(Enchantment::TYPE_MINING_SILK_TOUCH) === 0) {
                 switch ($target->getId()) {
                     case Block::COAL_ORE:
                         $exp = mt_rand(0, 2);
                         break;
                     case Block::DIAMOND_ORE:
                     case Block::EMERALD_ORE:
                         $exp = mt_rand(3, 7);
                         break;
                     case Block::NETHER_QUARTZ_ORE:
                     case Block::LAPIS_ORE:
                         $exp = mt_rand(2, 5);
                         break;
                     case Block::REDSTONE_ORE:
                     case Block::GLOWING_REDSTONE_ORE:
                         $exp = mt_rand(1, 5);
                         break;
                 }
             }
             switch ($target->getId()) {
                 case Block::MONSTER_SPAWNER:
                     $exp = mt_rand(15, 43);
                     break;
             }
             if ($exp > 0) {
                 $this->spawnXPOrb($vector->add(0, 1, 0), $exp);
             }
         }
     } elseif ($item !== null and !$target->isBreakable($item)) {
         return false;
     } else {
         $drops = $target->getDrops($item);
         //Fixes tile entities being deleted before getting drops
         foreach ($drops as $k => $i) {
             if (isset($i[0]) && isset($i[1]) && isset($i[2])) {
                 $drops[$k] = Item::get($i[0], $i[1], $i[2]);
             }
         }
     }
     $above = $this->getBlock(new Vector3($target->x, $target->y + 1, $target->z));
     if ($above !== null) {
         if ($above->getId() === Item::FIRE) {
             $this->setBlock($above, new Air(), true);
         }
     }
     $tag = $item->getNamedTagEntry("CanDestroy");
     if ($tag instanceof ListTag) {
         $canBreak = false;
         foreach ($tag as $v) {
             if ($v instanceof StringTag) {
                 $entry = Item::fromString($v->getValue());
                 if ($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()) {
                     $canBreak = true;
                     break;
                 }
             }
         }
         if (!$canBreak) {
             return false;
         }
     }
     if ($createParticles) {
         $players = $this->getChunkPlayers($target->x >> 4, $target->z >> 4);
         /*if($player !== null){
         			unset($players[$player->getLoaderId()]);
         		}*/
         $this->addParticle(new DestroyBlockParticle($target->add(0.5), $target), $players);
     }
     $target->onBreak($item);
     $tile = $this->getTile($target);
     if ($tile !== null) {
         if ($tile instanceof InventoryHolder) {
             if ($tile instanceof Chest) {
                 $tile->unpair();
             }
             foreach ($tile->getInventory()->getContents() as $chestItem) {
                 $this->dropItem($target, $chestItem);
             }
         }
         $tile->close();
     }
     if ($item !== null) {
         $item->useOn($target);
         if ($item->isTool() and $item->getDamage() >= $item->getMaxDurability()) {
             $item = Item::get(Item::AIR, 0, 0);
         }
     }
     if ($player === null or $player->isSurvival()) {
         foreach ($drops as $drop) {
             if ($drop->getCount() > 0) {
                 $this->dropItem($vector->add(0.5, 0.5, 0.5), $drop);
             }
         }
     }
     return true;
 }
Пример #23
0
 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;
 }
Пример #24
-1
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $targetBlock = Block::get($this->meta);
     if ($targetBlock instanceof Air) {
         if ($target instanceof Liquid and $target->getDamage() === 0) {
             $result = clone $this;
             $result->setDamage($target->getId());
             $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
             if (!$ev->isCancelled()) {
                 $player->getLevel()->setBlock($target, new Air(), true, true);
                 if ($player->isSurvival()) {
                     $player->getInventory()->setItemInHand($ev->getItem(), $player);
                 }
                 return true;
             } else {
                 $player->getInventory()->sendContents($player);
             }
         }
     } elseif ($targetBlock instanceof Liquid) {
         $result = clone $this;
         $result->setDamage(0);
         $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
         if (!$ev->isCancelled()) {
             $player->getLevel()->setBlock($block, $targetBlock, true, true);
             if ($player->isSurvival()) {
                 $player->getInventory()->setItemInHand($ev->getItem(), $player);
             }
             return true;
         } else {
             $player->getInventory()->sendContents($player);
         }
     }
     return false;
 }
Пример #25
-1
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $entity = null;
     $chunk = $level->getChunk($block->getX() >> 4, $block->getZ() >> 4);
     if (!$chunk instanceof FullChunk) {
         return false;
     }
     $nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $block->getX() + 0.5), new Double("", $block->getY()), new Double("", $block->getZ() + 0.5)]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", lcg_value() * 360), new Float("", 0)])]);
     if ($this->hasCustomName()) {
         $nbt->CustomName = new String("CustomName", $this->getCustomName());
     }
     $entity = Entity::createEntity($this->meta, $chunk, $nbt);
     if ($entity instanceof Entity) {
         $entity->setDataProperty(15, Entity::DATA_TYPE_BYTE, 1);
         $entity->getLevel()->getServer()->broadcastPopup(TextFormat::RED . "Mob AI isn't implemented yet!");
         if ($player->isSurvival()) {
             --$this->count;
         }
         $entity->spawnToAll();
         return true;
     }
     return false;
 }
Пример #26
-1
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if ($target->isTransparent() === false and $face > 1 and $block->isSolid() === false) {
         $chunk = $level->getChunk($block->getX() >> 4, $block->getZ() >> 4);
         $faces = [2 => 1, 3 => 3, 4 => 0, 5 => 2];
         $motives = [["Kebab", 1, 1], ["Aztec", 1, 1], ["Alban", 1, 1], ["Aztec2", 1, 1], ["Bomb", 1, 1], ["Plant", 1, 1], ["Wasteland", 1, 1], ["Wanderer", 1, 2], ["Graham", 1, 2], ["Pool", 2, 1], ["Courbet", 2, 1], ["Sunset", 2, 1], ["Sea", 2, 1], ["Creebet", 2, 1], ["Match", 2, 2], ["Bust", 2, 2], ["Stage", 2, 2], ["Void", 2, 2], ["SkullAndRoses", 2, 2], ["Fighters", 4, 2], ["Skeleton", 4, 3], ["DonkeyKong", 4, 3], ["Pointer", 4, 4], ["Pigscene", 4, 4], ["Flaming Skull", 4, 4]];
         if ($this->hasCustomName()) {
             $nbt->CustomName = new String("CustomName", $this->getCustomName());
         }
         $motive = $motives[mt_rand(0, count($motives) - 1)];
         $data = ["x" => $target->x, "y" => $target->y, "z" => $target->z, "yaw" => $faces[$face] * 90, "Motive" => $motive[0]];
         $nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $target->x), new Double("", $target->y), new Double("", $target->z)]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", $faces[$face] * 90), new Float("", 0)])]);
         $entity = Entity::createEntity($this->meta, $chunk, $nbt, $data);
         if ($entity instanceof Entity) {
             if ($player->isSurvival()) {
                 --$this->count;
             }
             $entity->spawnToAll();
             return true;
         }
         return true;
     }
     return false;
 }
Пример #27
-1
 /**
  * Tries to break a block using a item, including Player time checks if available
  * It'll try to lower the durability if Item is a tool, and set it to Air if broken.
  *
  * @param Vector3 $vector
  * @param Item    &$item (if null, can break anything)
  * @param Player  $player
  *
  * @return boolean
  */
 public function useBreakOn(Vector3 $vector, Item &$item = null, Player $player = null)
 {
     $target = $this->getBlock($vector);
     //TODO: Adventure mode checks
     if ($item === null) {
         $item = Item::get(Item::AIR, 0, 0);
     }
     if ($player instanceof Player) {
         $ev = new BlockBreakEvent($player, $target, $item, ($player->getGamemode() & 0x1) === 1 ? true : false);
         if ($player->isSurvival() and $item instanceof Item and !$target->isBreakable($item)) {
             $ev->setCancelled();
         }
         if (!$player->isOp() and ($distance = $this->server->getConfigInt("spawn-protection", 16)) > -1) {
             $t = new Vector2($target->x, $target->z);
             $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z);
             if ($t->distance($s) <= $distance) {
                 //set it to cancelled so plugins can bypass this
                 $ev->setCancelled();
             }
         }
         $this->server->getPluginManager()->callEvent($ev);
         if ($ev->isCancelled()) {
             return false;
         }
         $breakTime = $player->isCreative() ? 0.15 : $target->getBreakTime($item);
         if (!$ev->getInstaBreak() and $player->lastBreak + $breakTime >= microtime(true)) {
             return false;
         }
         $player->lastBreak = microtime(true);
     } elseif ($item instanceof Item and !$target->isBreakable($item)) {
         return false;
     }
     $level = $target->getLevel();
     if ($level instanceof Level) {
         $above = $level->getBlock(new Vector3($target->x, $target->y + 1, $target->z));
         if ($above instanceof Block) {
             if ($above->getId() === Item::FIRE) {
                 $level->setBlock($above, new Air(), true);
             }
         }
     }
     $drops = $target->getDrops($item);
     //Fixes tile entities being deleted before getting drops
     $target->onBreak($item);
     $tile = $this->getTile($target);
     if ($tile instanceof Tile) {
         if ($tile instanceof InventoryHolder) {
             if ($tile instanceof Chest) {
                 $tile->unpair();
             }
             foreach ($tile->getInventory()->getContents() as $chestItem) {
                 $this->dropItem($target, $chestItem);
             }
         }
         $tile->close();
     }
     if ($item instanceof Item) {
         $item->useOn($target);
         if ($item->isTool() and $item->getDamage() >= $item->getMaxDurability()) {
             $item = Item::get(Item::AIR, 0, 0);
         }
     }
     if (!$player instanceof Player or $player->isSurvival()) {
         foreach ($drops as $drop) {
             if ($drop[2] > 0) {
                 $this->dropItem($vector->add(0.5, 0.5, 0.5), Item::get(...$drop));
             }
         }
     }
     return true;
 }
Пример #28
-1
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if ($target->getId() === Block::OBSIDIAN and $player->getServer()->netherEnabled) {
         //黑曜石 4*5最小 23*23最大
         //$level->setBlock($block, new Fire(), true);
         $tx = $target->getX();
         $ty = $target->getY();
         $tz = $target->getZ();
         //x方向
         $x_max = $tx;
         //x最大值
         $x_min = $tx;
         //x最小值
         for ($x = $tx + 1; $level->getBlock($this->temporalVector->setComponents($x, $ty, $tz))->getId() == Block::OBSIDIAN; $x++) {
             $x_max++;
         }
         for ($x = $tx - 1; $level->getBlock($this->temporalVector->setComponents($x, $ty, $tz))->getId() == Block::OBSIDIAN; $x--) {
             $x_min--;
         }
         $count_x = $x_max - $x_min + 1;
         //x方向方块
         if ($count_x >= 4 and $count_x <= 23) {
             //4 23
             $x_max_y = $ty;
             //x最大值时的y最大值
             $x_min_y = $ty;
             //x最小值时的y最大值
             for ($y = $ty; $level->getBlock($this->temporalVector->setComponents($x_max, $y, $tz))->getId() == Block::OBSIDIAN; $y++) {
                 $x_max_y++;
             }
             for ($y = $ty; $level->getBlock($this->temporalVector->setComponents($x_min, $y, $tz))->getId() == Block::OBSIDIAN; $y++) {
                 $x_min_y++;
             }
             $y_max = min($x_max_y, $x_min_y) - 1;
             //y最大值
             $count_y = $y_max - $ty + 2;
             //方向方块
             //Server::getInstance()->broadcastMessage("$y_max $x_max_y $x_min_y $x_max $x_min");
             if ($count_y >= 5 and $count_y <= 23) {
                 //5 23
                 $count_up = 0;
                 //上面
                 for ($ux = $x_min; $level->getBlock($this->temporalVector->setComponents($ux, $y_max, $tz))->getId() == Block::OBSIDIAN and $ux <= $x_max; $ux++) {
                     $count_up++;
                 }
                 //Server::getInstance()->broadcastMessage("$count_up $count_x");
                 if ($count_up == $count_x) {
                     for ($px = $x_min + 1; $px < $x_max; $px++) {
                         for ($py = $ty + 1; $py < $y_max; $py++) {
                             $level->setBlock($this->temporalVector->setComponents($px, $py, $tz), new Portal());
                         }
                     }
                     if ($player->isSurvival()) {
                         $this->useOn($block, 2);
                         $player->getInventory()->setItemInHand($this);
                     }
                     return true;
                 }
             }
         }
         //z方向
         $z_max = $tz;
         //z最大值
         $z_min = $tz;
         //z最小值
         $count_z = 0;
         //z方向方块
         for ($z = $tz + 1; $level->getBlock($this->temporalVector->setComponents($tx, $ty, $z))->getId() == Block::OBSIDIAN; $z++) {
             $z_max++;
         }
         for ($z = $tz - 1; $level->getBlock($this->temporalVector->setComponents($tx, $ty, $z))->getId() == Block::OBSIDIAN; $z--) {
             $z_min--;
         }
         $count_z = $z_max - $z_min + 1;
         if ($count_z >= 4 and $count_z <= 23) {
             //4 23
             $z_max_y = $ty;
             //z最大值时的y最大值
             $z_min_y = $ty;
             //z最小值时的y最大值
             for ($y = $ty; $level->getBlock($this->temporalVector->setComponents($tx, $y, $z_max))->getId() == Block::OBSIDIAN; $y++) {
                 $z_max_y++;
             }
             for ($y = $ty; $level->getBlock($this->temporalVector->setComponents($tx, $y, $z_min))->getId() == Block::OBSIDIAN; $y++) {
                 $z_min_y++;
             }
             $y_max = min($z_max_y, $z_min_y) - 1;
             //y最大值
             $count_y = $y_max - $ty + 2;
             //方向方块
             if ($count_y >= 5 and $count_y <= 23) {
                 //5 23
                 $count_up = 0;
                 //上面
                 for ($uz = $z_min; $level->getBlock($this->temporalVector->setComponents($tx, $y_max, $uz))->getId() == Block::OBSIDIAN and $uz <= $z_max; $uz++) {
                     $count_up++;
                 }
                 //Server::getInstance()->broadcastMessage("$count_up $count_z");
                 if ($count_up == $count_z) {
                     for ($pz = $z_min + 1; $pz < $z_max; $pz++) {
                         for ($py = $ty + 1; $py < $y_max; $py++) {
                             $level->setBlock($this->temporalVector->setComponents($tx, $py, $pz), new Portal());
                         }
                     }
                     if ($player->isSurvival()) {
                         $this->useOn($block, 2);
                         $player->getInventory()->setItemInHand($this);
                     }
                     return true;
                 }
             }
         }
         //return true;
     }
     if ($block->getId() === self::AIR and $target instanceof Solid) {
         $level->setBlock($block, new Fire(), true);
         /** @var Fire $block */
         $block = $level->getBlock($block);
         if ($block->getSide(Vector3::SIDE_DOWN)->isTopFacingSurfaceSolid() or $block->canNeighborBurn()) {
             $level->scheduleUpdate($block, $block->getTickRate() + mt_rand(0, 10));
             //	return true;
         }
         if ($player->isSurvival()) {
             $this->useOn($block, 2);
             //耐久跟报废分别写在 tool 跟 level 了
             $player->getInventory()->setItemInHand($this);
         }
         return true;
     }
     return false;
 }
Пример #29
-1
 /**
  * Tries to break a block using a item, including Player time checks if available
  * It'll try to lower the durability if Item is a tool, and set it to Air if broken.
  *
  * @param Vector3 $vector
  * @param Item    &$item (if null, can break anything)
  * @param Player  $player
  * @param bool    $createParticles
  *
  * @return boolean
  */
 public function useBreakOn(Vector3 $vector, Item &$item = null, Player $player = null, $createParticles = false)
 {
     $target = $this->getBlock($vector);
     //TODO: Adventure mode checks
     if ($item === null) {
         $item = Item::get(Item::AIR, 0, 0);
     }
     if ($player !== null) {
         $ev = new BlockBreakEvent($player, $target, $item, $player->isCreative() ? true : false);
         if ($player->isSurvival() and $item instanceof Item and !$target->isBreakable($item)) {
             $ev->setCancelled();
         } elseif (!$player->isOp() and ($distance = $this->server->getSpawnRadius()) > -1) {
             $t = new Vector2($target->x, $target->z);
             $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z);
             if (count($this->server->getOps()->getAll()) > 0 and $t->distance($s) <= $distance) {
                 //set it to cancelled so plugins can bypass this
                 $ev->setCancelled();
             }
         }
         $this->server->getPluginManager()->callEvent($ev);
         if ($ev->isCancelled()) {
             return false;
         }
         $breakTime = $player->isCreative() ? 0.15 : $target->getBreakTime($item);
         if ($player->hasEffect(Effect::SWIFTNESS)) {
             $breakTime *= 1 - 0.2 * ($player->getEffect(Effect::SWIFTNESS)->getAmplifier() + 1);
         }
         if ($player->hasEffect(Effect::MINING_FATIGUE)) {
             $breakTime *= 1 + 0.3 * ($player->getEffect(Effect::MINING_FATIGUE)->getAmplifier() + 1);
         }
         $breakTime -= 0.05;
         //1 tick compensation
         if (!$ev->getInstaBreak() and $player->lastBreak + $breakTime > microtime(true)) {
             return false;
         }
         $player->lastBreak = PHP_INT_MAX;
         $drops = $ev->getDrops();
     } elseif ($item !== null and !$target->isBreakable($item)) {
         return false;
     } else {
         $drops = $target->getDrops($item);
         //Fixes tile entities being deleted before getting drops
         foreach ($drops as $k => $i) {
             $drops[$k] = Item::get($i[0], $i[1], $i[2]);
         }
     }
     $above = $this->getBlock(new Vector3($target->x, $target->y + 1, $target->z));
     if ($above !== null) {
         if ($above->getId() === Item::FIRE) {
             $this->setBlock($above, new Air(), true);
         }
     }
     if ($createParticles) {
         $players = $this->getChunkPlayers($target->x >> 4, $target->z >> 4);
         if ($player !== null) {
             unset($players[$player->getLoaderId()]);
         }
         $pk = new LevelEventPacket();
         $pk->evid = 2001;
         $pk->x = $target->x + 0.5;
         $pk->y = $target->y + 0.5;
         $pk->z = $target->z + 0.5;
         $pk->data = $target->getId() + ($target->getDamage() << 12);
         Server::broadcastPacket($players, $pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
     }
     $target->onBreak($item);
     $tile = $this->getTile($target);
     if ($tile !== null) {
         if ($tile instanceof InventoryHolder) {
             if ($tile instanceof Chest) {
                 $tile->unpair();
             }
             foreach ($tile->getInventory()->getContents() as $chestItem) {
                 $this->dropItem($target, $chestItem);
             }
         }
         $tile->close();
     }
     if ($item !== null) {
         $item->useOn($target);
         if ($item->isTool() and $item->getDamage() >= $item->getMaxDurability()) {
             $item = Item::get(Item::AIR, 0, 0);
         }
     }
     if ($player === null or $player->isSurvival()) {
         foreach ($drops as $drop) {
             if ($drop->getCount() > 0) {
                 $this->dropItem($vector->add(0.5, 0.5, 0.5), $drop);
             }
         }
     }
     return true;
 }
Пример #30
-2
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $blockTemp = $level->getBlock($block->add(0, -1, 0));
     //if(!$block instanceof RailBlock || !$block instanceof Rail) return false; in previuos version IM
     //if($blockTemp->getId() != self::RAIL and $blockTemp->getId() != self::POWERED_RAIL) return; in previuos version Genisys
     $minecart = new MinecartEntity($player->getLevel()->getChunk($block->getX() >> 4, $block->getZ() >> 4), new CompoundTag("", array("Pos" => new ListTag("Pos", array(new DoubleTag("", $block->getX()), new DoubleTag("", $block->getY() + 1), new DoubleTag("", $block->getZ()))), "Motion" => new ListTag("Motion", array(new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0))), "Rotation" => new ListTag("Rotation", array(new FloatTag("", 0), new FloatTag("", 0))))));
     $minecart->spawnToAll();
     if ($player->isSurvival()) {
         $item = $player->getInventory()->getItemInHand();
         $count = $item->getCount();
         if (--$count <= 0) {
             $player->getInventory()->setItemInHand(Item::get(Item::AIR));
             return;
         }
         $item->setCount($count);
         $player->getInventory()->setItemInHand($item);
     }
     return true;
 }