getBlock() public method

Gets the Block object on the Vector3 location
public getBlock ( Vector3 $pos, boolean $cached = true ) : Block
$pos pocketmine\math\Vector3
$cached boolean
return pocketmine\block\Block
Esempio n. 1
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 CompoundTag("", ["Pos" => new EnumTag("Pos", [new DoubleTag("", $block->getX()), new DoubleTag("", $block->getY() + 1), new DoubleTag("", $block->getZ())]), "Motion" => new EnumTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new EnumTag("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;
         }
         $item->setCount($count);
         $player->getInventory()->setItemInHand($item);
     }
     return true;
 }
Esempio n. 2
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(!$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 Compound("", array("Pos" => new Enum("Pos", array(new Double("", $block->getX()), new Double("", $block->getY() + 1), new Double("", $block->getZ()))), "Motion" => new Enum("Motion", array(new Double("", 0), new Double("", 0), new Double("", 0))), "Rotation" => new Enum("Rotation", array(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;
 }
Esempio n. 3
0
 public function __construct(Level $level, Vector3 $pos)
 {
     if (!($pos instanceof Vector3 && $level instanceof Level)) {
         echo "this is not Floor!\n";
     }
     $this->vector = $pos;
     $this->x = $pos->getX();
     $this->y = $pos->getY();
     $this->z = $pos->getZ();
     $this->level = $level;
     $this->block = $level->getBlock($pos);
     $this->id = $this->block->getId();
     $this->data = $this->block->getDamage();
     $this->height = 128;
     //$this->level->getHeightMap($this->x, $this->z);
     echo "max height: {$this->height}\n";
     if (!($this->isElevatorBlock($this->block) || $this->isExtensionFloorBlock($this->block))) {
         echo "THIS IS NOT FLOOR!\n";
     }
 }
Esempio n. 4
0
 public function whatBlock(Level $level, $v3)
 {
     //boybook的y轴判断法 核心 什么方块?
     $block = $level->getBlock($v3);
     $id = $block->getID();
     $damage = $block->getDamage();
     switch ($id) {
         case 0:
         case 6:
         case 27:
         case 30:
         case 31:
         case 37:
         case 38:
         case 39:
         case 40:
         case 50:
         case 51:
         case 63:
         case 66:
         case 68:
         case 78:
         case 111:
         case 141:
         case 142:
         case 171:
         case 175:
         case 244:
         case 323:
             //无碰撞体积的板
         //无碰撞体积的板
         case 78:
         case 70:
         case 72:
         case 147:
         case 148:
             //透明方块
             return "air";
             break;
         case 8:
         case 9:
             //水
             return "water";
             break;
         case 10:
         case 11:
             //岩浆
             return "lava";
             break;
         case 44:
         case 158:
             //半砖
             if ($damage >= 8) {
                 return "block";
             } else {
                 return "half";
             }
             break;
         case 64:
             //门
             //var_dump($damage." ");
             //TODO 不知如何判断门是否开启,因为以下条件永远满足
             if ($block->isOpened()) {
                 return "air";
             } else {
                 return "block";
             }
             break;
         case 85:
         case 107:
         case 139:
             //1.5格高的无法跳跃物
             return "high";
             break;
         case 65:
         case 106:
             //可攀爬物
             return "climb";
             break;
         default:
             //普通方块
             return "block";
             break;
     }
 }
Esempio n. 5
0
 public function __construct(Level $level, Vector3 $start, Vector3 $direction, $yOffset = 0, $maxDistance = 0)
 {
     $this->level = $level;
     $this->maxDistance = (int) $maxDistance;
     $this->blockQueue = new \SplFixedArray(3);
     $startClone = new Vector3($start->x, $start->y, $start->z);
     $startClone->y += $yOffset;
     $this->currentDistance = 0;
     $mainDirection = 0;
     $secondDirection = 0;
     $thirdDirection = 0;
     $mainPosition = 0;
     $secondPosition = 0;
     $thirdPosition = 0;
     $pos = new Vector3($startClone->x, $startClone->y, $startClone->z);
     $startBlock = $this->level->getBlock(new Vector3(floor($pos->x), floor($pos->y), floor($pos->z)));
     if ($this->getXLength($direction) > $mainDirection) {
         $this->mainFace = $this->getXFace($direction);
         $mainDirection = $this->getXLength($direction);
         $mainPosition = $this->getXPosition($direction, $startClone, $startBlock);
         $this->secondFace = $this->getYFace($direction);
         $secondDirection = $this->getYLength($direction);
         $secondPosition = $this->getYPosition($direction, $startClone, $startBlock);
         $this->thirdFace = $this->getZFace($direction);
         $thirdDirection = $this->getZLength($direction);
         $thirdPosition = $this->getZPosition($direction, $startClone, $startBlock);
     }
     if ($this->getYLength($direction) > $mainDirection) {
         $this->mainFace = $this->getYFace($direction);
         $mainDirection = $this->getYLength($direction);
         $mainPosition = $this->getYPosition($direction, $startClone, $startBlock);
         $this->secondFace = $this->getZFace($direction);
         $secondDirection = $this->getZLength($direction);
         $secondPosition = $this->getZPosition($direction, $startClone, $startBlock);
         $this->thirdFace = $this->getXFace($direction);
         $thirdDirection = $this->getXLength($direction);
         $thirdPosition = $this->getXPosition($direction, $startClone, $startBlock);
     }
     if ($this->getZLength($direction) > $mainDirection) {
         $this->mainFace = $this->getZFace($direction);
         $mainDirection = $this->getZLength($direction);
         $mainPosition = $this->getZPosition($direction, $startClone, $startBlock);
         $this->secondFace = $this->getXFace($direction);
         $secondDirection = $this->getXLength($direction);
         $secondPosition = $this->getXPosition($direction, $startClone, $startBlock);
         $this->thirdFace = $this->getYFace($direction);
         $thirdDirection = $this->getYLength($direction);
         $thirdPosition = $this->getYPosition($direction, $startClone, $startBlock);
     }
     $d = $mainPosition / $mainDirection;
     $secondd = $secondPosition - $secondDirection * $d;
     $thirdd = $thirdPosition - $thirdDirection * $d;
     $this->secondError = floor($secondd * self::$gridSize);
     $this->secondStep = round($secondDirection / $mainDirection * self::$gridSize);
     $this->thirdError = floor($thirdd * self::$gridSize);
     $this->thirdStep = round($thirdDirection / $mainDirection * self::$gridSize);
     if ($this->secondError + $this->secondStep <= 0) {
         $this->secondError = -$this->secondStep + 1;
     }
     if ($this->thirdError + $this->thirdStep <= 0) {
         $this->thirdError = -$this->thirdStep + 1;
     }
     $lastBlock = $startBlock->getSide(Vector3::getOppositeSide($this->mainFace));
     if ($this->secondError < 0) {
         $this->secondError += self::$gridSize;
         $lastBlock = $lastBlock->getSide(Vector3::getOppositeSide($this->secondFace));
     }
     if ($this->thirdError < 0) {
         $this->thirdError += self::$gridSize;
         $lastBlock = $lastBlock->getSide(Vector3::getOppositeSide($this->thirdFace));
     }
     $this->secondError -= self::$gridSize;
     $this->thirdError -= self::$gridSize;
     $this->blockQueue[0] = $lastBlock;
     $this->currentBlock = -1;
     $this->scan();
     $startBlockFound = false;
     for ($cnt = $this->currentBlock; $cnt >= 0; --$cnt) {
         if ($this->blockEquals($this->blockQueue[$cnt], $startBlock)) {
             $this->currentBlock = $cnt;
             $startBlockFound = true;
             break;
         }
     }
     if (!$startBlockFound) {
         throw new \InvalidStateException("Start block missed in BlockIterator");
     }
     $this->maxDistanceInt = round($maxDistance / (sqrt($mainDirection ** 2 + $secondDirection ** 2 + $thirdDirection ** 2) / $mainDirection));
 }
 public function updateBlock2(Block $block, Level $level, $blockType)
 {
     $players = $level->getPlayers();
     foreach ($players as $p) {
         $pk = new UpdateBlockPacket();
         $pk->x = $block->getX();
         $pk->y = $block->getY();
         $pk->z = $block->getZ();
         $pk->block = $blockType;
         $pk->meta = 0;
         $p->dataPacket($pk);
         $level->setBlockIdAt($block->getX(), $block->getY(), $block->getZ(), $blockType);
         $pos = new Position($block->x, $block->y, $block->z);
         $block = $level->getBlock($pos, true);
         $direct = true;
         $update = true;
         $level->setBlock($pos, $block, $direct, $update);
     }
 }
 /**
  * Validate Blue Team Captured Flag
  *
  * @param Player $player
  * @param Level $level
  * @param unknown $rb
  */
 public function checkBlueTeamCapturedEnermyFlag(Player $player, Level $level, $rb)
 {
     $blueTeamEnemyFlagPos = $this->getSetup()->getFlagPos(CTFSetup::CTF_FLAG_BLUE_TEAM_ENEMY);
     if (round($rb->x) == round($blueTeamEnemyFlagPos->x) && round($rb->y) == round($blueTeamEnemyFlagPos->y) && round($rb->z) == round($blueTeamEnemyFlagPos->z)) {
         // check if enermy flag is destroyed
         $blueTeamFlagPos = $this->getSetup()->getFlagPos(CTFSetup::CTF_FLAG_RED_TEAM);
         $redflag = $level->getBlock($blueTeamFlagPos);
         if ($redflag->getId() != 0) {
             $player->sendMessage($this->getMsg("ctf.error.redteam-flag-exist"));
             // erase placed block
             $this->getBuilder()->resetBlock($rb, $level, 0);
             return;
         }
         // blue team has enermy flag, announce blue team winning
         $output = "";
         $output .= TextFormat::GRAY . "------------------------------\n";
         $output .= TextFormat::GREEN . $this->getMsg("ctf.conglatulations") . "\n";
         $output .= TextFormat::BLUE . $this->getMsg("ctf.blue-team.capturedflag") . "\n";
         $output .= TextFormat::GRAY . "------------------------------\n";
         // update blue team winning score
         $this->getPlugIn()->blueTeamWins++;
         $output .= TextFormat::LIGHT_PURPLE . $this->getMsg("ctf.blue-team.score") . $this->getPlugIn()->blueTeamWins . "\n";
         $output .= TextFormat::LIGHT_PURPLE . $this->getMsg("ctf.red-team.score") . $this->getPlugIn()->redTeamWins . "\n";
         $output .= TextFormat::GRAY . "------------------------------\n";
         //$level->getServer ()->broadcastMessage ( $output );
         $level->getServer()->broadcastMessage($output, $this->plugin->blueTeamPLayers);
         $level->getServer()->broadcastMessage($output, $this->plugin->redTeamPlayers);
         $this->getPlugIn()->gameMode = 0;
         $this->moveTeamBackToSpawnpointOnCapturedEnermyFlag();
         // send scheduled task
         $this->handleNextRoundOfGame($level);
     }
 }
Esempio n. 8
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if (($player->gamemode & 0x1) === 0 and $this->useOn($block) and $this->getDamage() >= $this->getMaxDurability()) {
         $player->getInventory()->setItemInHand(new Item(Item::AIR, 0, 0));
     }
     if ($target->getId() === 49 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最小值
         $count_x = 0;
         //x方向方块
         for ($x = $tx + 1; $level->getBlock(new Vector3($x, $ty, $tz))->getId() == 49; $x++) {
             $x_max++;
         }
         for ($x = $tx - 1; $level->getBlock(new Vector3($x, $ty, $tz))->getId() == 49; $x--) {
             $x_min--;
         }
         $count_x = $x_max - $x_min + 1;
         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(new Vector3($x_max, $y, $tz))->getId() == 49; $y++) {
                 $x_max_y++;
             }
             for ($y = $ty; $level->getBlock(new Vector3($x_min, $y, $tz))->getId() == 49; $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(new Vector3($ux, $y_max, $tz))->getId() == 49 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(new Vector3($px, $py, $tz), new Block(90, 0));
                         }
                     }
                 }
             }
         }
         //z方向
         $z_max = $tz;
         //z最大值
         $z_min = $tz;
         //z最小值
         $count_z = 0;
         //z方向方块
         for ($z = $tz + 1; $level->getBlock(new Vector3($tx, $ty, $z))->getId() == 49; $z++) {
             $z_max++;
         }
         for ($z = $tz - 1; $level->getBlock(new Vector3($tx, $ty, $z))->getId() == 49; $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(new Vector3($tx, $y, $z_max))->getId() == 49; $y++) {
                 $z_max_y++;
             }
             for ($y = $ty; $level->getBlock(new Vector3($tx, $y, $z_min))->getId() == 49; $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(new Vector3($tx, $y_max, $uz))->getId() == 49 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(new Vector3($tx, $py, $pz), new Block(90, 0));
                         }
                     }
                 }
             }
         }
         return true;
     }
     if ($block->getId() === self::AIR and $target instanceof Solid) {
         $level->setBlock($block, new Fire(), true);
         return true;
     }
     return false;
 }
Esempio n. 9
0
 public function tiankengy(Level $level, $x, $y, $z, $l, $id, $bd)
 {
     if ($level->getBlock(new Vector3($x, $y, $z))->getId() == 0) {
         $level->setBlock(new Vector3($x, $y, $z), Item::get($id, $bd)->getBlock());
     }
     if ($l >= 0) {
         $random = mt_rand(0, 99999) / 100000;
         $mz = $this->ranz(4);
         foreach ($mz as $sss) {
             switch ($mz[$sss]) {
                 case 0:
                     if ($level->getBlock(new Vector3($x, $y, $z - 1))->getId() == 0) {
                         $this->tiankengy($level, $x, $y, $z - 1, $l - $random, $id, $bd);
                     }
                     break;
                 case 1:
                     if ($level->getBlock(new Vector3($x, $y, $z + 1))->getId() == 0) {
                         $this->tiankengy($level, $x, $y, $z + 1, $l - $random, $id, $bd);
                     }
                     break;
                 case 2:
                     if ($level->getBlock(new Vector3($x + 1, $y, $z))->getId() == 0) {
                         $this->tiankengy($level, $x + 1, $y, $z, $l - $random, $id, $bd);
                     }
                     break;
                 case 3:
                     if ($level->getBlock(new Vector3($x - 1, $y, $z))->getId() == 0) {
                         $this->tiankengy($level, $x - 1, $y, $z, $l - $random, $id, $bd);
                     }
                     break;
             }
         }
     }
 }
Esempio n. 10
-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;
 }