本文整理汇总了PHP中pocketmine\block\Block::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Block::add方法的具体用法?PHP Block::add怎么用?PHP Block::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\block\Block
的用法示例。
在下文中一共展示了Block::add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onActivate
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;
}
示例2: onActivate
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;
}
示例3: onActivate
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;
}
示例4: getTreetop
/**
* @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;
}