/**
  * @param Block $block
  * @return bool
  */
 public function isFreezable(Block $block)
 {
     if (isset($this->configs[$ilevel = strtolower($block->getLevel()->getName())])) {
         return $this->configs[$ilevel]->exists($block->getId() . ":" . $block->getDamage(), true);
     }
     return false;
 }
 /**
  * @param CommandSender $sender
  * @param Block $block
  */
 public function sendBlockInfo(CommandSender $sender, Block $block)
 {
     $sender->sendMessage("Name: " . $block->getName());
     $sender->sendMessage("XYZ: " . $block->getFloorX() . ":" . $block->getFloorY() . ":" . $block->getFloorZ());
     $sender->sendMessage("Level: " . $block->getLevel()->getName());
     $sender->sendMessage("Block-id: " . $block->getId() . ":" . $block->getDamage());
     $sender->sendMessage("Hardness: " . $block->getHardness());
     $sender->sendMessage("Resistance: " . $block->getResistance());
     $sender->sendMessage("Tool-type: " . $block->getToolType());
     $sender->sendMessage("Friction: " . $block->getFrictionFactor());
     $sender->sendMessage("Light-level: " . $block->getLightLevel());
     //$sender->sendMessage("Is-placeable: ".($block->canBePlaced() ? TextFormat::GREEN."yes" : TextFormat::RED."no"));
     $sender->sendMessage("Is-replaceable: " . ($block->canBeReplaced() ? TextFormat::GREEN . "yes" : TextFormat::RED . "no"));
     $sender->sendMessage("Is-transparent: " . ($block->isTransparent() ? TextFormat::GREEN . "yes" : TextFormat::RED . "no"));
     $sender->sendMessage("Is-solid: " . ($block->isSolid() ? TextFormat::GREEN . "yes" : TextFormat::RED . "no"));
     //$sender->sendMessage("Is-flowable: ".($block->canBeFlowedInto() ? TextFormat::GREEN."yes" : TextFormat::RED."no"));
     //$sender->sendMessage("Is-activateable: ".($block->canBeActivated() ? TextFormat::GREEN."yes" : TextFormat::RED."no"));
     $sender->sendMessage("Is-passable: " . ($block->canPassThrough() ? TextFormat::GREEN . "yes" : TextFormat::RED . "no"));
     $dropCount = 0;
     $dropNames = "";
     foreach ($block->getDrops() as $drop) {
         $dropNames .= $drop->getName() . ", ";
         $dropCount++;
     }
     $sender->sendMessage("Drops (" . $dropCount . "): " . substr($dropNames, 0, -2));
 }
 /**
  * @param Block $block
  * @return bool
  */
 private function isBlockSpecified(Block $block)
 {
     $key = array_change_key_case($this->getConfig()->getNested("level." . $block->getLevel()->getName()), CASE_LOWER);
     if (is_array($key)) {
         return in_array($block->getId() . ":" . $block->getDamage(), $key);
     }
 }
 /**
  * @param Block $block
  * @return bool
  */
 public function isBlockSpecified(Block $block)
 {
     $key = array_change_key_case($this->getConfig()->get("level"), CASE_LOWER);
     $levelKey = $key[strtolower($block->getLevel()->getName())];
     if (is_array($levelKey)) {
         return in_array($block->getId() . ":" . $block->getDamage(), $levelKey);
     }
 }
 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->getLevel()->getGameRule("doTileDrops") ? $block->getDrops($item) : [] : [];
     foreach ($drops as $i) {
         $this->blockDrops[] = Item::get($i[0], $i[1], $i[2]);
     }
 }
Example #6
0
 /**
  * @param Block $sourceBlock a Block with the absolute X, Y and Z from the original level
  */
 public function addEntry(Block $sourceBlock)
 {
     if (!$this->isWritable) {
         throw new \InvalidStateException("This clip is not writable");
     }
     if (!$sourceBlock->isValid()) {
         throw new \InvalidArgumentException("Source block must contain a level and absolute coords");
     }
     if ($sourceBlock->getLevel()->getName() !== $this->levelName) {
         throw new \InvalidStateException("Block is not from the level clip is being written in");
     }
     $delta = $sourceBlock->subtract($this->anchor);
     $insert = Block::get($sourceBlock->getId(), $sourceBlock->getDamage(), Position::fromObject($delta->subtract($this->anchor)));
     $this->entries[] = $insert;
 }
Example #7
0
 public function getDispenserId(Block $block)
 {
     return $block->getX() . ":" . $block->getY() . ":" . $block->getZ() . ":" . $block->getLevel()->getFolderName();
 }
Example #8
0
 /**
  * @param Block $stump
  * @return int
  */
 public function getTreetop(Block $stump)
 {
     $level = $stump->getLevel();
     $floor = $level->getBlock($stump->getSide(0));
     if (!in_array($floor->getId(), self::FLOORS)) {
         return -1;
     }
     $found = null;
     $maxHeight = $this->getConfig()->get("maxWorldHeight") - $stump->getY();
     for ($height = 0; $height < $maxHeight; $height++) {
         $block = $level->getBlock($stump->add(0, $height, 0));
         if (in_array($block->getId(), self::WOODS)) {
             if ($found === null) {
                 $found = [$block->getId(), $block->getDamage()];
             } elseif ($found[0] !== $block->getId() or $found[1] !== $block->getDamage()) {
                 return -1;
             }
         } elseif ($found !== null and in_array($block->getId(), self::LEAVES)) {
             return $height;
         } else {
             return -1;
         }
     }
     return -1;
 }
 private static function rotateBlockByOne(Block $block)
 {
     return Block::get($block->getID(), $block->getDamage(), new Position($block->getZ(), $block->getY(), -$block->getX(), $block->getLevel()));
 }
Example #10
0
 /**
  * Adds a resettable chest
  * @param Block $chest
  */
 public function addChest(Block $chest)
 {
     $chests = $this->config->chests;
     $chests[count($this->chests)] = ['id' => $chest->getId(), 'x' => $chest->getX(), 'y' => $chest->getY(), 'z' => $chest->getZ(), 'level' => $chest->getLevel()->getId()];
     $this->config->set("chests", $chests);
     $this->config->save();
     array_push($this->chests, $chest);
 }
Example #11
0
 private function destroyTrunk(Block $bl)
 {
     $damage = 0;
     if ($bl->getId() != Block::WOOD) {
         return $damage;
     }
     $down = $bl->getSide(Vector3::SIDE_DOWN);
     if ($down->getId() == Block::WOOD) {
         return $damage;
     }
     $l = $bl->getLevel();
     for ($y = $bl->getY() + 1; $y < 128; ++$y) {
         $x = $bl->getX();
         $z = $bl->getZ();
         $bl = $l->getBlock(new Vector3($x, $y, $z));
         if ($bl->getId() != Block::WOOD) {
             break;
         }
         ++$damage;
         $l->dropItem($bl, new ItemBlock($bl));
         $l->setBlockIdAt($x, $y, $z, 0);
         $l->setBlockDataAt($x, $y, $z, 0);
     }
     return $damage;
 }
Example #12
0
 public function replaceBlock($startX, $startY, $startZ, $endX, $endY, $endZ, Block $block, Block $target, Player $player = null)
 {
     $count = 0;
     $x = $startX;
     $y = $startY;
     $z = $startZ;
     if (is_array($y)) {
         $startY = $y[1];
         $y = $y[0];
     }
     if (is_array($z)) {
         $startZ = $z[1];
         $z = $z[0];
     }
     while (true) {
         if ($count < $this->getData("limit-block", 130)) {
             $chunk = $block->getLevel()->getChunk($x >> 4, $z >> 4, true);
             if ($chunk !== null) {
                 $id = $chunk->getBlockId($x & 0xf, $y & 0x7f, $z & 0xf);
                 $meta = $chunk->getBlockData($x & 0xf, $y & 0x7f, $z & 0xf);
                 if ($id === $block->getId() && $meta === $block->getDamage()) {
                     ++$count;
                     $this->saveUndo($block, $pos = new Vector3($x, $y, $z));
                     $this->set($target, $pos);
                 }
             }
             if ($z < $endZ) {
                 $z++;
             } else {
                 $z = $startZ;
                 if ($y < $endY) {
                     $y++;
                 } else {
                     $y = $startY;
                     if ($x < $endX) {
                         $x++;
                     } else {
                         break;
                     }
                 }
             }
         } else {
             self::core()->getScheduler()->scheduleDelayedTask(new WorldEditorTask([$this, "replaceBlock"], [$x, [$y, $startY], [$z, $startZ], $endX, $endY, $endZ, $block, $target, $player], $this), 1);
             return;
         }
     }
     if ($player !== null) {
         $player->sendMessage("[WorldEditor]모든 블럭을 변경했어요");
     }
     if ($this->getData("debug", false)) {
         $name = $player === null ? "" : "{$player->getName()}님이 ";
         self::core()->getLogger()->info("[WorldEditor]{$name}블럭변경을 끝냈어요");
     }
 }
 /** 
  * @param Block $block 
  */
 public function removeRocketPad(Block $block)
 {
     $this->pads->remove($block->getFloorX() . ":" . $block->getFloorY() . ":" . $block->getFloorZ() . ":" . strtolower($block->getLevel()->getName()));
     $this->pads->save();
 }