本文整理汇总了PHP中pocketmine\inventory\BaseTransaction::getSourceItem方法的典型用法代码示例。如果您正苦于以下问题:PHP BaseTransaction::getSourceItem方法的具体用法?PHP BaseTransaction::getSourceItem怎么用?PHP BaseTransaction::getSourceItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\inventory\BaseTransaction
的用法示例。
在下文中一共展示了BaseTransaction::getSourceItem方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleDataPacket
//.........这里部分代码省略.........
case ProtocolInfo::CONTAINER_SET_SLOT_PACKET:
if ($this->spawned === false or $this->blocked === true or !$this->isAlive()) {
break;
}
if ($packet->slot < 0) {
break;
}
if ($packet->windowid === 0) {
//Our inventory
if ($packet->slot >= $this->inventory->getSize()) {
break;
}
if ($this->isCreative()) {
if (Item::getCreativeItemIndex($packet->item) !== -1) {
$this->inventory->setItem($packet->slot, $packet->item);
$this->inventory->setHotbarSlotIndex($packet->slot, $packet->slot);
//links $hotbar[$packet->slot] to $slots[$packet->slot]
}
}
$transaction = new BaseTransaction($this->inventory, $packet->slot, $this->inventory->getItem($packet->slot), $packet->item);
} elseif ($packet->windowid === ContainerSetContentPacket::SPECIAL_ARMOR) {
//Our armor
if ($packet->slot >= 4) {
break;
}
$transaction = new BaseTransaction($this->inventory, $packet->slot + $this->inventory->getSize(), $this->inventory->getArmorItem($packet->slot), $packet->item);
} elseif (isset($this->windowIndex[$packet->windowid])) {
$this->craftingType = 0;
$inv = $this->windowIndex[$packet->windowid];
$transaction = new BaseTransaction($inv, $packet->slot, $inv->getItem($packet->slot), $packet->item);
} else {
break;
}
if ($transaction->getSourceItem() === $transaction->getTargetItem() and $transaction->getTargetItem()->getCount() === $transaction->getSourceItem()->getCount()) {
//No changes!
//No changes, just a local inventory update sent by the server
break;
}
if ($this->currentTransaction === null or $this->currentTransaction->getCreationTime() < microtime(true) - 8) {
if ($this->currentTransaction !== null) {
foreach ($this->currentTransaction->getInventories() as $inventory) {
if ($inventory instanceof PlayerInventory) {
$inventory->sendArmorContents($this);
}
$inventory->sendContents($this);
}
}
$this->currentTransaction = new SimpleTransactionGroup($this);
}
$this->currentTransaction->addTransaction($transaction);
if ($this->currentTransaction->canExecute()) {
$achievements = [];
foreach ($this->currentTransaction->getTransactions() as $ts) {
$inv = $ts->getInventory();
if ($inv instanceof FurnaceInventory) {
if ($ts->getSlot() === 2) {
switch ($inv->getResult()->getId()) {
case Item::IRON_INGOT:
$achievements[] = "acquireIron";
break;
}
}
}
}
if ($this->currentTransaction->execute()) {
foreach ($achievements as $a) {
示例2: handleDataPacket
//.........这里部分代码省略.........
case ProtocolInfo::CONTAINER_SET_SLOT_PACKET:
if ($this->spawned === false or $this->blocked === true or $this->dead === true) {
break;
}
if ($packet->slot < 0) {
break;
}
if ($packet->windowid === 0) {
//Our inventory
if ($packet->slot >= $this->inventory->getSize()) {
break;
}
if ($this->isCreative()) {
if (Item::getCreativeItemIndex($packet->item) !== -1) {
$this->inventory->setItem($packet->slot, $packet->item);
$this->inventory->setHotbarSlotIndex($packet->slot, $packet->slot);
//links $hotbar[$packet->slot] to $slots[$packet->slot]
}
}
$transaction = new BaseTransaction($this->inventory, $packet->slot, $this->inventory->getItem($packet->slot), $packet->item);
} elseif ($packet->windowid === ContainerSetContentPacket::SPECIAL_ARMOR) {
//Our armor
if ($packet->slot >= 4) {
break;
}
$transaction = new BaseTransaction($this->inventory, $packet->slot + $this->inventory->getSize(), $this->inventory->getArmorItem($packet->slot), $packet->item);
} elseif (isset($this->windowIndex[$packet->windowid])) {
$this->craftingType = 0;
$inv = $this->windowIndex[$packet->windowid];
$transaction = new BaseTransaction($inv, $packet->slot, $inv->getItem($packet->slot), $packet->item);
} else {
break;
}
if ($transaction->getSourceItem()->equals($transaction->getTargetItem(), true) and $transaction->getTargetItem()->getCount() === $transaction->getSourceItem()->getCount()) {
//No changes!
//No changes, just a local inventory update sent by the server
break;
}
if ($this->currentTransaction === null or $this->currentTransaction->getCreationTime() < microtime(true) - 8) {
if ($this->currentTransaction instanceof SimpleTransactionGroup) {
foreach ($this->currentTransaction->getInventories() as $inventory) {
if ($inventory instanceof PlayerInventory) {
$inventory->sendArmorContents($this);
}
$inventory->sendContents($this);
}
}
$this->currentTransaction = new SimpleTransactionGroup($this);
}
$this->currentTransaction->addTransaction($transaction);
if ($this->currentTransaction->canExecute()) {
if ($this->currentTransaction->execute()) {
foreach ($this->currentTransaction->getTransactions() as $ts) {
$inv = $ts->getInventory();
if ($inv instanceof FurnaceInventory) {
if ($ts->getSlot() === 2) {
switch ($inv->getResult()->getId()) {
case Item::IRON_INGOT:
$this->awardAchievement("acquireIron");
break;
}
}
}
}
}
$this->currentTransaction = null;
示例3: handleDataPacket
//.........这里部分代码省略.........
case ProtocolInfo::CONTAINER_SET_SLOT_PACKET:
if ($this->spawned === false or $this->blocked === true or $this->dead === true) {
break;
}
if ($packet->slot < 0) {
break;
}
if ($packet->windowid === 0) {
//Our inventory
if ($packet->slot >= $this->inventory->getSize()) {
break;
}
if ($this->isCreative()) {
if ($this->getCreativeBlock($packet->item) !== -1) {
$this->inventory->setItem($packet->slot, $packet->item);
$this->inventory->setHotbarSlotIndex($packet->slot, $packet->slot);
//links $hotbar[$packet->slot] to $slots[$packet->slot]
}
}
$transaction = new BaseTransaction($this->inventory, $packet->slot, $this->inventory->getItem($packet->slot), $packet->item);
} elseif ($packet->windowid === 0x78) {
//Our armor
if ($packet->slot >= 4) {
break;
}
$transaction = new BaseTransaction($this->inventory, $packet->slot + $this->inventory->getSize(), $this->inventory->getArmorItem($packet->slot), $packet->item);
} elseif (isset($this->windowIndex[$packet->windowid])) {
$this->craftingType = 0;
$inv = $this->windowIndex[$packet->windowid];
$transaction = new BaseTransaction($inv, $packet->slot, $inv->getItem($packet->slot), $packet->item);
} else {
break;
}
if ($transaction->getSourceItem()->equals($transaction->getTargetItem(), true) and $transaction->getTargetItem()->getCount() === $transaction->getSourceItem()->getCount()) {
//No changes!
//No changes, just a local inventory update sent by the server
break;
}
if ($this->currentTransaction === null or $this->currentTransaction->getCreationTime() < microtime(true) - 0.5) {
if ($this->currentTransaction instanceof SimpleTransactionGroup) {
foreach ($this->currentTransaction->getInventories() as $inventory) {
if ($inventory instanceof PlayerInventory) {
$inventory->sendArmorContents($this);
}
$inventory->sendContents($this);
}
}
$this->currentTransaction = new SimpleTransactionGroup($this);
}
$this->currentTransaction->addTransaction($transaction);
if ($this->currentTransaction->canExecute()) {
if (!$this->currentTransaction->execute()) {
$this->currentTransaction = null;
break;
}
foreach ($this->currentTransaction->getTransactions() as $ts) {
$inv = $ts->getInventory();
if ($inv instanceof FurnaceInventory) {
if ($ts->getSlot() === 2) {
switch ($inv->getResult()->getId()) {
case Item::IRON_INGOT:
$this->awardAchievement("acquireIron");
break;
}
}
}
示例4: handleDataPacket
//.........这里部分代码省略.........
}
}
$transaction = new BaseTransaction($this->inventory, $packet->slot, $this->inventory->getItem($packet->slot), $packet->item);
} elseif ($packet->windowid === ContainerSetContentPacket::SPECIAL_ARMOR) {
//Our armor
if ($packet->slot >= 4) {
break;
}
$transaction = new BaseTransaction($this->inventory, $packet->slot + $this->inventory->getSize(), $this->inventory->getArmorItem($packet->slot), $packet->item);
} elseif (isset($this->windowIndex[$packet->windowid])) {
$this->craftingType = 0;
$inv = $this->windowIndex[$packet->windowid];
/** @var $packet \pocketmine\network\protocol\ContainerSetSlotPacket */
if ($inv instanceof EnchantInventory and $packet->item->hasEnchantments()) {
$inv->onEnchant($this, $inv->getItem($packet->slot), $packet->item);
}
if ($inv instanceof AnvilInventory) {
if ($packet->slot == 2) {
if ($packet->item->getId() != Item::AIR) {
$this->anvilItem = $packet->item;
} elseif ($this->anvilItem != null) {
if (!$inv->onRename($this->anvilItem, $this)) {
break;
//maybe cheating!
}
$this->anvilItem = null;
}
}
}
$transaction = new BaseTransaction($inv, $packet->slot, $inv->getItem($packet->slot), $packet->item);
} else {
break;
}
if ($transaction->getSourceItem()->deepEquals($transaction->getTargetItem()) and $transaction->getTargetItem()->getCount() === $transaction->getSourceItem()->getCount()) {
//No changes!
//No changes, just a local inventory update sent by the server
break;
}
if ($this->currentTransaction === null or $this->currentTransaction->getCreationTime() < microtime(true) - 8) {
if ($this->currentTransaction !== null) {
foreach ($this->currentTransaction->getInventories() as $inventory) {
if ($inventory instanceof PlayerInventory) {
$inventory->sendArmorContents($this);
}
$inventory->sendContents($this);
}
}
$this->currentTransaction = new SimpleTransactionGroup($this);
}
$this->currentTransaction->addTransaction($transaction);
if ($this->currentTransaction->canExecute()) {
$achievements = [];
foreach ($this->currentTransaction->getTransactions() as $ts) {
$inv = $ts->getInventory();
if ($inv instanceof FurnaceInventory) {
if ($ts->getSlot() === 2) {
switch ($inv->getResult()->getId()) {
case Item::IRON_INGOT:
$achievements[] = "acquireIron";
break;
}
}
}
}
if ($this->currentTransaction->execute()) {
foreach ($achievements as $a) {
示例5: handleDataPacket
//.........这里部分代码省略.........
case ProtocolInfo::CONTAINER_SET_SLOT_PACKET:
if ($this->spawned === false or $this->blocked === true or !$this->isAlive()) {
break;
}
if ($packet->slot < 0) {
break;
}
if ($packet->windowid === 0) {
//Our inventory
if ($packet->slot >= $this->inventory->getSize()) {
break;
}
if ($this->isCreative()) {
if (Item::getCreativeItemIndex($packet->item) !== -1) {
$this->inventory->setItem($packet->slot, $packet->item);
$this->inventory->setHotbarSlotIndex($packet->slot, $packet->slot);
//links $hotbar[$packet->slot] to $slots[$packet->slot]
}
}
$transaction = new BaseTransaction($this->inventory, $packet->slot, $this->inventory->getItem($packet->slot), $packet->item);
} elseif ($packet->windowid === ContainerSetContentPacket::SPECIAL_ARMOR) {
//Our armor
if ($packet->slot >= 4) {
break;
}
$transaction = new BaseTransaction($this->inventory, $packet->slot + $this->inventory->getSize(), $this->inventory->getArmorItem($packet->slot), $packet->item);
} elseif (isset($this->windowIndex[$packet->windowid])) {
$this->craftingType = 0;
$inv = $this->windowIndex[$packet->windowid];
$transaction = new BaseTransaction($inv, $packet->slot, $inv->getItem($packet->slot), $packet->item);
} else {
break;
}
if ($transaction->getSourceItem()->deepEquals($transaction->getTargetItem()) and $transaction->getTargetItem()->getCount() === $transaction->getSourceItem()->getCount()) {
//No changes!
//No changes, just a local inventory update sent by the server
break;
}
if ($this->currentTransaction === null or $this->currentTransaction->getCreationTime() < microtime(true) - 8) {
if ($this->currentTransaction !== null) {
foreach ($this->currentTransaction->getInventories() as $inventory) {
if ($inventory instanceof PlayerInventory) {
$inventory->sendArmorContents($this);
}
$inventory->sendContents($this);
}
}
$this->currentTransaction = new SimpleTransactionGroup($this);
}
$this->currentTransaction->addTransaction($transaction);
if ($this->currentTransaction->canExecute()) {
$achievements = [];
foreach ($this->currentTransaction->getTransactions() as $ts) {
$inv = $ts->getInventory();
if ($inv instanceof FurnaceInventory) {
if ($ts->getSlot() === 2) {
switch ($inv->getResult()->getId()) {
case Item::IRON_INGOT:
$achievements[] = "acquireIron";
break;
}
}
}
}
if ($this->currentTransaction->execute()) {
foreach ($achievements as $a) {