getBlockIdAt() public method

Gets the raw block id.
public getBlockIdAt ( integer $x, integer $y, integer $z ) : integer
$x integer
$y integer
$z integer
return integer 0-255
Ejemplo n.º 1
0
 public function sideCheck($x, $y, $z, Level $level, $name)
 {
     if ($level->getBlockIdAt($x, $y, $z) == Block::CHEST) {
         if (isset($this->configData["{$x}:{$y}:{$z}"])) {
             if ($this->configData["{$x}:{$y}:{$z}"] != $name) {
                 return true;
             }
         }
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  *
  * @param Level $level        	
  * @param Position $pos1        	
  * @param Position $pos2        	
  * @param string $output        	
  * @return number
  */
 public function countNotEmptyBlocks(Level $level, Position $pos1, Position $pos2, &$output = null)
 {
     $count = 0;
     $startX = min($pos1->x, $pos2->x);
     $endX = max($pos1->x, $pos2->x);
     $startY = min($pos1->y + 6, $pos2->y);
     $endY = max($pos1->y, $pos2->y);
     $startZ = min($pos1->z, $pos2->z);
     $endZ = max($pos1->z, $pos2->z);
     for ($x = $startX; $x <= $endX; ++$x) {
         for ($y = $startY; $y <= $endY; ++$y) {
             for ($z = $startZ; $z <= $endZ; ++$z) {
                 $blockid = $level->getBlockIdAt($x, $y, $z);
                 if ($blockid != 0) {
                     $count++;
                 }
             }
         }
     }
     $output .= "{$count} block(s) have been updated.\n";
     return $count;
 }
 public function setWaterField(Player $player, $x, $y, $z, Level $level)
 {
     if (isset($this->waterField[$player->getName()]["pos"]) and $this->waterField[$player->getName()]["pos"] == "{$x}:{$y}:{$z}") {
         return;
     }
     $downId = $level->getBlockIdAt($x, $y, $z);
     $pk = new UpdateBlockPacket();
     if (isset($this->waterField[$player->getName()]["pos"])) {
         $pos = explode(":", $this->waterField[$player->getName()]["pos"]);
         $sides = [[1, 1], [1, 0], [1, 1], [0, -1], [0, 0], [0, 1], [-1, -1], [-1, 0], [-1, 0]];
         foreach ($sides as $side) {
             $downId = $level->getBlockIdAt($pos[0] + $side[0], $pos[2], $pos[1] + $side[1]);
             $downDmg = $level->getBlockDataAt($pos[0] + $side[0], $pos[2], $pos[1] + $side[1]);
             $pk->records[] = [$pos[0] + $side[0], $pos[1] + $side[1], $pos[2], $downId, $downDmg, UpdateBlockPacket::FLAG_NONE];
         }
     }
     if ($downId != Block::STILL_WATER) {
         $pos = explode(":", $this->waterField[$player->getName()]["pos"]);
         $sides = [[1, 1], [1, 0], [1, 1], [0, -1], [0, 0], [0, 1], [-1, -1], [-1, 0], [-1, 0]];
         foreach ($sides as $side) {
             $downId = $level->getBlockIdAt($pos[0] + $side[0], $pos[2], $pos[1] + $side[1]);
             $downDmg = $level->getBlockDataAt($pos[0] + $side[0], $pos[2], $pos[1] + $side[1]);
             $pk->records[] = [$pos[0] + $side[0], $pos[1] + $side[1], $pos[2], $downId, $downDmg, UpdateBlockPacket::FLAG_NONE];
         }
     }
     $player->directDataPacket($pk->setChannel(Network::CHANNEL_BLOCKS));
     $this->waterField[$player->getName()]["pos"] = "{$x}:{$z}:{$y}";
 }
 public function canActivate(Level $level, Position $pos)
 {
     // +-x y +-z
     $minLength = 4;
     $minHeight = 5;
     $loopLimit = 27;
     $x = $pos->x;
     $y = $pos->y;
     $z = $pos->z;
     // INITIAL
     $nowLoop = 0;
     $firstPos = null;
     $secondPos = null;
     $height = 0;
     $initailSuccess = false;
     // DOWN LENGTH CHECK
     for (;;) {
         $x--;
         if ($nowLoop >= $loopLimit) {
             break;
         }
         if ($level->getBlockIdAt($x, $y, $z) != Block::OBSIDIAN) {
             break;
         }
         if ($level->getBlockIdAt($x, $y + 1, $z) != Block::AIR) {
             break;
         }
         if ($level->getBlockIdAt($x - 1, $y + 1, $z) == Block::OBSIDIAN) {
             $initailSuccess = true;
         }
         $nowLoop++;
     }
     if (!$initailSuccess) {
         $nowLoop = 0;
         $x = $pos->x;
         $y = $pos->y;
         $z = $pos->z;
         for (;;) {
             $z--;
             if ($nowLoop >= $loopLimit) {
                 break;
             }
             if ($level->getBlockIdAt($x, $y, $z) != Block::OBSIDIAN) {
                 break;
             }
             if ($level->getBlockIdAt($x, $y + 1, $z) != Block::AIR) {
                 break;
             }
             if ($level->getBlockIdAt($x, $y + 1, $z - 1) == Block::OBSIDIAN) {
                 $initailSuccess = true;
             }
             $nowLoop++;
         }
         if (!$initailSuccess) {
             return false;
         }
         $firstPos = new Vector3($x, $y, $z);
         $z += $nowLoop;
         for (;;) {
             $z++;
             if ($nowLoop >= $loopLimit) {
                 break;
             }
             if ($level->getBlockIdAt($x, $y, $z) != Block::OBSIDIAN) {
                 break;
             }
             if ($level->getBlockIdAt($x, $y + 1, $z) != Block::AIR) {
                 break;
             }
             if ($level->getBlockIdAt($x, $y + 1, $z + 1) == Block::OBSIDIAN) {
                 $initailSuccess = true;
             }
             $nowLoop++;
         }
         if (!$initailSuccess) {
             return false;
         }
         $secondPos = new Vector3($x, $y, $z);
     } else {
         if ($secondPos == null) {
             $firstPos = new Vector3($x, $y, $z);
             $x += $nowLoop;
             for (;;) {
                 $x++;
                 if ($nowLoop >= $loopLimit) {
                     break;
                 }
                 if ($level->getBlockIdAt($x, $y, $z) != Block::OBSIDIAN) {
                     break;
                 }
                 if ($level->getBlockIdAt($x, $y + 1, $z) != Block::AIR) {
                     break;
                 }
                 if ($level->getBlockIdAt($x + 1, $y + 1, $z) == Block::OBSIDIAN) {
                     $initailSuccess = true;
                 }
                 $nowLoop++;
             }
             if (!$initailSuccess) {
                 return false;
             }
             $secondPos = new Vector3($x, $y, $z);
         }
     }
     // HEIGHT CHECK
     if ($firstPos->x == $secondPos->x) {
         // z 축으로 배치됨
         $diff = abs($firstPos->z - $secondPos->z);
         if ($diff < $minLength) {
             return false;
         }
         $fheight = 0;
         $fx = $firstPos->x;
         $fy = $firstPos->y;
         $fz = $firstPos->z;
         for (;;) {
             if ($level->getBlockIdAt($fx, $fy + $fheight, $fz) != Block::OBSIDIAN) {
                 break;
             }
             if ($fheight > $loopLimit) {
                 return false;
             }
             $fheight++;
         }
         $height = $fy + $fheight;
         $sheight = 0;
         $sx = $secondPos->x;
         $sy = $secondPos->y;
         $sz = $secondPos->z;
         for (;;) {
             $sheight++;
             if ($level->getBlockIdAt($sx, $sy + $sheight, $sz) != Block::OBSIDIAN) {
                 break;
             }
             if ($sheight > $loopLimit) {
                 return false;
             }
         }
         if ($fheight !== $sheight) {
             return false;
         }
     } else {
         // x 축으로 배치됨
         $diff = abs($firstPos->x - $secondPos->x);
         if ($diff < $minLength) {
             return false;
         }
         $fheight = 0;
         $fx = $firstPos->x - 1;
         $fy = $firstPos->y;
         $fz = $firstPos->z;
         for (;;) {
             $fheight++;
             if ($level->getBlockIdAt($fx, $fy + $fheight, $fz) != Block::OBSIDIAN) {
                 break;
             }
             if ($fheight > $loopLimit) {
                 return false;
             }
         }
         $sheight = 0;
         $sx = $secondPos->x + 1;
         $sy = $secondPos->y;
         $sz = $secondPos->z;
         for (;;) {
             $sheight++;
             if ($level->getBlockIdAt($sx, $sy + $sheight, $sz) != Block::OBSIDIAN) {
                 break;
             }
             if ($sheight > $loopLimit) {
                 return false;
             }
         }
         if ($fheight !== $sheight) {
             return false;
         }
         $height = $fheight;
     }
     if ($height < $minHeight) {
         return false;
     }
     $returnFirstPos = clone $firstPos;
     $returnSecondPos = clone $secondPos->setComponents($secondPos->x, $height, $secondPos->z);
     $x = $secondPos->x;
     $y = $secondPos->y;
     $z = $secondPos->z;
     $firstPos = null;
     $secondPos = null;
     $initailSuccess = false;
     // UP LENGTH CHECK
     for (;;) {
         $x--;
         if ($nowLoop >= $loopLimit) {
             break;
         }
         if ($level->getBlockIdAt($x, $y, $z) != Block::OBSIDIAN) {
             break;
         }
         if ($level->getBlockIdAt($x, $y + 1, $z) != Block::AIR) {
             break;
         }
         if ($level->getBlockIdAt($x - 1, $y + 1, $z) == Block::OBSIDIAN) {
             $initailSuccess = true;
         }
         $nowLoop++;
     }
     if (!$initailSuccess) {
         $nowLoop = 0;
         $x = $pos->x;
         $y = $pos->y;
         $z = $pos->z;
         for (;;) {
             $z--;
             if ($nowLoop >= $loopLimit) {
                 break;
             }
             if ($level->getBlockIdAt($x, $y, $z) != Block::OBSIDIAN) {
                 break;
             }
             if ($level->getBlockIdAt($x, $y + 1, $z) != Block::AIR) {
                 break;
             }
             if ($level->getBlockIdAt($x, $y + 1, $z - 1) == Block::OBSIDIAN) {
                 $initailSuccess = true;
             }
             $nowLoop++;
         }
         if (!$initailSuccess) {
             return false;
         }
         $firstPos = new Vector3($x, $y, $z);
         $z += $nowLoop;
         for (;;) {
             $z++;
             if ($nowLoop >= $loopLimit) {
                 break;
             }
             if ($level->getBlockIdAt($x, $y, $z) != Block::OBSIDIAN) {
                 break;
             }
             if ($level->getBlockIdAt($x, $y + 1, $z) != Block::AIR) {
                 break;
             }
             if ($level->getBlockIdAt($x, $y + 1, $z + 1) == Block::OBSIDIAN) {
                 $initailSuccess = true;
             }
             $nowLoop++;
         }
         if (!$initailSuccess) {
             return false;
         }
         $secondPos = new Vector3($x, $y, $z);
     } else {
         if ($secondPos == null) {
             $firstPos = new Vector3($x, $y, $z);
             $x += $nowLoop;
             for (;;) {
                 $x++;
                 if ($nowLoop >= $loopLimit) {
                     break;
                 }
                 if ($level->getBlockIdAt($x, $y, $z) != Block::OBSIDIAN) {
                     break;
                 }
                 if ($level->getBlockIdAt($x, $y + 1, $z) != Block::AIR) {
                     break;
                 }
                 if ($level->getBlockIdAt($x + 1, $y + 1, $z) == Block::OBSIDIAN) {
                     $initailSuccess = true;
                 }
                 $nowLoop++;
             }
             if (!$initailSuccess) {
                 return false;
             }
             $secondPos = new Vector3($x, $y, $z);
         }
     }
     return [$returnFirstPos, $returnSecondPos];
 }
Ejemplo n.º 5
0
 public function whatBlock(Level $level, $v3)
 {
     //boybook的y轴判断法 核心 什么方块?
     $id = $level->getBlockIdAt($v3->x, $v3->y, $v3->z);
     $damage = $level->getBlockDataAt($v3->x, $v3->y, $v3->z);
     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:
             //透明方块
             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 (($damage & 0x8) === 0x8) {
                 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;
     }
 }
Ejemplo n.º 6
0
 /**
  * @param $key
  * @param Level $level
  * @param Vector3 $position
  * @return bool
  */
 public function updateHorizontalGrowingCrops($key, Level $level, Vector3 $position)
 {
     $cropBlock = null;
     switch ($this->farmData[$key]["id"]) {
         case Block::PUMPKIN_STEM:
             $cropBlock = Block::get(Block::PUMPKIN);
             break;
         case Block::MELON_STEM:
             $cropBlock = Block::get(Block::MELON_BLOCK);
             break;
         default:
             return true;
     }
     if (++$this->farmData[$key]["damage"] >= 8) {
         // FULL GROWN!
         for ($xOffset = -1; $xOffset <= 1; $xOffset++) {
             for ($zOffset = -1; $zOffset <= 1; $zOffset++) {
                 if ($xOffset === 0 and $zOffset === 0) {
                     //STEM
                     continue;
                 }
                 $cropPosition = $position->setComponents($position->x + $xOffset, $position->y, $position->z + $zOffset);
                 if ($level->getBlockIdAt($cropPosition->x, $cropPosition->y, $cropPosition->z) !== Item::AIR) {
                     //SOMETHING EXISTS
                     $level->setBlock($cropPosition, $cropBlock);
                     return true;
                 }
             }
         }
         return true;
     }
     $level->setBlock($position, Block::get($this->farmData[$key]["id"], $this->farmData[$key]["damage"]));
     return false;
 }
Ejemplo n.º 7
0
 public function lavaSpawn(Level $level, $x, $y, $z)
 {
     $level->getServer()->getLogger()->info("生成岩浆中 " . "floor({$x})" . ", " . "floor({$y})" . ", " . floor($z));
     for ($xx = $x - 20; $xx <= $x + 20; $xx++) {
         for ($zz = $z - 20; $zz <= $z + 20; $zz++) {
             for ($yy = $y; $yy > $y - 4; $yy--) {
                 $id = $level->getBlockIdAt($xx, $yy, $zz);
                 if ($id == 0) {
                     $level->setBlockIdAt($xx, $yy, $zz, 10);
                     $level->setBlockDataAt($xx, $yy, $zz, 0);
                 }
             }
         }
     }
     $level->setBlock(new Vector3($x, $y, $z), new Lava());
 }