本文整理汇总了PHP中pocketmine\level\Level::setBlock方法的典型用法代码示例。如果您正苦于以下问题:PHP Level::setBlock方法的具体用法?PHP Level::setBlock怎么用?PHP Level::setBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\level\Level
的用法示例。
在下文中一共展示了Level::setBlock方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onActivate
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
{
if ($this->meta === Item::AIR) {
if ($target instanceof Liquid) {
$level->setBlock($target, new Air(), true);
if (($player->gamemode & 0x1) === 0) {
$this->meta = $target instanceof Water ? Item::WATER : Item::LAVA;
}
return true;
}
} elseif ($this->meta === Item::WATER) {
//Support Make Non-Support Water to Support Water
if ($block->getID() === self::AIR || $block instanceof Water && ($block->getDamage() & 0x7) != 0x0) {
$water = new Water();
$level->setBlock($block, $water, true);
$water->place(clone $this, $block, $target, $face, $fx, $fy, $fz, $player);
if (($player->gamemode & 0x1) === 0) {
$this->meta = 0;
}
return true;
}
} elseif ($this->meta === Item::LAVA) {
if ($block->getID() === self::AIR) {
$level->setBlock($block, new Lava(), true);
if (($player->gamemode & 0x1) === 0) {
$this->meta = 0;
}
return true;
}
}
return false;
}
示例2: setBlock
private function setBlock(Vector3 $p, Level $lvl, ItemBlock $b, $meta)
{
$block = $b->getBlock();
$block->setDamage($meta);
$lvl->setBlock($p, $b);
return true;
}
示例3: onActivate
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 ($block->getId() === self::AIR and $target instanceof Solid) {
$level->setBlock($block, new Fire(), \true);
return \true;
}
return \false;
}
示例4: updateBlock2
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);
}
}
示例5: setWall
/**
*
* @param Position $p1
* @param Position $p2
* @param unknown $block
* @param string $output
* @return boolean
*/
public function setWall(Level $level, Position $p1, Position $p2, $block, &$output = null)
{
$send = false;
//$level = $p1->getLevel ();
$bcnt = 1;
$startX = min($p1->x, $p2->x);
$endX = max($p1->x, $p2->x);
$startY = min($p1->y, $p2->y);
$endY = max($p1->y, $p2->y);
$startZ = min($p1->z, $p2->z);
$endZ = max($p1->z, $p2->z);
$count = 0;
for ($x = $startX; $x <= $endX; ++$x) {
for ($y = $startY; $y <= $endY; ++$y) {
for ($z = $startZ; $z <= $endZ; ++$z) {
if ($x == $startX || $x == $endX || $z == $startZ || $z == $endZ) {
$level->setBlock(new Position($x, $y, $z), $block, false, true);
$count++;
}
}
}
}
$output .= "{$count} block(s) have been updated.\n";
return true;
}
示例6: setPortal
public function setPortal(Level $level, $twoPos)
{
if (!$twoPos[0] instanceof Vector3) {
return;
}
if (!$twoPos[1] instanceof Vector3) {
return;
}
$startX = $twoPos[0]->x;
$startY = $twoPos[0]->y;
$startZ = $twoPos[0]->z;
$endX = $twoPos[1]->x;
$endY = $twoPos[1]->y;
$endZ = $twoPos[1]->z;
if ($startX > $endX) {
$backup = $endX;
$endX = $startX;
$startX = $backup;
}
if ($startY > $endY) {
$backup = $endY;
$endY = $startY;
$startY = $backup;
}
if ($startZ > $endZ) {
$backup = $endZ;
$endZ = $startZ;
$startZ = $backup;
}
$startY++;
$endY = $endY - 2;
if ($startZ == $endZ) {
$startX++;
$endX--;
} else {
$startZ++;
$endZ--;
}
$portalBlock = new Block(90);
$vector = new Vector3(0, 0, 0);
for ($x = $startX; $x <= $endX; $x++) {
for ($y = $startY; $y <= $endY; $y++) {
for ($z = $startZ; $z <= $endZ; $z++) {
$level->setBlock($vector->setComponents($x, $y, $z), $portalBlock);
}
}
}
}
示例7: updateHorizontalGrowingCrops
/**
* @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;
}
示例8: onActivate
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++) {
//.........这里部分代码省略.........
示例9: tiankengy
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;
}
}
}
}
示例10: onActivate
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++) {
//.........这里部分代码省略.........