本文整理匯總了PHP中pocketmine\item\Item::getCreativeItemIndex方法的典型用法代碼示例。如果您正苦於以下問題:PHP Item::getCreativeItemIndex方法的具體用法?PHP Item::getCreativeItemIndex怎麽用?PHP Item::getCreativeItemIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pocketmine\item\Item
的用法示例。
在下文中一共展示了Item::getCreativeItemIndex方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: handleDataPacket
//.........這裏部分代碼省略.........
$revert = false;
if ($this->dead === true or $this->spawned !== true) {
$revert = true;
$this->forceMovement = new Vector3($this->x, $this->y, $this->z);
}
if ($this->teleportPosition !== null or $this->forceMovement instanceof Vector3 and (($dist = $newPos->distanceSquared($this->forceMovement)) > 0.1 or $revert)) {
$this->sendPosition($this->forceMovement, $packet->yaw, $packet->pitch);
} else {
$packet->yaw %= 360;
$packet->pitch %= 360;
if ($packet->yaw < 0) {
$packet->yaw += 360;
}
$this->setRotation($packet->yaw, $packet->pitch);
$this->newPosition = $newPos;
$this->forceMovement = null;
}
break;
case ProtocolInfo::PLAYER_EQUIPMENT_PACKET:
if ($this->spawned === false or $this->dead === true) {
break;
}
if ($packet->slot === 0x28 or $packet->slot === 0 or $packet->slot === 255) {
//0 for 0.8.0 compatibility
$packet->slot = -1;
//Air
} else {
$packet->slot -= 9;
//Get real block slot
}
if ($this->isCreative()) {
//Creative mode match
$item = Item::get($packet->item, $packet->meta, 1);
$slot = Item::getCreativeItemIndex($item);
} else {
$item = $this->inventory->getItem($packet->slot);
$slot = $packet->slot;
}
if ($packet->slot === -1) {
//Air
if ($this->isCreative()) {
$found = false;
for ($i = 0; $i < $this->inventory->getHotbarSize(); ++$i) {
if ($this->inventory->getHotbarSlotIndex($i) === -1) {
$this->inventory->setHeldItemIndex($i);
$found = true;
break;
}
}
if (!$found) {
//couldn't find a empty slot (error)
$this->inventory->sendContents($this);
break;
}
} else {
if ($packet->selectedSlot >= 0 and $packet->selectedSlot < 9) {
$this->inventory->setHeldItemIndex($packet->selectedSlot);
$this->inventory->setHeldItemSlot($packet->slot);
} else {
$this->inventory->sendContents($this);
break;
}
}
} elseif (!isset($item) or $slot === -1 or $item->getId() !== $packet->item or $item->getDamage() !== $packet->meta) {
// packet error or not implemented
$this->inventory->sendContents($this);
示例2: handleDataPacket
//.........這裏部分代碼省略.........
$revert = true;
$this->forceMovement = new Vector3($this->x, $this->y, $this->z);
}
if ($this->forceMovement instanceof Vector3 and (($dist = $newPos->distanceSquared($this->forceMovement)) > 0.04 or $revert)) {
$this->sendPosition($this->forceMovement, $packet->yaw, $packet->pitch);
} else {
$packet->yaw %= 360;
$packet->pitch %= 360;
if ($packet->yaw < 0) {
$packet->yaw += 360;
}
$this->setRotation($packet->yaw, $packet->pitch);
$this->newPosition = $newPos;
$this->forceMovement = null;
}
break;
case ProtocolInfo::MOB_EQUIPMENT_PACKET:
if ($this->spawned === false or $this->dead === true) {
break;
}
if ($packet->slot === 0x28 or $packet->slot === 0 or $packet->slot === 255) {
//0 for 0.8.0 compatibility
$packet->slot = -1;
//Air
} else {
$packet->slot -= 9;
//Get real block slot
}
/** @var Item $item */
$item = null;
if ($this->isCreative()) {
//Creative mode match
$item = $packet->item;
$slot = Item::getCreativeItemIndex($item);
} else {
$item = $this->inventory->getItem($packet->slot);
$slot = $packet->slot;
}
if ($packet->slot === -1) {
//Air
if ($this->isCreative()) {
$found = false;
for ($i = 0; $i < $this->inventory->getHotbarSize(); ++$i) {
if ($this->inventory->getHotbarSlotIndex($i) === -1) {
$this->inventory->setHeldItemIndex($i);
$found = true;
break;
}
}
if (!$found) {
//couldn't find a empty slot (error)
$this->inventory->sendContents($this);
break;
}
} else {
if ($packet->selectedSlot >= 0 and $packet->selectedSlot < 9) {
$this->inventory->setHeldItemIndex($packet->selectedSlot);
$this->inventory->setHeldItemSlot($packet->slot);
} else {
$this->inventory->sendContents($this);
break;
}
}
} elseif ($item === null or $slot === -1 or !$item->deepEquals($packet->item)) {
// packet error or not implemented
$this->inventory->sendContents($this);
示例3: handleDataPacket
//.........這裏部分代碼省略.........
}
if ($this->teleportPosition !== null or $this->forceMovement instanceof Vector3 and (($dist = $newPos->distanceSquared($this->forceMovement)) > 0.1 or $revert)) {
if ($this->forceMovement instanceof Vector3) {
$this->sendPosition($this->forceMovement, $packet->yaw, $packet->pitch);
}
} else {
$packet->yaw %= 360;
$packet->pitch %= 360;
if ($packet->yaw < 0) {
$packet->yaw += 360;
}
$this->setRotation($packet->yaw, $packet->pitch);
$this->newPosition = $newPos;
$this->forceMovement = null;
}
break;
case ProtocolInfo::MOB_EQUIPMENT_PACKET:
if ($this->spawned === false or !$this->isAlive()) {
break;
}
if ($packet->slot === 0x28 or $packet->slot === 0 or $packet->slot === 255) {
//0 for 0.8.0 compatibility
$packet->slot = -1;
//Air
} else {
$packet->slot -= 9;
//Get real block slot
}
/** @var Item $item */
$item = null;
if ($this->isCreative()) {
//Creative mode match
$item = $packet->item;
$slot = Item::getCreativeItemIndex($item);
} else {
$item = $this->inventory->getItem($packet->slot);
$slot = $packet->slot;
}
if ($packet->slot === -1) {
//Air
if ($this->isCreative()) {
$found = false;
for ($i = 0; $i < $this->inventory->getHotbarSize(); ++$i) {
if ($this->inventory->getHotbarSlotIndex($i) === -1) {
$this->inventory->setHeldItemIndex($i);
$found = true;
break;
}
}
if (!$found) {
//couldn't find a empty slot (error)
$this->inventory->sendContents($this);
break;
}
} else {
if ($packet->selectedSlot >= 0 and $packet->selectedSlot < 9) {
$this->inventory->setHeldItemIndex($packet->selectedSlot, false);
$this->inventory->setHeldItemSlot($packet->slot);
$this->inventory->sendHeldItem($this->getViewers());
} else {
$this->inventory->sendContents($this);
break;
}
}
} elseif ($item === null or $slot === -1 or !$item->deepEquals($packet->item)) {
// packet error or not implemented
示例4: handleDataPacket
//.........這裏部分代碼省略.........
$revert = true;
$this->forceMovement = new Vector3($this->x, $this->y, $this->z);
}
if ($this->teleportPosition !== null or $this->forceMovement instanceof Vector3 and (($dist = $newPos->distanceSquared($this->forceMovement)) > 0.1 or $revert)) {
$this->sendPosition($this->forceMovement, $packet->yaw, $packet->pitch);
} else {
$packet->yaw %= 360;
$packet->pitch %= 360;
if ($packet->yaw < 0) {
$packet->yaw += 360;
}
$this->setRotation($packet->yaw, $packet->pitch);
$this->newPosition = $newPos;
$this->forceMovement = null;
}
break;
case ProtocolInfo::MOB_EQUIPMENT_PACKET:
if ($this->spawned === false or !$this->isAlive()) {
break;
}
if ($packet->slot === 0x28 or $packet->slot === 0 or $packet->slot === 255) {
//0 for 0.8.0 compatibility
$packet->slot = -1;
//Air
} else {
$packet->slot -= 9;
//Get real block slot
}
/** @var Item $item */
$item = null;
if ($this->isCreative()) {
//Creative mode match
$item = $packet->item;
$slot = Item::getCreativeItemIndex($item);
} else {
$item = $this->inventory->getItem($packet->slot);
$slot = $packet->slot;
}
if ($packet->slot === -1) {
//Air
if ($this->isCreative()) {
$found = false;
for ($i = 0; $i < $this->inventory->getHotbarSize(); ++$i) {
if ($this->inventory->getHotbarSlotIndex($i) === -1) {
$this->inventory->setHeldItemIndex($i);
$found = true;
break;
}
}
if (!$found) {
//couldn't find a empty slot (error)
$this->inventory->sendContents($this);
break;
}
} else {
if ($packet->selectedSlot >= 0 and $packet->selectedSlot < 9) {
$this->inventory->setHeldItemIndex($packet->selectedSlot);
$this->inventory->setHeldItemSlot($packet->slot);
} else {
$this->inventory->sendContents($this);
break;
}
}
} elseif ($item === null or $slot === -1 or !$item->deepEquals($packet->item)) {
// packet error or not implemented
$this->inventory->sendContents($this);