本文整理汇总了PHP中pocketmine\Player::getInventory方法的典型用法代码示例。如果您正苦于以下问题:PHP Player::getInventory方法的具体用法?PHP Player::getInventory怎么用?PHP Player::getInventory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\Player
的用法示例。
在下文中一共展示了Player::getInventory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onActivate
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
{
if ($player === null or $player->isSurvival() !== true) {
return false;
}
if ($target->getId() === Block::STILL_WATER or $target->getId() === Block::WATER) {
$player->getServer()->getPluginManager()->callEvent($ev = new PlayerGlassBottleEvent($player, $target, $this));
if ($ev->isCancelled()) {
return false;
} else {
if ($this->count <= 1) {
$player->getInventory()->setItemInHand(Item::get(Item::POTION, 0, 1));
return true;
} else {
$this->count--;
$player->getInventory()->setItemInHand($this);
}
if ($player->getInventory()->canAddItem(Item::get(Item::POTION, 0, 1)) === true) {
$player->getInventory()->AddItem(Item::get(Item::POTION, 0, 1));
} else {
$motion = $player->getDirectionVector()->multiply(0.4);
$position = clone $player->getPosition();
$player->getLevel()->dropItem($position->add(0, 0.5, 0), Item::get(Item::POTION, 0, 1), $motion, 40);
}
return true;
}
}
return false;
}
示例2: onActivate
public function onActivate(Item $item, Player $player = null)
{
$tile = $this->getLevel()->getTile($this);
if (!$tile instanceof ItemFrameTile) {
$nbt = new CompoundTag("", [new StringTag("id", Tile::ITEM_FRAME), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z), new ByteTag("ItemRotation", 0), new FloatTag("ItemDropChance", 1.0)]);
Tile::createTile(Tile::ITEM_FRAME, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
}
$tile = $this->getLevel()->getTile($this);
if (!$tile instanceof ItemFrameTile) {
return false;
}
if ($tile->getItem()->getId() === 0) {
$tile->setItem(Item::get($item->getId(), $item->getDamage(), 1));
if ($player instanceof Player) {
if ($player->isSurvival()) {
$count = $item->getCount();
if (--$count <= 0) {
$player->getInventory()->setItemInHand(Item::get(Item::AIR));
return true;
}
$item->setCount($count);
$player->getInventory()->setItemInHand($item);
}
}
} else {
$itemRot = $tile->getItemRotation();
if ($itemRot === 7) {
$itemRot = 0;
} else {
$itemRot++;
}
$tile->setItemRotation($itemRot);
}
return true;
}
示例3: applyTo
public function applyTo(Player $p)
{
$inventory = $p->getInventory()->getContents();
$size = $p->getInventory()->getSize();
foreach ($this->items as $id => $item) {
if (!is_numeric($id)) {
switch ($id) {
case 'helmet':
$id = $size;
break;
case 'chestplate':
$id = $size + 1;
break;
case 'leggings':
$id = $size + 2;
break;
case 'boots':
$id = $size + 3;
break;
}
}
$inventory[$id] = $item;
}
$p->getInventory()->setContents($inventory);
$p->getInventory()->sendArmorContents([$p]);
foreach ($this->commands as $command) {
$command = str_replace("{player}", $p->getName(), $command);
$this->getPlugin()->getServer()->dispatchCommand(new ConsoleCommandSender(), $command);
}
if ($this->onGiveMessage !== false) {
$p->sendMessage($this->onGiveMessage);
}
}
示例4: handle
private function handle($cmd, $args, Player $player, CommandSender $issuer)
{
switch ($cmd) {
case "getping":
$issuer->sendMessage("Ping of " . $player->getName() . ": unknown ms");
return true;
case "seearmor":
$issuer->sendMessage("Armor of " . $player->getName() . ":");
$issuer->sendMessage("Helmet: " . $this->formatItem($player->getInventory()->getArmorItem(0)));
$issuer->sendMessage("Chestplate: " . $this->formatItem($player->getInventory()->getArmorItem(1)));
$issuer->sendMessage("Leggings: " . $this->formatItem($player->getInventory()->getArmorItem(2)));
$issuer->sendMessage("Boots: " . $this->formatItem($player->getInventory()->getArmorItem(3)));
return true;
case "seegm":
$issuer->sendMessage("Gamemode of " . $player->getName() . ": " . $this->formatGamemode($player->getGamemode()));
return true;
case "getpos":
$issuer->sendMessage($player->getName() . " is at (" . TextFormat::YELLOW . $player->x . ", " . TextFormat::GREEN . $player->y . ", " . TextFormat::AQUA . $player->z . ") in world " . TextFormat::RED . $player->getLevel()->getName() . ".");
return true;
case "setarmor":
// TODO
break;
case "rmarmor":
// TODO
break;
case "sessions":
// TODO
break;
}
return false;
}
示例5: onActivate
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
{
if ($target->isTransparent() === false and $face > 1 and $block->isSolid() === false) {
$faces = [2 => 0, 3 => 2, 4 => 1, 5 => 3];
$motives = [["Kebab", 1, 1], ["Aztec", 1, 1], ["Alban", 1, 1], ["Aztec2", 1, 1], ["Bomb", 1, 1], ["Plant", 1, 1], ["Wasteland", 1, 1], ["Wanderer", 1, 2], ["Graham", 1, 2], ["Pool", 2, 1], ["Courbet", 2, 1], ["Sunset", 2, 1], ["Sea", 2, 1], ["Creebet", 2, 1], ["Match", 2, 2], ["Bust", 2, 2], ["Stage", 2, 2], ["Void", 2, 2], ["SkullAndRoses", 2, 2], ["Fighters", 4, 2], ["Skeleton", 4, 3], ["DonkeyKong", 4, 3], ["Pointer", 4, 4], ["Pigscene", 4, 4], ["Flaming Skull", 4, 4]];
$motive = $motives[mt_rand(0, count($motives) - 1)];
$data = ["x" => $target->x, "y" => $target->y + 0.4, "z" => $target->z, "yaw" => $faces[$face] * 90, "Motive" => $motive[0]];
$nbt = new CompoundTag("", ["Motive" => new StringTag("Motive", $data["Motive"]), "Pos" => new EnumTag("Pos", [new DoubleTag("", $data["x"]), new DoubleTag("", $data["y"]), new DoubleTag("", $data["z"])]), "Motion" => new EnumTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new EnumTag("Rotation", [new FloatTag("", $data["yaw"]), new FloatTag("", 0)])]);
$painting = new PaintingEntity($player->getLevel()->getChunk($block->getX() >> 4, $block->getZ() >> 4), $nbt);
$painting->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);
}
//TODO
//$e = $server->api->entity->add($level, ENTITY_OBJECT, OBJECT_PAINTING, $data);
//$e->spawnToAll();
/*if(($player->gamemode & 0x01) === 0x00){
$player->removeItem(Item::get($this->getId(), $this->getDamage(), 1));
}*/
return true;
}
return false;
}
示例6: burstArrow
public function burstArrow(Player $player)
{
if ($player->getInventory()->getItemInHand()->getId() === Item::BOW) {
$bow = $player->getInventory()->getItemInHand();
$nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $player->x), new Double("", $player->y + $player->getEyeHeight()), new Double("", $player->z)]), "Motion" => new Enum("Motion", [new Double("", -\sin($player->yaw / 180 * M_PI) * \cos($player->pitch / 180 * M_PI)), new Double("", -\sin($player->pitch / 180 * M_PI)), new Double("", \cos($player->yaw / 180 * M_PI) * \cos($player->pitch / 180 * M_PI))]), "Rotation" => new Enum("Rotation", [new Float("", $player->yaw), new Float("", $player->pitch)])]);
$ev = new EntityShootBowEvent($player, $bow, Entity::createEntity("Arrow", $player->chunk, $nbt, $player), 1.5);
$this->getServer()->getPluginManager()->callEvent($ev);
if ($ev->isCancelled()) {
$ev->getProjectile()->kill();
} else {
$ev->getProjectile()->setMotion($ev->getProjectile()->getMotion()->multiply($ev->getForce()));
if ($ev->getProjectile() instanceof Projectile) {
$this->getServer()->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($ev->getProjectile()));
if ($projectileEv->isCancelled()) {
$ev->getProjectile()->kill();
} else {
$this->object_hash[spl_object_hash($ev->getProjectile())] = 1;
$ev->getProjectile()->spawnToAll();
}
} else {
$this->object_hash[spl_object_hash($ev->getProjectile())] = 1;
$ev->getProjectile()->spawnToAll();
}
}
}
}
示例7: giveCraftingTable
public function giveCraftingTable(Player $player)
{
foreach ($player->getInventory()->getContents() as $item) {
if ($item->getId() === Item::CRAFTING_TABLE) {
return;
}
}
$player->getInventory()->addItem(Item::get(Item::CRAFTING_TABLE));
}
示例8: restorePlayer
public function restorePlayer(Player $player)
{
if (isset($this->players[$player->getName()])) {
$get = $this->players[$player->getName()];
$player->setGamemode($get["gamemode"]);
$player->getInventory()->setContents(unserialize($get["inventory"]));
$player->getInventory()->setArmorContents(unserialize($get["armor"]));
$player->teleport(unserialize($get["spawn"]));
unset($this->players[$player->getName()]);
}
}
示例9: onActivate
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
{
$realPos = $block->getSide($face);
$boat = Entity::createEntity("Boat", $player->getLevel()->getChunk($realPos->x >> 4, $realPos->z >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $realPos->x), new Double("", $realPos->y), new Double("", $realPos->z)]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)])]));
$boat->spawnToAll();
--$this->count;
if ($this->count <= 0) {
$player->getInventory()->setItemInHand(Item::get(Item::AIR));
return true;
}
$player->getInventory()->setItemInHand($this);
return true;
}
示例10: onActivate
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
{
$realPos = $block->getSide($face);
$boat = new BoatEntity($player->getLevel()->getChunk($realPos->getX() >> 4, $realPos->getZ() >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $realPos->getX()), new Double("", $realPos->getY()), new Double("", $realPos->getZ())]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)])]));
$boat->spawnToAll();
$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;
}
示例11: onActivate
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
{
$targetBlock = Block::get($this->meta);
if ($targetBlock instanceof Air) {
if ($target instanceof Liquid and $target->getDamage() === 0) {
$result = clone $this;
$result->setDamage($target->getId());
$player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
if (!$ev->isCancelled()) {
$player->getLevel()->setBlock($target, new Air(), true, true);
if ($player->isSurvival()) {
$player->getInventory()->setItemInHand($ev->getItem());
}
return true;
} else {
$player->getInventory()->sendContents($player);
}
}
} elseif ($targetBlock instanceof Liquid) {
$result = clone $this;
$result->setDamage(0);
$player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
if (!$ev->isCancelled()) {
$player->getLevel()->setBlock($block, $targetBlock, true, true);
if ($player->isSurvival()) {
$player->getInventory()->setItemInHand($ev->getItem());
}
return true;
} else {
$player->getInventory()->sendContents($player);
}
}
return false;
}
示例12: onActivate
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
{
$minecart = new MinecartEntity($player->getLevel()->getChunk($block->getX() >> 4, $block->getZ() >> 4), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $block->getX()), new DoubleTag("", $block->getY() + 0.8), new DoubleTag("", $block->getZ())]), "Motion" => new ListTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new ListTag("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 true;
}
$item->setCount($count);
$player->getInventory()->setItemInHand($item);
}
return true;
}
示例13: onActivate
public function onActivate(Item $item, Player $player = null)
{
$tile = $this->getLevel()->getTile($this);
if ($tile instanceof FlowerPotTile) {
if ($tile->getFlowerPotItem() === Item::AIR) {
switch ($item->getId()) {
case Item::TALL_GRASS:
if ($item->getDamage() === 1) {
break;
}
case Item::SAPLING:
case Item::DEAD_BUSH:
case Item::DANDELION:
case Item::RED_FLOWER:
case Item::BROWN_MUSHROOM:
case Item::RED_MUSHROOM:
case Item::CACTUS:
$tile->setFlowerPotData($item->getId(), $item->getDamage());
$this->setDamage($item->getId());
$this->getLevel()->setBlock($this, $this, true, false);
if ($player->isSurvival()) {
$item->setCount($item->getCount() - 1);
$player->getInventory()->setItemInHand($item->getCount() > 0 ? $item : Item::get(Item::AIR));
}
return true;
break;
}
}
}
return false;
}
示例14: onActivate
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
{
if ($block->getId() === self::AIR and $target instanceof Solid) {
$level->setBlock($block, new Fire(), true);
if (($player->gamemode & 0x1) === 0 and $this->useOn($block)) {
if ($this->getDamage() >= $this->getMaxDurability()) {
$player->getInventory()->setItemInHand(new Item(Item::AIR, 0, 0));
} else {
$this->meta++;
$player->getInventory()->setItemInHand($this);
}
}
return true;
}
return false;
}
示例15: 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 Compound("", ["Pos" => new Enum("Pos", [new Double("", $block->getX()), new Double("", $block->getY() + 1), new Double("", $block->getZ())]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [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;
}